/* =========================================================
   舒尔特方格 · 静态页面样式
   ========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  color-scheme: light dark;

  --bg: #f4f2eb;
  --surface: #fdfcf8;
  --surface-2: #efede4;
  --cell: #fcfbf7;
  --cell-hover: #f0f5f1;

  --ink: #1d1f1a;
  --ink-soft: #55584e;
  --muted: #696b61;
  --line: #e2e0d6;
  --line-strong: #cbc9bd;

  --accent: #176d5b;
  --accent-strong: #0e5647;
  --accent-ink: #0e5647;
  --accent-soft: #e2efe9;
  --accent-line: #b9d6ca;
  --on-accent: #f7fbf8;

  --danger: #a9432f;
  --danger-soft: #f8e6df;

  --on-ink: #f8f7f1;
  --overlay: rgba(253, 252, 248, 0.8);
  --shadow: 0 1px 2px rgba(29, 31, 26, 0.04), 0 28px 60px -42px rgba(29, 31, 26, 0.32);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue",
    Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Mono", "Roboto Mono", "IBM Plex Mono",
    ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --radius-xl: 28px;
  --radius-lg: 18px;
  --radius: 11px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111310;
    --surface: #191b17;
    --surface-2: #20231e;
    --cell: #1d201b;
    --cell-hover: #253028;

    --ink: #ecece4;
    --ink-soft: #b7b9ae;
    --muted: #96998e;
    --line: #2b2e27;
    --line-strong: #3c4036;

    --accent: #7fc7b2;
    --accent-strong: #9bdac7;
    --accent-ink: #a5e0cf;
    --accent-soft: #1e332c;
    --accent-line: #355a4e;
    --on-accent: #0d1a16;

    --danger: #ef9b86;
    --danger-soft: #3a231d;

    --on-ink: #141611;
    --overlay: rgba(25, 27, 23, 0.84);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 30px 70px -45px rgba(0, 0, 0, 0.8);
  }
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 75% 42% at 50% -8%, rgba(23, 109, 91, 0.075), transparent 72%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 72px 72px;
  opacity: 0.34;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 58%);
  mask-image: linear-gradient(to bottom, #000 0%, transparent 58%);
}

::selection {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 940px;
  margin-inline: auto;
  padding:
    clamp(24px, 4vw, 34px)
    clamp(16px, 3.4vw, 32px)
    calc(26px + env(safe-area-inset-bottom));
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 640px;
  margin-inline: auto;
}

.sidebar {
  min-width: 0;
}

/* ---------- Header ---------- */

.wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

.wordmark svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--accent);
}

h1 {
  margin: 28px 0 12px;
  font-size: clamp(2.2rem, 6vw, 3.1rem);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 1.06;
}

.intro {
  max-width: 52ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: clamp(0.9rem, 1.6vw, 0.98rem);
  line-height: 1.75;
}

/* ---------- Difficulty ---------- */

.setup {
  margin-top: clamp(24px, 4vw, 32px);
}

