/* =============================================================
   Final Fight 風チャットボットUI
   ============================================================= */

/* カラー変数 ---------------------------------------------------- */
:root {
    --ff-red: #c8241f;
    --ff-red-bright: #ff3a32;
    --ff-yellow: #f9c515;
    --ff-yellow-bright: #ffd84a;
    --ff-blue: #1d6fa5;
    --ff-blue-bright: #4fc3f7;
    --ff-dark: #0a0412;
    --ff-dark-2: #1a1025;
    --ff-dark-3: #2a1c3a;
    --ff-pink: #d62976;
    --ff-purple: #4a148c;
    --ff-orange: #ff6b00;
    --ff-text: #ffe9c4;
    --ff-text-dim: #a68f6a;

    /* フォント */
    --font-arcade: 'Press Start 2P', 'Courier New', monospace;
    --font-terminal: 'VT323', 'Courier New', monospace;
}

/* リセット ------------------------------------------------------ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-terminal);
    background: var(--ff-dark);
    color: var(--ff-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
    /* 夕暮れのグラデーション + 中央に光 */
    background:
        radial-gradient(ellipse at 50% 20%, rgba(255, 107, 0, 0.25) 0%, transparent 50%),
        radial-gradient(ellipse at 30% 80%, rgba(214, 41, 118, 0.2) 0%, transparent 50%),
        linear-gradient(180deg, #2a0b3a 0%, #6b1538 40%, #1a0812 100%);
}

/* 背景の都市シルエット ------------------------------------------ */
.city-skyline {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 35vh;
    z-index: 0;
    pointer-events: none;
    opacity: 0.95;
}

.city-skyline svg {
    width: 100%;
    height: 100%;
}

/* 窓の明かりをチカチカさせる */
.city-skyline g:nth-child(3) rect:nth-child(3n) {
    animation: window-flicker 3s infinite;
}
.city-skyline g:nth-child(3) rect:nth-child(5n) {
    animation: window-flicker 4.5s infinite;
}

@keyframes window-flicker {
    0%, 100% { opacity: 0.9; }
    45% { opacity: 0.9; }
    50% { opacity: 0.2; }
    55% { opacity: 0.9; }
}

/* CRT スキャンライン ------------------------------------------- */
.scanlines {
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 9999;
    mix-blend-mode: multiply;
}

/* メインチャット枠 --------------------------------------------- */
.chat-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 800px;
    height: 680px;
    background: linear-gradient(180deg, #1e0830 0%, #2a0f40 100%);
    border: 4px solid var(--ff-yellow);
    box-shadow:
        0 0 0 4px var(--ff-red),
        0 0 0 8px #000,
        0 0 40px rgba(249, 197, 21, 0.5),
        0 0 80px rgba(200, 36, 31, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* 角を四角くしてアーケード感を出す */
    border-radius: 0;
}

/* ヘッダー ------------------------------------------------------ */
.chat-header {
    position: relative;
    background:
        linear-gradient(180deg, var(--ff-red) 0%, #8b1510 100%);
    color: var(--ff-yellow);
    padding: 20px 24px 16px;
    text-align: center;
    border-bottom: 4px solid var(--ff-yellow);
    /* ドットパターン */
    background-image:
        linear-gradient(180deg, var(--ff-red) 0%, #8b1510 100%),
        radial-gradient(circle, rgba(0, 0, 0, 0.3) 1px, transparent 1px);
    background-size: cover, 8px 8px;
    background-blend-mode: overlay;
}

.chat-header::before,
.chat-header::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 4px;
    background: repeating-linear-gradient(
        180deg,
        var(--ff-yellow) 0px,
        var(--ff-yellow) 8px,
        #000 8px,
        #000 16px
    );
}
.chat-header::before { left: 0; }
.chat-header::after { right: 0; }

.arcade-badge {
    position: absolute;
    top: 8px;
    right: 16px;
    font-family: var(--font-arcade);
    font-size: 9px;
    color: var(--ff-yellow);
    background: #000;
    padding: 4px 8px;
    border: 2px solid var(--ff-yellow);
    letter-spacing: 1px;
}

.title {
    font-family: var(--font-arcade);
    font-size: 24px;
    color: var(--ff-yellow);
    letter-spacing: 2px;
    text-shadow:
        3px 3px 0 #000,
        4px 4px 0 var(--ff-blue),
        -1px -1px 0 var(--ff-yellow-bright);
    margin-bottom: 8px;
    line-height: 1.2;
    animation: title-pulse 2s ease-in-out infinite;
}

.bot-emoji {
    display: inline-block;
    font-size: 28px;
    vertical-align: middle;
    filter: drop-shadow(2px 2px 0 #000);
    animation: bot-bounce 1.5s ease-in-out infinite;
}

@keyframes title-pulse {
    0%, 100% { text-shadow: 3px 3px 0 #000, 4px 4px 0 var(--ff-blue), -1px -1px 0 var(--ff-yellow-bright); }
    50% { text-shadow: 3px 3px 0 #000, 4px 4px 0 var(--ff-red-bright), -1px -1px 0 #fff; }
}

@keyframes bot-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-4px) rotate(-5deg); }
    75% { transform: translateY(-2px) rotate(5deg); }
}

.subtitle {
    font-family: var(--font-arcade);
    font-size: 10px;
    color: #fff;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 12px;
}

/* HPバー ------------------------------------------------------- */
.hp-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
}

.hp-label {
    font-family: var(--font-arcade);
    font-size: 10px;
    color: var(--ff-yellow);
    text-shadow: 1px 1px 0 #000;
}

.hp-track {
    flex: 1;
    height: 12px;
    background: #000;
    border: 2px solid var(--ff-yellow);
    padding: 1px;
    position: relative;
}

.hp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--ff-red) 0%, var(--ff-yellow) 50%, #4ade80 100%);
    width: 100%;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
    animation: hp-shine 3s linear infinite;
    background-size: 200% 100%;
}

