/* BlackBox web game and account pages. Mirrors the WPF app: src/BlackBox/Themes/Controls.xaml and Board.xaml.
   Keep the token names close to the XAML brush names so a change in one is easy to carry to the other. */
:root {
    /* Controls.xaml */
    --page: #0d1117;            /* PageBrush */
    --card: #151b24;            /* CardBrush */
    --card-border: #252d3a;     /* CardBorderBrush */
    --text: #e6eaf0;            /* PrimaryTextBrush */
    --muted: #8b95a7;           /* SecondaryTextBrush */
    --accent-button: #1fa597;   /* AccentButtonBrush */
    --accent-button-hover: #27bdae;
    --danger: #ff7b7f;          /* DangerTextBrush */
    --success: #3dd68c;         /* SuccessTextBrush */
    --warning: #f5b83d;         /* WarningTextBrush */
    --flat: #1f2732;            /* FlatButton background */
    --flat-border: #303a49;
    --flat-hover: #283242;
    --flat-pressed: #18202a;
    --segment-checked: #2a3443;
    --row-alt: #18202a;
    --row-hover: #222b38;
    --row-selected: #17423d;
    --header-row: #1a212c;
    --notice: #16302c;          /* the teal notice / "new" tag */
    --latest-row: #12241f;
    --toast: #1c2430f2;
    --gold: #e0b23a;
    --silver: #aeb7c4;
    --bronze: #c07a45;
    /* Board.xaml */
    --box: #07090d;
    --box-border: #2a3140;
    --cell: #121721;
    --cell-hover: #1d2533;
    --cell-stroke: #1f2735;
    --port: #1a202b;
    --port-stroke: #3a4456;
    --port-text: #9aa6b8;
    --accent: #2ec4b6;
    --hit: #e5484d;
    --reflection: #f5b83d;
    --correct: #3dd68c;
    --wrong: #e5484d;
    --missed: #f5b83d;

    --radius-card: 12px;
    --radius-control: 8px;
    --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--page);
    color: var(--text);
    font: 14px/1.45 var(--font);
}
a { color: var(--accent-button-hover); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 0.95em; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ----- text styles (PageTitle, SectionTitle, Muted, FieldLabel, StatValue) ----- */
.brand-title { font-size: 44px; font-weight: 700; letter-spacing: 0; margin: 0; line-height: 1.1; }
.page-title { font-size: 28px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { font-size: 16px; font-weight: 600; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.field-label { display: block; color: var(--muted); font-size: 12px; margin: 0 0 4px; }
.stat-value { font-size: 26px; font-weight: 600; }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }
.warning-text { color: var(--warning); }
.center { text-align: center; }

/* ----- layout ----- */
.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 40px 40px;
}
.page.narrow { max-width: 560px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .page-title { flex: 1 1 auto; min-width: 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }

/* The account strip above every page: small, right-aligned, out of the app's way. */
.account-bar {
    display: flex; align-items: center; gap: 6px; justify-content: flex-end;
    max-width: 1100px; margin: 0 auto; padding: 10px 40px 0;
    font-size: 13px; color: var(--muted);
}
.account-bar .who { color: var(--text); font-weight: 600; }
.account-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; }
.account-bar form { display: inline; margin: 0; }

/* ----- Card ----- */
.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-card);
    padding: 20px;
}
.card.compact { padding: 14px 20px; }
.card + .card { margin-top: 16px; }

/* ----- buttons: FlatButton, AccentButton, LinkButton ----- */
.btn, button.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 36px; padding: 8px 16px;
    font: inherit; font-size: 14px; color: var(--text);
    background: var(--flat); border: 1px solid var(--flat-border); border-radius: var(--radius-control);
    cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--flat-hover); text-decoration: none; }
.btn:active { background: var(--flat-pressed); }
.btn:disabled, .btn.disabled { opacity: 0.45; cursor: default; pointer-events: none; }
.btn.accent { color: #fff; font-weight: 600; background: var(--accent-button); border-color: var(--accent-button); }
.btn.accent:hover { background: var(--accent-button-hover); }
.btn.accent:active { opacity: 0.85; }
.btn.accent:disabled { opacity: 0.4; }
.btn.big { min-height: 44px; font-size: 16px; }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 30px; padding: 4px 14px; }
.btn.danger { color: var(--danger); }
.btn.link { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 10px; }
.btn.link:hover { background: var(--flat); color: var(--text); }
.btn .icon { width: 16px; height: 16px; flex: none; }
.back-link { margin-left: -10px; }

