/* ---------- Theme variables ---------- */
:root, [data-theme="light"] {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --text: #344861;
  --text-dim: #94a3b7;
  --accent: #325aaf;
  --accent-soft: #dce3f1;
  --grid-line: #bfc6d4;
  --grid-line-strong: #344861;
  --cell-selected: #bbdefb;
  --cell-related: #e2ebf3;
  --cell-same: #c3d7ea;
  --cell-conflict-bg: #f7cfd6;
  --user-value: #325aaf;
  --wrong-value: #e55c6c;
  --note-color: #6e7c8c;
  --btn-bg: #eaeef4;
  --btn-hover: #dce3f1;
  --shadow: 0 4px 16px rgba(52, 72, 97, .12);
  --ex-pattern-bg: #b7d3ff;
  --ex-link-bg: #ffe4bd;
  --ex-elim-bg: #f7cfd6;
}
[data-theme="dark"] {
  --bg: #10151c;
  --surface: #1a2028;
  --text: #d7e0ea;
  --text-dim: #6b7787;
  --accent: #6ea8fe;
  --accent-soft: #263650;
  --grid-line: #3a4553;
  --grid-line-strong: #8fa2b8;
  --cell-selected: #2e4a6b;
  --cell-related: #212a35;
  --cell-same: #2a3f58;
  --cell-conflict-bg: #4a2630;
  --user-value: #6ea8fe;
  --wrong-value: #ff7a8a;
  --note-color: #ffffff;
  --btn-bg: #232c37;
  --btn-hover: #2c3846;
  --shadow: 0 4px 16px rgba(0, 0, 0, .4);
  --ex-pattern-bg: #2c4570;
  --ex-link-bg: #4d3a1c;
  --ex-elim-bg: #4a2630;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* ---------- Header ---------- */
.header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 900px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px))
           0 calc(20px + env(safe-area-inset-left, 0px));
}
.logo { font-size: 26px; font-weight: 700; margin: 0; color: var(--accent); letter-spacing: .5px; }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--btn-bg); color: var(--text);
  transition: background .15s;
}
.icon-btn:hover { background: var(--btn-hover); }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Layout ---------- */
.layout {
  display: flex; gap: 28px; justify-content: center; align-items: flex-start;
  max-width: 900px; margin: 0 auto;
  padding: 16px calc(20px + env(safe-area-inset-right, 0px)) 40px calc(20px + env(safe-area-inset-left, 0px));
}
.board-panel { flex: 0 1 500px; min-width: 0; }
.controls-panel { flex: 0 0 260px; display: flex; flex-direction: column; gap: 16px; padding-top: 42px; }

/* ---------- Status bar ---------- */
.statusbar { display: flex; justify-content: space-between; padding: 0 2px 8px; }
.status-item { display: flex; flex-direction: column; gap: 1px; }
.status-label { font-size: 12px; color: var(--text-dim); }
.status-value { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.difficulty-select {
  max-width: 100px; margin: 0; padding: 0 18px 0 0;
  border: none; border-radius: 4px; outline: none;
  background-color: transparent; color: var(--text);
  font: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer;
}
.difficulty-select:hover { color: var(--accent); }
.difficulty-select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.difficulty-select option { background: var(--surface); color: var(--text); }
.pause-btn {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--btn-bg); color: var(--text-dim);
}
.pause-btn:hover { background: var(--btn-hover); }
.pause-btn .icon-play { display: none; }
.paused .pause-btn .icon-play { display: block; }
.paused .pause-btn .icon-pause { display: none; }

/* ---------- Board ---------- */
.board-wrap { position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  aspect-ratio: 1;
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--grid-line-strong);
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
}
.cell {
  position: relative;
  display: grid; place-items: center;
  font-size: clamp(18px, 4.2vmin, 30px);
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  color: var(--text);
  cursor: pointer;
}
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }
.cell.box-right { border-right: 2px solid var(--grid-line-strong); }
.cell.box-bottom { border-bottom: 2px solid var(--grid-line-strong); }

