/* ═══════════════════════════════════════════════
   HappySad.chat - TUI Black & White Theme
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg: #000000;
    --bg-card: #0a0a0a;
    --bg-input: #0a0a0a;
    --bg-hover: #1a1a1a;
    --text: #aaaaaa;
    --text-muted: #555555;
    --text-heading: #ffffff;
    --border: #333333;
    --shadow: none;
    --font: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    overflow-x: hidden;
}

/* Base */
body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.6;
    padding: 24px;
    max-width: 1100px;
    margin: 0 auto;
    min-height: 100vh;
}

/* Links */
a {
    color: var(--text-heading);
    text-decoration: underline;
    transition: color 0.15s;
}

a:hover {
    color: var(--text);
}

/* ─── Headings ─── */
h2 {
    color: var(--text-heading);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

h3 {
    color: var(--text-heading);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

h4 {
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* ═══════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════ */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

/* Legacy terminal-box — same as card */
.terminal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1.25rem;
    margin: 12px 0;
    position: relative;
}

.terminal-box[data-title]::before {
    content: attr(data-title);
    position: absolute;
    top: -9px;
    left: 12px;
    background: var(--bg-card);
    padding: 0 8px;
    color: var(--text-muted);
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    font-weight: 600;
}

/* ═══════════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════════ */

#site-header {
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 20px;
}

.site-title {
    color: var(--text-heading);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

.header-info {
    max-width: 700px;
}

.project-desc {
    color: var(--text-muted);
    margin-bottom: 6px;
    font-size: 0.8rem;
    line-height: 1.6;
}

.credit {
    color: var(--text-muted);
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ═══════════════════════════════════════════════
   INPUTS & BUTTONS
   ═══════════════════════════════════════════════ */

input[type="text"] {
    width: 100%;
    padding: 0.4rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.8rem;
    font-family: var(--font);
    outline: none;
    flex: 1;
    min-width: 120px;
    transition: border-color 0.15s, color 0.15s;
}

input[type="text"]:focus {
    border-color: var(--text-heading);
    color: var(--text-heading);
}

input[type="text"]::placeholder {
    color: var(--text-muted);
}

input[type="text"]:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Buttons */
button, .btn {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font-size: 0.75rem;
    font-family: var(--font);
    text-decoration: none;
    transition: all 0.15s;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

button:hover:not(:disabled), .btn:hover {
    background: var(--bg-hover);
    color: var(--text-heading);
    border-color: var(--text-muted);
}

.btn-primary {
    background: var(--text-heading);
    border-color: var(--text-heading);
    color: #000;
    font-weight: 600;
}

.btn-primary:hover {
    background: #cccccc;
    border-color: #cccccc;
    color: #000;
}

button:disabled, .btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.prompt {
    color: var(--text-heading);
    font-weight: 700;
}

.hidden {
    display: none !important;
}

/* ═══════════════════════════════════════════════
   NICKNAME SECTION
   ═══════════════════════════════════════════════ */

.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.input-row label {
    white-space: nowrap;
    font-size: 0.8rem;
    color: var(--text);
}

.input-hint {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-top: 8px;
    letter-spacing: 0.5px;
}

.error-msg {
    color: var(--text-heading);
    margin-top: 8px;
    font-size: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--text-heading);
}

/* ═══════════════════════════════════════════════
   CAMERA SECTION
   ═══════════════════════════════════════════════ */

.privacy-notice {
    margin-bottom: 16px;
    line-height: 1.8;
    font-size: 0.8rem;
    color: var(--text);
}

.privacy-notice p:first-child {
    color: var(--text-heading);
    margin-bottom: 6px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════
   MAIN APP LAYOUT
   ═══════════════════════════════════════════════ */

.app-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 16px;
    align-items: start;
}

/* Camera Column */
.camera-column {
    position: sticky;
    top: 24px;
}

.video-container {
    width: 100%;
    aspect-ratio: 4/3;
    overflow: hidden;
    background: #0a0a0a;
    border: 1px solid var(--border);
    position: relative;
}

.privacy-tag {
    position: absolute;
    bottom: 6px;
    left: 6px;
    font-size: 0.55rem;
    color: var(--text-heading);
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 5px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    pointer-events: none;
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: grayscale(100%) contrast(1.3);
    display: block;
}

/* ═══════════════════════════════════════════════
   EMOTION DISPLAY
   ═══════════════════════════════════════════════ */

#emotion-display {
    font-size: 0.75rem;
    line-height: 1.5;
}

.emotion-bar {
    white-space: pre;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.emotion-active {
    color: var(--text-heading);
    font-weight: 700;
}

.no-face {
    color: var(--text-muted);
    text-align: center;
    padding: 8px 0;
    font-size: 0.75rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.emotion-hint {
    color: var(--text-muted);
    font-size: 0.65rem;
    text-align: center;
    padding: 6px 0;
    margin-top: 4px;
    border-top: 1px solid var(--border);
    line-height: 1.6;
    letter-spacing: 0.3px;
}

#current-room-label {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

#room-name {
    color: var(--text-heading);
}

/* ═══════════════════════════════════════════════
   CHAT PROMPT (no room assigned)
   ═══════════════════════════════════════════════ */

.chat-prompt {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 650px;
}

.chat-prompt-inner {
    text-align: center;
}

.chat-prompt-title {
    color: var(--text-heading);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 16px;
}

.chat-prompt-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 2;
    letter-spacing: 0.5px;
}

.prompt-room {
    color: var(--text-heading);
    font-weight: 600;
}

/* ═══════════════════════════════════════════════
   CHAT
   ═══════════════════════════════════════════════ */

.chat-box {
    display: flex;
    flex-direction: column;
    height: 650px;
}

.chat-header {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    font-size: 0.75rem;
}

.room-banner {
    text-align: center;
    padding: 12px 0;
    margin-bottom: 8px;
}

#room-banner-name {
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-heading);
    letter-spacing: 4px;
    text-transform: uppercase;
}

