/* METHHEAD — Worn CRT terminal aesthetic
   Phosphor burn, scan lines, grit. Not clean. Not pretty. Honest. */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');

:root {
    --bg: #060808;
    --bg-hud: #0a0d0d;
    --bg-input: #080a0a;
    --bg-bar: #0e1212;
    --text: #c4a44a;
    --text-dim: #6b5e35;
    --text-bright: #e8cc60;
    --text-ghost: #3a3420;
    --green: #3d8a3d;
    --green-bright: #58c258;
    --red: #b03535;
    --red-bright: #e84444;
    --blue: #4477a8;
    --cyan: #3a9999;
    --cyan-bright: #55cccc;
    --purple: #8855aa;
    --amber: #c89030;
    --border: #1a1e1e;
    --border-bright: #2a3030;
    --glow: rgba(200, 170, 60, 0.03);

    /* Bar colors — desaturated, CRT phosphor feel */
    --bar-health: #a83535;
    --bar-health-low: #e84444;
    --bar-hunger: #b89038;
    --bar-hunger-low: #e8b030;
    --bar-energy: #3870a0;
    --bar-energy-low: #5090cc;
    --bar-hygiene: #488888;
    --bar-hygiene-low: #66aaaa;
    --bar-high: #7744aa;
    --bar-addiction: #cc3838;
    --bar-anxiety: #b88828;
    --bar-depression: #445588;
    --bar-anger: #c02828;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Mono', 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* CRT vignette overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.4) 100%);
    pointer-events: none;
    z-index: 200;
}

/* Scanline overlay */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.12) 2px,
        rgba(0,0,0,0.12) 4px
    );
    pointer-events: none;
    z-index: 201;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ====== HUD ====== */
#hud {
    background: var(--bg-hud);
    border-bottom: 1px solid var(--border);
    padding: 7px 14px;
    padding-right: 140px; /* room for toolbar buttons */
    display: flex;
    align-items: stretch;
    gap: 0;
    flex-shrink: 0;
    position: relative;
}

/* Faint glow line under HUD */
#hud::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--text-ghost), transparent);
}

/* Location & time — left column */
#hud-location {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 130px;
    padding-right: 14px;
    border-right: 1px solid var(--border);
    margin-right: 14px;
}

#location-name {
    color: var(--text-bright);
    font-weight: 500;
    font-size: 13px;
    letter-spacing: 0.5px;
}

#time-display {
    color: var(--text-dim);
    font-size: 10px;
    letter-spacing: 0.3px;
}

/* Bar sections — grouped by type */
#hud-bars {
    display: flex;
    gap: 0;
    flex: 1;
    align-items: center;
}

/* Visual separator between bar groups */
.bar-separator {
    width: 1px;
    height: 22px;
    background: var(--border);
    margin: 0 10px;
    flex-shrink: 0;
}

.bar-group {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 0 4px;
}

.bar-group label {
    font-size: 9px;
    font-weight: 500;
    color: var(--text-dim);
    width: 26px;
    text-align: right;
    letter-spacing: 0.5px;
    user-select: none;
}

.bar {
    width: 68px;
    height: 8px;
    background: var(--bg-bar);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

/* Subtle inner shadow for depth */
.bar::before {
    content: '';
    position: absolute;
    inset: 0;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
    z-index: 1;
    pointer-events: none;
}

.bar-fill {
    height: 100%;
    transition: width 0.4s ease;
    position: relative;
}

/* Phosphor glow on bar fills */
.bar-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 60%);
}

.bar-health { background: var(--bar-health); width: 100%; }
.bar-hunger { background: var(--bar-hunger); width: 70%; }
.bar-energy { background: var(--bar-energy); width: 80%; }
.bar-hygiene { background: var(--bar-hygiene); width: 60%; }
.bar-high { background: var(--bar-high); width: 0%; }
.bar-addiction { background: var(--bar-addiction); width: 0%; }
.bar-anxiety { background: var(--bar-anxiety); width: 0%; }
.bar-depression { background: var(--bar-depression); width: 0%; }
.bar-anger { background: var(--bar-anger); width: 0%; }

