/* DL2CC RufzXP TX — web port of the desktop FormRufzXPTX in the desktop's
   V2 dark-console skin (ClassRemoteControlV2Theme): graphite panels, engraved
   caption labels, amber digit readouts, LED-tinted result rows. A serious
   competition instrument, not an arcade game. */

:root {
    --panel: #1c1f26;         /* PanelBase rgb(28,31,38) — form background */
    --chrome: #2e333f;        /* ChromeBar rgb(46,51,63) */
    --surface: #21252d;       /* Surface rgb(33,37,45) — cards, rows */
    --surface-alt: #1d2128;   /* SurfaceAlternate rgb(29,33,40) */
    --divider: #343842;       /* SurfaceDivider rgb(52,56,66) */
    --border: #545b6e;        /* WindowBorder rgb(84,91,110) */
    --engraved: #aaaaaf;      /* EngravedLight rgb(170,170,175) — captions */
    --engraved-dim: #6e6e76;  /* EngravedDim rgb(110,110,118) */
    --text: #d7d8de;          /* TextPrimary rgb(215,216,222) */
    --text-strong: #ebecf0;   /* TextStrong rgb(235,236,240) */
    --well: #0a0d12;          /* ReadoutWell rgb(10,13,18) — digit wells */
    --btn-text: #dcdce1;      /* ButtonText rgb(220,220,225) */
    --btn-active: #ffc85a;    /* ButtonTextActive rgb(255,200,90) */
    --amber: #ffb230;         /* DigitActive rgb(255,178,48) — value readouts */
    --brand: #ffbe5a;         /* ChromeBrandText rgb(255,190,90) */
    --green-on: #64f582;      /* LedGreenOn rgb(100,245,130) */
    --green-off: #16341c;     /* LedGreenOff rgb(22,52,28) */
    --red-on: #ff5a46;        /* LedRedOn rgb(255,90,70) */
    --red-off: #341412;       /* LedRedOff rgb(52,20,18) */
    --mono: Consolas, "Cascadia Code", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--panel);
    color: var(--text);
    font-size: 15px;
    display: flex;
    flex-direction: column;
}

.app {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 16px 0;
    min-height: 0;
}

/* ── Header (site chrome, matches the other apps) ──────────────── */

.app-header {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--divider); padding-bottom: 10px; margin-bottom: 10px;
    flex: 0 0 auto;
}
.app-header h1 { font-size: 1.15rem; margin: 0; flex: 0 0 auto; color: var(--text-strong); }
.app-nav { display: flex; gap: 4px; flex: 1 1 auto; flex-wrap: wrap; }

.nav-switch {
    align-self: center;
    color: var(--engraved-dim);
    padding: 6px 8px;
    font-size: .9rem;
    text-decoration: none;
    white-space: nowrap;
}
.nav-switch:hover { color: var(--text); text-decoration: underline; }

.box-status { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--engraved-dim); flex-wrap: wrap; }
.box-status.connected #box-status-text { color: var(--green-on); }
.box-status button {
    background: var(--surface); color: var(--btn-text); border: 1px solid var(--divider);
    padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: .85rem;
}
.box-status button:hover:not(:disabled) { border-color: var(--border); }
.box-status button:disabled { opacity: .45; cursor: not-allowed; }

/* Box-link controls: path dropdown + pairing key (cwchat/remote pattern). */
.box-status select,
.box-status input[type="password"] {
    background: var(--surface); color: var(--text); border: 1px solid var(--divider);
    padding: 6px 8px; border-radius: 4px; font-size: .85rem;
}
.box-status select:disabled,
.box-status input[type="password"]:disabled { opacity: .45; }
.box-status input[type="password"] { width: 150px; }
.network-key-field { display: inline-flex; align-items: center; gap: 6px; }
.network-key-field[hidden] { display: none; }
.remember-inline {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: .78rem; white-space: nowrap; cursor: pointer;
}

/* ── Console: chrome bar + shell ───────────────────────────────── */

.console {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}