.room-tabs {
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
}

.room-tab {
    cursor: pointer;
    transition: color 0.15s;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

.room-tab:hover {
    color: var(--text-heading);
}

.room-active {
    color: var(--text-heading);
    font-weight: 700;
    cursor: default;
}

.room-inactive {
    color: var(--text-muted);
}

.room-tooltip {
    color: var(--text-heading);
    font-size: 0.7rem;
    margin-top: 6px;
    padding: 4px 0;
    letter-spacing: 0.5px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-card);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
}

.chat-message {
    padding: 2px 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-size: 0.75rem;
}

.msg-time {
    color: var(--text-muted);
}

.msg-nick {
    color: var(--text-heading);
    font-weight: 700;
}

.msg-text {
    color: var(--text);
}

.msg-verified {
    color: var(--text-heading);
    font-weight: 700;
    font-size: 0.65rem;
    letter-spacing: 0.5px;
    border: 1px solid var(--text-heading);
    padding: 0 3px;
}

.system-message {
    color: var(--text-muted);
    text-align: center;
    padding: 6px 0;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

.chat-input-area .prompt {
    flex-shrink: 0;
}

#load-more {
    display: block;
    margin: 4px auto;
    font-size: 0.7rem;
    padding: 4px 10px;
    border-color: var(--text-muted);
    color: var(--text-muted);
}

#load-more:hover:not(:disabled) {
    color: var(--text-heading);
    border-color: var(--text-heading);
    background: var(--bg-hover);
}

/* ═══════════════════════════════════════════════
   ANNOUNCEMENT BANNER
   ═══════════════════════════════════════════════ */