@keyframes hp-shine {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* メッセージエリア --------------------------------------------- */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background:
        linear-gradient(180deg, rgba(10, 4, 18, 0.85) 0%, rgba(26, 8, 48, 0.85) 100%);
    /* アーケード風のグリッド */
    background-image:
        linear-gradient(180deg, rgba(10, 4, 18, 0.92) 0%, rgba(26, 8, 48, 0.92) 100%),
        repeating-linear-gradient(0deg, transparent 0, transparent 19px, rgba(249, 197, 21, 0.03) 19px, rgba(249, 197, 21, 0.03) 20px),
        repeating-linear-gradient(90deg, transparent 0, transparent 19px, rgba(249, 197, 21, 0.03) 19px, rgba(249, 197, 21, 0.03) 20px);
}

.message {
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    animation: message-in 0.3s ease-out;
}

.message.user-message {
    justify-content: flex-end;
    flex-direction: row-reverse;
}

.message.bot-message {
    justify-content: flex-start;
}

.message-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: #000;
    border: 2px solid var(--ff-yellow);
    flex-shrink: 0;
    filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.5));
}

.message-content {
    max-width: 70%;
    padding: 10px 14px;
    position: relative;
    display: flex;
    flex-direction: column;
    font-family: var(--font-terminal);
    font-size: 18px;
    line-height: 1.4;
    /* ピクセル風の角 */
    border: 3px solid;
    box-shadow: 3px 3px 0 #000;
}

.user-message .message-content {
    background: var(--ff-blue);
    color: #fff;
    border-color: var(--ff-blue-bright);
}

.bot-message .message-content {
    background: var(--ff-yellow);
    color: var(--ff-dark);
    border-color: #fff;
}

.message-text {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

/* 生成画像 ----------------------------------------------------- */
.message-image {
    display: block;
    width: 100%;
    max-width: 512px;
    height: auto;
    margin-top: 10px;
    border: 3px solid #000;
    box-shadow: 3px 3px 0 #000;
    image-rendering: auto;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.message-image:hover {
    transform: scale(1.01);
}

.message-time {
    font-family: var(--font-arcade);
    font-size: 8px;
    opacity: 0.8;
    letter-spacing: 1px;
}

/* メッセージフッター（時刻 + スピーカー） */
.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.user-message .message-footer {
    flex-direction: row-reverse;
}

/* スピーカーボタン */
.speaker-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: #000;
    border: 2px solid var(--ff-red);
    color: var(--ff-yellow);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5);
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}

.speaker-button:hover {
    background: var(--ff-red);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
}

.speaker-button:active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}

.speaker-button.loading {
    background: var(--ff-blue);
    border-color: var(--ff-blue-bright);
    animation: speaker-load 0.8s linear infinite;
    pointer-events: none;
}