/* ----- form controls (Fluent dark TextBox / ComboBox / CheckBox look) ----- */
.field { display: block; margin: 0 0 14px; }
.field > .field-label { margin-bottom: 4px; }
.input, .select, textarea.input {
    display: block; width: 100%;
    min-height: 34px; padding: 6px 11px;
    font: inherit; color: var(--text);
    background: #1d232c; border: 1px solid #2c3442; border-bottom-color: #4a5466; border-radius: 4px;
}
.input:hover, .select:hover { background: #222934; }
.input:focus, .select:focus { outline: none; background: #141920; border-bottom: 2px solid var(--accent); padding-bottom: 5px; }
.input.otp { font-family: var(--mono); font-size: 22px; letter-spacing: 0.3em; text-align: center; max-width: 220px; }
.select { appearance: none; padding-right: 32px; cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
    background-size: 5px 5px; background-repeat: no-repeat; }
.select option { background: #1d232c; color: var(--text); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent-button); margin: 0; }
.field-error { display: block; color: var(--danger); font-size: 12px; margin-top: 4px; }
.hint { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type="range"] { accent-color: var(--accent-button); width: 100%; }

/* Segmented switch (Points / Time) */
.segment { display: inline-flex; padding: 2px; background: var(--card); border: 1px solid var(--card-border); border-radius: 6px; }
.segment button, .segment a {
    font: inherit; font-size: 12px; color: var(--muted); background: transparent; border: 0; border-radius: 5px;
    padding: 3px 10px; cursor: pointer; text-decoration: none;
}
.segment button:hover, .segment a:hover { background: var(--flat); }
.segment .on, .segment [aria-pressed="true"] { background: var(--segment-checked); color: var(--text); }

/* ----- notices, flash, toast ----- */
.notice {
    padding: 10px 14px; border-radius: var(--radius-control);
    background: var(--notice); border: 1px solid var(--accent-button);
    margin: 0 0 16px;
}
.notice.error { background: #2d1416; border-color: #7a2e33; }
.notice.warning { background: #2d2410; border-color: #7a5d1d; }
.notice.info { background: #172131; border-color: #2f4a70; }
.toast {
    position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 50;
    max-width: min(560px, calc(100vw - 32px));
    display: flex; align-items: center; gap: 10px;
    padding: 8px 6px 8px 14px; border-radius: var(--radius-control);
    background: var(--toast); border: 1px solid var(--card-border);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.45); font-size: 13px;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.toast .btn.link { padding: 0 8px; min-height: 26px; }

/* ----- tables (DataGrid) ----- */
.table-wrap { background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius-control); overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
    background: var(--header-row); color: var(--muted); font-weight: 600; text-align: left;
    padding: 8px 12px; border-bottom: 1px solid var(--card-border); white-space: nowrap;
}
table.grid th.num, table.grid td.num { text-align: right; }
table.grid td { padding: 7px 12px; }
table.grid tbody tr:nth-child(even) { background: var(--row-alt); }
table.grid tbody tr.clickable { cursor: pointer; }
table.grid tbody tr.clickable:hover { background: var(--row-hover); }
table.grid tbody tr.selected { background: var(--row-selected); color: #fff; }

/* ----- leaderboard row (LeaderRowTemplate) ----- */
.leaders { list-style: none; margin: 0; padding: 0; }
.leaders li {
    display: grid; grid-template-columns: 30px 1fr auto 56px; align-items: center;
    padding: 4px 6px; margin: 1px 0; border-radius: 6px;
}
.leaders .badge {
    width: 22px; height: 22px; border-radius: 11px; background: var(--card-border);
    display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600;
}
.leaders .rank-1 .badge { background: var(--gold); color: #201600; }
.leaders .rank-2 .badge { background: var(--silver); color: #151b24; }
.leaders .rank-3 .badge { background: var(--bronze); color: #201000; }
.leaders .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaders .pts { font-weight: 600; padding-left: 8px; }
.leaders .time { color: var(--muted); text-align: right; }
.leaders.by-time .pts { font-weight: 400; color: var(--muted); }
.leaders.by-time .time { font-weight: 600; color: var(--text); }
.leaders .me .name { font-weight: 600; color: var(--success); }
.leaders .latest { background: var(--latest-row); }
.tag { display: inline-block; margin-left: 8px; padding: 0 5px; font-size: 11px; border-radius: 4px;
    background: var(--notice); border: 1px solid var(--accent-button); }

/* ----- account pages ----- */
.auth { max-width: 440px; margin: 0 auto; }
.auth .brand-title { font-size: 36px; text-align: center; margin: 16px 0 4px; }
.auth .brand-title a { color: var(--text); text-decoration: none; }
.auth .lead { text-align: center; margin: 0 0 20px; }
.auth form .btn.accent { margin-top: 6px; }
.auth .below { text-align: center; margin-top: 14px; }
.qr { display: flex; justify-content: center; margin: 14px 0; }
.qr img, .qr canvas { background: #fff; padding: 10px; border-radius: 8px; }
.secret { display: block; text-align: center; letter-spacing: 0.08em; margin-bottom: 14px; }
.codes { columns: 2; list-style: none; padding: 0; margin: 14px 0; font-family: var(--mono); font-size: 15px; }
.codes li { padding: 4px 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.stats .field-label { margin: 0; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--card-border); }
.list-plain li:first-child { border-top: 0; }
details.danger-zone summary { cursor: pointer; color: var(--danger); }

/* ----- small screens ----- */
@media (max-width: 860px) {
    .cols { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .page { padding: 20px 16px 32px; }
    .account-bar { padding: 10px 16px 0; }
    .brand-title { font-size: 36px; }
    .page-title { font-size: 22px; }
    .grid2 { grid-template-columns: 1fr; }
    .codes { columns: 1; }
}

/* =====================================================================================================
   The game (server/public/assets/js). Sizes follow the XAML: board 560 + 2x10 padding in a Viewbox,
   side panel 340 wide with a 24 gap, cards 12 radius / 20 padding.
   ===================================================================================================== */

.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; flex: none; }
.m0 { margin: 0; }
.m2 { margin: 2px 0 0; }
.mt4 { margin-top: 4px; }
.mt8 { margin-top: 8px; }
.mt10 { margin-top: 10px; }
.mt12 { margin-top: 12px; }
.mt16 { margin-top: 16px; }
.mb8 { margin-bottom: 8px; }
.mb20 { margin: 2px 0 20px; }
.strong { font-weight: 600; }
.text { color: var(--text); }
.right { text-align: right; }
.nowrap { flex-wrap: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.big-value { font-size: 20px; font-weight: 600; }
.head-row { margin-bottom: 8px; flex-wrap: nowrap; }
.head-row.top { align-items: flex-start; }
.page.wide { max-width: 1400px; padding: 24px; }
.card.inner { padding: 12px 14px; }

/* ----- home ----- */
.mt24 { margin-top: 24px; }
.block { display: block; }
.home .hero {
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 32px; align-items: center;
    padding: 32px; border-radius: 16px; border: 1px solid var(--card-border); position: relative; overflow: hidden;
    background:
        radial-gradient(circle at 85% 30%, rgba(46, 196, 182, 0.22), transparent 55%),
        radial-gradient(circle at 10% 110%, rgba(76, 141, 255, 0.16), transparent 50%),
        var(--card);
}
.hero-title {
    font-size: clamp(44px, 7vw, 76px); letter-spacing: 0.06em;
    background: linear-gradient(100deg, #fff 20%, var(--accent) 60%, #4c8dff 100%);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    text-shadow: 0 0 40px rgba(46, 196, 182, 0.25);
}
.hero-lead { font-size: 17px; line-height: 1.5; color: var(--text); margin: 12px 0 24px; max-width: 34em; }
.btn.hero-play {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 56px; padding: 0 32px; font-size: 19px; border-radius: 12px;
    box-shadow: 0 0 0 0 rgba(46, 196, 182, 0.5); animation: hero-pulse 2.4s ease-out infinite;
}
.btn.hero-play .icon { width: 20px; height: 20px; fill: currentColor; stroke: none; }
.btn.hero-play:disabled { animation: none; }
@keyframes hero-pulse { 70% { box-shadow: 0 0 0 16px rgba(46, 196, 182, 0); } 100% { box-shadow: 0 0 0 0 rgba(46, 196, 182, 0); } }
.hero-board { max-width: 420px; width: 100%; justify-self: center; filter: drop-shadow(0 12px 40px rgba(0, 0, 0, 0.5)); }
.board.demo { pointer-events: none; }
.board.demo .cell.path { transition: background 0.3s, border-color 0.3s; }
.big-menu { display: grid; gap: 10px; }
.btn.big-tile {
    display: flex; align-items: center; gap: 16px; justify-content: flex-start; text-align: left;
    min-height: 76px; padding: 14px 20px; border-radius: 12px; font-size: 18px;
}
.btn.big-tile .icon { width: 30px; height: 30px; flex: none; color: var(--accent); }
.btn.big-tile:hover { border-color: var(--accent-button); }
.tile-text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.lock-tag { flex: none; font-size: 12px; color: var(--muted); border: 1px solid var(--flat-border); border-radius: 999px; padding: 2px 10px; }
.locked-card { text-align: center; }
.locked-card .row { justify-content: center; }
.locked-icon { font-size: 36px; line-height: 1; margin-bottom: 8px; }
.tile-title { font-weight: 600; font-size: 19px; }
.tile-sub { font-size: 13px; color: var(--muted); }
.latest-list { margin-top: 8px; }
.latest-row {
    display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 8px; margin: 0 -8px; box-sizing: content-box;
    background: none; border: 0; border-top: 1px solid var(--card-border); color: inherit; font: inherit; text-align: left; cursor: pointer;
    border-radius: 6px;
}
.latest-row:first-child { border-top-color: transparent; }
.latest-row:hover { background: var(--row-hover); }
.latest-row .grow { min-width: 0; }
.latest-leader { display: flex; align-items: center; gap: 8px; text-align: right; flex: none; }
.trophy { font-size: 18px; }
.reward-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px;
    background: var(--notice); border: 1px solid var(--accent-button); font-size: 13px; }
.reward-banner { border-color: var(--gold); background: linear-gradient(120deg, rgba(224, 178, 58, 0.14), var(--card) 60%); }
.reward-banner p + p { margin-top: 4px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.badge-card { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 10px;
    background: var(--card); border: 1px solid var(--card-border); }
.badge-card.unlocked { border-color: var(--gold); background: linear-gradient(135deg, rgba(224, 178, 58, 0.12), var(--card) 55%); }
.badge-medal { font-size: 28px; line-height: 1; flex: none; width: 36px; text-align: center; }
.badge-card.locked .badge-medal { filter: grayscale(1); opacity: 0.35; }
.badge-card.locked .badge-text > .strong { color: var(--muted); }
.badge-text { min-width: 0; display: grid; gap: 2px; }
.badge-progress { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.badge-progress .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--card-border); overflow: hidden; }
.badge-progress .fill { display: block; height: 100%; background: var(--accent-button); }
.standing.with-rewards { grid-template-columns: 30px 1fr 50px 50px 40px 36px; }
details.random-fold summary { cursor: pointer; margin: 0; list-style-position: inside; }
.hero .guide-link { display: block; margin-top: 16px; }
@media (prefers-reduced-motion: reduce) { .btn.hero-play { animation: none; } }
@media (max-width: 860px) {
    .home .hero { grid-template-columns: 1fr; padding: 24px 20px; gap: 20px; }
    .hero-title { font-size: clamp(40px, 13vw, 64px); }
    .hero-board { max-width: 320px; }
}
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.player-card { display: flex; align-items: center; gap: 8px; }
.player-card .select { margin-top: 4px; }
.player-name { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; margin: 2px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; flex: none; }
.legend { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.legend-dot { width: 26px; height: 26px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; color: #fff; }
.legend-dot.hit { background: var(--hit); }
.legend-dot.reflection { background: var(--reflection); color: #201600; }
.legend-dot.detour { background: #4c8dff; }
.legend-dot.missed { background: radial-gradient(circle at 35% 30%, #fff0cc 0%, #f5b83d 45%, #7a5512 100%); }

/* ----- how-to-play guide (GuideView.xaml) ----- */
.guide-progress { flex-wrap: nowrap; gap: 8px; }
.guide-dots { display: flex; gap: 6px; flex-wrap: wrap; }
.guide-dot {
    width: 24px; height: 24px; border-radius: 50%; padding: 0; cursor: pointer; font: inherit; font-size: 11px; font-weight: 600;
    background: var(--port); border: 1.5px solid var(--port-stroke); color: var(--port-text);
}
.guide-dot:hover { border-color: var(--accent); }
.guide-dot.current { background: var(--accent-button); border-color: var(--accent-button); color: #fff; }
.guide-text { font-size: 15px; line-height: 22px; margin: 16px 0 0; }
.guide-done { border-color: var(--accent-button); }
.guide-last { color: var(--accent); }
.guide-result { font-size: 22px; }
.guide-nav { gap: 8px; }
.guide-link { display: inline-block; margin-top: 6px; font-size: 14px; color: var(--accent); }

/* ----- account strip on the game pages ----- */
#account:empty { display: none; }
#account .icon { color: var(--muted); }

/* ----- play page: board left, side panel right (GameView / EditorView) ----- */
.play-page {
    display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px;
    padding: 24px; max-width: 1400px; margin: 0 auto; align-items: start;
}
.side { min-width: 0; }
.side-top { margin: 0 0 8px -10px; flex-wrap: nowrap; gap: 2px; }
.side-top .grow-left { margin-right: auto; }
.toggle {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 6px;
    background: transparent; border: 0; color: var(--muted); font: inherit; cursor: pointer;
}
.toggle:hover { background: var(--flat); }
.toggle:disabled { opacity: 0.35; cursor: default; }
.toggle.off { opacity: 0.7; text-decoration: line-through; }
.result-title { font-size: 26px; font-weight: 600; }
.divider { border-top: 1px solid var(--card-border); margin-top: 14px; padding-top: 12px; }
.divider p { margin: 0 0 6px; }
.ellipsis-row { line-height: 1; margin: -2px 0 -4px; }

/* ----- the board (Board.xaml) ----- */
.board { container-type: inline-size; width: 100%; max-width: min(100%, calc(100vh - 48px)); margin: 0 auto; }
.board-box {
    background: var(--box); border: 1px solid var(--box-border); border-radius: 3.1cqw; padding: 1.72cqw;
    aspect-ratio: 1;
}
.board-grid { display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(10, 1fr); width: 100%; height: 100%; }
.board-grid > * { min-width: 0; min-height: 0; }
.cell, .port { position: relative; padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.cell:disabled, .port:disabled { cursor: default; }
.cell {
    margin: 0.345cqw; border-radius: 1.03cqw; background: var(--cell); border: 1px solid var(--cell-stroke);
}
.cell:not(:disabled):hover { background: var(--cell-hover); }
.cell > span { position: absolute; display: none; pointer-events: none; }
.cell .atom { inset: 1.2cqw; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #b8fff6 0%, #2ec4b6 45%, #0b5f5a 100%); }
.cell .ring { inset: 0.52cqw; border-radius: 50%; border: 0.52cqw dotted var(--missed); }
.cell .cross { inset: 2.6cqw; }
.cell .cross::before, .cell .cross::after {
    content: ""; position: absolute; left: 50%; top: -12%; width: 0.69cqw; height: 124%; margin-left: -0.345cqw;
    border-radius: 0.4cqw; background: var(--wrong); transform: rotate(45deg);
}
.cell .cross::after { transform: rotate(-45deg); }
.cell[data-state="guess"] .atom, .cell[data-state="atom"] .atom { display: block; }
.cell[data-state="correct"] { border-color: var(--correct); }
.cell[data-state="correct"] .atom { display: block; background: radial-gradient(circle at 35% 30%, #d3ffe6 0%, #3dd68c 45%, #146b41 100%); }
.cell[data-state="wrong"] { border-color: var(--wrong); }
.cell[data-state="wrong"] .cross { display: block; }
.cell[data-state="missed"] .atom { display: block; opacity: 0.85; background: radial-gradient(circle at 35% 30%, #fff0cc 0%, #f5b83d 45%, #7a5512 100%); }
.cell[data-state="missed"] .ring { display: block; }
.port .disc {
    position: absolute; inset: 1.03cqw; border-radius: 50%; background: var(--port); border: 0.26cqw solid var(--port-stroke);
}
.port .label {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 2.6cqw; font-weight: 600; color: var(--port-text);
}
.port:not(:disabled):hover .disc { border-color: var(--accent); }
.port:not(:disabled):hover .label { color: #fff; }
.port.hit .disc { background: var(--hit); border-color: var(--hit); }
.port.reflection .disc { background: var(--reflection); border-color: var(--reflection); }
.port.detour .disc { background: var(--detour); border-color: var(--detour); }
.port.hit .label, .port.detour .label { color: #fff; }
.port.reflection .label { color: #201600; }
/* How-to-play guide: the cells a ray went through (PathBrush) and the port to click (pulsing halo). */
.cell.path { background: #16302c; border-color: var(--accent-button); }
.port.target::before {
    content: ""; position: absolute; inset: 0.17cqw; border-radius: 50%; background: var(--accent);
    animation: port-pulse 0.7s ease-in-out infinite alternate;
}
.port.target .disc { border-color: var(--accent); border-width: 0.45cqw; }
.port.target .label { color: #fff; }
@keyframes port-pulse { from { opacity: 0.1; } to { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .port.target::before { animation: none; opacity: 0.35; } }

/* ----- dialogs (InputDialog / message boxes) ----- */
.dialog-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog {
    width: min(440px, 100%); background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius-card);
    padding: 20px; box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.dialog p { margin: 0 0 10px; }
.dialog-buttons { margin-top: 16px; }
.dialog-buttons .btn { min-width: 90px; }

/* ----- library ----- */
.filters { display: grid; grid-template-columns: minmax(180px, 2fr) 1fr 1fr 1fr auto; gap: 8px; margin: 16px 0 12px; align-items: center; }
.library-layout { display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 20px; align-items: start; }
table.grid.games td { height: 36px; }
table.grid th .sort { all: unset; cursor: pointer; }
table.grid th[aria-sort="ascending"] .sort::after { content: " \25B2"; font-size: 9px; }
table.grid th[aria-sort="descending"] .sort::after { content: " \25BC"; font-size: 9px; }
.webcell { white-space: nowrap; text-align: center; }
.webdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #3a4456; margin: 0 2px; vertical-align: middle; }
.webdot.from { background: #4c9aff; }
.webdot.on { background: #3dd68c; }
.web-legend .webdot { margin: 0 5px 0 14px; width: 8px; height: 8px; }
.table-foot { margin-top: 8px; padding-left: 2px; }
.empty-state { text-align: center; padding: 60px 20px; }
.details .detail-title { font-size: 22px; font-weight: 600; margin: 0; overflow-wrap: anywhere; }
.code-big { font-size: 16px; }
.history-row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--card-border); }

/* ----- leaderboards ----- */
.segment.big button { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.leader-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.board-tools { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.board-tools .grow { min-width: 200px; }
.boards { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.board-card { width: 330px; padding: 14px 16px; }
.board-card + .board-card { margin-top: 0; }
.board-card .leaders { margin: 8px -6px 0; }
.board-name { font-size: 15px; }
.standing { display: grid; grid-template-columns: 30px 1fr 54px 54px 44px; align-items: center; padding: 5px 6px; margin: 1px 0; border-radius: 6px; }
.standing.head { padding-bottom: 4px; }
.standing .num { text-align: right; }
.standing .badge { width: 22px; height: 22px; border-radius: 11px; background: var(--card-border); display: inline-flex;
    align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.standing.rank-1 .badge { background: var(--gold); color: #201600; }
.standing.rank-2 .badge { background: var(--silver); color: #151b24; }
.standing.rank-3 .badge { background: var(--bronze); color: #201000; }
.standing .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing.me { background: var(--latest-row); }
.standing.me .name { font-weight: 600; color: var(--success); }
.progress { height: 3px; margin-bottom: 12px; border-radius: 2px; overflow: hidden; background: var(--flat); position: relative; }
.progress::after { content: ""; position: absolute; inset: 0; width: 30%; background: var(--accent); animation: progress 1.1s ease-in-out infinite; }
@keyframes progress { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.sync-bar { flex-wrap: nowrap; }
.sync-status { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- settings ----- */
.settings-page { max-width: 1100px; padding: 24px 40px; }
.list-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid var(--card-border); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.pad-top { padding-top: 34px; }
.slider-row { flex-wrap: nowrap; }
.slider-row input[type="range"] { flex: 1 1 auto; }
.pct { width: 44px; text-align: right; flex: none; }
.effect-row {
    display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(200px, 1.3fr) minmax(150px, 1fr) auto; gap: 16px;
    align-items: center; padding: 12px 0; border-top: 1px solid var(--card-border);
}
.btn[aria-pressed="true"] { background: var(--segment-checked); border-color: var(--accent-button); }

/* ----- smaller screens ----- */
@media (max-width: 1100px) {
    .library-layout { grid-template-columns: 1fr; }
    .effect-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
    .play-page { grid-template-columns: 1fr; padding: 16px; }
    .board { max-width: 640px; }
    .leader-layout { grid-template-columns: 1fr; }
    .filters { grid-template-columns: 1fr 1fr; }
    .filters .input { grid-column: 1 / -1; }
    .two-col { grid-template-columns: 1fr; gap: 12px; }
    .pad-top { padding-top: 0; }
}
@media (max-width: 600px) {
    .page.wide, .settings-page { padding: 16px; }
    .board-card { width: 100%; }
    .effect-row { grid-template-columns: 1fr; gap: 8px; }
    table.grid.games th:nth-child(n+3):not(:nth-child(5)), table.grid.games td:nth-child(n+3):not(:nth-child(5)) { display: none; }
}
