/* ── /loop — base stylesheet ─────────────────────────────────────────
   Mobile-first. 320×180 internal canvas resolution scaled to fill
   the viewport while maintaining 16:9 aspect ratio.
   All measurements in px unless otherwise noted.
──────────────────────────────────────────────────────────────────── */

/* ── CSS VARIABLES ───────────────────────────────────────────────── */
:root {
    --system-black:     #0A0B10;
    --deep-navy:        #0D1B2A;
    --loop-cyan:        #00F2FF;
    --execution-gold:   #F4C430;
    --stagnation-grey:  #4A4D5E;
    --intelligence:     #1A6BFF;
    --strength:         #E63B2E;
    --charisma:         #9B5DE5;
    --dexterity:        #00A878;

    --panel-bg:         rgba(10, 11, 16, 0.96);
    --panel-border:     rgba(0, 242, 255, 0.25);
    --panel-border-hot: rgba(0, 242, 255, 0.7);

    --font-mono:        'Courier New', Courier, monospace;
    --font-size-base:   13px;
    --font-size-sm:     11px;
    --font-size-xs:     9px;

    --tap-target:       44px;
    --ui-padding:       12px;
    --panel-radius:     2px;
}

/* ── RESET ───────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    width: 100%;
    height: 100%;
    /* dvh accounts for mobile browser chrome (address bar, nav).
       Fallback to 100vh for browsers that don't support dvh yet. */
    height: 100dvh;
}

body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--system-black);
    color: var(--loop-cyan);
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    line-height: 1.4;
    touch-action: none;

    /* Positioning context for the absolutely positioned canvas */
    position: relative;
}

/* ── CANVAS ───────────────────────────────────────────────────────── */
/*
   320×180 internal resolution. JS sets exact CSS width+height each frame.
   image-rendering: pixelated — no smoothing, sharp pixels at all scales.
   No aspect-ratio rule here — the browser already applies intrinsic
   "auto 320/180" from the canvas attributes. Adding a second
   aspect-ratio declaration causes the two to conflict and shrink the
   canvas height. JS owns the sizing entirely.
*/
#game-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    image-rendering: pixelated;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;

    display: block;
    background: var(--system-black);   /* system black — never shows during play */
}

/* ── UI OVERLAY ───────────────────────────────────────────────────── */
/*
   Sits on top of the canvas. Pointer events pass through the overlay
   container itself — only actual UI elements capture touches.
*/
#ui-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

#ui-overlay > * {
    pointer-events: auto;
}

/* ── SYSTEM WINDOW BUTTON ────────────────────────────────────────── */
#btn-system {
    position: absolute;
    top: var(--ui-padding);
    right: var(--ui-padding);
    width: var(--tap-target);
    height: var(--tap-target);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--panel-radius);
    color: var(--loop-cyan);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s;
}

#btn-system:hover,
#btn-system:focus-visible {
    border-color: var(--panel-border-hot);
    background: rgba(0, 242, 255, 0.08);
    outline: none;
}

#btn-system:active {
    background: rgba(0, 242, 255, 0.15);
}

/* ── PANELS (shared base) ─────────────────────────────────────────── */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--panel-radius);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.panel[hidden] {
    display: none !important;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px var(--ui-padding);
    border-bottom: 1px solid var(--panel-border);
}

.panel-title {
    font-size: var(--font-size-sm);
    letter-spacing: 2px;
    color: var(--loop-cyan);
    text-transform: uppercase;
}

.panel-header button {
    background: none;
    border: none;
    color: var(--stagnation-grey);
    font-size: 14px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--panel-radius);
    transition: color 0.15s;
}

.panel-header button:hover {
    color: var(--loop-cyan);
}

.panel-body {
    padding: var(--ui-padding);
}

