/* SudokuGridBase — Ink Grid Desk (scoped).
   Fonts: next/font Source Sans 3 / DM Mono via --font-* on <html> (no remote @import).
   Board look locked to 设计稿 App.tsx Grid: 3px box ink, gap-px hairlines, DM Mono digits. */

/* Tokens: 设计冻结表（冷纸纠偏）· 格态抄 Make App.tsx，禁止自造描边/奶油底 */
[data-theme="sgb"],
.sgb-root {
  --sgb-primary: #0d6e6e;
  --sgb-primary-hover: #0a5858;
  --sgb-ink: #1c1916;
  --sgb-paper: #e9e6df;
  --sgb-surface: #f7f5f0;
  --sgb-selected: #d8efef;
  --sgb-box: #1c1916;
  --sgb-conflict: #b42318;
  --sgb-font-ui: var(--font-source-sans), "Source Sans 3", "Segoe UI", sans-serif;
  --sgb-font-mono: var(--font-dm-mono), "DM Mono", ui-monospace, monospace;
  --background: var(--sgb-paper);
  --foreground: var(--sgb-ink);
  --card: var(--sgb-surface);
  --card-foreground: var(--sgb-ink);
  --primary: var(--sgb-primary);
  --primary-foreground: #ffffff;
  --muted: #e5e0d8;
  --muted-foreground: #6b665f;
  --border: #d4cfc4;
  --secondary: #e5e0d8;
  --accent: var(--sgb-selected);
  --accent-foreground: var(--sgb-primary);
  --radius: 0;
  background: var(--background);
  color: var(--foreground);
  max-width: 100%;
  overflow-x: clip;
  box-sizing: border-box;
  font-family: var(--sgb-font-ui);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  font-synthesis: none;
}

/* Dark — Make theme.css .dark */
.sgb-root[data-sgb-mode="dark"],
[data-theme="sgb"][data-sgb-mode="dark"] {
  --sgb-primary: #2dd4bf;
  --sgb-primary-hover: #5eead4;
  --sgb-ink: #e0dcd3;
  --sgb-paper: #141210;
  --sgb-surface: #25231f;
  --sgb-selected: #115e59;
  --sgb-box: #e0dcd3;
  --sgb-conflict: #ef4444;
  --background: #141210;
  --foreground: #e0dcd3;
  --card: #25231f;
  --card-foreground: #e0dcd3;
  --primary: #2dd4bf;
  --primary-foreground: #115e59;
  --muted: #33302b;
  --muted-foreground: #9a948a;
  --border: #423d36;
  --secondary: #33302b;
  --accent: #115e59;
  --accent-foreground: #ccfbf1;
}

.sgb-chrome-header {
  background: var(--background);
}

/* Match p8b: mobile 320×100 / desktop leaderboard 728×90 */
.sgb-ad-slot {
  height: 100px;
  margin-top: 0.5rem;
  border: 1px dashed var(--border);
  background: color-mix(in srgb, var(--card) 50%, transparent);
}

@media (min-width: 640px) {
  .sgb-ad-slot {
    height: 90px;
    margin-top: 0.75rem;
  }
}

.sgb-ad-label-mobile {
  display: none;
}

@media (max-width: 639px) {
  .sgb-ad-label-desktop {
    display: none;
  }

  .sgb-ad-label-mobile {
    display: inline;
  }
}

/* Board + chrome column under page head */
.sgb-play-body {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.625rem;
}

@media (min-width: 640px) {
  .sgb-play-body {
    padding-top: 0.75rem;
  }
}

@media (min-width: 768px) {
  .sgb-play-body {
    gap: 0.5rem;
  }
}

/* Board + controls row on wide screens; stacked on mobile */
.sgb-play-stage {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 0.35rem;
}

.sgb-play-board-col {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 0.35rem;
}

