:root {
  --font-ui: "Zen Kaku Gothic New", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Zen Kaku Gothic New", ui-sans-serif, system-ui, sans-serif;

  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e5e2db;
  --border-strong: #d4d0c6;
  --ink: #16161a;
  --text: #1f1f24;
  --sub: #66646c;
  --muted: #a3a0a8;
  --primary: #16161a;
  --primary-ink: #ffffff;
  --accent: #f5a524;
  --accent-soft: #fdf1dc;
  --line: #2856e0;
  --success: #138a4c;
  --success-soft: #e3f4ea;
  --danger: #d6382f;
  --cross: #c9473f;
  --maybe: #c28a0c;
  --hover: rgba(40, 86, 224, 0.12);
  --sol: rgba(19, 138, 76, 0.6);
  --board-bg: #ffffff;
  --hint: #e0870b;
  --hint-bg: rgba(245, 165, 36, 0.18);
  --shadow-sm: 0 1px 2px rgba(20, 18, 12, .05);
  --shadow: 0 1px 2px rgba(20, 18, 12, .04), 0 4px 16px rgba(20, 18, 12, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111114; --surface: #1a1a1f; --surface-2: #23232a; --border: #2c2c34; --border-strong: #3a3a44;
    --ink: #f1f0ed; --text: #e9e8e4; --sub: #9e9ca6; --muted: #67656e;
    --primary: #f1f0ed; --primary-ink: #111114; --accent: #f5a524; --accent-soft: #2e2414;
    --line: #7ea3ff; --success: #3ccf80; --success-soft: #16291e; --danger: #ff6359;
    --cross: #ff7d75; --maybe: #f2c14e; --hover: rgba(126, 163, 255, .15); --sol: rgba(60, 207, 128, .55);
    --board-bg: #17171c; --hint: #f5a524; --hint-bg: rgba(245, 165, 36, 0.16); --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111114; --surface: #1a1a1f; --surface-2: #23232a; --border: #2c2c34; --border-strong: #3a3a44;
  --ink: #f1f0ed; --text: #e9e8e4; --sub: #9e9ca6; --muted: #67656e;
  --primary: #f1f0ed; --primary-ink: #111114; --accent: #f5a524; --accent-soft: #2e2414;
  --line: #7ea3ff; --success: #3ccf80; --success-soft: #16291e; --danger: #ff6359;
  --cross: #ff7d75; --maybe: #f2c14e; --hover: rgba(126, 163, 255, .15); --sol: rgba(60, 207, 128, .55);
  --board-bg: #17171c; --hint: #f5a524; --hint-bg: rgba(245, 165, 36, 0.16); --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 2px rgba(0,0,0,.35), 0 6px 20px rgba(0,0,0,.3);
  color-scheme: dark;
}

.size-seg { display: flex; margin-bottom: 6px; }
.size-seg button { flex: 1; font-variant-numeric: tabular-nums; }
:root { --tier0: #1f9d57; --tier1: #2f7fd8; --tier2: #e08a12; --tier3: #d63a5e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tier0: #3fcf7f; --tier1: #6aa8ff; --tier2: #f5a524; --tier3: #ff6b8b; } }
:root[data-theme="dark"] { --tier0: #3fcf7f; --tier1: #6aa8ff; --tier2: #f5a524; --tier3: #ff6b8b; }
.rating { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; font-variant-numeric: tabular-nums; cursor: help; }
.rating svg { display: block; flex-shrink: 0; }
.rating .track { fill: none; stroke: var(--border); stroke-width: 3.2; }
.rating .arc { fill: none; stroke-width: 3.2; stroke-linecap: round; stroke: var(--tier, var(--text)); }
.rating b { font: 600 13px var(--font-display); color: var(--tier, var(--text)); }
.rating.t0 { --tier: var(--tier0); } .rating.t1 { --tier: var(--tier1); } .rating.t2 { --tier: var(--tier2); } .rating.t3 { --tier: var(--tier3); }
.game-title span#diffLabel { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.daily h2 .rating b { font-size: 16px; }

/* ---------- game ---------- */
.timer-group { display: flex; align-items: center; gap: 2px; }
.menu-anchor { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.16); padding: 6px; min-width: 250px; z-index: 40; animation: fade .12s; }
.menu button { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 0; background: none; padding: 9px 12px; border-radius: 9px; text-align: left; font-weight: 500; font-size: 14.5px; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }
.menu .sw { width: 30px; height: 18px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .15s; flex-shrink: 0; }
.menu .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.menu .sw.on { background: var(--success); }
.menu .sw.on::after { transform: translateX(12px); }

/* context strip: opponents / daily stats */
.strip { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 14px; color: var(--sub); min-height: 24px; }
.strip .stat b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.strip .sep { color: var(--muted); }
.strip .link { font-size: 14px; color: var(--sub); }

/* result / status banner */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 14px 20px; box-shadow: var(--shadow-sm); animation: rise .25s ease-out; }
.banner.win { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.banner-main { display: flex; flex-direction: column; gap: 1px; }
.banner-main > b { font: 600 19px var(--font-display); letter-spacing: -.01em; }
.banner-sub { font-size: 14px; color: var(--sub); }
.banner-sub > span { display: block; margin-top: 2px; }
.banner-sub strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.banner-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner select { padding: 8px 10px; font-size: 14px; }

.play { display: flex; flex-direction: column; gap: 12px; }
.board-wrap { position: relative; display: flex; justify-content: center; background: var(--board-bg); border: 1px solid var(--border); border-radius: 20px; padding: 12px; box-shadow: var(--shadow); min-height: 240px; }
#board { touch-action: none; display: block; user-select: none; -webkit-user-select: none; }
.board-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in srgb, var(--board-bg) 85%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: 20px; text-align: center; padding: 24px; }
.board-overlay .ov { display: flex; flex-direction: column; gap: 10px; align-items: center; max-width: 340px; }
.board-overlay h3 { font-size: 24px; }
.board-overlay p { margin: 0 0 6px; color: var(--sub); }
.spinner { width: 26px; height: 26px; border: 2.5px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; }
.tools .q { font: 700 15px var(--font-display); color: var(--maybe); width: 16px; text-align: center; }

/* lobby */
.switch-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; margin-bottom: 20px; cursor: pointer; }
.switch-row b { display: block; font-weight: 600; font-size: 14.5px; }
.switch-row small { color: var(--sub); font-size: 13px; }
.switch-row input { appearance: none; -webkit-appearance: none; width: 40px; height: 24px; border-radius: 99px; background: var(--border-strong); position: relative; cursor: pointer; flex-shrink: 0; padding: 0; border: 0; transition: background .15s; }
.switch-row input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch-row input:checked { background: var(--text); }
.switch-row input:checked::after { transform: translateX(16px); }
.settings { width: 100%; display: flex; flex-direction: column; }
.more-rules { width: 100%; margin-bottom: 18px; text-align: left; border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; }
.more-rules summary { cursor: pointer; padding: 11px 0; display: flex; flex-direction: column; list-style: none; }
.more-rules summary::-webkit-details-marker { display: none; }
.more-rules summary span { font-weight: 600; font-size: 14.5px; display: flex; justify-content: space-between; }
.more-rules summary span::after { content: "Edit"; color: var(--sub); font-weight: 500; font-size: 13.5px; }
.more-rules[open] summary span::after { content: "Done"; }
.more-rules summary small { color: var(--sub); font-size: 13px; }
.more-rules[open] summary small { display: none; }
.more-rules .switch-row { margin-bottom: 14px; }
.rules-summary { width: 100%; background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; text-align: left; }
.rules-summary .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.rules-summary .tag { font-size: 13px; font-weight: 500; background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 2px 10px; }
.rules-summary small { color: var(--sub); font-size: 12.5px; }
#startNowBtn { margin-top: 10px; font-size: 14px; color: var(--sub); }
.standings { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; color: var(--sub); }
.standings b { color: var(--text); font-weight: 600; }
.standings .pl { font: 600 13px var(--font-display); color: var(--muted); margin-right: 4px; }