/* ── SYSTEM WINDOW PANEL ─────────────────────────────────────────── */
#system-window {
    position: absolute;
    top: calc(var(--tap-target) + var(--ui-padding) + 8px);
    right: var(--ui-padding);
    width: min(320px, calc(100vw - 24px));
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    overflow-x: hidden;

    /* Scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: var(--stagnation-grey) transparent;
}

#system-window::-webkit-scrollbar {
    width: 4px;
}

#system-window::-webkit-scrollbar-track {
    background: transparent;
}

#system-window::-webkit-scrollbar-thumb {
    background: var(--stagnation-grey);
    border-radius: 2px;
}

/* SYD output lines */
.syd-line {
    font-size: var(--font-size-sm);
    letter-spacing: 1px;
    color: var(--loop-cyan);
    margin-bottom: 6px;
    line-height: 1.5;
}

.syd-line.dim {
    /* Was var(--stagnation-grey) = #4A4D5E — too dark on panel background.
       Brightened to a readable mid-cyan-grey. */
    color: #8ab4c0;
}

.syd-line.gold {
    color: var(--execution-gold);
}

/* Stat bars */
.stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.stat-label {
    font-size: var(--font-size-xs);
    letter-spacing: 2px;
    width: 88px;
    flex-shrink: 0;
    color: var(--loop-cyan);
}

.stat-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(74, 77, 94, 0.4);
    border-radius: 1px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    border-radius: 1px;
    transition: width 0.4s ease;
}

.stat-bar-fill.intelligence { background: var(--intelligence); }
.stat-bar-fill.strength     { background: var(--strength); }
.stat-bar-fill.charisma     { background: var(--charisma); }
.stat-bar-fill.dexterity    { background: var(--dexterity); }
.stat-bar-fill.luck         { background: var(--execution-gold); }

.stat-value {
    font-size: var(--font-size-xs);
    width: 28px;
    text-align: right;
    flex-shrink: 0;
    color: var(--stagnation-grey);
}

/* ── DIALOGUE BOX ─────────────────────────────────────────────────── */
#dialogue-box {
    position: absolute;
    bottom: var(--ui-padding);
    left: var(--ui-padding);
    right: var(--ui-padding);
    max-width: 480px;
    margin: 0 auto;
}

#dialogue-box .panel-body {
    position: relative;
    padding-right: 40px; /* Room for advance button */
}

#dialogue-speaker {
    color: var(--execution-gold);
}

#dialogue-text {
    font-size: var(--font-size-sm);
    color: var(--loop-cyan);
    line-height: 1.6;
    min-height: 40px;
}

#dialogue-advance {
    position: absolute;
    right: var(--ui-padding);
    bottom: var(--ui-padding);
    background: none;
    border: 1px solid var(--panel-border);
    border-radius: var(--panel-radius);
    color: var(--loop-cyan);
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    transition: border-color 0.15s;
}

#dialogue-advance:hover {
    border-color: var(--panel-border-hot);
}

/* ── NOTIFICATION TOAST ──────────────────────────────────────────── */
#notification {
    position: absolute;
    top: var(--ui-padding);
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--panel-radius);
    padding: 6px 14px;
    font-size: var(--font-size-sm);
    letter-spacing: 1px;
    color: var(--loop-cyan);
    white-space: nowrap;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s;
}

#notification[hidden] {
    display: none !important;
}

#notification.fading {
    opacity: 0;
}

/* ── DEV OVERLAY ──────────────────────────────────────────────────── */
#dev-overlay {
    position: absolute;
    bottom: var(--ui-padding);
    right: var(--ui-padding);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    pointer-events: none;
}

#dev-overlay span {
    font-size: var(--font-size-xs);
    color: rgba(74, 77, 94, 0.7);
    letter-spacing: 1px;
}

/* ════════════════════════════════════════════════════════════════════
   SYSTEM WINDOW — VISUAL REWORK
   Inspired by SYD /terminal: name prominent, card sections,
   numbers large, bars alive with shimmer and glow.
════════════════════════════════════════════════════════════════════ */

/* ── Panel body base ─────────────────────────────────────────────── */
#system-window-body {
    padding: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ── Section card ────────────────────────────────────────────────── */