.speaker-button.playing {
    background: var(--ff-red);
    border-color: var(--ff-yellow);
    animation: speaker-pulse 0.6s ease-in-out infinite;
}

@keyframes speaker-load {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes speaker-pulse {
    0%, 100% { transform: scale(1); box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5); }
    50% { transform: scale(1.08); box-shadow: 0 0 12px var(--ff-yellow); }
}

.speaker-icon {
    display: inline-block;
    line-height: 1;
}

.user-message .message-time {
    color: #fff;
}

.bot-message .message-time {
    color: var(--ff-red);
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 「入力中...」の点滅 */
.typing-indicator .message-text::after {
    content: '';
    animation: typing-dots 1.2s steps(4) infinite;
}

@keyframes typing-dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

/* 入力エリア --------------------------------------------------- */
.chat-input-container {
    padding: 16px 20px;
    background: linear-gradient(180deg, #150824 0%, #0a0412 100%);
    border-top: 3px solid var(--ff-yellow);
}

.chat-input {
    display: flex;
    gap: 10px;
    align-items: center;
}

.prompt-indicator {
    color: var(--ff-yellow);
    font-size: 20px;
    animation: prompt-blink 1s steps(2) infinite;
}

@keyframes prompt-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

#messageInput {
    flex: 1;
    padding: 10px 14px;
    background: #000;
    border: 3px solid var(--ff-yellow);
    color: var(--ff-yellow);
    font-family: var(--font-terminal);
    font-size: 20px;
    letter-spacing: 1px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    text-transform: uppercase;
}

#messageInput::placeholder {
    color: var(--ff-text-dim);
    text-transform: uppercase;
    letter-spacing: 2px;
}

#messageInput:focus {
    border-color: var(--ff-yellow-bright);
    box-shadow: 0 0 0 2px #000, 0 0 10px var(--ff-yellow);
}

#messageInput:disabled {
    background: #1a0a1a;
    color: var(--ff-text-dim);
    cursor: not-allowed;
}

#sendButton {
    flex-shrink: 0;
    padding: 10px 18px;
    background: var(--ff-red);
    border: 3px solid #fff;
    color: #fff;
    font-family: var(--font-arcade);
    font-size: 12px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
    box-shadow: 3px 3px 0 #000;
    text-shadow: 1px 1px 0 #000;
}

#sendButton:hover:not(:disabled) {
    background: var(--ff-red-bright);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #000;
}

#sendButton:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #000;
}

#sendButton:disabled {
    background: #4a2020;
    border-color: #666;
    color: #888;
    cursor: not-allowed;
    box-shadow: 2px 2px 0 #000;
    text-shadow: none;
}

.input-info {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    font-family: var(--font-arcade);
    font-size: 9px;
    color: var(--ff-text-dim);
    letter-spacing: 1px;
}

.info-label {
    color: var(--ff-yellow);
}

#charCount {
    color: var(--ff-yellow-bright);
}

/* スクロールバー ----------------------------------------------- */
.chat-messages::-webkit-scrollbar {
    width: 12px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #000;
    border-left: 2px solid var(--ff-yellow);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--ff-red);
    border: 2px solid #000;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--ff-red-bright);
}

/* レスポンシブ -------------------------------------------------- */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .chat-container {
        height: calc(100vh - 16px);
        box-shadow:
            0 0 0 3px var(--ff-red),
            0 0 0 6px #000,
            0 0 30px rgba(249, 197, 21, 0.4);
    }

    .chat-header {
        padding: 16px 20px 12px;
    }

    .title {
        font-size: 16px;
        letter-spacing: 1px;
    }

    .bot-emoji {
        font-size: 20px;
    }

    .subtitle {
        font-size: 8px;
    }

    .arcade-badge {
        font-size: 8px;
        padding: 3px 6px;
    }

    .message-content {
        max-width: 80%;
        font-size: 16px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    #messageInput {
        font-size: 16px;
        padding: 8px 10px;
    }

    #sendButton {
        font-size: 10px;
        padding: 8px 12px;
    }

    .city-skyline {
        height: 25vh;
    }
}

/* ============================================================================
   認証画面（ファイナルファイト風）
   ============================================================================ */