/* Chrome bar replacing the arcade title (ClassRemoteControlV2ChromeBar). */
.console-chrome {
    flex: 0 0 auto;
    height: 40px;
    background: linear-gradient(var(--chrome), #262b35);
    border-bottom: 1px solid var(--divider);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    font-family: var(--mono);
    user-select: none;
}
.chrome-brand {
    color: var(--brand);
    font-weight: 700;
    font-size: .82rem;
    letter-spacing: .28em;
}
.chrome-status {
    color: var(--engraved-dim);
    font-size: .68rem;
    letter-spacing: .18em;
}

.game-shell {
    flex: 1 1 auto;
    display: flex;
    gap: 1px;
    min-height: 480px;
    background: var(--divider);   /* hairline between panel and board */
    overflow: hidden;
}

.arcade-sidebar {
    position: relative;
    flex: 0 0 180px;
    background: var(--panel);
    overflow: hidden;   /* the inner .sidebar-scroll scrolls, so the settings overlay stays put */
    display: flex;
    flex-direction: column;
    font-family: var(--mono);
}

.sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

/* ── Panel building blocks ─────────────────────────────────────── */

.arcade-title-row {
    display: flex; align-items: center; justify-content: space-between;
    min-height: 28px;
}
.arcade-title {
    flex: 1 1 auto;
    color: var(--engraved-dim);
    font-weight: 700;
    font-size: .66rem;
    letter-spacing: .22em;
}
.gear-btn, .close-btn {
    flex: 0 0 auto;
    background: transparent; border: none; cursor: pointer;
    color: var(--engraved); font-size: .95rem; padding: 2px 6px; border-radius: 3px;
}
.gear-btn:hover:not(:disabled) { background: var(--surface); color: var(--text-strong); }
.gear-btn:disabled { opacity: .35; cursor: not-allowed; }
.close-btn { color: var(--red-on); border: 1px solid #6e3a32; font-size: .8rem; }
.close-btn:hover { background: var(--red-off); }

.arcade-sep { border: none; border-top: 1px solid var(--divider); margin: 5px 0; width: 100%; }

.arcade-stat { display: flex; flex-direction: column; gap: 1px; }
.cap {
    color: var(--engraved-dim);
    font-size: .64rem;
    letter-spacing: .12em;
}
.section-cap { margin-top: 9px; }
.val { font-weight: 700; line-height: 1.15; color: var(--amber); }
.val.big { font-size: 1.45rem; }
.val.mid { font-size: 1rem; color: var(--text); }

.conn-row { display: flex; justify-content: space-between; align-items: baseline; }
.mode-badge { font-size: .72rem; font-weight: 700; user-select: none; }
/* Idle only: the badge is a mode toggle (click flips PADDLE ⇆ KEYBD). */
.mode-badge.clickable { cursor: pointer; }
.mode-badge.clickable:hover { text-decoration: underline; }
.conn-text { font-size: .74rem; color: var(--engraved-dim); word-break: break-word; }

/* ── Buttons (flat machined faces, V2 rig-button styling) ──────── */

.arcade-primary {
    margin-top: 6px;
    background: linear-gradient(#2a2f3a, #232730);
    border: 1px solid var(--border);
    color: var(--btn-active);
    font-family: var(--mono);
    font-weight: 700;
    font-size: .88rem;
    letter-spacing: .06em;
    padding: 9px 0;
    border-radius: 4px;
    cursor: pointer;
}
.arcade-primary:hover { background: linear-gradient(#313848, #262b35); }
.arcade-primary:active { background: #20242c; }

.arcade-btn {
    background: linear-gradient(#2a2f3a, #232730);
    border: 1px solid var(--divider);
    color: var(--btn-text);
    font-family: var(--mono);
    font-weight: 700;
    font-size: 1rem;
    width: 36px; height: 28px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1;
}
.arcade-btn:hover:not(:disabled) { border-color: var(--border); color: var(--text-strong); }
.arcade-btn:active:not(:disabled) { background: #20242c; }
.arcade-btn:disabled { color: #787c86; border-color: var(--surface-alt); cursor: not-allowed; opacity: .6; }

.stepper { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.stepper-val {
    flex: 1 1 auto;
    text-align: center;
    color: var(--amber);
    font-family: var(--mono);
    font-weight: 700;
    font-size: 1rem;
}
.stepper-val.small { font-size: .8rem; }
.stepper-val.dim { color: var(--engraved-dim); }

.leaderboard-eligibility {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 10px;
    padding: 8px;
    border: 1px solid var(--divider);
    background: var(--well);
}
.eligibility-title {
    font-size: .61rem;
    font-weight: 700;
    letter-spacing: .08em;
}
.eligibility-detail { color: var(--engraved); font-size: .64rem; line-height: 1.35; }
.leaderboard-eligibility.eligible .eligibility-title { color: var(--green-on); }
.leaderboard-eligibility.practice .eligibility-title { color: var(--amber); }

.leaderboard-rules-note {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 6px 0 8px;
    padding: 8px;
    border-left: 3px solid var(--amber);
    background: var(--well);
    color: var(--engraved);
    font-size: .62rem;
    line-height: 1.35;
}
.leaderboard-rules-note strong { color: var(--amber); letter-spacing: .08em; }
.leaderboard-rules-note small { color: var(--engraved-dim); font-size: .6rem; }

.toggle-row { display: flex; gap: 4px; }
.arcade-toggle {
    flex: 1 1 0;
    background: var(--surface-alt);
    border: 1px solid var(--divider);
    color: var(--engraved-dim);
    font-family: var(--mono);
    font-weight: 700;
    font-size: .72rem;
    letter-spacing: .08em;
    padding: 7px 0;
    border-radius: 4px;
    cursor: pointer;
}
.arcade-toggle.active {
    background: var(--chrome);
    color: var(--btn-active);
    border-color: var(--border);
}
.arcade-toggle:disabled { opacity: .4; cursor: not-allowed; }

/* Slider in console colours. */
#vol-slider {
    width: 100%;
    margin: 4px 0 8px;
    accent-color: var(--amber);
}

/* ── Settings overlay (covers the panel, like PnlSettings) ─────── */

.settings-panel {
    position: absolute;
    inset: 0;
    background: var(--panel);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overscroll-behavior: contain;  /* don't chain scrolling into the page */
    z-index: 5;
}
.settings-panel[hidden] { display: none; }

/* Visually hidden but still focusable — must NOT use display/visibility:none
   or opacity-collapsed sizing, or iOS Safari won't open the soft keyboard. */
.game-hidden-input {
    position: absolute; left: -9999px; width: 1px; height: 1px;
    opacity: 0; border: 0; padding: 0; margin: 0;
}

/* ── Operating area (message, answer well, results table) ──────── */

.board {
    flex: 1 1 auto;
    min-width: 0;
    background: var(--panel);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 28px 20px 20px;
    overflow-y: auto;
    font-family: var(--mono);
}

.board-message {
    min-height: 1.4em;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-strong);
    text-align: center;
}
.board-message.ok { color: var(--green-on); }
.board-message.err { color: var(--red-on); }

/* The decoded/typed answer — digit well (ReadoutWell + DigitActive). */
.answer-well {
    width: min(560px, 100%);
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--well);
    border: 1px solid var(--divider);
    border-radius: 6px;
    box-shadow: inset 0 2px 8px rgba(0,0,0,.55);
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: .12em;
    color: var(--amber);
    text-transform: uppercase;
    overflow-wrap: anywhere;
    text-align: center;
    padding: 8px 14px;
    transition: background-color .12s, border-color .12s;
}
.answer-well.idle { color: #3a3f4a; }              /* unlit digits */
.answer-well.active { border-color: var(--border); }
.answer-well.correct { background: var(--green-off); border-color: #2c5c38; color: var(--green-on); }
.answer-well.wrong { background: var(--red-off); border-color: #6e3a32; color: var(--red-on); }

/* Blinking caret while an answer is being collected. */
.answer-well.active::after {
    content: "";
    display: inline-block;
    width: 3px; height: 1.2em;
    margin-left: 6px;
    background: var(--amber);
    animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

.board-instructions {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: .85rem;
    color: var(--engraved-dim);
    text-align: center;
    max-width: 560px;
}

/* Per-round results — revealed at run end; LED row tints like the
   desktop dgvResults (green = correct, red = wrong). */
.results-wrap {
    width: min(560px, 100%);
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--divider);
    border-radius: 6px;
}
.results-wrap[hidden] { display: none; }
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .85rem;
}
.results-table th {
    position: sticky; top: 0;
    background: var(--chrome);
    color: var(--engraved);
    font-size: .68rem;
    letter-spacing: .1em;
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--divider);
}
.results-table td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--surface-alt);
    color: var(--text);
    background: var(--surface);
    white-space: nowrap;
}
.results-table tr.correct td { background: var(--green-off); color: var(--green-on); }
.results-table tr.wrong td { background: var(--red-off); color: var(--red-on); }
.results-table td.num { text-align: right; }

/* ── Legal footer ──────────────────────────────────────────────── */

.legal-footer {
    flex: 0 0 auto;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
    font-size: .8rem; color: var(--engraved-dim);
}
.legal-footer a, .legal-footer a:visited { color: inherit; text-decoration: none; }
.legal-footer a:hover { text-decoration: underline; }
.legal-footer .sep { color: var(--divider); }
.legal-footer .copy { margin-left: auto; }

/* ── Small screens: panel shrinks, shell stacks ────────────────── */

@media (max-width: 640px) {
    .app { padding: 8px 8px 0; }
    .game-shell { flex-direction: column; min-height: 0; }
    .arcade-sidebar { flex: 0 0 auto; max-height: 44vh; }
    /* Stats pack into three columns; every control row keeps full width so
       captions stay glued to their steppers. */
    .sidebar-scroll {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        align-items: start;
        column-gap: 8px;
    }
    .sidebar-scroll > * { grid-column: 1 / -1; }
    .sidebar-scroll > .arcade-stat { grid-column: auto; }
    .board { flex: 1 1 auto; min-height: 320px; padding: 18px 10px 14px; }
    .answer-well { font-size: 1.6rem; }
    .settings-panel { position: fixed; inset: 0; z-index: 50; }
    .legal-footer .copy { margin-left: 0; flex-basis: 100%; }
}

/* -- Box-connect dock -------------------------------------------- */
/* Moved out of the header so the main content owns the top of the
   screen; the link controls sit in their own strip above the footer. */

.box-dock {
    flex: 0 0 auto;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
}
.box-dock .box-status {
    border-top: 1px solid var(--divider);
    padding-top: 10px;
}