.sgb-play-side {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@media (min-width: 768px) {
  .sgb-play-stage {
    flex-direction: row;
    align-items: stretch;
    gap: clamp(1rem, 2.5vw, 1.75rem);
  }

  .sgb-play-board-col {
    flex: 1 1 auto;
    min-height: 0;
    justify-content: center;
  }

  .sgb-play-side {
    flex: 0 0 clamp(11.5rem, 22vw, 16.5rem);
    width: clamp(11.5rem, 22vw, 16.5rem);
    min-height: 0;
    justify-content: center;
    gap: 0.75rem;
    padding-block: 0.25rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

[data-theme="sgb"] *,
.sgb-root * {
  box-sizing: border-box;
}

.sgb-root .sgb-mono,
[data-theme="sgb"] .sgb-mono {
  font-family: var(--sgb-font-mono);
  font-variant-numeric: tabular-nums;
}

/*
 * First fold — #play = 100svh − hero (via --sgb-hero-h on <html>).
 * Default ≈ measured chrome+H1 band (~189–193px). useLayoutEffect syncs the
 * real offsetHeight; do not seed React state at 64px (that caused CLS ~0.12).
 * Write the var on <html>, never as inline style on React-owned .sgb-root.
 */
html {
  --sgb-hero-h: 12rem;
}

.sgb-root .play-surface {
  background: var(--sgb-paper);
  height: calc(100svh - var(--sgb-hero-h));
  max-height: calc(100svh - var(--sgb-hero-h));
  min-height: 0;
  overflow: hidden;
}

/* Tall PC: pack play cluster so SEO can peek (SOP §0.16). */
@media (min-width: 1024px) and (min-height: 1100px) {
  .sgb-root .play-surface {
    height: auto;
    max-height: none;
    overflow: visible;
  }
}

.sgb-meta-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 2px;
  background: var(--muted);
  padding: 0.125rem 0.625rem;
  font-family: var(--sgb-font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

/* SEO page head — H1/sub carry keywords; difficulty + timer only */
.sgb-page-head {
  display: grid;
  gap: 0.45rem 1rem;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.sgb-page-head-main {
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 768px) {
  .sgb-page-head {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .sgb-page-head-meta {
    justify-self: end;
  }
}

.sgb-page-h1 {
  margin: 0;
  max-width: 100%;
  font-size: clamp(1.25rem, 2.6vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--foreground);
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
}

.sgb-page-lead {
  margin: 0.35rem 0 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--muted-foreground);
  text-align: left;
  white-space: normal;
  overflow: visible;
}

/* Mobile only: swipe lead when short — contain inside head (min-width:0) */
@media (max-width: 767px) {
  .sgb-page-lead {
    display: block;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }

  .sgb-page-lead::-webkit-scrollbar {
    display: none;
  }
}

.sgb-page-trust {
  margin: 0.3rem 0 0;
  max-width: 100%;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted-foreground);
  text-align: center;
  white-space: normal;
}

.sgb-page-head-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.65rem 1rem;
  min-width: 0;
  max-width: 100%;
}

@media (min-width: 768px) {
  .sgb-page-h1,
  .sgb-page-trust {
    text-align: left;
  }

  .sgb-page-lead {
    max-width: 40rem;
    white-space: normal;
    overflow: visible;
  }

  .sgb-page-head-meta {
    justify-content: flex-end;
  }
}

/* Technique hint — board → hint → buttons */
.sgb-board-hint {
  display: flex;
  min-height: 1.4rem;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.55rem;
  margin-bottom: 0.45rem;
  padding: 0 0.25rem;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--primary);
}

.sgb-board-hint-icon {
  flex-shrink: 0;
}

/* Short viewports: tighten play area only — keep H1 + description layout unchanged */
@media (max-height: 720px) {
  .sgb-play-body {
    padding-top: 0.35rem;
  }

  .sgb-board-slot {
    padding-block: 0.25rem;
  }

  .sgb-board-hint {
    min-height: 1rem;
    margin-top: 0.25rem;
    margin-bottom: 0.2rem;
    font-size: 0.8125rem;
  }
}

@media (max-height: 640px) {
  .sgb-play-body {
    padding-top: 0.25rem;
  }
}

/* Small screens only: compact action + numpad; ad slot height stays 90px */
@media (max-width: 767px) {
  .sgb-action-strip {
    gap: 0.3rem;
    padding: 0;
  }

  .sgb-btn {
    height: 1.625rem;
    min-height: 1.625rem;
    padding: 0 0.35rem;
    font-size: 0.6875rem;
    font-weight: 400;
    gap: 0.15rem;
    border-width: 1px;
  }

  .sgb-btn-primary {
    padding-inline: 0.4rem;
    font-weight: 500;
  }

  .sgb-btn-icon {
    width: 1.625rem;
  }

  .sgb-btn-ghost {
    height: 1.5rem;
    min-height: 1.5rem;
    font-size: 0.625rem;
    font-weight: 400;
    padding: 0 0.2rem;
  }

  .sgb-action-strip .sgb-btn svg {
    width: 11px;
    height: 11px;
    stroke-width: 1.75;
  }

  .sgb-root .sgb-action-strip .sgb-pwa-install > span > button {
    width: 1.625rem !important;
    min-width: 1.625rem !important;
    height: 1.625rem !important;
  }

  .sgb-root .sgb-action-strip .sgb-pwa-install > span > button > svg {
    width: 12px;
    height: 12px;
  }
}

/* Small + short: squeeze controls + hint strip */
@media (max-width: 767px) and (max-height: 720px) {
  .sgb-board-hint {
    min-height: 1rem;
    margin-top: 0.2rem;
    margin-bottom: 0.15rem;
    font-size: 0.75rem;
  }

  .sgb-action-strip {
    gap: 0.3rem;
  }

  .sgb-btn {
    height: 1.875rem;
    min-height: 1.875rem;
    padding: 0 0.55rem;
    font-size: 0.75rem;
    gap: 0.2rem;
    border-width: 1px;
  }

  .sgb-btn-primary {
    padding-inline: 0.7rem;
  }

  .sgb-btn-icon {
    width: 1.875rem;
  }

  .sgb-btn-ghost {
    height: 1.625rem;
    min-height: 1.625rem;
    font-size: 0.6875rem;
  }

  .sgb-action-strip .sgb-btn svg {
    width: 12px;
    height: 12px;
  }

  .sgb-root .sgb-action-strip .sgb-pwa-install > span > button {
    width: 1.875rem !important;
    min-width: 1.875rem !important;
    height: 1.875rem !important;
  }

  .sgb-root .sgb-action-strip .sgb-pwa-install > span > button > svg {
    width: 12px;
    height: 12px;
  }
}

@media (max-width: 767px) and (max-height: 640px) {
  .sgb-board-slot {
    padding-block: 0.15rem;
  }

  .sgb-board-hint {
    min-height: 0.75rem;
    margin-top: 0.08rem;
    margin-bottom: 0.08rem;
    font-size: 0.6875rem;
  }

  .sgb-play-side .sgb-action-strip {
    gap: 0.25rem;
  }

  .sgb-play-side .sgb-numpad {
    gap: 0.25rem;
    margin-top: 0.35rem;
  }

  .sgb-play-side .sgb-key {
    width: 1.875rem;
    height: 1.875rem;
    min-height: 1.875rem;
    font-size: 0.8125rem;
  }

  .sgb-play-side .sgb-numpad-erase {
    height: 1.875rem;
    min-height: 1.875rem;
  }

  .sgb-action-strip {
    gap: 0.25rem;
  }

  .sgb-btn {
    height: 1.625rem;
    min-height: 1.625rem;
    padding: 0 0.45rem;
    font-size: 0.6875rem;
  }

  .sgb-btn-primary {
    padding-inline: 0.6rem;
  }

  .sgb-btn-icon {
    width: 1.625rem;
  }

  .sgb-btn-ghost {
    height: 1.5rem;
    min-height: 1.5rem;
    font-size: 0.625rem;
  }

  .sgb-action-strip .sgb-btn svg {
    width: 11px;
    height: 11px;
  }

  .sgb-root .sgb-action-strip .sgb-pwa-install > span > button {
    width: 1.625rem !important;
    min-width: 1.625rem !important;
    height: 1.625rem !important;
  }

  .sgb-root .sgb-action-strip .sgb-pwa-install > span > button > svg {
    width: 11px;
    height: 11px;
  }

  .sgb-ad-slot {
    margin-top: 0.4rem;
  }
}

/* Slot is the size container — Make: aspect-square h-full w-auto max-w-full */
.sgb-board-slot {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding-block: clamp(0.5rem, 1.5vh, 0.875rem);
  container-type: size;
}

@media (min-width: 768px) {
  .sgb-board-slot {
    padding-block: clamp(0.625rem, 1.8vh, 1rem);
  }
}

/*
 * Make App.tsx Grid wrapper:
 *   relative aspect-square h-full max-h-full w-auto max-w-full
 *   border-[3px] border-foreground bg-foreground p-px
 */
.sgb-board {
  position: relative;
  box-sizing: border-box;
  /* Size from container query; height follows aspect-ratio (avoid mismatched height %) */
  width: min(100cqw, 100cqh);
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid var(--foreground);
  background: var(--foreground);
  padding: 1px;
}

/* First load: empty grid, no selection cross — calm paper cells + soft pulse */
.sgb-board.is-loading .sgb-cell {
  background: var(--card);
  color: transparent;
  pointer-events: none;
}

.sgb-board.is-loading .sgb-cell:hover {
  background: var(--card);
}

.sgb-board-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: color-mix(in srgb, var(--sgb-paper) 55%, transparent);
  pointer-events: none;
}

.sgb-board-loading-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 0;
  background: var(--primary);
  animation: sgb-load-pulse 0.9s ease-in-out infinite;
}