.sw-card {
    background: rgba(255, 255, 255, 0.028);
    border: 1px solid rgba(0, 242, 255, 0.1);
    border-radius: 2px;
    padding: 12px 14px;
    position: relative;
}

/* ── Identity card ───────────────────────────────────────────────── */
.sw-identity-name {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 4px;
    color: var(--loop-cyan);
    margin: 6px 0 8px;
    line-height: 1.2;
}

.sw-identity-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sw-class-badge {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 2px;
    border: 1px solid;
    padding: 2px 8px;
    border-radius: 2px;
}

.sw-rank-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 2px;
    color: #9ab4c4;   /* readable secondary — brighter than stagnation-grey */
}

/* ── Vital rows (HP / Momentum) ──────────────────────────────────── */
.sw-vital-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 5px;
}

.sw-vital-label {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--loop-cyan);
    flex: 1;
    min-height: 14px;
}

.sw-vital-label.dim { color: #6a8a98; }

.sw-vital-value {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: bold;
    letter-spacing: 1px;
    color: var(--loop-cyan);
}

.sw-vital-value.gold { color: var(--execution-gold); }

.sw-vital-max {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--stagnation-grey);
}

.sw-momentum-row {
    margin-top: 10px;
}

.sw-streak {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 2px;
    color: var(--execution-gold);
    margin-left: auto;
    min-height: 12px;
}

/* ── Shared bar track ────────────────────────────────────────────── */
.sw-bar-track {
    height: 5px;
    background: rgba(74, 77, 94, 0.35);
    border-radius: 1px;
    overflow: hidden;
    margin-bottom: 4px;
    position: relative;
}

.sw-bar-fill {
    height: 100%;
    border-radius: 1px;
    width: 0%;
    transition: width 0.55s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

/* Stat-specific fills and glows */
.sw-bar-fill.intelligence { background: var(--intelligence); box-shadow: 0 0 6px rgba(26,107,255,0.5); }
.sw-bar-fill.strength     { background: var(--strength);     box-shadow: 0 0 6px rgba(230,59,46,0.5); }
.sw-bar-fill.charisma     { background: var(--charisma);     box-shadow: 0 0 6px rgba(155,93,229,0.5); }
.sw-bar-fill.dexterity    { background: var(--dexterity);    box-shadow: 0 0 6px rgba(0,168,120,0.5); }
.sw-bar-fill.luck         { background: var(--execution-gold); box-shadow: 0 0 6px rgba(244,196,48,0.5); }

/* Shimmer sweep */
.sw-shimmer {
    position: absolute;
    top: 0; left: -80%;
    width: 60%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.3), transparent);
    animation: sw-shimmer-anim 2.8s ease-in-out infinite;
}

@keyframes sw-shimmer-anim {
    0%   { left: -80%; }
    60%  { left: 130%; }
    100% { left: 130%; }
}

/* ── Stats card ──────────────────────────────────────────────────── */
.sw-section-title {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--loop-cyan);
    margin-bottom: 10px;
    min-height: 14px;
}

.sw-stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 9px;
}

.sw-stat-label {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 2px;
    color: #6a8a98;
    width: 32px;
    flex-shrink: 0;
}

.sw-stat-track {
    flex: 1;
    height: 4px;
}

.sw-stat-val {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: bold;
    width: 26px;
    text-align: right;
    flex-shrink: 0;
    color: var(--loop-cyan);
}

/* ── Footer card ─────────────────────────────────────────────────── */
.sw-footer-hint {
    opacity: 0.35;
    font-size: 9px;
    letter-spacing: 1px;
    margin-top: 4px;
}

/* ── Animations ──────────────────────────────────────────────────── */
.sw-typing::after {
    content: '▮';
    color: var(--loop-cyan);
    animation: boot-blink 0.5s step-end infinite;
    margin-left: 2px;
}

.sw-blink-cursor.sw-typed::after {
    content: ' ▮';
    color: var(--loop-cyan);
    animation: boot-blink 0.9s step-end infinite;
}

.sw-corrupted {
    color: var(--strength) !important;
    animation: sw-corrupt-pulse 1s ease-in-out infinite;
}

