/* 3D view: the canvas fills the window and every panel floats on top of it. */

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #0b0b18;
    color: #e8e8f5;
    /* Pattern 5 body: Inter, with Kanit trailing for Thai glyphs Inter lacks */
    font-family: "Inter", "Kanit", sans-serif;
}

/* Pattern 5 headings: Oswald (condensed), Kanit for Thai */
.hud-title,
.score-total,
.score-timer,
.go-title,
.modal-title {
    font-family: "Oswald", "Kanit", sans-serif;
}

#scene {
    position: fixed;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
}

/* ---- Colour grade: sits above the canvas, below every HUD panel ---- */
#grade {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    /* pull the corners down so the eye lands on the machines in the middle */
    background: radial-gradient(ellipse at 50% 45%, rgba(0, 0, 0, 0) 40%, rgba(6, 2, 14, 0.62) 100%);
}

/* Paper grain. feTurbulence is generated by the browser, so this costs no
   request and no image file. Keep it faint — at full strength it reads as
   broken video rather than print. */
#grade::after {
    content: "";
    position: absolute;
    inset: 0;
    opacity: 0.16;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- Crosshair ---- */
#crosshair {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    pointer-events: none;
    z-index: 20;
    transition: opacity 0.15s;
}
/* only meaningful while the mouse is locked; otherwise you aim with the cursor */
#crosshair.hidden { opacity: 0; }
#crosshair::before,
#crosshair::after {
    content: "";
    position: absolute;
    background: rgba(255, 255, 255, 0.75);
    transition: background 0.12s, box-shadow 0.12s;
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; margin-left: -1px; }
#crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; margin-top: -1px; }
/* aiming at a machine */
#crosshair.hot::before,
#crosshair.hot::after {
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
}

/* ---- Bottom hint ---- */
#hint {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    z-index: 20;
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(10, 10, 24, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.85rem;
    white-space: nowrap;
    pointer-events: none;
    transition: opacity 0.25s;
}
#hint.hidden { opacity: 0; }

/* ---- Score: the headline number, centred above the crosshair ---- */
.hud-score {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 15;
    text-align: center;
    /* no panel chrome here — it would box in the middle of the view. It also
       must never swallow a click meant for a machine behind it. */
    pointer-events: none;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9);
}

.score-label {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #9a9ab8;
}

.score-total {
    font-size: 4.6rem;
    font-weight: 700;   /* Oswald tops out at 700 */
    letter-spacing: 0.02em;
    line-height: 1;
    color: #f5d76e;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 26px rgba(245, 215, 110, 0.45), 0 2px 10px rgba(0, 0, 0, 0.9);
}

.score-avg {
    margin-top: 2px;
    font-size: 0.9rem;
    color: #9a9ab8;
}
.score-avg b {
    color: #4ade80;
    font-variant-numeric: tabular-nums;
}

.score-timer {
    margin-top: 6px;
    font-size: 1.5rem;
    font-weight: 500;
    color: #4ade80;
    font-variant-numeric: tabular-nums;
}
/* last 5 seconds */
.score-timer.urgent { color: #f87171; }
.score-timer.hidden { display: none; }

/* ---- End-of-game banner ---- */
#gameOver {
    position: fixed;
    top: 38%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 25;
    text-align: center;
    pointer-events: none;
    padding: 22px 40px;
    border-radius: 14px;
    background: rgba(10, 10, 24, 0.9);
    border: 1px solid rgba(245, 215, 110, 0.5);
    transition: opacity 0.3s;
}
#gameOver.hidden { opacity: 0; }

.go-title {
    font-size: 2rem;
    font-weight: 500;
    color: #f5d76e;
}
.go-score {
    margin-top: 6px;
    font-size: 1.1rem;
    color: #e8e8f5;
}
.go-best {
    margin-top: 4px;
    font-size: 0.9rem;
    color: #9a9ab8;
}

/* ---- True-value editor ---- */
.setup-rows {
    max-height: 46vh;
    overflow-y: auto;
}
.setup-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.setup-row:last-child { border-bottom: none; }
.setup-row .swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    flex: 0 0 auto;
}
.setup-row .name { flex: 1; font-size: 0.9rem; }
.setup-row input[type="number"] {
    width: 76px;
    background: #1c1c30;
    color: #e8e8f5;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    padding: 2px 6px;
}
.setup-row input[type="range"] { flex: 1 1 120px; }

/* ---- Language switch ---- */
.lang-switch {
    display: flex;
    gap: 4px;
    margin-top: 10px;
}
.lang-switch button {
    flex: 1;
    padding: 3px 0;
    font-size: 0.75rem;
    color: #9a9ab8;
    background: #1c1c30;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.lang-switch button:hover { color: #e8e8f5; }
.lang-switch button.active {
    background: #f5d76e;
    border-color: #f5d76e;
    color: #14142a;
    font-weight: 700;
}

/* ---- HUD panels ---- */
.hud {
    position: fixed;
    z-index: 10;
    background: rgba(12, 12, 28, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 12px 14px;
    backdrop-filter: blur(6px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

.hud-title {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: #f5d76e;
}

.hud-stats {
    top: 14px;
    left: 14px;
    min-width: 210px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 0.88rem;
    padding: 2px 0;
}
.stat-row span { color: #9a9ab8; }
.stat-row b { color: #4ade80; }

.help-buttons {
    margin-top: 10px;
    display: flex;
    gap: 6px;
}

.hud-controls {
    top: 14px;
    right: 14px;
    width: 280px;
    /* the panel grew past the viewport on short screens once the game-mode and
       true-value rows landed */
    max-height: calc(100vh - 28px);
    overflow-y: auto;
}

.hud-controls .ctrl {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.hud-controls .ctrl:last-child { border-bottom: none; }

.hud-controls label {
    margin: 0;
    font-size: 0.8rem;
    color: #9a9ab8;
    flex: 1 1 100%;
}

.hud-controls input[type="number"] {
    width: 62px;
    background: #1c1c30;
    color: #e8e8f5;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.85rem;
}

.check-toggle {
    flex: 1 1 100% !important;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    color: #e8e8f5 !important;
}

.hud-chart {
    right: 14px;
    bottom: 14px;
    width: 340px;
}
.hud-chart canvas {
    width: 100% !important;
    height: 140px !important;
}

/* ---- Modals: darken to match the room ---- */
.modal-content {
    background: #14142a;
    color: #e8e8f5;
    border: 1px solid rgba(255, 255, 255, 0.15);
}
.modal-header, .modal-footer { border-color: rgba(255, 255, 255, 0.1); }
.modal-content .close { color: #e8e8f5; text-shadow: none; opacity: 0.8; }
.modal-content .table { color: #e8e8f5; }
.modal-content .table-striped tbody tr:nth-of-type(odd) { background: rgba(255, 255, 255, 0.04); }
.modal-content .table td, .modal-content .table th { border-color: rgba(255, 255, 255, 0.1); }
.modal-content .text-muted { color: #9a9ab8 !important; }

/* ---- Small screens: stack the HUD so it stays usable ---- */
@media (max-width: 820px) {
    .hud-controls { width: 200px; }
    .hud-chart { width: 220px; }
    .hud-chart canvas { height: 100px !important; }
    #hint { font-size: 0.7rem; white-space: normal; text-align: center; max-width: 90vw; }
    .score-total { font-size: 2.6rem; }
    .score-label, .score-avg { font-size: 0.7rem; }
}
