:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #192944;
  background: #131d3e;
  font-synthesis: none;
  --ink: #192944;
  --muted: #5a6c88;
  --line: #e2eaf5;
  --indigo: #3456aa;
  --teal: #087e86;
  --teal-dark: #056871;
  --radius: 26px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-width: 280px;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(ellipse at 16% 92%, #24566e 0%, transparent 40%),
    radial-gradient(ellipse at 82% 8%, #344780 0%, transparent 43%),
    #131d3e;
  padding: 0 max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible { outline: 3px solid #587bef; outline-offset: 3px; }
h1, h2, p { margin: 0; }
.site-header {
  max-width: 1200px;
  margin: auto;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #f6faff;
}
.brand { display: flex; align-items: center; gap: 11px; font-size: 21px; font-weight: 760; letter-spacing: .06em; }
.brand-mark { display: grid; grid-template: repeat(2, 6px) / repeat(2, 6px); gap: 3px; padding: 7px; border-radius: 9px; background: #bff9eb; }
.brand-mark i { background: #185667; border-radius: 1px; }
.brand-mark i:nth-child(2) { opacity: .4; }
.header-mode { color: #d8e4ff; font-size: 14px; letter-spacing: .08em; }
main { max-width: 1200px; margin: auto; }
.panel { background: #fff; border-radius: var(--radius); box-shadow: 0 18px 60px #09153444; overflow: hidden; }
.login { max-width: 878px; margin: clamp(14px, 8vh, 80px) auto 0; display: grid; grid-template-columns: 1fr 1fr; }
.login-art {
  display: grid;
  place-items: center;
  min-height: 420px;
  background: radial-gradient(circle at 74% 86%, #2ea0a2, transparent 56%), linear-gradient(143deg, #2d4097, #152b66 62%);
}
.art-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(61%, 250px);
  aspect-ratio: 1;
  background: #41619d;
  border: 1px solid #83a9ce;
  border-radius: 14px;
  overflow: hidden;
  gap: 1px;
  color: #d9fff5;
  transform: rotate(-9deg);
  box-shadow: 12px 20px 0 #14264c66;
}
.art-grid span { display: grid; place-items: center; background: #233b72; font: 650 clamp(18px, 4vw, 37px) / 1 system-ui; }
.art-grid span:nth-child(4n + 2) { border-right: 1px solid #83a9ce; }
.art-grid span:nth-child(n + 5):nth-child(-n + 8) { border-bottom: 1px solid #83a9ce; }
.art-grid span:nth-child(2), .art-grid span:nth-child(15) { background: #0d6474; }
.login-content { padding: 42px clamp(24px, 5vw, 54px); align-self: center; }
.login-content h1 { font-size: clamp(28px, 4vw, 38px); }
.login-content > p { color: var(--muted); margin: 8px 0 27px; }
#login-form { display: grid; gap: 8px; }
#login-form label { font-weight: 650; font-size: 14px; }
#login-form input { min-width: 0; padding: 12px; border-radius: 10px; border: 1px solid #c8d4e5; color: var(--ink); }
#login-form input + label { margin-top: 7px; }
.primary, .secondary, .chip, .key, .text-button {
  border: 1px solid transparent; border-radius: 11px; font-weight: 700;
  min-height: 42px; padding: 7px 12px;
}
.primary { color: white; background: linear-gradient(125deg, var(--teal), var(--teal-dark)); }
.primary:hover:enabled { background: #075b64; }
.secondary { background: #f1f5fd; border-color: #dbe5f5; color: #29477f; }
.secondary:hover:enabled, .chip:hover:enabled { background: #e5edfc; }
.chip { background: #f2f6ff; border-color: #dbe5f5; color: #34578b; font-size: 14px; }
.text-button { color: #34578b; background: transparent; }
.text-button:hover:enabled { background: #edf3fc; }
.error { color: #ac2d45; font-size: 14px; }
.error:not(:empty) { margin: 4px 0; }
.match { border: 2px solid #aebfef; }
body:has(.match:not([hidden])) .site-header { height: 52px; }
.match-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 4px clamp(12px, 2vw, 24px);
  background: #edf3ff;
  border-bottom: 1px solid #dce6f9;
}
.player { min-width: 0; display: flex; gap: 10px; align-items: center; color: #304d80; font-weight: 700; }
#player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#player-id { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.timer { font-size: 21px; font-variant-numeric: tabular-nums; font-weight: 780; color: #294383; padding: 6px 14px; border-radius: 11px; background: #dfe9ff; }
.timer::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid currentColor; border-radius: 50%; vertical-align: 1px; background: linear-gradient(currentColor, currentColor) 50% 30% / 1px 4px no-repeat; }
.timer.urgent { background: #ffe8ea; color: #983244; }
.fullscreen, .card-toggle { justify-self: end; }
.card-toggle { display: none; }
.match-body { display: grid; grid-template-columns: minmax(0, 1fr) clamp(252px, 28%, 330px); min-height: calc(100dvh - 126px); }
.play-area { min-width: 0; padding: 12px clamp(10px, 1.4vw, 18px); }
.question-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 14px; font-weight: 650; }
.question-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.question-heading h1 { min-width: 0; font-size: clamp(21px, 2.5vw, 28px); line-height: 1.25; overflow-wrap: anywhere; }
.question-heading .chip { min-height: 36px; padding-block: 3px; white-space: nowrap; }
.rule { color: #435472; line-height: 1.4; margin-top: 3px; }
.board-area { width: min(100%, max(210px, calc(100dvh - 238px))); margin: 8px auto 0; }
.board {
  --region-border: 2px solid #000;
  --cell-line: #fff;
  --answer-ink: #0066d6;
  --selection-line: #155aca;
  display: grid;
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border: var(--region-border);
  border-radius: 4px;
  background: #fff;
  container-type: inline-size;
  touch-action: manipulation;
}
.cell {
  display: grid;
  place-items: center;
  position: relative;
  padding: 0;
  min-width: 0;
  border: 0;
  border-right: 1px solid var(--cell-line, #afb9ca);
  border-bottom: 1px solid var(--cell-line, #afb9ca);
  background: var(--cell-fill, #fff);
  color: var(--answer-ink, #2854ae);
  font-size: calc(67cqw / var(--size));
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.cell.box-right { border-right: var(--region-border); }
.cell.box-bottom { border-bottom: var(--region-border); }
.cell.edge-right { border-right: 0; }
.cell.edge-bottom { border-bottom: 0; }
.cell.given { color: #26314a; background: var(--cell-fill, #f1f4fa); font-weight: 800; }
.cell.selected { background: var(--cell-fill, #cddfff); box-shadow: inset 0 0 0 2px var(--selection-line, #4f74c8); }
.cell[data-region="0"] { --cell-fill: #d8f7ef; }
.cell[data-region="1"] { --cell-fill: #e7efff; }
.cell[data-region="2"] { --cell-fill: #fff1df; }
.cell[data-region="3"] { --cell-fill: #fae2fb; }
.cell[data-region="4"] { --cell-fill: #e9f9db; }
.cell[data-region="5"] { --cell-fill: #e5e1ff; }
.cell[data-region="6"] { --cell-fill: #cdf4fb; }
.cell[data-region="7"] { --cell-fill: #ffeaf0; }
.cell[data-region="8"] { --cell-fill: #fff7be; }
.cell:focus-visible { outline-offset: -3px; z-index: 1; }
.cell-notes { width: 84%; height: 86%; display: grid; grid-template-columns: repeat(var(--note-cols), 1fr); grid-template-rows: repeat(var(--note-rows), 1fr); color: #415980; font-size: calc(27cqw / var(--size)); font-weight: 650; }
.cell-notes span { align-self: center; justify-self: center; }
.console {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: clamp(15px, 2vw, 27px);
  background: #f8faff;
  border-left: 1px solid #e0e9f7;
}
.desktop-card h2, .result-details h2 { font-size: 17px; margin-bottom: 12px; }
.question-list { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
.question-button {
  position: relative;
  min-height: 43px;
  padding: 0;
  background: #fff;
  border: 1px solid #d5e0f1;
  border-radius: 10px;
  color: #435677;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.question-button:hover { background: #e7efff; }
.question-button.current { box-shadow: inset 0 0 0 2px #5176c4; color: #223e76; background: #edf3ff; }
.question-button.complete::after, .question-button.partial::after { content: ""; position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: #128579; }
.question-button.partial::after { background: #ae6b16; }
.legend { color: var(--muted); font-size: 13px; margin-top: 12px; }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #128579; }
.legend-dot.partial { background: #ae6b16; margin-left: 12px; }
.controls { display: grid; gap: 9px; }
.save-status { min-height: 1.2em; text-align: right; color: var(--muted); font-size: 13px; }
.save-status.warn { color: #a02742; }
.save-status:empty { display: none; }
.key-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.digits { flex: 1 0 75%; display: grid; grid-template-columns: repeat(var(--key-cols), minmax(0, 1fr)); gap: 6px; }
.key { background: #fff; border-color: #d8e3f2; color: #2b4e89; min-height: 44px; min-width: 0; padding: 3px 0; font-size: 20px; font-variant-numeric: tabular-nums; }
.key:hover { background: #eaf2ff; }
.erase { flex: 1 0 36px; font-size: 21px; }
.key-row:has(.digits[data-size="9"]) { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.key-row .digits[data-size="9"] { display: contents; }
@media (min-width: 700px) {
  .key-row:has(.digits[data-size="6"]) { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .key-row .digits[data-size="6"] { display: contents; }
  .key-row:has(.digits[data-size="6"]) .erase { grid-column: span 2; }
}
.control-row { display: flex; justify-content: space-between; align-items: center; }
.note-toggle[aria-pressed="true"] { background: #d2f4ee; border-color: #73bcb4; color: #185b59; }
.navigation { display: grid; grid-template-columns: 1fr 1.35fr; gap: 8px; }
.navigation button { min-height: 47px; }
dialog { width: min(calc(100% - 28px), 415px); border: 1px solid #d1def0; border-radius: 20px; padding: 21px; color: var(--ink); box-shadow: 0 16px 60px #14264d55; }
dialog::backdrop { background: #10193294; }
dialog h2 { font-size: 21px; }
dialog p:not(.legend) { margin: 12px 0 20px; color: #435472; line-height: 1.55; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog-close { min-height: 35px; font-size: 18px; padding: 0 12px; }
.dialog-wide { width: 100%; margin-top: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.results { max-width: 730px; margin: 12px auto 0; }
.result-top { text-align: center; background: #edf4ff; padding: 28px 16px; }
.result-kicker { color: #46659b; font-size: 14px; font-weight: 720; }
.result-top h1 { margin: 5px 0; }
.result-top p { color: var(--muted); }
.score { color: #0a7178; margin: 10px 0; font-variant-numeric: tabular-nums; }
.score strong { font-size: 52px; line-height: 1; }
.score span { font-size: 19px; margin-left: 5px; }
.result-details { padding: 20px clamp(14px, 4vw, 32px); }
.result-details ol { list-style: none; padding: 0; margin: 0 0 16px; }
.result-details li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.result-details li span:nth-child(2) { color: var(--muted); }
.result-details li strong { color: #305290; white-space: nowrap; font-variant-numeric: tabular-nums; }
.result-details .primary { width: 100%; }

@media (max-width: 699px) {
  :root { --radius: 17px; }
  body { padding-right: max(8px, env(safe-area-inset-right)); padding-left: max(8px, env(safe-area-inset-left)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .site-header { height: 52px; padding: 0 5px; }
  body:has(.match:not([hidden])) {
    padding-inline: max(4px, env(safe-area-inset-left)) max(4px, env(safe-area-inset-right));
  }
  .brand { font-size: 17px; gap: 8px; }
  .header-mode { font-size: 12px; letter-spacing: 0; }
  .login { grid-template-columns: 1fr; max-width: 440px; }
  .login-art { min-height: 145px; }
  .art-grid { width: 108px; box-shadow: 6px 9px 0 #14264c66; }
  .art-grid span { font-size: 16px; }
  .login-content { padding: 24px 22px; }
  .match { overflow: clip; border-width: 1px; }
  .match-bar { min-height: 48px; padding: 6px 9px; gap: 4px; }
  .player { gap: 1px; display: grid; font-size: 14px; }
  #player-id { font-size: 10px; }
  .timer { font-size: 17px; padding: 5px 8px; }
  .timer::before { width: 8px; height: 8px; margin-right: 6px; }
  .fullscreen { display: none !important; }
  .card-toggle { display: inline-block; min-height: 39px; padding: 5px 8px; white-space: nowrap; }
  .match-body { display: flex; flex-direction: column; min-height: calc(100dvh - 110px - env(safe-area-inset-bottom)); }
  .play-area { flex: 1; padding: 6px 4px 8px; }
  .question-heading, .question-meta, .rule { margin-inline: 4px; }
  .question-heading h1 { font-size: 20px; }
  .question-heading .chip { min-height: 31px; padding: 3px 8px; }
  .rule { font-size: 13px; line-height: 1.3; }
  .board-area { width: min(100%, 100dvh); margin-top: 4px; }
  .console { position: sticky; bottom: 0; display: block; padding: 4px 10px max(9px, env(safe-area-inset-bottom)); border-left: 0; border-top: 1px solid var(--line); }
  .desktop-card { display: none; }
  .controls { grid-template-columns: auto minmax(0, 1fr); gap: 5px; align-items: center; }
  .controls > :not(.control-row, .navigation) { grid-column: 1 / -1; }
  .control-row { gap: 3px; }
  .navigation { gap: 4px; }
  .save-status { min-height: 0; font-size: 12px; }
  .save-status:not(:empty) { min-height: 1.2em; }
  .key-row { gap: 4px; }
  .digits { gap: 4px; }
  .key { font-size: 17px; min-height: 39px; }
  .erase { flex-basis: 31px; font-size: 19px; }
  .control-row button { min-height: 36px; padding-block: 4px; }
  .navigation button { min-height: 42px; padding-inline: 4px; }
}
@media (min-width: 700px) and (max-height: 630px) {
  body:has(.match:not([hidden])) .site-header { height: 44px; }
  .match-bar { min-height: 48px; padding-block: 3px; }
  .play-area, .console { padding: 10px 14px; }
  .board-area { width: min(100%, max(210px, calc(100dvh - 217px))); margin-top: 6px; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color .12s, box-shadow .12s; }
}

.match:fullscreen { border: 0; border-radius: 0; overflow: auto; }
.match:fullscreen .match-body { min-height: calc(100dvh - 52px); }
@media (min-width: 700px) {
  .match:fullscreen .board-area { width: min(100%, max(210px, calc(100dvh - 165px))); }
}

.mode-nav { display: flex; gap: 4px; align-items: center; }
.mode-nav a { color: #dce8ff; border-radius: 8px; padding: 7px 9px; text-decoration: none; font-size: 14px; }
.mode-nav a:hover, .mode-nav a[aria-current] { color: white; background: #ffffff20; }
.cell.given:disabled { opacity: 1; cursor: default; }
.question-list { grid-template-columns: repeat(auto-fit, minmax(38px, 1fr)); }
.practice-match .console { justify-content: end; }
.practice-match .navigation { grid-template-columns: 1fr; }
.library { max-width: 950px; margin: 0 auto; padding: clamp(16px, 4vw, 36px); }
.library h1 { margin-bottom: 6px; font-size: clamp(23px, 4vw, 32px); }
.library h2 { font-size: 18px; }
.library > p { color: var(--muted); }
.filters, .bank-fields, .bank-actions, .bank-tabs {
  display: flex; flex-wrap: wrap; align-items: end; gap: 8px;
}
.filters { margin: 16px 0; }
.filters label, .bank-fields label { display: grid; gap: 4px; font-size: 14px; }
.filters select, .bank-fields select, .bank-fields input, .bank-actions input {
  border: 1px solid #c8d4e5;
  border-radius: 8px;
  padding: 8px;
  min-height: 42px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.bank-fields input[type="number"], .bank-actions input { width: 100px; }
.practice-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 8px; }
.practice-list button { text-align: left; }
.bank-message:not(:empty) { margin: 10px 0; }
.library .bank-message.error { color: #ac2d45; }
.bank-tabs { margin: 16px 0; }
.bank-tabs [aria-pressed="true"] { color: #fff; background: var(--teal-dark); }
.bank-section { padding: 15px 0; border-top: 1px solid var(--line); }
.bank-heading, .bank-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
.bank-fields { margin-top: 8px; }
.bank-fields p { color: var(--muted); padding: 8px 0; }
.bank-list { margin: 12px 0 0; padding: 0; list-style: none; }
.bank-list li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.bank-actions input { width: 72px; }
.bank-actions .secondary { padding-inline: 9px; font-size: 13px; }

@media (max-width: 699px) {
  .mode-nav { gap: 1px; }
  .mode-nav a { font-size: 12px; padding: 7px 5px; }
}

.practice-switcher { display: grid; gap: 5px; padding-top: 4px; }
#match-practice-switch:empty, #result-practice-switch:empty { display: none; }
.practice-switch-heading { display: flex; justify-content: space-between; align-items: center; gap: 5px; }
#practice-position { color: var(--muted); font-size: 13px; }
.practice-switch-heading a { color: #30568d; font-size: 13px; font-weight: 700; padding: 4px; }
.practice-switch-controls, #practice-number-form { display: flex; align-items: stretch; gap: 5px; }
.practice-switch-controls > button { flex: 0 0 auto; }
#practice-number-form { flex: 1 1 auto; min-width: 0; }
#practice-number { flex: 1 1 0; min-width: 38px; max-width: 112px; padding: 5px; border: 1px solid #c8d4e5; border-radius: 8px; }
#practice-number-form button, .practice-switch-controls > button { padding-inline: 8px; white-space: nowrap; font-size: 14px; }
#result-practice-switch { margin-top: 12px; }
@media (max-width: 699px) {
  .practice-switch-controls button { min-height: 36px; }
}

.practice-feedback:empty { display: none; }
.practice-feedback { color: #435472; font-size: 14px; }
.practice-feedback[data-assessment="incorrect"] { color: #a02742; font-weight: 650; }
.result-kicker.practice-correct { color: var(--teal-dark); }

.review-dialog {
  width: min(calc(100% - 24px), 940px);
  max-height: min(90dvh, 880px);
  padding: 0;
  overflow: hidden;
}
.review-dialog[open] { display: flex; flex-direction: column; }
.review-header, .review-footer { flex: none; padding: 12px clamp(12px, 3vw, 24px); }
.review-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.review-heading .timer { font-size: 16px; }
.review-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.review-filters button { min-width: 0; padding-inline: 4px; font-size: 14px; }
.review-filters button[aria-pressed="true"] { background: #285bb2; border-color: #285bb2; color: #fff; }
.review-scroll { overflow-y: auto; overscroll-behavior: contain; min-height: 0; padding: 0 clamp(12px, 3vw, 24px); }
.review-list { list-style: none; padding: 0; margin: 0; }
.review-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.review-list h3 { grid-column: 1 / -1; margin: 0; font-size: 16px; }
.review-board { width: min(100%, 315px); border-radius: 2px; }
.review-view { white-space: nowrap; }
.review-footer { border-top: 1px solid var(--line); }
.review-dialog .review-lock-note { margin: 0 0 8px; font-size: 14px; }
.review-dialog #review-error { margin: 0 0 8px; }
.review-dialog #review-error:empty { display: none; }
.review-dialog #review-empty { margin: 12px 0; }
.review-submit { background: #a74b18; min-width: 96px; }
.review-submit:hover:enabled { background: #86390d; }