@keyframes sw-corrupt-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

/* Inline colour helpers */
.syd-line .gold  { color: var(--execution-gold); }
.syd-line.strength { color: var(--strength); }

/* ── MAP TRANSITION OVERLAY ─────────────────────────────────────────── */
#transition-overlay {
    position: absolute;
    inset: 0;
    background: #0A0B10;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    transition: opacity 0.3s ease;
}

/* ── ANIMATIONS ───────────────────────────────────────────────────── */
@keyframes scanline {
    0%   { background-position: 0 0; }
    100% { background-position: 0 4px; }
}

/* Corrupted State scanline overlay — applied to body via JS */
body.corrupted::after {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 242, 255, 0.03) 2px,
        rgba(0, 242, 255, 0.03) 4px
    );
    pointer-events: none;
    z-index: 100;
    animation: scanline 0.1s linear infinite;
}

/* SYD transmission flicker on new message */
@keyframes syd-flicker {
    0%   { opacity: 0.2; }
    15%  { opacity: 1; }
    20%  { opacity: 0.5; }
    25%  { opacity: 1; }
    100% { opacity: 1; }
}

.syd-new {
    animation: syd-flicker 0.4s ease forwards;
}

/* ── RESPONSIVE SCALE ─────────────────────────────────────────────── */
/*
   The canvas is scaled by JS. The UI overlay panels are in real pixels,
   so they do not scale with the canvas — they sit on top at actual size.
   On very small screens, clamp the system window width.
*/
@media (max-width: 360px) {
    :root {
        --ui-padding: 8px;
        --font-size-base: 12px;
        --font-size-sm: 10px;
    }

    #system-window {
        width: calc(100vw - 16px);
    }
}

/* ── UTILITY ──────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ════════════════════════════════════════════════════════════════════
   BOOT SEQUENCE OVERLAY
════════════════════════════════════════════════════════════════════ */

#boot-overlay {
    position: fixed;
    inset: 0;
    background: var(--system-black);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

#boot-overlay.boot-fade-out {
    opacity: 0;
    pointer-events: none;
}

#boot-inner {
    width: min(400px, calc(100vw - 48px));
    max-height: calc(100vh - 80px);
    overflow: hidden;
    position: relative;
    padding: 0 20px;
    box-sizing: border-box;
}

#boot-lines {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    max-height: calc(100vh - 180px);
    /* Hide scrollbar visually — scroll is driven by JS _scroll() */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
#boot-lines::-webkit-scrollbar {
    display: none;
}

.boot-line {
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 2px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.boot-blank  { height: 8px; }
.boot-title  { color: var(--loop-cyan); font-size: 18px; letter-spacing: 6px; font-weight: bold; }
.boot-cyan   { color: var(--loop-cyan); }
.boot-dim    { color: #5a7a88; }
.boot-warning { color: var(--strength); }
.boot-gold   { color: var(--execution-gold); letter-spacing: 3px; }
.boot-large  { font-size: 14px; letter-spacing: 4px; }

#boot-cursor {
    display: inline-block;
    color: var(--loop-cyan);
    font-size: 14px;
    animation: boot-blink 0.7s step-end infinite;
    margin-top: 8px;
}

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

/* ════════════════════════════════════════════════════════════════════
   SYSTEM WINDOW — HI-TECH REWORK
════════════════════════════════════════════════════════════════════ */

/* Panel opening flash */
@keyframes sw-open-flash {
    0%   { opacity: 0; transform: translateY(-4px) scaleY(0.96); }
    40%  { opacity: 1; transform: translateY(0)    scaleY(1.01); }
    100% { opacity: 1; transform: translateY(0)    scaleY(1); }
}

#system-window.sw-opening {
    animation: sw-open-flash 0.25s ease forwards;
}

/* CRT scanline texture on the panel itself */
#system-window::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(0, 242, 255, 0.018) 3px,
        rgba(0, 242, 255, 0.018) 4px
    );
    pointer-events: none;
    z-index: 1;
    border-radius: var(--panel-radius);
}