.sgb-board-loading-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.sgb-board-loading-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes sgb-load-pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

/* New puzzle while old grid still visible */
.sgb-board.is-busy {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.sgb-board.is-busy .sgb-cell {
  pointer-events: none;
}

/* Inner: grid h-full grid-cols-9 gap-px bg-foreground */
.sgb-board-cells {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  gap: 1px;
}

.sgb-board-cells[data-size="6"] .sgb-digit {
  font-size: clamp(1.05rem, 4.2vmin, 1.55rem);
}

.sgb-board-cells[data-size="16"] .sgb-digit {
  font-size: clamp(0.55rem, 1.8vmin, 0.85rem);
}

.sgb-board-cells[data-size="16"] .sgb-pencils {
  font-size: 0.45rem;
  line-height: 1;
}

/* Samurai: 21×21 canvas with dead gaps — still square; allow scroll in slot on short viewports */
.sgb-board-slot.is-samurai {
  overflow: auto;
  align-items: flex-start;
  justify-content: center;
}

.sgb-board.is-samurai {
  /* Prefer fitting width; height can exceed slot (scroll) so cells stay readable */
  width: min(100cqw, max(100cqh, 18rem));
  max-height: none;
  aspect-ratio: 1;
  background: var(--sgb-paper);
}

.sgb-board.is-samurai .sgb-board-cells {
  /* Ink shows through 1px gaps between live cells; dead cells paint paper holes */
  background: var(--foreground);
  gap: 1px;
}

.sgb-board-cells.is-samurai .sgb-digit {
  font-size: clamp(0.42rem, 1.55vmin, 0.72rem);
}

.sgb-board-cells.is-samurai .sgb-pencils {
  font-size: 0.38rem;
  line-height: 1;
  gap: 0;
}

.sgb-cell.sgb-cell-dead {
  pointer-events: none;
  background: var(--sgb-paper) !important;
  border: none;
  box-shadow: none;
}

.sgb-board.is-loading .sgb-cell.sgb-cell-dead {
  background: var(--sgb-paper) !important;
}

.sgb-numpad[data-size="16"] {
  flex-wrap: wrap;
  max-width: 18rem;
}

.sgb-numpad[data-size="16"] .sgb-key {
  min-width: 2rem;
  flex: 0 0 calc(25% - 0.25rem);
}

.sgb-cell {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: var(--card);
  color: var(--primary);
  font-family: var(--sgb-font-mono);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  cursor: pointer;
  transition: background-color 75ms;
  appearance: none;
  -webkit-appearance: none;
}

.sgb-digit {
  font-family: var(--sgb-font-mono);
  font-size: clamp(16px, 4vh, 32px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.sgb-cell:hover:not(.is-selected) {
  background: var(--muted);
}

/* Design: givens = text-foreground / font-medium */
.sgb-cell.is-given {
  color: var(--foreground);
}

.sgb-cell.is-given .sgb-digit {
  font-weight: 500;
  color: inherit;
}

/* Design: related empty → muted/30; filled related → card/70 */
.sgb-cell.is-related:not(.is-selected):not(.is-same):not(.is-filled) {
  background: color-mix(in srgb, var(--muted) 30%, transparent);
}

.sgb-cell.is-related.is-filled:not(.is-selected):not(.is-same) {
  background: color-mix(in srgb, var(--card) 70%, var(--background));
}

/* Design: same digit → bg-secondary */
.sgb-cell.is-same:not(.is-selected) {
  background: var(--secondary);
}

/* Design: selected → bg-accent; user digit bold primary; given accent-foreground */
.sgb-cell.is-selected {
  background: var(--accent);
  z-index: 1;
}

.sgb-cell.is-selected .sgb-digit {
  color: var(--primary);
  font-weight: 700;
}

.sgb-cell.is-selected.is-given .sgb-digit {
  color: var(--accent-foreground);
  font-weight: 500;
}

.sgb-cell.is-conflict {
  color: var(--sgb-conflict) !important;
  background: color-mix(in srgb, var(--sgb-conflict) 12%, var(--card));
}

.sgb-cell.is-conflict .sgb-digit {
  color: inherit;
}

/*
 * Hint coaching — must stay visible on the selected tip cell.
 * Hint always selects h.index, so :not(.is-selected) would hide the primary target.
 */
.sgb-cell.is-hint:not(.is-conflict) {
  background: color-mix(in srgb, var(--primary) 18%, var(--card));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 75%, transparent);
  z-index: 2;
}

.sgb-cell.is-hint.is-selected:not(.is-conflict) {
  background: color-mix(in srgb, var(--primary) 30%, var(--accent));
  box-shadow: inset 0 0 0 3px var(--primary);
}

/* Elimination targets — dashed outline; can stack with is-hint */
.sgb-cell.is-hint-elim:not(.is-conflict) {
  outline: 2px dashed color-mix(in srgb, var(--primary) 45%, var(--sgb-ink));
  outline-offset: -3px;
}

/* 3×3 — design border-r/b-[3px] border-foreground on cells */
.sgb-cell.box-r {
  border-right: 3px solid var(--foreground);
}

.sgb-cell.box-b {
  border-bottom: 3px solid var(--foreground);
}

/* Killer cages — dashed ink outline + alternate tint */
.sgb-cell.is-cage-tint:not(.is-selected) {
  background: color-mix(in srgb, var(--primary) 5%, var(--card));
}

.sgb-cell.cage-edge::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-style: dashed;
  border-color: color-mix(in srgb, var(--primary) 50%, transparent);
  border-width: 0;
  pointer-events: none;
  z-index: 2;
}

.sgb-cell.cage-t::before {
  border-top-width: 1px;
}

.sgb-cell.cage-r::before {
  border-right-width: 1px;
}

.sgb-cell.cage-b::before {
  border-bottom-width: 1px;
}

.sgb-cell.cage-l::before {
  border-left-width: 1px;
}

/* Pencil — design: grid w-full h-full p-0.5, clamp(6px,1.2vh,10px) */
.sgb-pencils {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
  color: var(--muted-foreground);
  font-family: var(--sgb-font-mono);
  font-size: clamp(6px, 1.2vh, 10px);
  font-weight: 500;
  line-height: 1;
}

.sgb-pencils span {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Killer sum overlay — design inset-[3px] */
.sgb-cages {
  pointer-events: none;
  position: absolute;
  inset: 3px;
  z-index: 3;
}

.sgb-cage-label {
  position: absolute;
  z-index: 3;
  padding: 1px 2px;
  font-family: var(--sgb-font-mono);
  font-size: clamp(8px, 1vh, 11px);
  font-weight: 500;
  color: var(--primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* Action bar — §0.16: mobile single-row scroll; PC wrap (no clip).
   Do not use justify-content:center with overflow-x:auto — clips both ends. */
.sgb-action-strip {
  display: flex;
  width: 100%;
  max-width: min(48rem, 100%);
  margin-inline: auto;
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 0.15rem 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sgb-action-strip::-webkit-scrollbar {
  display: none;
}

/* Own display — .sgb-btn { display:inline-flex } would override Tailwind md:hidden */
.sgb-mobile-only {
  display: inline-flex !important;
}

@media (min-width: 768px) {
  .sgb-mobile-only {
    display: none !important;
  }
}

.sgb-btn {
  display: inline-flex;
  height: 3rem;
  min-height: 3rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 2px solid var(--border);
  border-radius: 0;
  background: transparent;
  padding: 0 1.25rem;
  font-family: var(--sgb-font-ui);
  font-size: 0.9375rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--foreground);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.sgb-btn:hover:not(:disabled) {
  border-color: var(--foreground);
  background: var(--muted);
}

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

.sgb-btn.is-active {
  border-color: var(--primary);
  background: var(--accent);
  color: var(--primary);
}

.sgb-btn-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-foreground);
  padding-inline: 1.5rem;
}

.sgb-btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--primary) 90%, black);
  border-color: color-mix(in srgb, var(--primary) 90%, black);
  color: var(--primary-foreground);
}