.cell.related { background: var(--cell-related); }
.cell.same { background: var(--cell-same); }
.cell.conflict { background: var(--cell-conflict-bg); }
.cell.selected { background: var(--cell-selected); }
.cell.user { color: var(--user-value); }
.cell.wrong { color: var(--wrong-value); }

.cell .notes {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: clamp(8px, 1.5vmin, 12px);
  color: var(--note-color); line-height: 1;
}
.cell .notes span { display: grid; place-items: center; }
.cell .notes.auto { color: var(--text-dim); font-style: italic; }

@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.score-value { color: var(--accent); }
@keyframes score-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.score-value.bump { animation: score-bump .3s ease-out; display: inline-block; }
.cell.pop > .val { animation: pop .18s ease-out; display: block; }

/* ---------- Pause overlay ---------- */
.pause-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: var(--surface);
  border-radius: 6px; border: 2px solid var(--grid-line-strong);
}
.resume-btn {
  width: 76px; height: 76px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  box-shadow: var(--shadow);
}

/* ---------- Controls ---------- */
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tool-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 8px; border-radius: 10px;
  background: var(--btn-bg); color: var(--text-dim);
  font-size: 12px;
  transition: background .15s, color .15s;
}
.tool-btn:hover { background: var(--btn-hover); }
.tool-btn.active { color: var(--accent); background: var(--accent-soft); }
.badge {
  position: absolute; top: 2px; right: 2px;
  font-size: 9px; font-weight: 700;
  background: var(--text-dim); color: var(--surface);
  border-radius: 8px; padding: 2px 5px;
}
.tool-btn.active .badge { background: var(--accent); }
.badge-count { background: var(--accent); }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.num-btn {
  aspect-ratio: 1.35;
  font-size: 26px; font-weight: 500;
  border-radius: 10px;
  background: var(--btn-bg); color: var(--accent);
  transition: background .15s;
  position: relative;
}
.num-btn:hover { background: var(--btn-hover); }
.num-btn.done { opacity: 0; pointer-events: none; }
.num-btn.armed { background: var(--accent); color: #fff; }
.num-btn.armed .remaining { color: rgba(255, 255, 255, .8); }
.num-btn .remaining {
  position: absolute; bottom: 3px; right: 6px;
  font-size: 10px; color: var(--text-dim); font-weight: 600;
}

.primary-btn {
  padding: 14px; border-radius: 10px;
  background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 600;
  transition: filter .15s;
}
.primary-btn:hover { filter: brightness(1.1); }

/* ---------- Popover ---------- */
.popover {
  position: absolute; z-index: 30;
  background: var(--surface); border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px; min-width: 200px;
  border: 1px solid var(--grid-line);
}
.popover-title { font-size: 12px; color: var(--text-dim); padding: 6px 10px 4px; }
.popover-item {
  display: block; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 6px; font-size: 15px;
  color: var(--text);
}
.popover-item:hover { background: var(--btn-hover); }
.popover-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.popover-state {
  font-size: 11px; font-weight: 700; letter-spacing: .4px;
  color: var(--surface); background: var(--text-dim);
  border-radius: 8px; padding: 2px 7px;
}
.popover-toggle.is-on .popover-state { background: var(--accent); }
.popover-sep { height: 1px; background: var(--grid-line); margin: 5px 8px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .45);
  display: grid; place-items: center;
}
.modal {
  background: var(--surface); color: var(--text);
  border-radius: 14px; padding: 26px 28px;
  width: min(92vw, 480px);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  text-align: center;
}
.modal h2 { margin: 0 0 10px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.modal-actions .primary-btn { width: 100%; }
.modal-actions .secondary-btn {
  padding: 12px; border-radius: 10px;
  background: var(--btn-bg); color: var(--text); font-size: 15px;
}
.modal-actions .secondary-btn:hover { background: var(--btn-hover); }
.modal-actions .danger-btn {
  padding: 12px; border-radius: 10px;
  background: transparent; color: var(--wrong-value);
  border: 1px solid var(--wrong-value); font-size: 15px;
}
.modal-actions .danger-btn:hover { background: var(--cell-conflict-bg); }

.privacy-note { font-size: 12px; line-height: 1.5; color: var(--text-dim); margin-top: 14px; text-align: left; }
[data-theme="dark"] .privacy-note { color: #ffffff; }

/* ---------- Footer ---------- */
.footer {
  max-width: 900px; margin: 0 auto;
  padding: 0 calc(20px + env(safe-area-inset-right, 0px))
           calc(32px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
}
.footer .privacy-note { margin-top: 0; text-align: center; max-width: 480px; }
.delete-data-btn {
  padding: 9px 16px; border-radius: 8px;
  background: transparent; color: var(--wrong-value);
  border: 1px solid var(--wrong-value); font-size: 13px;
  transition: background .15s;
}
.delete-data-btn:hover { background: var(--cell-conflict-bg); }

.stats-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.stats-table th, .stats-table td { padding: 7px 4px; font-size: 14px; }
.stats-table th { color: var(--text-dim); font-weight: 500; text-align: left; font-size: 12px; }
.stats-table td:first-child { text-align: left; font-weight: 600; }
.stats-table td { text-align: center; }
.stats-table tr + tr { border-top: 1px solid var(--grid-line); }

/* ---------- Stats Tabs ---------- */
.stats-tabs-header {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--grid-line);
  margin: 0 -28px 16px -28px;
  padding: 0 28px;
}
.stats-tab {
  padding: 10px 14px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: color .15s, border-color .15s;
}
.stats-tab:hover {
  color: var(--text);
  border-bottom-color: var(--accent-soft);
}
.stats-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.stats-tabs-content {
  width: 100%;
}

.stats-tab-content {
  display: none;
}

.stats-tab-content.active {
  display: block;
}

.stats-columns {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stats-summary-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 140px));
  justify-content: center;
  gap: 24px;
  margin: 16px auto 0;
  max-width: 320px;
}