.auth-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 480px;
    background: linear-gradient(180deg, #1e0830 0%, #2a0f40 100%);
    border: 4px solid var(--ff-yellow);
    box-shadow:
        0 0 0 4px var(--ff-red),
        0 0 0 8px #000,
        0 0 40px rgba(249, 197, 21, 0.5),
        0 0 80px rgba(200, 36, 31, 0.3);
    padding: 0 0 24px;
    overflow: hidden;
}

.auth-header {
    position: relative;
    background: linear-gradient(180deg, var(--ff-red) 0%, #8b1510 100%);
    color: var(--ff-yellow);
    padding: 24px 24px 20px;
    text-align: center;
    border-bottom: 4px solid var(--ff-yellow);
}

.auth-header .title {
    font-size: 20px;
    margin-bottom: 8px;
}

.auth-header .bot-emoji {
    font-size: 22px;
}

.auth-header .subtitle {
    font-size: 9px;
    margin-bottom: 0;
}

.auth-tabs {
    display: flex;
    border-bottom: 3px solid var(--ff-yellow);
    background: #0a0412;
}

.auth-tab {
    flex: 1;
    padding: 14px 8px;
    background: #1a0a24;
    color: var(--ff-text-dim);
    border: none;
    border-right: 2px solid #000;
    font-family: var(--font-arcade);
    font-size: 11px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.auth-tab:last-child {
    border-right: none;
}

.auth-tab:hover {
    background: #2a1236;
    color: var(--ff-yellow);
}

.auth-tab.active {
    background: var(--ff-yellow);
    color: var(--ff-dark);
    text-shadow: 1px 1px 0 var(--ff-red);
}

.auth-message {
    margin: 16px 20px 0;
    padding: 10px 12px;
    font-family: var(--font-terminal);
    font-size: 16px;
    border: 2px solid;
    text-align: center;
}

.auth-message.error {
    background: rgba(200, 36, 31, 0.2);
    border-color: var(--ff-red);
    color: #ffb3b0;
}

.auth-message.info {
    background: rgba(79, 195, 247, 0.15);
    border-color: var(--ff-blue-bright);
    color: var(--ff-blue-bright);
}

.auth-form {
    padding: 20px 24px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-info {
    font-family: var(--font-terminal);
    font-size: 16px;
    color: var(--ff-yellow);
    text-align: center;
    margin-bottom: 4px;
}

.auth-label {
    font-family: var(--font-arcade);
    font-size: 9px;
    color: var(--ff-yellow);
    letter-spacing: 1px;
    text-shadow: 1px 1px 0 #000;
    margin-top: 4px;
}

.auth-input {
    padding: 10px 12px;
    background: #000;
    border: 3px solid var(--ff-yellow);
    color: var(--ff-yellow);
    font-family: var(--font-terminal);
    font-size: 18px;
    letter-spacing: 1px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-input::placeholder {
    color: var(--ff-text-dim);
    letter-spacing: 2px;
}

.auth-input:focus {
    border-color: var(--ff-yellow-bright);
    box-shadow: 0 0 0 2px #000, 0 0 10px var(--ff-yellow);
}

.auth-button {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--ff-red);
    border: 3px solid #fff;
    color: #fff;
    font-family: var(--font-arcade);
    font-size: 12px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
    box-shadow: 3px 3px 0 #000;
    text-shadow: 1px 1px 0 #000;
}

.auth-button:hover {
    background: var(--ff-red-bright);
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0 #000;
}

.auth-button:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 #000;
}

.auth-link {
    margin-top: 8px;
    padding: 8px;
    background: transparent;
    border: none;
    color: var(--ff-blue-bright);
    font-family: var(--font-terminal);
    font-size: 16px;
    cursor: pointer;
    text-decoration: underline;
}

.auth-link:hover {
    color: var(--ff-yellow);
}

/* チャットヘッダーのログアウトボタン */
.signout-button {
    position: absolute;
    top: 8px;
    left: 16px;
    background: #000;
    color: var(--ff-yellow);
    border: 2px solid var(--ff-yellow);
    font-family: var(--font-arcade);
    font-size: 9px;
    padding: 4px 8px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.signout-button:hover {
    background: var(--ff-yellow);
    color: var(--ff-dark);
}

/* レスポンシブ */
@media (max-width: 768px) {
    .auth-container {
        max-width: calc(100vw - 16px);
    }

    .auth-header .title {
        font-size: 16px;
    }

    .auth-form {
        padding: 16px 16px 0;
    }

    .auth-input {
        font-size: 16px;
    }
}
