/* LORD — Legend of the Red Dragon */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
    background: #000;
    color: #0f0;
    font-family: 'VT323', 'Courier New', Courier, monospace;
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    -webkit-text-size-adjust: 100%;
}

/* ---- terminal frame ---- */
.terminal {
    background: #0a0a0a;
    border: 3px solid #0f0;
    box-shadow:
        0 0 24px rgba(0,255,0,.25),
        0 0 60px rgba(0,255,0,.08),
        inset 0 0 60px rgba(0,255,0,.03);
    width: 100%;
    max-width: 44rem;
    padding: 1.5rem;
    border-radius: 6px;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 720px;
    min-height: 480px;
    overflow: hidden;
    transition: border-color .25s, box-shadow .25s;
}

/* CRT scanline overlay */
.crt-overlay {
    pointer-events: none;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: repeating-linear-gradient(
        0deg,
        rgba(0,0,0,.15) 0px,
        rgba(0,0,0,.15) 1px,
        transparent 1px,
        transparent 3px
    );
    border-radius: 6px;
}

/* active mode — frame feels "modal" */
.terminal[data-mode="combat"],
.terminal[data-mode="arena"] {
    border-color: #7f1d1d;
    box-shadow: 0 0 28px rgba(220,38,38,.35), inset 0 0 50px rgba(127,29,29,.08);
}
.terminal[data-mode="dragon"] {
    border-color: #b91c1c;
    box-shadow: 0 0 40px rgba(185,28,28,.5), 0 0 80px rgba(185,28,28,.2), inset 0 0 60px rgba(127,29,29,.12);
}
.terminal[data-mode="dead"] {
    border-color: #450a0a;
    box-shadow: 0 0 20px rgba(0,0,0,.5), inset 0 0 40px rgba(0,0,0,.2);
}
.terminal[data-mode="win"] {
    border-color: #22c55e;
    box-shadow: 0 0 32px rgba(34,197,94,.4), 0 0 60px rgba(34,197,94,.15), inset 0 0 50px rgba(22,101,52,.1);
}