.stats-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.stats-header {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  text-align: center;
}

.stats-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  text-align: center;
}

.scores-table {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--grid-line);
}

.hidden { display: none !important; }

/* ---------- Settings dialog ---------- */
.modal-settings, .modal-strategy, .modal-hint { width: min(94vw, 560px); text-align: left; }
.modal-settings h2, .modal-strategy h2, .modal-hint h2 { text-align: left; }

.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 14px 0; border-bottom: 1px solid var(--grid-line);
}
.set-row:last-of-type { border-bottom: none; }
.set-row-stack { flex-direction: column; align-items: stretch; gap: 10px; }
.set-text { min-width: 0; }
.set-label { font-size: 15px; font-weight: 600; }
.set-hint { font-size: 12.5px; line-height: 1.45; color: var(--text-dim); margin-top: 3px; }
.set-radios { display: flex; gap: 10px; }
.set-radio {
  flex: 1; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--btn-bg); font-size: 14px; cursor: pointer;
}
.set-radio:hover { background: var(--btn-hover); }
.set-radio input { accent-color: var(--accent); margin: 0; }
.set-radio:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.switch { position: relative; flex: none; display: inline-block; width: 44px; height: 24px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.switch-track {
  display: block; width: 44px; height: 24px; border-radius: 12px;
  background: var(--grid-line); transition: background .15s;
}
.switch-thumb {
  display: block; width: 18px; height: 18px; margin: 3px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.set-row .delete-data-btn { flex: none; }

/* ---------- Strategy tutorials ---------- */
.strat-group + .strat-group { margin-top: 20px; }
.strat-group-title {
  font-size: 12px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 8px;
}
.strat-item {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; margin-bottom: 4px; border-radius: 8px;
  background: var(--btn-bg); color: var(--text);
  transition: background .15s;
}
.strat-item:hover { background: var(--btn-hover); }
.strat-name { display: block; font-size: 15px; font-weight: 600; }
.strat-blurb { display: block; font-size: 12.5px; line-height: 1.4; color: var(--text-dim); margin-top: 2px; }

.strat-summary { font-size: 14.5px; line-height: 1.55; margin: 0 0 4px; }
.strat-heading {
  font-size: 12px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--text-dim); margin: 18px 0 6px;
}
.strat-steps { margin: 0; padding-left: 20px; font-size: 14px; line-height: 1.6; }
.strat-caption { font-size: 13px; color: var(--text-dim); margin: 0 0 10px; }
.strat-takeaway {
  font-size: 14px; line-height: 1.55; margin: 16px 0 0;
  padding: 12px 14px; border-radius: 10px;
  background: var(--btn-bg); border-left: 3px solid var(--accent);
}

.ex-board {
  display: grid; grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1; width: min(100%, 340px); margin: 0 auto;
  background: var(--surface);
  border: 2px solid var(--grid-line-strong); border-radius: 5px;
  overflow: hidden; user-select: none;
}
.ex-cell {
  position: relative; display: grid; place-items: center;
  border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line);
  font-size: clamp(11px, 3vw, 16px); color: var(--text);
}
.ex-cell:nth-child(9n) { border-right: none; }
.ex-cell:nth-child(n+73) { border-bottom: none; }
.ex-box-right { border-right: 2px solid var(--grid-line-strong); }
.ex-box-bottom { border-bottom: 2px solid var(--grid-line-strong); }
.ex-out { background: var(--cell-related); }
.ex-pattern { background: var(--ex-pattern-bg); }
.ex-link { background: var(--ex-link-bg); }
.ex-elim { background: var(--ex-elim-bg); }
.ex-val { font-weight: 600; }
.ex-notes {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  font-size: clamp(6px, 1.7vw, 9px); color: var(--note-color); line-height: 1;
}
.ex-notes span { display: grid; place-items: center; }
.ex-notes .ex-gone { color: var(--wrong-value); text-decoration: line-through; font-weight: 700; }