.announcement-banner {
    text-align: center;
    padding: 0.75rem 1.25rem;
    border: 1px solid var(--text-heading);
    color: var(--text-heading);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════
   AD BANNER
   ═══════════════════════════════════════════════ */

.ad-banner {
    padding: 10px 1.25rem;
}

.ad-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.ad-content {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.75rem;
    transition: color 0.15s;
}

.ad-content:hover {
    color: var(--text-heading);
}

.ad-title {
    font-weight: 700;
    white-space: nowrap;
    color: var(--text-heading);
}

.ad-separator {
    color: var(--text-muted);
}

.ad-desc {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* ═══════════════════════════════════════════════
   Q&A
   ═══════════════════════════════════════════════ */

#qa-section {
    margin-top: 32px;
}

#qa-section details summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}

#qa-section details summary::-webkit-details-marker {
    display: none;
}

#qa-section details summary h3 {
    display: inline;
}

#qa-section details summary h3::before {
    content: '[+] ';
    color: var(--text-muted);
}

#qa-section details[open] summary h3::before {
    content: '[-] ';
}

.qa-item {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #1a1a1a;
}

.qa-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.qa-q {
    color: var(--text-heading);
    font-weight: 700;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

.qa-a {
    color: var(--text-muted);
    padding-left: 16px;
    font-size: 0.8rem;
    line-height: 1.6;
}

/* ═══════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════ */

#site-footer {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    text-align: center;
    letter-spacing: 0.5px;
}

#site-footer a {
    color: var(--text-muted);
}

#site-footer a:hover {
    color: var(--text-heading);
}

.version {
    color: var(--text-muted);
    margin-left: 4px;
}

/* ═══════════════════════════════════════════════
   LOADING STATES
   ═══════════════════════════════════════════════ */

.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

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

/* ═══════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════ */