.sgb-btn-icon {
  width: 3rem;
  padding: 0;
  color: var(--muted-foreground);
}

.sgb-btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted-foreground);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 600;
  height: 2.5rem;
  min-height: 2.5rem;
  padding: 0 0.5rem;
}

.sgb-btn-ghost:hover:not(:disabled) {
  border-color: transparent;
  background: var(--muted);
  color: var(--foreground);
}

/* Touch digit row — plain keys (not in Make mock; no fake mini-grid) */
.sgb-numpad {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 0.75rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.sgb-numpad::-webkit-scrollbar {
  display: none;
}

.sgb-key {
  display: flex;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--foreground);
  font-family: var(--sgb-font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  cursor: pointer;
}

.sgb-key:hover {
  border-color: var(--foreground);
  background: var(--muted);
}

/* Mobile first-fold (≤767px): square board via size container; compact control rows */
@media (max-width: 767px) {
  .sgb-play-stage {
    flex: 1 1 auto;
    min-height: 0;
  }

  .sgb-play-board-col {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
  }

  .sgb-play-side {
    flex: 0 0 auto;
    width: 100%;
  }

  /*
   * Board size from slot: keep container-type:size so both cqw/cqh work.
   * Set only width (+ aspect-ratio); never set mismatched height/100% or the
   * square collapses into a flat strip.
   */
  .sgb-board-slot {
    flex: 1 1 auto;
    min-height: 0;
    padding-block: 0.2rem;
    container-type: size;
  }

  .sgb-board {
    width: min(100cqw, 100cqh);
    height: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1;
  }

  .sgb-board-hint {
    margin-top: 0.3rem;
    margin-bottom: 0.2rem;
  }

  /* §0.16: single-row scroll actions — not a 2-col grid (orphans Install) */
  .sgb-play-side .sgb-action-strip {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    margin-inline: 0;
    justify-content: flex-start;
    overflow-x: auto;
    gap: 0.3rem;
    padding: 0.1rem 0;
  }

  .sgb-play-side .sgb-action-strip .sgb-btn {
    width: auto;
    height: 1.625rem;
    min-height: 1.625rem;
    padding: 0 0.3rem;
    font-weight: 400;
  }

  .sgb-play-side .sgb-action-strip .sgb-btn-primary {
    padding-inline: 0.35rem;
    font-weight: 500;
  }

  .sgb-play-side .sgb-action-strip .sgb-mobile-only {
    display: inline-flex !important;
  }

  /* Digits: one scrollable row so board keeps height */
  .sgb-play-side .sgb-numpad {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.2rem;
    margin-top: 0.3rem;
    overflow-x: auto;
    width: 100%;
    scrollbar-width: none;
  }

  .sgb-play-side .sgb-numpad::-webkit-scrollbar {
    display: none;
  }

  .sgb-play-side .sgb-key {
    width: 1.625rem;
    height: 1.625rem;
    min-height: 1.625rem;
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 400;
    border-width: 1px;
  }

  .sgb-play-side .sgb-numpad-erase {
    grid-column: auto;
    width: auto;
    height: 1.625rem;
    min-height: 1.625rem;
    flex-shrink: 0;
    padding: 0 0.2rem;
    font-weight: 400;
  }
}

/* Wide two-column: side panel controls (after base flex numpad so grid wins) */
@media (min-width: 768px) {
  .sgb-play-board-col .sgb-board-hint {
    margin-top: 0.35rem;
    margin-bottom: 0;
    justify-content: center;
    text-align: center;
  }

  .sgb-play-side .sgb-action-strip {
    flex-direction: column;
    width: 100%;
    max-width: none;
    margin-inline: 0;
    justify-content: flex-start;
    overflow-x: visible;
    gap: 0.5rem;
    padding: 0;
  }

  .sgb-play-side .sgb-action-strip .sgb-btn {
    width: 100%;
  }

  .sgb-play-side .sgb-numpad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-items: stretch;
    margin-top: 0.25rem;
    gap: 0.35rem;
    overflow: visible;
  }

  .sgb-play-side .sgb-key {
    width: 100%;
    height: 2.35rem;
    min-height: 2.35rem;
  }

  .sgb-play-side .sgb-numpad-erase {
    grid-column: 1 / -1;
    width: 100%;
    height: 2.25rem;
    min-height: 2.25rem;
  }
}