/* Critical state — bar pulses when very low */
.bar-critical .bar {
    border-color: var(--red);
}
.bar-critical .bar-fill {
    animation: barPulse 1.5s ease-in-out infinite;
}
.bar-critical label {
    color: var(--red-bright);
}

@keyframes barPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.bar-val {
    font-size: 10px;
    font-weight: 300;
    color: var(--text-dim);
    width: 22px;
    text-align: right;
}

/* Money display */
#hud-money {
    color: var(--green-bright);
    font-weight: 500;
    font-size: 14px;
    min-width: 58px;
    text-align: right;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    margin-left: 10px;
    display: flex;
    align-items: center;
    letter-spacing: 0.3px;
}

/* Status flags */
#hud-flags {
    display: flex;
    gap: 5px;
    align-items: center;
    padding-left: 10px;
    margin-left: 6px;
    flex-wrap: wrap;
}

.flag {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border: 1px solid;
    text-transform: uppercase;
    letter-spacing: 1px;
    animation: flagBlink 1.2s ease-in-out infinite;
}

.flag-talking {
    color: var(--cyan);
    border-color: var(--cyan);
    animation: none;
    opacity: 0.8;
}

#flag-withdrawal {
    color: var(--red-bright);
    border-color: var(--red-bright);
    text-shadow: 0 0 6px rgba(232, 68, 68, 0.4);
}

#flag-infected {
    color: #a07828;
    border-color: #806020;
    background: rgba(160, 120, 40, 0.08);
    text-shadow: 0 0 4px rgba(160, 120, 40, 0.3);
    animation: infectedPulse 2s ease-in-out infinite;
}

@keyframes infectedPulse {
    0%, 100% { opacity: 1; border-color: #806020; }
    50% { opacity: 0.6; border-color: #a07828; }
}

#flag-psychosis {
    color: #aa55ee;
    border-color: #8833cc;
    text-shadow: 0 0 10px rgba(170, 85, 238, 0.5);
    animation: psychosisPulse 0.8s ease-in-out infinite;
}

@keyframes psychosisPulse {
    0%, 100% { opacity: 1; }
    30% { opacity: 0.3; }
    60% { opacity: 0.9; }
}

#flag-sleepdeprived {
    color: var(--amber);
    border-color: var(--amber);
}

@keyframes flagBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.hidden { display: none !important; }

/* ====== TERMINAL ====== */
#terminal {
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px;
    scroll-behavior: smooth;
    /* Subtle phosphor glow at top */
    background: linear-gradient(180deg, rgba(200,170,60,0.01) 0%, transparent 80px);
}

#output {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.line {
    margin-bottom: 1px;
}

.line-system {
    color: var(--text-dim);
}

.line-location {
    color: var(--green);
}

.line-npc {
    color: var(--cyan-bright);
}

.line-action {
    color: var(--text);
}

.line-warning {
    color: var(--red);
    text-shadow: 0 0 4px rgba(176, 53, 53, 0.3);
}

.line-money {
    color: var(--green-bright);
}

.line-title {
    color: var(--text-bright);
    font-weight: 500;
}

.line-input {
    color: var(--text-ghost);
}

.line-hallucination {
    color: #aa55ee;
    font-style: italic;
    text-shadow: 0 0 8px rgba(170, 85, 238, 0.4);
    animation: hallucinationDrift 3s ease-in-out infinite;
}

@keyframes hallucinationDrift {
    0%, 100% { transform: translateX(0); opacity: 0.9; }
    33% { transform: translateX(2px); opacity: 1; }
    66% { transform: translateX(-1px); opacity: 0.7; }
}