.strat-legend {
  display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center;
  font-size: 11.5px; color: var(--text-dim); margin-top: 12px;
}
.strat-legend span { display: inline-flex; align-items: center; gap: 6px; }
.strat-legend i {
  width: 12px; height: 12px; border-radius: 3px;
  border: 1px solid var(--grid-line); display: inline-block;
}
.key-pattern { background: var(--ex-pattern-bg); }
.key-link { background: var(--ex-link-bg); }
.key-elim { background: var(--ex-elim-bg); }
.key-gone {
  background: none; border: none; width: auto; height: auto;
  color: var(--wrong-value); font-style: normal; font-weight: 700;
  text-decoration: line-through;
}
.key-gone::before { content: "5"; }

/* ---------- Hint explanation ---------- */
.hint-answer {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  margin: 14px 0; padding: 14px 16px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
}
.hint-answer span { font-size: 13px; line-height: 1.4; }
.hint-answer b {
  flex: none; display: grid; place-items: center; width: 48px; height: 48px;
  border-radius: 10px; background: var(--surface); font-size: 28px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}
.hint-technique {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--grid-line);
  font-size: 14px;
}
.hint-technique span {
  font-size: 11px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--text-dim);
}
.hint-explanation { font-size: 14px; line-height: 1.55; }
.hint-explanation p { margin: 14px 0 0; }
.hint-reasons { margin: 10px 0 0; padding-left: 22px; }
.hint-reasons li + li { margin-top: 5px; }
.hint-conclusion {
  padding: 11px 13px; border-radius: 9px;
  background: var(--btn-bg); border-left: 3px solid var(--accent);
}