/* Wide + short (Nest Hub 1024×600): 2-col side buttons, tighter padding */
@media (min-width: 768px) and (max-height: 640px) {
  .sgb-play-side {
    gap: 0.35rem;
    padding-block: 0;
  }

  .sgb-play-side .sgb-action-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.3rem;
  }

  .sgb-play-side .sgb-action-strip .sgb-btn {
    width: 100%;
    height: 1.875rem;
    min-height: 1.875rem;
    padding: 0 0.4rem;
    font-size: 0.75rem;
    gap: 0.2rem;
    border-width: 1.5px;
  }

  .sgb-play-side .sgb-action-strip .sgb-btn-primary {
    padding-inline: 0.4rem;
  }

  .sgb-play-side .sgb-action-strip .sgb-btn svg {
    width: 12px;
    height: 12px;
  }

  .sgb-play-side .sgb-numpad {
    margin-top: 0.1rem;
    gap: 0.25rem;
  }

  .sgb-play-side .sgb-key {
    height: 1.75rem;
    min-height: 1.75rem;
    font-size: 0.8125rem;
  }

  .sgb-play-side .sgb-numpad-erase {
    height: 1.625rem;
    min-height: 1.625rem;
    font-size: 0.6875rem;
  }
}

/* Install control — icon-only, matches Make utility buttons */
.sgb-root .sgb-pwa-install {
  display: inline-flex;
  line-height: 0;
}