/* Travel time styling in exits */
.line-travel {
    color: var(--text-dim);
    font-size: 12px;
}

/* ====== INPUT ====== */
#input-area {
    background: var(--bg-input);
    border-top: 1px solid var(--border);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    position: relative;
}

/* Glow line above input */
#input-area::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--text-ghost), transparent);
}

#prompt {
    color: var(--green-bright);
    font-weight: 600;
    font-size: 14px;
    text-shadow: 0 0 6px rgba(88, 194, 88, 0.3);
}

#command-input {
    background: transparent;
    border: none;
    color: var(--text-bright);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 13px;
    flex: 1;
    outline: none;
    caret-color: var(--text-bright);
}

#command-input::placeholder {
    color: var(--text-ghost);
}

/* ====== AUTH SCREEN ====== */
#auth-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 110;
}

#auth-content {
    text-align: center;
}

#auth-title-art {
    color: var(--red);
    font-size: 9px;
    line-height: 1.15;
    margin-bottom: 20px;
    text-shadow: 0 0 12px rgba(176, 53, 53, 0.4);
    animation: titleFlicker 4s ease-in-out infinite;
}

@keyframes titleFlicker {
    0%, 100% { opacity: 1; }
    92% { opacity: 1; }
    93% { opacity: 0.7; }
    94% { opacity: 1; }
    96% { opacity: 0.85; }
    97% { opacity: 1; }
}

#auth-prompt {
    color: var(--text-dim);
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: lowercase;
    font-weight: 300;
    margin-bottom: 4px;
}

#auth-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

/* Identity label — flashes after code accepted */
#auth-label {
    margin-top: 24px;
    text-align: center;
}

#auth-label-text {
    color: var(--red-bright);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 6px;
    text-transform: uppercase;
    text-shadow: 0 0 20px rgba(232, 68, 68, 0.6), 0 0 40px rgba(232, 68, 68, 0.3);
    animation: labelBurn 2.5s ease-out forwards;
}

@keyframes labelBurn {
    0% { opacity: 0; letter-spacing: 12px; filter: blur(4px); }
    15% { opacity: 1; letter-spacing: 6px; filter: blur(0); }
    70% { opacity: 1; }
    100% { opacity: 0.4; }
}

#invite-code-input {
    background: var(--bg-hud);
    border: 1px solid var(--border);
    color: var(--text-bright);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 16px;
    font-weight: 500;
    padding: 10px 16px;
    text-align: center;
    letter-spacing: 4px;
    text-transform: uppercase;
    width: 220px;
    outline: none;
    caret-color: var(--text-bright);
    transition: border-color 0.2s;
}

#invite-code-input:focus {
    border-color: var(--text-dim);
}

#invite-code-input::placeholder {
    color: var(--text-ghost);
    letter-spacing: 2px;
    font-size: 12px;
    font-weight: 400;
}

#auth-error {
    color: var(--red-bright);
    font-size: 12px;
}

/* ====== START SCREEN ====== */
#start-screen {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#start-content {
    text-align: center;
}

#title-art {
    color: var(--red);
    font-size: 9px;
    line-height: 1.15;
    margin-bottom: 20px;
    text-shadow: 0 0 12px rgba(176, 53, 53, 0.4);
    animation: titleFlicker 4s ease-in-out infinite;
}

.subtitle {
    color: var(--text-dim);
    margin-bottom: 36px;
    font-size: 11px;
    letter-spacing: 3px;
    text-transform: uppercase;
    font-weight: 300;
}

#start-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.btn-main, .btn-secondary {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 1px;
    padding: 10px 28px;
    cursor: pointer;
    border: 1px solid;
    background: transparent;
    transition: all 0.15s;
}

.btn-main {
    color: var(--text-bright);
    border-color: var(--text-dim);
}

.btn-main:hover {
    background: var(--text-bright);
    color: var(--bg);
    border-color: var(--text-bright);
}