@media (max-width: 750px) {

    /* ── Shell: full viewport, no scroll on page level ── */
    html {
        height: 100%;
        height: 100dvh;
        overflow: hidden;
    }

    body {
        height: 100%;
        height: 100dvh;
        overflow: hidden;
        padding: 0;
        width: 100vw;       /* always exactly viewport width */
        max-width: 100vw;
        margin: 0;
        overscroll-behavior: none;
        display: flex;
        flex-direction: column;
    }

    /* Prevent iOS zoom: all text inputs must be >= 16px */
    input[type="text"] {
        font-size: 16px !important;
    }

    /* ── Header ── */
    #site-header {
        flex-shrink: 0;
        width: 100%;
        margin-bottom: 0;
        padding: 8px 12px;
        border-bottom: 1px solid var(--border);
        overflow: hidden;
    }

    .site-title {
        font-size: 1.1rem;
        margin-bottom: 0;
        letter-spacing: 1px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .project-desc {
        display: block;
        font-size: 0.7rem;
        margin-top: 3px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .credit {
        display: none;
    }

    /* ── Pre-app screens ── */
    #nickname-section,
    #camera-section {
        flex: 1;
        min-height: 0;
        width: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px 12px;
    }

    .input-row {
        flex-direction: column;
        align-items: stretch;
    }

    /* ── Main app ── */
    #app-section {
        flex: 1;
        min-height: 0;
        width: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .app-grid {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        width: 100%;
        gap: 0;
    }

    /* ── Camera strip ── */
    .camera-column {
        flex-shrink: 0;
        width: 100%;
        position: static;
        display: flex;
        flex-direction: row;
        align-items: center;
        border-bottom: 1px solid var(--border);
        background: var(--bg-card);
        overflow: hidden;
    }

    .camera-column .card {
        margin-bottom: 0;
        border: none;
        background: transparent;
        flex-shrink: 0;
    }

    .camera-column .card:first-child {
        width: 66px;
        flex: 0 0 66px;
        padding: 4px;
        border-right: 1px solid var(--border);
    }

    .camera-column .card:first-child h3 { display: none; }

    .video-container {
        width: 58px;
        height: 58px;
        aspect-ratio: 1;
        border: none;
    }

    .privacy-tag { display: none; }

    .camera-column .card:last-child {
        flex: 1;
        min-width: 0;
        padding: 4px 8px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        overflow: hidden;
    }

    .camera-column .card:last-child h3 { display: none; }

    #emotion-display {
        font-size: 0.65rem;
        overflow: hidden;
    }

    .emotion-bar {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .emotion-hint { display: none; }

    #current-room-label {
        margin-top: 3px;
        padding-top: 3px;
        font-size: 0.65rem;
    }

    /* ── Chat column ── */
    .chat-column {
        flex: 1;
        min-height: 0;
        width: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    /* Ad banner — single line, no overflow */
    #ad-banner {
        flex-shrink: 0;
        width: 100%;
        margin-bottom: 0;
        padding: 5px 10px;
        border: none;
        border-bottom: 1px solid var(--border);
        overflow: hidden;
    }

    .ad-label {
        display: inline;
        margin-right: 4px;
    }

    .ad-content {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        overflow: hidden;
        max-width: 100%;
        min-width: 0;
    }

    .ad-title {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex-shrink: 0;
        max-width: 35vw;
    }

    .ad-separator { flex-shrink: 0; }

    .ad-desc {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        min-width: 0;
        flex: 1;
    }

    /* Announcement banner */
    #announcement-banner {
        flex-shrink: 0;
        width: 100%;
        margin: 0;
        border-left: none;
        border-right: none;
    }

    /* Chat prompt */
    .chat-prompt {
        flex: 1;
        min-height: 0;
        height: auto;
        width: 100%;
        margin-bottom: 0;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    /* Chat box */
    .chat-box {
        flex: 1;
        min-height: 0;
        height: auto;
        width: 100%;
        display: flex;
        flex-direction: column;
        margin-bottom: 0;
        padding: 0;
        border: none;
        overflow: hidden;
    }

    .chat-box > h3 { display: none; }

    /* Chat header */
    .chat-header {
        flex-shrink: 0;
        width: 100%;
        padding: 5px 10px;
        margin-bottom: 0;
        border-bottom: 1px solid var(--border);
        overflow: hidden;
    }

    .room-banner {
        padding: 3px 0;
        margin-bottom: 2px;
        text-align: center;
    }

    #room-banner-name {
        font-size: 1.1rem;
        letter-spacing: 2px;
    }

    .room-tabs {
        overflow: hidden;
    }

    .room-tab {
        font-size: 0.75rem;
        padding: 3px 5px;
    }

    /* Messages — only scrollable element */
    .chat-messages {
        flex: 1;
        min-height: 0;
        width: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 6px 10px;
    }

    .chat-message {
        word-break: break-word;
        overflow-wrap: anywhere;
        max-width: 100%;
    }

    .system-message {
        display: block;
        width: 100%;
        text-align: center;
    }

    #load-more {
        display: block;
        margin: 4px auto;
        font-size: 0.75rem;
        padding: 6px 14px;
    }

    /* Input bar — pinned to bottom */
    .chat-input-area {
        flex-shrink: 0;
        width: 100%;
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        background: var(--bg-card);
    }

    .chat-input-area .prompt {
        flex-shrink: 0;
    }

    #chat-input {
        flex: 1;
        min-width: 0;
        padding: 0.5rem 0.5rem;
    }

    #chat-send {
        flex-shrink: 0;
        padding: 0.5rem 0.9rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* Touch targets */
    button, .btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }

    .btn-primary {
        padding: 0.6rem 1.2rem;
        font-size: 0.85rem;
    }

    /* Hide Q&A and footer by default on mobile */
    #qa-section,
    #site-footer {
        display: none;
    }

    /* Show Q&A on pre-app screens (nickname / camera), allow body to scroll */
    #app-section.hidden ~ #qa-section {
        display: block;
        padding: 0 12px 16px;
    }

    /* When app is not yet shown, body can scroll to reveal FAQ */
    body:has(#app-section.hidden) {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Pre-app sections don't need to fill height when body scrolls */
    body:has(#app-section.hidden) #nickname-section,
    body:has(#app-section.hidden) #camera-section {
        flex: 0 0 auto;
        overflow-y: visible;
    }
}