.sgb-root .sgb-pwa-install > span {
  display: inline-flex;
}

.sgb-root .sgb-pwa-install > span > button {
  box-sizing: border-box !important;
  display: inline-grid !important;
  place-items: center !important;
  width: 2.25rem !important;
  min-width: 2.25rem !important;
  height: 2.25rem !important;
  padding: 0 !important;
  gap: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  background: transparent !important;
  color: var(--muted-foreground) !important;
  box-shadow: none !important;
  opacity: 1 !important;
}

.sgb-root .sgb-pwa-install > span > button:hover {
  background: var(--muted) !important;
  color: var(--foreground) !important;
}

.sgb-root .sgb-action-strip .sgb-pwa-install > span > button {
  width: 3rem !important;
  min-width: 3rem !important;
  height: 3rem !important;
  border: 2px solid var(--border) !important;
}

.sgb-root .sgb-action-strip .sgb-pwa-install > span > button:hover {
  border-color: var(--foreground) !important;
}

.sgb-root .sgb-pwa-install > span > button > span {
  display: none !important;
}

.sgb-root .sgb-pwa-install > span > button > svg {
  width: 18px;
  height: 18px;
}

/* SEO band — below first fold; paper desk reading surface (design App.tsx) */
.sgb-seo {
  border-top: 1px solid var(--border);
  background: var(--sgb-surface);
  content-visibility: auto;
  contain-intrinsic-size: auto 1200px;
}