/* Corner bracket decorations */
#system-window::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--panel-radius);
    background:
        /* top-left corner */
        linear-gradient(to right,  var(--loop-cyan) 8px, transparent 8px) 0 0 / 8px 1px no-repeat,
        linear-gradient(to bottom, var(--loop-cyan) 8px, transparent 8px) 0 0 / 1px 8px no-repeat,
        /* top-right corner */
        linear-gradient(to left,   var(--loop-cyan) 8px, transparent 8px) 100% 0 / 8px 1px no-repeat,
        linear-gradient(to bottom, var(--loop-cyan) 8px, transparent 8px) 100% 0 / 1px 8px no-repeat,
        /* bottom-left corner */
        linear-gradient(to right,  var(--loop-cyan) 8px, transparent 8px) 0 100% / 8px 1px no-repeat,
        linear-gradient(to top,    var(--loop-cyan) 8px, transparent 8px) 0 100% / 1px 8px no-repeat,
        /* bottom-right corner */
        linear-gradient(to left,   var(--loop-cyan) 8px, transparent 8px) 100% 100% / 8px 1px no-repeat,
        linear-gradient(to top,    var(--loop-cyan) 8px, transparent 8px) 100% 100% / 1px 8px no-repeat;
    pointer-events: none;
    z-index: 2;
}

/* Ensure panel body is above scanline/corner overlays */
#system-window-body,
.panel-header {
    position: relative;
    z-index: 3;
}

/* Shimmer animation inside stat bars */
.stat-bar-shimmer {
    position: absolute;
    top: 0; left: -60%;
    width: 50%;
    height: 100%;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255,255,255,0.25) 50%,
        transparent 100%
    );
    animation: bar-shimmer 2.5s ease-in-out infinite;
}

@keyframes bar-shimmer {
    0%   { left: -60%; }
    60%  { left: 120%; }
    100% { left: 120%; }
}

.stat-bar-fill {
    position: relative;
    overflow: hidden;
}

/* Stat bar glow — each bar glows its own colour */
.stat-bar-fill.intelligence { box-shadow: 0 0 6px rgba(26,107,255,0.5); }
.stat-bar-fill.strength     { box-shadow: 0 0 6px rgba(230,59,46,0.5); }
.stat-bar-fill.charisma     { box-shadow: 0 0 6px rgba(155,93,229,0.5); }
.stat-bar-fill.dexterity    { box-shadow: 0 0 6px rgba(0,168,120,0.5); }
.stat-bar-fill.luck         { box-shadow: 0 0 6px rgba(244,196,48,0.5); }
.sw-hp-fill                 { box-shadow: 0 0 8px rgba(0,168,120,0.6); }

/* Typewriter cursor at end of active typing */
.sw-typing::after {
    content: '▮';
    color: var(--loop-cyan);
    animation: boot-blink 0.5s step-end infinite;
    margin-left: 2px;
}

/* Blink cursor on footer line */
.sw-blink-cursor.sw-typed::after {
    content: ' ▮';
    color: var(--loop-cyan);
    animation: boot-blink 0.8s step-end infinite;
}

/* Row label flex layout */
.sw-row-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

/* Streak label */
.sw-streak-label {
    display: block;
    font-size: var(--font-size-xs);
    letter-spacing: 2px;
    color: var(--execution-gold);
    margin-top: 4px;
    min-height: 14px;
}

/* Corrupted state bar */
.sw-corrupted {
    color: var(--strength) !important;
    animation: sw-corrupt-pulse 1s ease-in-out infinite;
}
@keyframes sw-corrupt-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

/* Class selection — reworked buttons */
.sw-class-btn {
    position: relative;
    overflow: hidden;
}

.sw-class-icon {
    font-size: 18px;
    color: var(--cls-colour, var(--loop-cyan));
    display: block;
    margin-bottom: 4px;
}