/* ---------- modal / overlays ---------- */
.controls { border-top: 1px solid var(--border); padding-top: 12px; margin-bottom: 10px; }
.controls summary { cursor: pointer; font-weight: 600; }
.controls ul { padding-left: 18px; margin: 10px 0 0; font-size: 14px; color: var(--sub); }
.controls li { margin-bottom: 5px; }
.countdown { position: fixed; inset: 0; display: grid; place-items: center; z-index: 60; pointer-events: none; }
.countdown span { font: 700 min(34vw, 200px)/1 var(--font-display); color: var(--text); animation: pop .9s ease-out; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(1.5); opacity: 0; } 30% { opacity: 1; } to { transform: scale(.92); opacity: .85; } }

@media (max-width: 720px) {
  .board-wrap { padding: 6px; border-radius: 16px; }
}

/* hints */
.hint-bar { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid color-mix(in srgb, var(--hint) 45%, var(--border)); border-left: 4px solid var(--hint); border-radius: 14px; padding: 12px 12px 12px 16px; box-shadow: var(--shadow-sm); animation: rise .2s ease-out; }
.hint-bar .hb-body { flex: 1; min-width: 0; }
.hint-bar .hb-title { font: 600 15px var(--font-display); display: flex; align-items: center; gap: 8px; }
.hint-bar .hb-title small { font: 500 12px var(--font-ui); color: var(--sub); background: var(--surface-2); border-radius: 99px; padding: 1px 8px; }
.hint-bar p { margin: 3px 0 0; color: var(--sub); font-size: 14px; }
.hint-bar .hb-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.hint-bar .hb-actions button { padding: 6px 12px; font-size: 13.5px; }
.hint-bar.resolved { border-color: color-mix(in srgb, var(--success) 45%, var(--border)); border-left-color: var(--success); }
.hint-bar .hb-check { color: var(--success); }
/* finish celebration */
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }
.banner.win { animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
.banner.win .banner-main > b::before { content: "🎉 "; }
@keyframes pop { 0% { transform: scale(.92); opacity: 0; } 100% { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .banner.win { animation: none; } }
.hint-bar .hb-title small.inner { background: color-mix(in srgb, var(--hint) 22%, transparent); color: var(--text); }
.hint-bar .hb-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 12.5px; margin-top: 8px; }
.hint-bar .hb-legend i { font-style: normal; display: inline-block; }
.hint-bar .hb-legend .lg-line { width: 18px; height: 4px; border-radius: 2px; background: var(--hint); vertical-align: middle; }
.hint-bar .hb-legend .lg-x { color: var(--hint); font-weight: 700; }
.hint-bar .hb-legend span { color: var(--muted); }
.hint-bar .hb-actions button.primary { white-space: nowrap; }
.hint-bar.walking { min-height: 118px; }
.hint-bar.walking .hb-body p { min-height: 2.9em; }
.banner-sub .k-right, .banner-sub .k-miss { color: var(--success); }
.banner-sub .k-wrong { color: var(--danger); }
.banner-sub .k-miss { text-decoration: underline dashed; text-underline-offset: 3px; }
button.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger-btn:hover { filter: brightness(1.08); }


/* ---------- header actions: frequent actions visible, the rest in ⋯ ---------- */
.head-actions { display: flex; gap: 4px; }
.head-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 11px; font-size: 14px; font-weight: 500; border-color: transparent; background: transparent; color: var(--sub); border-radius: 10px; }
.head-btn:hover { background: var(--surface-2); color: var(--text); }
.menu .mi { display: flex; flex-direction: column; gap: 1px; }
.menu .mi small { font-size: 12px; color: var(--muted); font-weight: 400; }
.menu button.danger .mi small { color: color-mix(in srgb, var(--danger) 70%, var(--muted)); }
@media (max-width: 720px) {
  .head-btn span { display: none; }
  .head-btn { padding: 7px 8px; }
}