.sgb-seo-inner {
  margin: 0 auto;
  max-width: 880px;
  padding: 3.5rem 1.25rem 4rem;
}

@media (min-width: 1024px) {
  .sgb-seo-inner {
    padding: 4.5rem 2rem 5rem;
  }
}

.sgb-article {
  color: var(--sgb-ink);
}

.sgb-article .article-lead {
  margin-bottom: 2.75rem;
  padding-bottom: 2.25rem;
  border-bottom: 1px solid var(--border);
}

.sgb-article .article-kicker {
  margin: 0 0 0.75rem;
  font-family: var(--sgb-font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sgb-primary);
}

.sgb-article .article-lead-title {
  margin: 0 0 1.25rem;
  font-size: clamp(1.75rem, 3.5vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.12;
  color: var(--sgb-ink);
}

.sgb-article .article-section {
  margin-top: 2.75rem;
  padding-top: 1.75rem;
  border-top: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
}

.sgb-article .article-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.sgb-article .article-section h2 {
  margin: 0.35rem 0 0.9rem;
  font-size: clamp(1.35rem, 2.4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  color: var(--sgb-ink);
}

.sgb-article .article-section p,
.sgb-article .article-section li {
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--muted-foreground);
  font-weight: 500;
}

.sgb-article .article-section p + p {
  margin-top: 1rem;
}

.sgb-article .article-section a {
  color: var(--sgb-ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--sgb-primary) 45%, transparent);
  text-underline-offset: 3px;
}

.sgb-article .article-section a:hover {
  color: var(--sgb-primary);
  text-decoration-color: var(--sgb-primary);
}

.sgb-article .article-section ol,
.sgb-article .article-section ul {
  margin: 0.85rem 0 0;
  padding: 0;
  list-style: none;
}

.sgb-article .article-section ol > li,
.sgb-article .article-section ul > li {
  position: relative;
  padding: 0.65rem 0 0.65rem 1.65rem;
  border-bottom: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
}

.sgb-article .article-section ol > li:last-child,
.sgb-article .article-section ul > li:last-child {
  border-bottom: none;
}

.sgb-article .article-section ol {
  counter-reset: sgb-step;
}

.sgb-article .article-section ol > li {
  counter-increment: sgb-step;
}

.sgb-article .article-section ol > li::before {
  content: counter(sgb-step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.75rem;
  font-family: var(--sgb-font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--sgb-primary);
}

.sgb-article .article-section ul > li::before {
  content: "";
  position: absolute;
  left: 0.35rem;
  top: 1.15rem;
  width: 0.35rem;
  height: 0.35rem;
  background: var(--sgb-primary);
}

.sgb-article .article-section strong {
  color: var(--sgb-ink);
  font-weight: 700;
}

/* Text + figure stagger — stack on narrow; alternate sides from md up */
.sgb-split {
  display: grid;
  gap: 1.25rem;
  margin: 0.35rem 0 1.1rem;
  align-items: start;
}

.sgb-split-copy > p:first-child,
.sgb-split-copy > ol:first-child,
.sgb-split-copy > ul:first-child {
  margin-top: 0;
}

.sgb-split-copy > p + p,
.sgb-split-copy > ol + p {
  margin-top: 1rem;
}

@media (min-width: 800px) {
  .sgb-split {
    grid-template-columns: minmax(0, 1fr) minmax(12.5rem, 17.5rem);
    gap: 1.75rem 2rem;
    align-items: center;
  }

  .sgb-split--figure-end .sgb-article-figure {
    grid-column: 2;
    grid-row: 1;
  }

  .sgb-split--figure-end .sgb-split-copy {
    grid-column: 1;
    grid-row: 1;
  }

  .sgb-split--figure-start {
    grid-template-columns: minmax(12.5rem, 17.5rem) minmax(0, 1fr);
  }

  .sgb-split--figure-start .sgb-article-figure {
    grid-column: 1;
    grid-row: 1;
  }

  .sgb-split--figure-start .sgb-split-copy {
    grid-column: 2;
    grid-row: 1;
  }

  /* Slight vertical offset so blocks don't read as a rigid table */
  .sgb-split--figure-end .sgb-article-figure {
    margin-top: 0.35rem;
  }

  .sgb-split--figure-start .sgb-article-figure {
    margin-top: -0.15rem;
  }
}

/* Below-fold diagrams — inline SVG; reserved aspect avoids CLS */
.sgb-article-figure {
  margin: 0;
  width: 100%;
  max-width: 22.5rem;
  justify-self: start;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--sgb-paper) 70%, var(--sgb-surface));
}