.sw-class-select-hint {
    display: block;
    font-size: var(--font-size-xs);
    letter-spacing: 2px;
    color: var(--stagnation-grey);
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.sw-class-btn:hover .sw-class-select-hint,
.sw-class-btn:focus-visible .sw-class-select-hint {
    opacity: 1;
    color: var(--cls-colour, var(--loop-cyan));
}

/* Scan sweep on class button hover */
.sw-class-btn::after {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(
        to right,
        transparent,
        rgba(255,255,255,0.06),
        transparent
    );
    transition: left 0.3s ease;
    pointer-events: none;
}
.sw-class-btn:hover::after {
    left: 150%;
}

/* ── ZOOM INDICATOR ──────────────────────────────────────────────── */
#zoom-indicator {
    position: absolute;
    bottom: calc(var(--ui-padding) + 24px);
    right: var(--ui-padding);
    font-size: var(--font-size-xs);
    letter-spacing: 2px;
    color: var(--loop-cyan);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    padding: 3px 8px;
    border-radius: var(--panel-radius);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}
#zoom-indicator.visible {
    opacity: 1;
}

/* ── SYSTEM WINDOW BUTTON — pulse when class not chosen ─────────── */
@keyframes sw-btn-pulse {
    0%, 100% { border-color: var(--panel-border); box-shadow: none; }
    50% {
        border-color: rgba(0,242,255,0.7);
        box-shadow: 0 0 10px rgba(0,242,255,0.3);
    }
}
#btn-system.needs-attention {
    animation: sw-btn-pulse 1.8s ease-in-out infinite;
}

/* ── BOOT SEQUENCE — INTERACTIVE ELEMENTS ───────────────────────── */

/* Name input row */
.boot-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 4px 0;
}

.boot-prompt-arrow {
    color: var(--loop-cyan);
    font-size: 12px;
    flex-shrink: 0;
}

#boot-name-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--loop-cyan);
    color: var(--loop-cyan);
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 3px;
    padding: 4px 2px;
    outline: none;
    caret-color: var(--loop-cyan);
    text-transform: uppercase;
    flex: 1;
    min-width: 0;
}

#boot-name-input::placeholder {
    color: var(--stagnation-grey);
    letter-spacing: 2px;
}

#boot-name-input:focus {
    border-bottom-color: rgba(0, 242, 255, 0.8);
}

@keyframes boot-input-shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-4px); }
    40%       { transform: translateX(4px); }
    60%       { transform: translateX(-3px); }
    80%       { transform: translateX(3px); }
}

.boot-input-error {
    animation: boot-input-shake 0.35s ease;
    border-bottom-color: var(--strength) !important;
}

/* Confirm button (mobile tap) */
.boot-submit-btn {
    display: block;
    margin: 8px 0;
    background: transparent;
    border: 1px solid var(--loop-cyan);
    color: var(--loop-cyan);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 2px;
    padding: 6px 16px;
    cursor: pointer;
    border-radius: 2px;
    transition: background 0.15s;
}

.boot-submit-btn:hover,
.boot-submit-btn:active {
    background: rgba(0, 242, 255, 0.1);
}

/* Boot continue prompt */
.boot-continue {
    color: var(--stagnation-grey) !important;
    animation: boot-blink 1.2s ease-in-out infinite;
    letter-spacing: 2px;
}

/* Class options */
.boot-class-option {
    padding: 10px 0;
    cursor: pointer;
    border-left: 2px solid transparent;
    padding-left: 10px;
    transition: border-color 0.15s, background 0.15s;
    border-radius: 2px;
    line-height: 1.8;
}

.boot-class-option:hover {
    background: rgba(0, 242, 255, 0.04);
    border-left-color: var(--cls-colour, var(--loop-cyan));
}

.boot-class-option.boot-class-selected {
    border-left-color: var(--cls-colour, var(--loop-cyan));
    background: rgba(0, 242, 255, 0.06);
}

.boot-class-key {
    color: var(--stagnation-grey);
    font-size: 11px;
    letter-spacing: 2px;
}

.boot-class-name {
    font-size: 12px;
    letter-spacing: 3px;
    font-weight: bold;
}