/* ---------- settings ---------- */
.prefs { display: flex; flex-direction: column; }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--border); cursor: pointer; }
.pref:first-child { border-top: 0; }
.pref > span { display: flex; flex-direction: column; gap: 2px; }
.pref b { font-weight: 600; }
.pref small { color: var(--muted); font-size: 13px; }
.pref.locked { cursor: default; opacity: .7; }
.pref input[role="switch"] { appearance: none; width: 38px; height: 22px; border-radius: 99px; background: var(--border-strong); position: relative; flex-shrink: 0; cursor: inherit; transition: background .15s; margin: 0; }
.pref input[role="switch"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.pref input[role="switch"]:checked { background: var(--success); }
.pref input[role="switch"]:checked::after { transform: translateX(16px); }
.pref input[role="switch"]:focus-visible { outline: 2px solid var(--line); outline-offset: 2px; }

.game-title b, .game-title span#diffLabel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-title span#diffLabel { flex-wrap: nowrap; }
@media (max-width: 720px) {
  .game-head { gap: 2px; }
  .game-title b { font-size: 15px; }
  .timer { font-size: 21px; min-width: 0; }
  .timer-group .icon-btn { width: 32px; }
  .head-actions { gap: 0; }
}
.menu button:disabled { opacity: .55; cursor: default; }
.menu button:disabled:hover { background: none; }
/* buttons don't keep focus after a click; keyboard focus gets a tidy ring inside the control */
/* normal hand pointer over the board; only the eraser gets its own cursor */
#board { cursor: pointer; }
#board[data-tool="4"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24'%3E%3Cpath d='M8 20h12M5.5 13.5l7-7a2 2 0 012.8 0l2.2 2.2a2 2 0 010 2.8L12 17H8.5z' fill='white' stroke='%2316161a' stroke-width='1.8' stroke-linejoin='round' stroke-linecap='round'/%3E%3Cpath d='M9 10l5 5' stroke='%2316161a' stroke-width='1.5'/%3E%3C/svg%3E") 6 20, cell; }
.banner-sub .solve-stats { color: var(--muted); font-size: 13.5px; }
.banner-sub .solve-stats .clean { color: var(--success); font-weight: 600; }