/* ---- header ---- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .75rem;
    border-bottom: 1px solid #166534;
    padding-bottom: .5rem;
    margin-bottom: .5rem;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}
.header h1 {
    font-size: 1.4rem;
    font-weight: bold;
    color: #4ade80;
    margin: 0;
    line-height: 1.2;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(74,222,128,.4);
}
.header h1 i { color: #f87171; margin-right: .3rem; }
.header-sub {
    font-size: 12px;
    color: #14532d;
    margin-top: 2px;
    letter-spacing: .5px;
}

/* ---- stats card ---- */
.stats {
    font-size: 12px;
    color: #86efac;
    text-align: right;
    white-space: nowrap;
    line-height: 1.5;
    min-width: 0;
    flex-shrink: 0;
    background: #0a0f0a;
    border: 1px solid #14532d;
    border-radius: 6px;
    padding: .4rem .55rem;
    box-shadow: inset 0 0 20px rgba(0,255,0,.04);
    position: relative;
    z-index: 1;
}
.stats__title {
    font-weight: bold;
    color: #4ade80;
    font-size: 13px;
    margin-bottom: .3rem;
    padding-bottom: .2rem;
    border-bottom: 1px solid #14532d;
    letter-spacing: 1px;
    text-shadow: 0 0 8px rgba(74,222,128,.3);
}
.stats__row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .35rem;
    margin-bottom: .15rem;
}
.stats__row:last-child { margin-bottom: 0; }
.stats__label { color: #14532d; font-size: 11px; min-width: 1.8em; }
.stats__bar-wrap {
    width: 72px;
    height: 7px;
    background: #0d1f0d;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid #14532d;
}
.stats__bar-fill { height: 100%; transition: width .3s; border-radius: 2px; }
.stats__bar-fill.bar-hp { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.4); }
.stats__bar-fill.bar-hp-mid { background: #eab308; box-shadow: 0 0 6px rgba(234,179,8,.4); }
.stats__bar-fill.bar-hp-low { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.4); animation: pulse 1s infinite; }
.stats__bar-fill.bar-xp { background: #6366f1; box-shadow: 0 0 6px rgba(99,102,241,.4); }
.stats__bar-fill.bar-enemy { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.4); }
.stats__values { color: #86efac; font-size: 12px; min-width: 3.5em; text-align: right; }
.stats__section { margin-top: .3rem; padding-top: .3rem; border-top: 1px solid #14532d; }
.stats__section--enemy {
    margin-top: .4rem;
    padding: .3rem .4rem;
    background: rgba(127,29,29,.15);
    border: 1px solid #7f1d1d;
    border-radius: 4px;
    text-align: center;
}
.stats__section--enemy .stats__title { color: #fca5a5; border-bottom-color: #7f1d1d; text-shadow: 0 0 8px rgba(252,165,165,.3); }
.stats__section--enemy .stats__bar-wrap { border-color: #7f1d1d; }
.stats__poison { color: #f87171; font-size: 11px; margin-top: .2rem; }
.stats__buffs { color: #facc15; font-size: 11px; }

/* ---- log window ---- */
.log {
    height: 260px;
    min-height: 140px;
    flex-shrink: 1;
    overflow-y: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    background: #000;
    border: 1px solid #14532d;
    padding: .6rem;
    margin-bottom: .5rem;
    font-size: 14px;
    color: #4ade80;
    line-height: 1.7;
    position: relative;
    z-index: 1;
    text-shadow: 0 0 4px rgba(74,222,128,.15);
}
.log::-webkit-scrollbar { display: none; }
.log div { margin-bottom: 1px; }

/* combat/arena/dragon — log and controls feel like active "scene" */
.terminal[data-mode="combat"] .log,
.terminal[data-mode="arena"] .log {
    border-color: #7f1d1d;
    border-width: 2px;
    box-shadow: inset 0 0 20px rgba(127,29,29,.15);
}
.terminal[data-mode="dragon"] .log {
    border-color: #b91c1c;
    border-width: 2px;
    box-shadow: inset 0 0 24px rgba(185,28,28,.2);
}
.terminal[data-mode="combat"] .controls,
.terminal[data-mode="arena"] .controls {
    border-top: 1px solid #7f1d1d;
    padding-top: .5rem;
    margin-top: 2px;
}
.terminal[data-mode="dragon"] .controls {
    border-top: 1px solid #b91c1c;
    padding-top: .5rem;
    margin-top: 2px;
}

/* ---- mode strip ---- */
.mode-strip {
    flex-shrink: 0;
    padding: .35rem .75rem;
    margin: 0 0 .5rem 0;
    font-size: 13px;
    font-weight: bold;
    letter-spacing: 2px;
    text-align: center;
    border-radius: 4px;
    min-height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s, background .2s, color .2s;
    position: relative;
    z-index: 1;
}
.mode-strip:empty,
.mode-strip.mode-strip--idle {
    opacity: 0;
    min-height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}
.mode-strip.mode-strip--combat,
.mode-strip.mode-strip--arena {
    background: #450a0a;
    color: #fca5a5;
    border: 1px solid #7f1d1d;
    animation: modeStripPulse 1.5s ease-in-out infinite;
    text-shadow: 0 0 8px rgba(252,165,165,.3);
}
.mode-strip.mode-strip--dragon {
    background: #7f1d1d;
    color: #fecaca;
    border: 1px solid #b91c1c;
    animation: modeStripPulse .8s ease-in-out infinite;
    text-shadow: 0 0 12px rgba(254,202,202,.4);
}
.mode-strip.mode-strip--dead {
    background: #1c1917;
    color: #f87171;
    border: 1px solid #450a0a;
}
.mode-strip.mode-strip--win {
    background: #14532d;
    color: #86efac;
    border: 1px solid #22c55e;
    text-shadow: 0 0 10px rgba(134,239,172,.4);
}
@keyframes modeStripPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .8; }
}

/* ---- controls grid ---- */
.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .35rem;
    flex: 1;
    align-content: start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #166534 transparent;
    padding-right: 2px;
    position: relative;
    z-index: 1;
}
.controls::-webkit-scrollbar { width: 4px; }
.controls::-webkit-scrollbar-thumb { background: #166534; border-radius: 2px; }
.controls::-webkit-scrollbar-track { background: transparent; }

/* ---- buttons ---- */
.controls button, button.btn {
    background: #14532d;
    color: #bbf7d0;
    border: 1px solid #166534;
    padding: .55rem .5rem;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 15px;
    cursor: pointer;
    transition: background-color .1s, color .1s, border-color .1s, box-shadow .1s;
    text-align: center;
    line-height: 1.3;
    min-height: 44px;
    -webkit-tap-highlight-color: rgba(0,255,0,.15);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    border-radius: 4px;
    letter-spacing: .5px;
}
.controls button:hover, button.btn:hover {
    background: #0f0 !important;
    color: #000 !important;
    border-color: #0f0;
    box-shadow: 0 0 12px rgba(0,255,0,.3);
}
.controls button:active {
    background: #22c55e !important;
    color: #000 !important;
    transform: scale(.97);
}
.col-2 { grid-column: span 2; }
.btn-danger {
    background: #450a0a !important;
    border-color: #7f1d1d !important;
    text-shadow: 0 0 6px rgba(252,165,165,.3);
}
.btn-danger:hover {
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    box-shadow: 0 0 16px rgba(239,68,68,.4) !important;
}
.btn-lg { padding: .7rem .5rem; font-size: 1.1rem; font-weight: bold; letter-spacing: 1px; }
.btn-sm { padding: .35rem .5rem; font-size: 13px; min-height: 38px; }
.btn-pink { background: #831843 !important; border-color: #9d174d !important; }
.btn-pink:hover { background: #f472b6 !important; border-color: #f472b6 !important; box-shadow: 0 0 12px rgba(244,114,182,.3) !important; }
.btn-dim { opacity: .4; pointer-events: none; }

/* ---- footer ---- */
.footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: .4rem;
    padding-top: .4rem;
    border-top: 1px solid #0a2e14;
    font-size: 11px;
    color: #14532d;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    letter-spacing: .5px;
}
.save-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: #166534;
    transition: background-color .3s;
    vertical-align: middle;
}
.sound-toggle {
    background: none;
    border: none;
    color: #14532d;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 6px;
    margin-right: 4px;
    transition: color .2s;
    vertical-align: middle;
    -webkit-tap-highlight-color: transparent;
}
.sound-toggle:hover, .sound-toggle.active { color: #4ade80; }

/* ---- confetti canvas ---- */
.confetti-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* ---- legacy bars ---- */
.bar-wrap {
    width: 96px;
    height: 5px;
    background: #14532d;
    border-radius: 3px;
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
}
.bar-fill {
    height: 100%;
    transition: width .3s;
    border-radius: 3px;
}
.bar-hp { background: #22c55e; }
.bar-hp-mid { background: #eab308; }
.bar-hp-low { background: #ef4444; }
.bar-xp { background: #6366f1; }
.bar-enemy { background: #ef4444; }

/* ---- animations ---- */
.dragon { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.5; } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.fade-in { animation: fadeIn .2s ease-in; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-5px) rotate(-.5deg); }
    30% { transform: translateX(5px) rotate(.5deg); }
    45% { transform: translateX(-4px); }
    60% { transform: translateX(4px); }
    75% { transform: translateX(-2px); }
}
.shake { animation: shake .4s ease-out; }

@keyframes lvlup {
    0% { box-shadow: 0 0 24px rgba(0,255,0,.25), inset 0 0 60px rgba(0,255,0,.03); }
    30% { box-shadow: 0 0 50px rgba(250,204,21,.6), 0 0 100px rgba(250,204,21,.2), inset 0 0 80px rgba(250,204,21,.12); border-color: #facc15; }
    100% { box-shadow: 0 0 24px rgba(0,255,0,.25), inset 0 0 60px rgba(0,255,0,.03); }
}
.lvlup-flash { animation: lvlup .8s ease-out; }

@keyframes dmgFlash {
    0% { background: #0a0a0a; }
    20% { background: #2a0000; }
    100% { background: #0a0a0a; }
}
.dmg-flash { animation: dmgFlash .25s ease-out; }

@keyframes goldPickup {
    0% { text-shadow: 0 0 4px rgba(74,222,128,.15); }
    30% { text-shadow: 0 0 12px rgba(250,204,21,.6); }
    100% { text-shadow: 0 0 4px rgba(74,222,128,.15); }
}
.gold-flash .log { animation: goldPickup .5s ease-out; }

/* ---- text colors ---- */
.c-red { color: #f87171; }
.c-yellow { color: #facc15; }
.c-pink { color: #f472b6; }
.c-green { color: #4ade80; }
.c-dim { color: #14532d; }
.c-blue { color: #818cf8; }
.c-orange { color: #fb923c; }
.c-white { color: #e5e7eb; }
.bold { font-weight: bold; }
.text-center { text-align: center; }

/* ---- shop items ---- */
.shop-item {
    text-align: left;
    padding: .45rem .5rem;
    font-size: 13px;
    line-height: 1.4;
}
.shop-label { color: #bbf7d0; }
.shop-cost { color: #4ade80; font-size: 12px; }

/* ========== RESPONSIVE ========== */

/* iPhone / small screens */
@media (max-width: 480px) {
    body { padding: .5rem; align-items: flex-start; }
    .terminal {
        padding: .75rem;
        height: calc(100dvh - 1rem);
        min-height: 480px;
        max-height: none;
        border-width: 2px;
        border-radius: 4px;
    }
    .crt-overlay {
        background: repeating-linear-gradient(
            0deg,
            rgba(0,0,0,.1) 0px,
            rgba(0,0,0,.1) 1px,
            transparent 1px,
            transparent 2px
        );
    }
    .header { flex-wrap: wrap; gap: .5rem; padding-bottom: .35rem; margin-bottom: .35rem; }
    .header h1 { font-size: 1.1rem; }
    .stats {
        font-size: 11px;
        padding: .35rem .45rem;
        width: 100%;
    }
    .stats__title { font-size: 12px; margin-bottom: .2rem; }
    .stats__bar-wrap { width: 52px; height: 5px; }
    .stats__values { min-width: 2.5em; font-size: 11px; }
    .log { height: 160px; min-height: 120px; font-size: 13px; padding: .5rem; }
    .controls { gap: .3rem; }
    .controls button { font-size: 14px; padding: .5rem .4rem; min-height: 44px; }
    .btn-lg { font-size: 1rem; padding: .6rem .4rem; }
    .btn-sm { font-size: 12px; min-height: 40px; }
    .footer { font-size: 10px; padding-top: .3rem; margin-top: .3rem; }
    .mode-strip { font-size: 12px; padding: .3rem .5rem; min-height: 24px; letter-spacing: 1px; }
    .shop-item { font-size: 12px; padding: .4rem; }
    .shop-cost { font-size: 11px; }
}

/* tiny phones (iPhone SE) */
@media (max-width: 380px) {
    .header h1 { font-size: .95rem; }
    .log { height: 130px; min-height: 100px; font-size: 12px; }
    .stats__bar-wrap { width: 44px; }
}

/* tall desktop */
@media (min-height: 900px) and (min-width: 481px) {
    .terminal { height: 800px; }
    .log { height: 300px; }
}

/* safe areas for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .terminal { padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
}