.boot-class-desc {
    display: block;
    color: var(--stagnation-grey);
    font-size: 10px;
    letter-spacing: 1px;
    margin-top: 2px;
    padding-left: 44px;
}

/* ── Boot terminal — name input ─────────────────────────────────── */
#boot-input-area {
    margin-top: 16px;
}

.boot-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 2px;
    flex-wrap: wrap;
}

.boot-input-prefix {
    color: var(--loop-cyan);
    white-space: nowrap;
}

.boot-name-input {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--loop-cyan);
    color: var(--loop-cyan);
    font-family: var(--font-mono);
    font-size: 13px;
    letter-spacing: 2px;
    outline: none;
    width: 160px;
    caret-color: var(--loop-cyan);
    text-transform: uppercase;
}

.boot-name-input::placeholder {
    color: var(--stagnation-grey);
    opacity: 0.6;
}

.boot-name-input.boot-input-error {
    border-bottom-color: var(--strength);
    color: var(--strength);
    animation: boot-shake 0.3s ease;
}

@keyframes boot-shake {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-4px); }
    75%       { transform: translateX(4px); }
}

.boot-confirm-btn {
    background: transparent;
    border: 1px solid var(--loop-cyan);
    color: var(--loop-cyan);
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 2px;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.boot-confirm-btn:hover {
    background: rgba(0, 242, 255, 0.1);
}

.boot-input-echo {
    color: #5a7a88;
}

/* ── Boot terminal — class selection ────────────────────────────── */
.boot-class-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.boot-class-btn {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--cls-colour, var(--panel-border));
    padding: 10px 14px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--font-mono);
    position: relative;
    overflow: hidden;
}

.boot-class-btn:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: var(--cls-colour, var(--panel-border-hot));
}

.boot-class-key {
    color: var(--cls-colour, var(--loop-cyan));
    font-size: 13px;
    letter-spacing: 2px;
    white-space: nowrap;
    flex-shrink: 0;
    padding-top: 1px;
}

.boot-class-name {
    color: var(--cls-colour, var(--loop-cyan));
    font-size: 13px;
    letter-spacing: 3px;
    white-space: nowrap;
    flex-shrink: 0;
    padding-top: 1px;
}

.boot-class-desc {
    color: #5a7a88;
    font-size: 10px;
    letter-spacing: 1px;
    line-height: 1.6;
    padding-top: 3px;
}

/* Scan sweep on hover */
.boot-class-btn::after {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.04), transparent);
    transition: left 0.35s ease;
    pointer-events: none;
}
.boot-class-btn:hover::after { left: 150%; }

/* ── Boot line — prompt blink ───────────────────────────────────── */
.boot-prompt {
    color: var(--loop-cyan);
    animation: boot-blink 0.9s step-end infinite;
    letter-spacing: 2px;
    margin-top: 12px;
}

/* ── Boot opening cursor ─────────────────────────────────────────── */
#boot-opening-cursor {
    font-family: var(--font-mono);
    font-size: 20px;
    color: var(--loop-cyan);
    animation: boot-blink 0.6s step-end infinite;
    display: block;
    padding: 4px 0;
}

/* ── Boot inner — smooth fade transition between screens ─────────── */
/* JS sets opacity via style attribute during transitions.
   The transition property is applied inline by _clearScreen()
   so it only fires during screen changes, not on every render. */
/* Boot inner: no persistent transition — applied inline by _clearScreen() */
/* ── Stat / vital tooltips ───────────────────────────────────────── */
#sw-tooltip {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 11, 16, 0.97);
    border: 1px solid rgba(0, 242, 255, 0.4);
    border-radius: 2px;
    padding: 8px 14px;
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.5px;
    color: var(--loop-cyan);
    line-height: 1.6;
    max-width: 280px;
    text-align: center;
    pointer-events: none;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: normal;
}

#sw-tooltip.visible { opacity: 1; }

#sw-tooltip .tip-label {
    color: var(--execution-gold);
    letter-spacing: 2px;
    display: block;
    margin-bottom: 3px;
}

