:root {
    --accent:          #F59E0B;
    --accent-light:    #FCD34D;
    --accent-dark:     #D97706;
    --pollen-dark:     #0F0E17;
    --pollen-darker:   #09080F;
    --pollen-card:     #1A1630;
    --pollen-card-light: #221E40;
    --text-primary:    #FFFFFF;
    --text-secondary:  #A0AEC0;
    --text-muted:      #718096;
    --success:         #48BB78;
    --warning:         #ECC94B;
    --danger:          #F56565;
    --state-waking:    #60A5FA;
    --state-fetching:  #A78BFA;
    --state-telling:   #34D399;
    --state-laughing:  #FBBF24;
    --state-sleeping:  #94A3B8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--pollen-darker);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
    position: sticky;
    top: 0;
    z-index: 10;
}

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

.logo img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
}

.logo-text {
    font-weight: 700;
    font-size: 1em;
    color: var(--accent-light);
}

.logo-text span {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 0.85em;
}

.user-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-badge {
    background: var(--pollen-card);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.8em;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.75em;
    min-height: 44px;
}

/* ── Main Layout ─────────────────────────────────────────────── */
.app-container {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 8px;
    max-width: 900px;
    margin: 0 auto;
}

/* ── Video ───────────────────────────────────────────────────── */
.video-container {
    position: relative;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    width: 100%;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: linear-gradient(135deg, #09080F 0%, #1A1630 100%);
}

.video-overlay-top {
    position: absolute;
    top: 0; left: 0; right: 0;
    padding: 12px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.connection-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.5);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8em;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
}

.status-indicator.connected  { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-indicator.connecting { background: var(--warning); animation: blink 0.8s infinite; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.robot-name {
    background: rgba(0,0,0,0.5);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8em;
    font-weight: 500;
}

.video-overlay-bottom {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 12px;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
}

.video-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.btn-primary   { background: var(--accent); color: #000; }
.btn-secondary { background: rgba(255,255,255,0.15); color: white; }
.btn-danger    { background: var(--danger); color: white; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Panels ──────────────────────────────────────────────────── */
.panel {
    background: var(--pollen-card);
    border-radius: 12px;
    overflow: hidden;
}

.panel-header {
    padding: 10px 14px;
    background: rgba(0,0,0,0.2);
    font-weight: 600;
    font-size: 0.85em;
    color: var(--accent-light);
}

.panel-content { padding: 12px; }

/* ── Robot Selector ──────────────────────────────────────────── */
.robot-list { display: flex; flex-direction: column; gap: 8px; }

.robot-card {
    padding: 10px 14px;
    background: var(--pollen-darker);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
}

.robot-card:hover    { background: var(--pollen-card-light); }
.robot-card.selected { border-color: var(--accent); }
.robot-card .name    { font-weight: 600; font-size: 0.9em; }
.robot-card .id      { font-size: 0.75em; color: var(--text-muted); font-family: monospace; }

/* ── Joke Display ────────────────────────────────────────────── */
.joke-display {
    min-height: 80px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.joke-placeholder {
    color: var(--text-muted);
    font-size: 0.88em;
    font-style: italic;
    text-align: center;
    padding: 12px 0;
}

.joke-setup {
    color: var(--text-primary);
    font-size: 0.95em;
    line-height: 1.5;
    padding: 10px 14px;
    background: var(--pollen-darker);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
}

.joke-punchline {
    color: var(--accent-light);
    font-size: 1em;
    font-weight: 600;
    line-height: 1.5;
    padding: 10px 14px;
    background: rgba(245, 158, 11, 0.08);
    border-radius: 8px;
    border-left: 3px solid var(--accent-light);
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Control Panel ───────────────────────────────────────────── */
.control-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px 12px;
}

.state-label {
    font-size: 0.9em;
    font-weight: 600;
    letter-spacing: 0.04em;
    transition: color 0.3s;
    color: var(--text-muted);
}

.state-idle     { color: var(--text-muted); }
.state-waking   { color: var(--state-waking);   animation: pulse 1.2s ease-in-out infinite; }
.state-fetching { color: var(--state-fetching); animation: pulse 1.0s ease-in-out infinite; }
.state-telling  { color: var(--state-telling);  animation: pulse 0.8s ease-in-out infinite; }
.state-laughing { color: var(--state-laughing); animation: bounce 0.5s ease-in-out infinite alternate; }
.state-sleeping { color: var(--state-sleeping); }

@keyframes pulse  { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-4px); } }

.joke-btn {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    background: transparent;
    color: var(--accent-light);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s;
}

.joke-btn:hover:not(:disabled) {
    background: rgba(245, 158, 11, 0.12);
    transform: scale(1.06);
    box-shadow: 0 0 24px rgba(245, 158, 11, 0.25);
}

.joke-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.joke-btn-emoji { font-size: 2.2em; line-height: 1; }
.joke-btn-text  { font-size: 0.72em; font-weight: 700; }

.error-msg {
    color: var(--danger);
    font-size: 0.82em;
    text-align: center;
    padding: 6px 12px;
    background: rgba(245, 101, 101, 0.1);
    border-radius: 8px;
    max-width: 100%;
    word-break: break-word;
}

/* ── Login View ──────────────────────────────────────────────── */
.login-view {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--pollen-card);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    max-width: 380px;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.login-logo {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    border-radius: 12px;
}

.login-card h2 {
    color: var(--accent-light);
    margin-bottom: 10px;
    font-size: 1.5em;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.9em;
    line-height: 1.5;
}

.btn-hf {
    background: #FFD21E;
    color: #000;
    border: none;
    padding: 12px 28px;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
}

/* ── Desktop Layout ──────────────────────────────────────────── */
@media (min-width: 768px) {
    .app-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "video    joke"
            "robots   control";
        align-items: start;
        gap: 12px;
    }

    .video-container { grid-area: video;   }
    #robotSelector   { grid-area: robots;  }
    #jokePanel       { grid-area: joke;    }
    #controlPanel    { grid-area: control; }
}

/* ── Settings button ─────────────────────────────────────────── */
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    min-width: 44px;
    min-height: 44px;
    transition: color 0.2s;
}
.btn-icon:hover { color: var(--accent-light); }
.btn-icon svg   { width: 20px; height: 20px; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}

.modal-card {
    background: var(--pollen-card);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-card h3 {
    color: var(--accent-light);
    font-size: 1.1em;
    margin-bottom: 4px;
}

.setting-label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-secondary);
}

.setting-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--pollen-darker);
    border: 1px solid var(--pollen-card-light);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.85em;
    font-family: monospace;
}
.setting-input:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-hint {
    font-size: 0.78em;
    color: var(--text-muted);
    line-height: 1.4;
}
.setting-hint a    { color: var(--accent-light); text-decoration: none; }
.setting-hint code { font-size: 0.9em; color: var(--accent); }
.setting-required  { font-weight: 400; color: var(--accent); font-size: 0.9em; }

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
}

.hidden { display: none !important; }