.setup-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.field-label,
.record-label {
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.setup-note {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.size-group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  width: 100%;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 15px;
}

.size-btn {
  appearance: none;
  min-width: 0;
  padding: 8px 9px 7px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition:
    background-color 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.size-btn strong {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.size-btn span {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.14em;
  line-height: 1.4;
}

.size-btn:hover {
  background: var(--surface);
  color: var(--ink);
}

.size-btn[aria-pressed="true"] {
  background: var(--ink);
  color: var(--on-ink);
  box-shadow: 0 7px 18px -12px rgba(0, 0, 0, 0.55);
}

.size-btn[aria-pressed="true"] span {
  color: var(--on-ink);
  opacity: 0.58;
}

.size-btn[aria-pressed="true"]:hover {
  background: var(--ink);
  color: var(--on-ink);
}

.size-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.record {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.record strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.record strong.is-flash {
  animation: best-pop 0.6s ease;
}

/* ---------- Trainer ---------- */

.trainer {
  min-width: 0;
  margin-top: 18px;
  padding: clamp(13px, 2.2vw, 20px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  container-type: inline-size;
}

.hud {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 4px 10px;
}

.hud-time {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
}

#timer {
  font-family: var(--font-mono);
  font-size: clamp(1.8rem, 4.6vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 0.92;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

@supports (font-size: 1cqw) {
  #timer {
    font-size: clamp(1.7rem, 7cqw, 2.4rem);
  }
}

.hud-next {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-bottom: 1px;
  flex: none;
}

.hud-next strong {
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-size: clamp(1.2rem, 3vw, 1.55rem);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-meta {
  display: flex;
  align-items: flex-end;
  gap: 22px;
  margin-left: auto;
  padding-bottom: 2px;
}

.hud-meta > div {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.hud-meta strong {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#errors.is-bump {
  animation: error-bump 0.32s ease;
}

.progress-track {
  height: 3px;
  margin: 0 4px 11px;
  overflow: hidden;
  background: var(--line);
  border-radius: 999px;
}

.progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Board ---------- */

.board-wrap {
  position: relative;
  padding: clamp(5px, 0.9vw, 8px);
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 17px;
}

.board {
  --n: 5;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: clamp(4px, 0.8vw, 7px);
  container-type: inline-size;
  transition: filter 0.22s ease, opacity 0.22s ease;
}

.board.is-obscured {
  filter: blur(9px);
  opacity: 0.45;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: clamp(7px, 1.1vw, 11px);
  background: var(--cell);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: clamp(0.72rem, calc(100cqw / var(--n) * 0.36), 1.85rem);
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition:
    background-color 0.14s ease,
    border-color 0.14s ease,
    color 0.14s ease,
    opacity 0.14s ease,
    transform 0.1s ease;
}

@supports not (font-size: 1cqw) {
  .cell {
    font-size: clamp(0.75rem, 2.6vw, 1.35rem);
  }
}

@media (hover: hover) {
  .cell:hover {
    background: var(--cell-hover);
    border-color: var(--accent-line);
  }
}

.cell:active {
  transform: scale(0.955);
}

.cell:focus-visible {
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cell.is-correct {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-ink);
  animation: cell-confirm 0.2s ease;
}

.cell.is-wrong {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
  animation: cell-shake 0.32s ease;
}

/* ---------- State overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: clamp(18px, 4vw, 32px);
  background: var(--overlay);
  -webkit-backdrop-filter: blur(9px) saturate(0.9);
  backdrop-filter: blur(9px) saturate(0.9);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.overlay.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .overlay {
    background: var(--surface);
  }
}

.overlay-panel {
  width: 100%;
  max-width: 350px;
  text-align: center;
  animation: panel-in 0.28s ease both;
}

.focus-mark {
  position: relative;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.focus-mark::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.focus-mark::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 50%;
  opacity: 0.75;
}

.overlay-kicker {
  margin: 0 0 10px;
  color: var(--accent-ink);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.overlay-panel h2 {
  margin: 0 0 10px;
  font-size: clamp(1.14rem, 3.1vw, 1.45rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.45;
}

.overlay-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.result-time {
  margin: 2px 0 12px;
  font-family: var(--font-mono);
  font-size: clamp(2.1rem, 6.2vw, 2.9rem);
  font-weight: 500;
  letter-spacing: -0.06em;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 12px;
}

.result-badge {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  gap: 10px;
  padding-top: 14px;
}

.btn {
  appearance: none;
  height: 50px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    transform 0.1s ease,
    opacity 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  flex: 1;
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-ghost {
  min-width: 104px;
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--ink);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

/* ---------- Guide & footer ---------- */

.guide {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.guide summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 2px;
  color: var(--ink-soft);
  font-size: 12px;
  letter-spacing: 0.04em;
  list-style: none;
  cursor: pointer;
}

.guide summary::-webkit-details-marker {
  display: none;
}

.guide summary::after {
  content: "+";
  color: var(--muted);
  font-size: 17px;
  font-weight: 300;
  line-height: 1;
  transition: transform 0.2s ease;
}

.guide[open] summary::after {
  transform: rotate(45deg);
}

.guide summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.guide ol {
  margin: 0;
  padding: 0 0 18px 18px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.8;
}

.guide li {
  padding-left: 4px;
  margin-bottom: 5px;
}

.guide li::marker {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
}

.noscript {
  margin: 18px auto 0;
  max-width: 640px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 26px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
}

.footer p {
  margin: 0;
}

/* ---------- Motion ---------- */

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cell-confirm {
  0% { transform: scale(0.97); }
  55% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

@keyframes error-bump {
  0%, 100% { transform: scale(1); color: var(--ink); }
  35% { transform: scale(1.2); color: var(--danger); }
}

@keyframes best-pop {
  0%, 100% { color: var(--ink); }
  30% { color: var(--accent); transform: scale(1.06); }
  60% { color: var(--accent); transform: scale(1); }
}

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .page {
    padding-top: 34px;
  }

  .layout {
    max-width: none;
    grid-template-columns: minmax(260px, 300px) auto;
    grid-template-areas:
      "sidebar trainer"
      "guide trainer";
    grid-template-rows: auto 1fr;
    align-items: start;
    justify-content: start;
    column-gap: 36px;
    row-gap: 22px;
  }

  .sidebar {
    grid-area: sidebar;
    padding-top: 4px;
  }

  .trainer {
    grid-area: trainer;
    width: min(540px, calc(100vh - 195px));
    width: min(540px, calc(100dvh - 195px));
    margin-top: 0;
  }

  .hud {
    gap: 18px;
  }

  .hud-next {
    position: relative;
    padding-left: 20px;
  }

  .hud-next::before {
    content: "";
    position: absolute;
    top: 2px;
    bottom: 2px;
    left: 0;
    width: 1px;
    background: var(--line);
  }

  .guide {
    grid-area: guide;
    align-self: start;
    margin-top: 0;
    border-bottom: 0;
  }

  h1 {
    font-size: clamp(2.2rem, 3.4vw, 2.9rem);
  }

  .size-group {
    grid-template-columns: repeat(2, 1fr);
  }

  .size-btn {
    flex-direction: row;
    justify-content: space-between;
    padding: 9px 12px;
  }

  .footer {
    max-width: 876px;
    margin-inline: auto;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
  .page {
    padding-top: 24px;
    padding-inline: 14px;
  }

  h1 {
    margin-top: 24px;
    margin-bottom: 0;
  }

  .intro {
    display: none;
  }

  .setup {
    margin-top: 24px;
  }

  .trainer {
    border-radius: 22px;
  }

  .hud {
    gap: 10px;
    padding-bottom: 9px;
  }

  .hud-meta {
    gap: 16px;
  }

  .btn {
    height: 48px;
  }

  .btn-ghost {
    min-width: 88px;
    padding-inline: 18px;
  }

  .footer {
    flex-direction: column;
    gap: 5px;
    margin-top: 24px;
  }

  .noscript {
    margin-top: 14px;
  }
}

@media (max-width: 380px) {
  .wordmark {
    letter-spacing: 0.12em;
  }

  .size-btn {
    padding-inline: 4px;
  }

  .size-btn strong {
    font-size: 13px;
  }

  .size-btn span {
    font-size: 8px;
  }

  .hud {
    gap: 8px;
  }

  .hud-meta {
    gap: 12px;
  }

  #timer {
    font-size: 1.6rem;
  }
}

@media (max-width: 600px) {
  @container (max-width: 350px) {
    .hud {
      flex-wrap: wrap;
      row-gap: 8px;
    }

    .hud-next {
      margin-left: auto;
    }

    .hud-meta {
      flex: 1 1 100%;
      justify-content: space-between;
      margin-left: 0;
      gap: 12px;
    }

    .hud-meta > div:first-child {
      align-items: flex-start;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