.sw-stat-label, .sw-vital-label {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

/* ════════════════════════════════════════════════════════════════════
   STEP 4 — LIFE DIRECTIVES — tabbed view
════════════════════════════════════════════════════════════════════ */

/* Header row */
.sw-dir-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
}

.sw-dir-meta {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 1px;
    color: var(--stagnation-grey);
}

/* Overall progress bar */
.sw-dir-progress { margin-bottom: 10px; height: 3px; }

/* ── Tabs ────────────────────────────────────────────────────────── */
.sw-dir-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
}

.sw-dir-tab {
    flex: 1;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(74,77,94,0.4);
    border-radius: 2px;
    color: var(--stagnation-grey);
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 2px;
    padding: 6px 0 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    min-height: 44px;
    justify-content: center;
}

.sw-dir-tab:hover {
    background: rgba(255,255,255,0.06);
    color: var(--loop-cyan);
}

.sw-dir-tab.active {
    border-color: var(--tab-colour, var(--loop-cyan));
    color: var(--tab-colour, var(--loop-cyan));
    background: rgba(0,242,255,0.06);
}

.sw-dir-tab.all-done {
    border-color: rgba(0, 168, 120, 0.5);
    color: var(--dexterity);
    background: rgba(0, 168, 120, 0.06);
}

/* Badge */
.sw-dir-badge {
    font-family: var(--font-mono);
    font-size: 8px;
    letter-spacing: 0;
    color: var(--stagnation-grey);
    background: rgba(255,255,255,0.04);
    border-radius: 2px;
    padding: 1px 4px;
}

.sw-dir-badge.badge-done {
    color: var(--dexterity);
    background: rgba(0,168,120,0.15);
}

/* ── Directive cards ─────────────────────────────────────────────── */
.sw-dir-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sw-dir-card {
    background: rgba(0,242,255,0.04);
    border: 1px solid rgba(0,242,255,0.12);
    border-radius: 2px;
    padding: 9px 10px;
    transition: background 0.15s;
}

.sw-dir-card.sw-dir-done {
    background: rgba(255,255,255,0.02);
    border-color: rgba(74,77,94,0.25);
    opacity: 0.55;
}

.sw-dir-card-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 5px;
}

.sw-dir-title {
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 1.5px;
    color: var(--loop-cyan);
    flex: 1;
    line-height: 1.4;
}

.sw-dir-done .sw-dir-title {
    text-decoration: line-through;
    color: var(--stagnation-grey);
}

.sw-dir-tier {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--stagnation-grey);
    flex-shrink: 0;
}

.sw-dir-reward {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--execution-gold);
    flex-shrink: 0;
}

/* Brief text (the mission statement) */
.sw-dir-brief {
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.5px;
    color: #6a8a98;
    line-height: 1.6;
    margin-bottom: 7px;
}

.sw-dir-done .sw-dir-brief { display: none; }

/* Complete button */
.sw-dir-complete-btn {
    display: block;
    width: 100%;
    background: transparent;
    border: 1px solid rgba(0,242,255,0.25);
    border-radius: 2px;
    color: var(--loop-cyan);
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 2px;
    padding: 6px 0;
    cursor: pointer;
    min-height: 34px;
    transition: background 0.15s, border-color 0.15s;
}

.sw-dir-complete-btn:hover  { background: rgba(0,242,255,0.08); border-color: rgba(0,242,255,0.5); }
.sw-dir-complete-btn:active { background: rgba(0,242,255,0.15); }

/* ── Reset button ────────────────────────────────────────────────── */
.sw-reset-btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    background: transparent;
    border: 1px solid rgba(230,59,46,0.25);
    border-radius: 2px;
    color: rgba(230,59,46,0.7);
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 2px;
    padding: 7px 0;
    cursor: pointer;
    min-height: var(--tap-target);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sw-reset-btn:hover {
    background: rgba(230,59,46,0.07);
    border-color: rgba(230,59,46,0.6);
    color: var(--strength);
}