.btn-secondary {
    color: var(--text-dim);
    border-color: var(--border-bright);
}

.btn-secondary:hover {
    color: var(--text);
    border-color: var(--text-dim);
}

/* ====== TOOLBAR ====== */
#toolbar {
    position: fixed;
    top: 5px;
    right: 6px;
    display: flex;
    gap: 3px;
    z-index: 50;
}

.tb-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 9px;
    font-weight: 500;
    letter-spacing: 0.5px;
    padding: 3px 7px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-hud);
    color: var(--text-ghost);
    transition: all 0.15s;
}

.tb-btn:hover {
    color: var(--text-dim);
    border-color: var(--border-bright);
}

/* ====== SCROLLBAR ====== */
#terminal::-webkit-scrollbar {
    width: 4px;
}

#terminal::-webkit-scrollbar-track {
    background: transparent;
}

#terminal::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

#terminal::-webkit-scrollbar-thumb:hover {
    background: var(--text-ghost);
}

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
    #hud {
        padding: 6px 10px;
        padding-right: 10px;
        flex-wrap: wrap;
        gap: 4px;
    }
    #hud-location {
        min-width: 100px;
        padding-right: 10px;
        margin-right: 10px;
    }
    #hud-bars {
        flex-wrap: wrap;
        gap: 2px;
    }
    .bar { width: 50px; }
    .bar-separator { display: none; }
    .bar-group { padding: 1px 2px; }
    #hud-money { min-width: 50px; }
    /* Move toolbar below HUD on tablets */
    #toolbar {
        position: fixed;
        top: auto;
        bottom: 46px;
        right: 6px;
    }
}

@media (max-width: 600px) {
    #hud {
        padding: 5px 8px;
        padding-right: 8px;
        flex-direction: column;
        gap: 3px;
    }
    /* Location + money on same row */
    #hud-location {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        min-width: unset;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding-right: 0;
        padding-bottom: 4px;
        margin-right: 0;
        margin-bottom: 0;
    }
    #location-name { font-size: 12px; flex: 1; }
    #time-display { font-size: 9px; }
    /* Bars wrap into grid */
    #hud-bars {
        flex-wrap: wrap;
        gap: 1px;
    }
    .bar { width: 40px; height: 6px; }
    .bar-group label { font-size: 8px; width: 22px; }
    .bar-val { font-size: 9px; width: 18px; }
    /* Money + flags row */
    #hud-money {
        font-size: 12px;
        min-width: unset;
        border-left: none;
        margin-left: 0;
        padding-left: 0;
    }
    #hud-flags { padding-left: 0; margin-left: 0; }
    /* Toolbar: compact row above input */
    #toolbar {
        position: fixed;
        top: auto;
        bottom: 42px;
        right: 4px;
        gap: 2px;
    }
    .tb-btn { font-size: 8px; padding: 2px 5px; }
    #title-art, #auth-title-art { font-size: 5px; }
    #terminal { padding: 10px 12px; }
    #input-area { padding: 8px 12px; }
    body { font-size: 12px; }
    /* Auth label smaller on mobile */
    #auth-label-text { font-size: 16px; letter-spacing: 4px; }
}

/* ====== TYPEWRITER CURSOR ====== */
.typing-cursor {
    display: inline-block;
    width: 6px;
    height: 13px;
    background: var(--text-bright);
    animation: cursorBlink 0.6s step-end infinite;
    vertical-align: text-bottom;
    box-shadow: 0 0 4px rgba(232, 204, 96, 0.3);
}

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

/* Save slot styles (kept for compatibility) */
#load-list { margin-top: 16px; }
#load-list p { margin-bottom: 8px; color: var(--text-dim); }
#save-slots { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.save-slot-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    padding: 8px 16px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-hud);
    color: var(--text);
    text-align: left;
    transition: border-color 0.2s;
}
.save-slot-btn:hover { border-color: var(--text-dim); }