.sgb-split--figure-end .sgb-article-figure {
  justify-self: end;
}

.sgb-article-figure-frame {
  display: block;
  width: 100%;
  background: var(--sgb-paper);
}

.sgb-article-figure-img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 320px;
  aspect-ratio: 320 / 168;
}

.sgb-article-figure-cap {
  margin: 0;
  padding: 0.55rem 0.75rem 0.65rem;
  border-top: 1px dashed var(--border);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--muted-foreground);
}

/* Collapsible FAQ — native details/summary (home + tool pages) */
.sgb-faq-list {
  display: grid;
  gap: 0.65rem;
  margin-top: 1.15rem;
}

.sgb-faq-item {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--sgb-surface);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.sgb-faq-item[open] {
  border-color: color-mix(in srgb, var(--sgb-primary) 35%, var(--border));
  background: color-mix(in srgb, var(--sgb-selected) 28%, var(--sgb-surface));
}

.sgb-faq-q {
  position: relative;
  display: block;
  padding: 1rem 2.75rem 1rem 1.15rem;
  list-style: none;
  cursor: pointer;
  font-size: 1.0125rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.35;
  color: var(--sgb-ink);
  user-select: none;
}

.sgb-faq-q::-webkit-details-marker {
  display: none;
}

.sgb-faq-q::marker {
  content: "";
}

.sgb-faq-q::after {
  content: "+";
  position: absolute;
  right: 1.05rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--sgb-font-mono);
  font-size: 1.2rem;
  font-weight: 500;
  line-height: 1;
  color: var(--sgb-primary);
  transition: transform 0.12s ease;
}

.sgb-faq-item[open] > .sgb-faq-q::after {
  content: "−";
}

.sgb-faq-q:hover {
  color: var(--sgb-primary);
}

.sgb-faq-a {
  margin: 0;
  padding: 0 1.15rem 1.15rem;
  border-top: 1px dashed color-mix(in srgb, var(--border) 80%, transparent);
  padding-top: 0.85rem;
  margin-top: -0.15rem;
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.65;
  color: var(--muted-foreground);
  max-width: 40rem;
}

.sgb-link-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.35rem;
}

.sgb-link-rail a {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  background: var(--sgb-surface);
  color: var(--sgb-ink) !important;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none !important;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.sgb-link-rail a:hover {
  border-color: var(--sgb-primary);
  background: var(--sgb-selected);
  color: var(--sgb-primary) !important;
}

.sgb-compare-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin: 0.25rem 0 0;
}

.sgb-compare-line span {
  font-size: 0.975rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

/* Footer language — same IA as p8b; ink desk (radius 0) */
.sgb-root .footer-lang {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sgb-root .footer-lang-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.sgb-root .footer-lang-picker {
  position: relative;
}

.sgb-root .footer-lang-static {
  display: inline-flex;
  align-items: center;
  height: 36px;
  min-width: 132px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--background);
  padding: 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--foreground);
}

.sgb-root .footer-lang-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  min-width: 132px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--background);
  padding: 0 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--foreground);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.sgb-root .footer-lang-trigger:hover,
.sgb-root .footer-lang-trigger.is-open {
  border-color: var(--sgb-ink);
}

.sgb-root .footer-lang-trigger-text {
  flex: 1;
  text-align: left;
}

.sgb-root .footer-lang-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--muted-foreground);
  transition: transform 0.15s ease;
}

.sgb-root .footer-lang-trigger.is-open .footer-lang-chevron {
  transform: rotate(180deg);
}

.sgb-root .footer-lang-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 40;
  width: min(220px, calc(100vw - 40px));
  max-height: min(320px, 52vh);
  overflow-y: auto;
  border-radius: 0;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 6px;
  box-shadow: 0 10px 28px rgb(28 25 22 / 14%);
  scrollbar-width: thin;
}

.sgb-root .footer-lang-option {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--foreground);
  text-align: left;
  cursor: pointer;
}

.sgb-root .footer-lang-option:hover:not(.is-selected) {
  background: var(--muted);
}

.sgb-root .footer-lang-option.is-selected {
  background: var(--sgb-selected);
  color: var(--sgb-primary);
}