/* ---------- Sudoku Rally competitive shell ---------- */
.logo span { color: var(--accent); font-weight: 800; }
.account-btn {
  min-height: 38px;
  max-width: 180px;
  padding: 0 13px;
  border: 1px solid var(--grid-line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.account-btn.signed-in { border-color: color-mix(in srgb, var(--accent) 55%, var(--grid-line)); }
.mode-nav {
  width: min(96vw, 620px);
  margin: 0 auto 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--grid-line);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(10, 30, 50, .06);
}
.mode-nav-btn {
  min-width: 0;
  min-height: 38px;
  padding: 7px 5px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.mode-nav-btn:hover { color: var(--text); background: var(--cell-related); }
.mode-nav-btn.active { color: white; background: var(--accent); }
.mode-nav-btn.rally:not(.active) { color: var(--accent); }
.mode-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  background: linear-gradient(110deg, color-mix(in srgb, var(--accent) 16%, var(--surface)), var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--grid-line));
  color: var(--text);
  font-size: 13px;
}
.mode-banner span { color: var(--accent); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.mode-banner.rally-active { display: grid; gap: 8px; overflow: hidden; }
.mode-banner-label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rally-track { display: flex; align-items: center; gap: 9px; overflow-x: auto; padding: 5px 2px 7px; scrollbar-width: thin; }
.rally-track::before { content: ''; position: absolute; }
.rally-track-node {
  position: relative;
  flex: 0 0 25px;
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--grid-line);
  background: var(--surface);
  color: var(--text-dim);
  font-style: normal;
  font-size: 9px;
  font-weight: 850;
}
.rally-track-node:nth-child(3n + 2) { transform: translateY(-3px); }
.rally-track-node:nth-child(3n) { transform: translateY(2px); }
.rally-track-node:not(:first-child)::before { content: ''; position: absolute; right: 100%; top: 50%; width: 11px; height: 2px; background: var(--grid-line); }
.rally-track-node.cleared { border-color: var(--correct); background: var(--correct); color: #fff; }
.rally-track-node.cleared::before, .rally-track-node.current::before { background: var(--correct); }
.rally-track-node.current { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.rally-track b { flex: 0 0 auto; font-size: 17px; }
.competitive-busy .board { opacity: .84; pointer-events: none; }
.tool-btn:disabled, .difficulty-select:disabled, .popover-item.disabled {
  opacity: .45;
  cursor: not-allowed;
}
.ad-slot {
  width: min(96vw, 620px);
  min-height: 48px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--grid-line);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.modal-rally { width: min(94vw, 620px); text-align: left; }
.modal-leaderboard { width: min(96vw, 760px); }
.rally-form { display: grid; gap: 13px; }
.rally-form label {
  display: grid;
  gap: 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 750;
}
.rally-form input, .rally-form select, .inline-form input, .leaderboard-filters select {
  width: 100%;
  min-height: 42px;
  box-sizing: border-box;
  padding: 9px 11px;
  border: 1px solid var(--grid-line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.form-submit { width: 100%; margin-top: 2px; }
.form-message {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--cell-related);
  color: var(--text-dim);
  font-size: 13px;
}
.form-message.error { background: color-mix(in srgb, var(--wrong-value) 12%, var(--surface)); color: var(--wrong-value); }
.form-message.success { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--accent); }
.form-footnote, .muted { color: var(--text-dim); font-size: 12px; }
.text-btn {
  display: block;
  margin: 12px auto 0;
  padding: 7px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.danger-text { color: var(--wrong-value); }
.danger-button { background: var(--wrong-value); border-color: var(--wrong-value); color: #fff; }
.stats-period { display: grid; gap: 6px; margin-bottom: 12px; font-size: .82rem; font-weight: 700; }
.stats-period select { min-height: 42px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); padding: 0 10px; }
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin: 16px 0;
}
.difficulty-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid var(--grid-line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.difficulty-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.difficulty-card span { color: var(--text-dim); font-size: 11px; }
.rally-road-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  overflow: hidden;
  margin: 4px 0 18px;
  padding: 16px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #234d3d, #426b4f 52%, #8b6f42);
  color: white;
  font-size: 11px;
  font-weight: 800;
}
.rally-road-preview i { flex: 1; min-width: 10px; height: 2px; background: rgba(255,255,255,.48); }
.profile-hero { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; background: var(--cell-related); }
.profile-flag { font-size: 32px; }
.profile-hero div { display: grid; gap: 3px; flex: 1; }
.profile-hero div span { color: var(--text-dim); font-size: 12px; }
.verified-badge, .rating-pill {
  padding: 5px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent);
  font-size: 10px;
  font-weight: 850;
}
.rating-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.achievement-mini, .social-list { margin: 0; padding: 0; list-style: none; }
.achievement-mini li, .social-list li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--grid-line);
}
.achievement-mini li strong { flex: 1; text-transform: capitalize; }
.achievement-mini li small, .social-list li small { margin-left: auto; color: var(--text-dim); }
.account-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 16px; }
.account-actions .text-btn { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; margin-bottom: 10px; }
.inline-form input { flex: 1; }
.inline-form button { flex: 0 0 auto; }
.mini-btn {
  margin-left: auto;
  padding: 5px 9px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-size: 11px;
  font-weight: 750;
}
.loading-card { padding: 28px 12px; text-align: center; color: var(--text-dim); }
.leaderboard-filters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.leaderboard-filters select { min-height: 36px; padding: 6px; font-size: 11px; }
.rally-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rally-table th, .rally-table td { padding: 9px 7px; border-bottom: 1px solid var(--grid-line); text-align: left; }
.rally-table th { color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
.rally-table tr.me { background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 750; }
.player-link { border: 0; padding: 0; background: transparent; color: inherit; font: inherit; font-weight: inherit; cursor: pointer; text-align: left; }
.player-link:hover { color: var(--accent); text-decoration: underline; }
.verification-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #d09b32; }
.verification-dot.verified { background: #2ca56c; }
.verification-dot.invalidated { background: var(--wrong-value); }
.provisional-label { margin-bottom: 6px; color: var(--text-dim); font-size: 11px; }
.checkpoint-score { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-radius: 13px; background: var(--cell-related); }
.checkpoint-score span { color: var(--text-dim); }
.checkpoint-score strong { color: var(--accent); }
.checkpoint-rank { margin: 12px 0; text-align: center; }
.result-verification { color: var(--accent); font-size: 12px; font-weight: 750; }

@media (max-width: 620px) {
  .mode-nav { width: calc(100vw - 16px); }
  .mode-nav-btn { font-size: 10.5px; }
  .account-btn { max-width: 110px; }
  .leaderboard-filters { grid-template-columns: repeat(2, 1fr); }
  .leaderboard-filters select:first-child { grid-column: 1 / -1; }
  .rally-table th:nth-child(4), .rally-table td:nth-child(4) { display: none; }
  .account-actions { grid-template-columns: 1fr; }
  .account-actions .text-btn { grid-column: auto; }
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .layout { flex-direction: column; align-items: stretch; gap: 14px; padding-bottom: 24px; }
  .controls-panel { flex: none; padding-top: 0; }
  .board-panel { flex: none; }
  .tools { grid-template-columns: repeat(4, 1fr); }
  .numpad { grid-template-columns: repeat(9, 1fr); gap: 4px; }
  .num-btn { aspect-ratio: auto; padding: 10px 0; font-size: 20px; }
  .num-btn .remaining { display: none; }
  .modal-settings, .modal-strategy, .modal-hint { padding: 22px 18px; }
  .set-row { gap: 12px; }
  .set-radios { flex-direction: column; }
  .ex-notes { font-size: clamp(6px, 2.2vw, 9px); }
}
