:root {
  color-scheme: light;

  /* Font family */
  --font-sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "SFMono-Regular", Consolas, monospace;

  /* Light theme: zen paper */
  --bg-primary: #f7f5f0;
  --bg-secondary: #efece3;
  --text-main: #1a1e21;
  --text-muted: #6e7275;
  --border-grid: #d5d1c5;

  /* Night theme: midnight minimal */
  --night-bg-primary: #0f121a;
  --night-bg-secondary: #171b26;
  --night-text-main: #e2e8f0;
  --night-text-muted: #64748b;
  --night-border-grid: #2d3748;

  /* Interactive states */
  --accent-glowing: #00f5d4;
  --accent-error: #ff0054;
  --accent-marker: #7b2cbf;
  --shadow-subtle: rgba(0, 0, 0, 0.05);

  /* Sizing units */
  --radius-minimal: 4px;
  --border-thickness: 1px;
  --gameplay-line-width: 3px;

  /* Semantic aliases */
  --surface-page: var(--bg-primary);
  --surface-panel: var(--bg-secondary);
  --surface-raised: #fffdf8;
  --surface-control: #faf8f2;
  --text-primary: var(--text-main);
  --text-secondary: var(--text-muted);
  --border-subtle: #dedacf;
  --grid-line: var(--border-grid);
  --focus-ring: rgba(0, 245, 212, 0.38);

  /* Layout tokens */
  --header-height: 48px;
  --mobile-ad-height: 50px;
  --bottom-bar-height: 72px;
  --desktop-ad-width: 160px;
  --right-shelf-width: 280px;
  --game-max: min(72vh, 680px);
  --page-gutter: clamp(10px, 2vw, 24px);
  --gap-page: clamp(12px, 1.6vw, 22px);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
}

/* svh inside a custom property invalidates every use site on browsers without svh. */
@supports (height: 1svh) {
  :root {
    --game-max: min(72svh, 680px);
  }
}

:root[data-theme="night"] {
  color-scheme: dark;
  --surface-page: var(--night-bg-primary);
  --surface-panel: var(--night-bg-secondary);
  --surface-raised: #1d2330;
  --surface-control: #121722;
  --text-primary: var(--night-text-main);
  --text-secondary: var(--night-text-muted);
  --border-subtle: #273142;
  --grid-line: var(--night-border-grid);
  --shadow-subtle: rgba(0, 0, 0, 0.28);
  --focus-ring: rgba(0, 245, 212, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--surface-page);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background: var(--surface-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

button,
select {
  font: inherit;
}

button {
  min-height: 36px;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

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

.tabular,
.timer,
.cell-clue,
.island-clue {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "zero" 1;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding-inline: var(--page-gutter);
  border-bottom: var(--border-thickness) solid var(--border-subtle);
  background: color-mix(in srgb, var(--surface-page) 92%, transparent);
  backdrop-filter: blur(12px);
}

.brand,
.header-actions,
.language-picker,
.theme-toggle {
  display: inline-flex;
  align-items: center;
}

.brand {
  gap: var(--space-2);
  min-width: 0;
  font-weight: 700;
}

.brand-mark {
  position: relative;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border: 2px solid var(--accent-glowing);
  border-radius: 50%;
}

.brand-mark::after {
  position: absolute;
  inset: 5px -3px auto auto;
  width: 10px;
  height: 10px;
  border-top: 2px solid var(--accent-marker);
  border-right: 2px solid var(--accent-marker);
  content: "";
}

.header-actions {
  gap: var(--space-2);
}

.language-picker select {
  height: 32px;
  min-width: 124px;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-control);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle {
  width: 54px;
  height: 32px;
  justify-content: center;
  padding: 0;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: 999px;
  background: var(--surface-control);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle__track {
  position: relative;
  width: 42px;
  height: 22px;
}

.theme-toggle__track::before,
.theme-toggle__track::after {
  position: absolute;
  top: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  content: "";
}

.theme-toggle__track::before {
  left: 4px;
  background: #f2b705;
}

.theme-toggle__track::after {
  right: 5px;
  background: var(--night-text-main);
  box-shadow: -3px 0 0 var(--surface-control);
}

.theme-toggle__thumb {
  position: absolute;
  top: 2px;
  left: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-primary);
  box-shadow: 0 1px 4px var(--shadow-subtle);
  transition: transform 0.2s ease, background 0.2s ease;
}

:root[data-theme="night"] .theme-toggle__thumb {
  transform: translateX(21px);
}

.mobile-ad {
  display: none;
}

.portal-layout {
  /* Flex (not fixed 3-col grid): when ad blockers remove/hide .desktop-ad, the
     board and tool shelf stay centered instead of the board falling into the 160px track. */
  display: flex;
  flex-wrap: nowrap;
  gap: var(--gap-page);
  align-items: start;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  min-height: calc(100vh - var(--header-height));
  min-height: calc(100svh - var(--header-height));
  padding: var(--space-4) var(--page-gutter) var(--space-6);
}

.desktop-ad {
  position: sticky;
  top: calc(var(--header-height) + var(--space-4));
  flex: 0 0 var(--desktop-ad-width);
  display: grid;
  place-items: center;
  width: var(--desktop-ad-width);
  height: min(600px, calc(100vh - var(--header-height) - var(--space-6)));
  height: min(600px, calc(100svh - var(--header-height) - var(--space-6)));
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-panel);
  color: var(--text-secondary);
  font-size: 12px;
}

.game-column {
  display: grid;
  flex: 0 1 var(--game-max);
  gap: var(--space-3);
  width: min(100%, var(--game-max));
  max-width: var(--game-max);
  min-width: 0;
}

.game-status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding-inline: var(--space-1);
  color: var(--text-secondary);
}

.puzzle-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timer {
  color: var(--text-primary);
  font-weight: 700;
}

.game-square {
  position: relative;
  width: min(100%, var(--game-max));
  aspect-ratio: 1;
  justify-self: center;
  contain: layout paint;
}

.game-frame {
  position: absolute;
  inset: 0;
  display: grid;
  padding: clamp(8px, 1.8vw, 16px);
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-raised);
  box-shadow: 0 10px 28px var(--shadow-subtle);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.game-board {
  position: relative;
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--surface-control);
  cursor: crosshair;
  touch-action: manipulation;
  transition: background 0.2s ease, border-color 0.2s ease;
  user-select: none;
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.fence-board,
.bridges-board {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.fence-cells {
  display: grid;
  grid-template-columns: repeat(var(--fence-size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--fence-size), minmax(0, 1fr));
  width: 100%;
  height: 100%;
  border-top: var(--border-thickness) solid var(--grid-line);
  border-left: var(--border-thickness) solid var(--grid-line);
}

.fence-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-right: var(--border-thickness) solid var(--grid-line);
  border-bottom: var(--border-thickness) solid var(--grid-line);
  color: var(--text-primary);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.fence-edge {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-marker);
  cursor: pointer;
}

.fence-edge::before {
  display: block;
  border-radius: 999px;
  background: transparent;
  content: "";
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.fence-edge.is-line::before {
  background: var(--accent-glowing);
  box-shadow: 0 0 7px rgba(0, 245, 212, 0.42);
}

.fence-edge.is-marked::after {
  color: var(--accent-marker);
  content: "x";
  font-family: var(--font-mono);
  font-size: clamp(10px, 2.6vw, 18px);
  font-weight: 700;
  line-height: 1;
}

.fence-edge.is-error::before {
  background: var(--accent-error);
  box-shadow: 0 0 7px rgba(255, 0, 84, 0.32);
}

.fence-edge--h {
  left: calc(var(--col) * 100% / var(--fence-size));
  top: calc(var(--row) * 100% / var(--fence-size) - 12px);
  width: calc(100% / var(--fence-size));
  height: 24px;
}

.fence-edge--h::before {
  width: calc(100% - 10px);
  height: var(--gameplay-line-width);
}

.fence-edge--v {
  left: calc(var(--col) * 100% / var(--fence-size) - 12px);
  top: calc(var(--row) * 100% / var(--fence-size));
  width: 24px;
  height: calc(100% / var(--fence-size));
}

.fence-edge--v::before {
  width: var(--gameplay-line-width);
  height: calc(100% - 10px);
}

.fence-node {
  position: absolute;
  z-index: 6;
  left: calc(var(--col) * 100% / var(--fence-size));
  top: calc(var(--row) * 100% / var(--fence-size));
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cell-clue,
.marker {
  position: relative;
  z-index: 2;
}

.cell-clue {
  font-size: clamp(18px, 5.2vw, 40px);
  font-weight: 700;
  line-height: 1;
}

.cell-clue.is-satisfied,
.island-clue.is-satisfied,
.row-clue.is-satisfied {
  color: var(--text-secondary);
  text-decoration: line-through;
  text-decoration-thickness: 0.08em;
  text-decoration-color: color-mix(in srgb, var(--text-secondary) 68%, transparent);
}

.marker {
  color: var(--accent-marker);
  font-family: var(--font-mono);
  font-size: clamp(16px, 4vw, 30px);
  font-weight: 700;
}

.fence-cell.is-error {
  background: color-mix(in srgb, var(--accent-error) 10%, transparent);
}

.fence-cell.is-error .cell-clue {
  color: var(--accent-error);
}

.bridges-board {
  --bridge-size: 7;
  background-image:
    linear-gradient(to right, var(--grid-line) var(--border-thickness), transparent var(--border-thickness)),
    linear-gradient(to bottom, var(--grid-line) var(--border-thickness), transparent var(--border-thickness));
  background-size: calc(100% / var(--bridge-size)) calc(100% / var(--bridge-size));
  background-position: 0 0;
}

.bridge-link {
  position: absolute;
  z-index: 2;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.bridge-link::before,
.bridge-link::after {
  position: absolute;
  border-radius: 999px;
  background: transparent;
  content: "";
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.bridge-link.is-single::before,
.bridge-link.is-double::before,
.bridge-link.is-double::after {
  background: var(--accent-glowing);
  box-shadow: 0 0 7px rgba(0, 245, 212, 0.34);
}

.bridge-link.is-error::before,
.bridge-link.is-error::after {
  background: var(--accent-error);
}

.bridge-link--h {
  left: var(--left);
  top: calc(var(--top) - 14px);
  width: var(--width);
  height: 28px;
}

.bridge-link--h::before,
.bridge-link--h::after {
  left: 0;
  right: 0;
  height: var(--gameplay-line-width);
}

.bridge-link--h::before {
  top: 10px;
}

.bridge-link--h::after {
  bottom: 10px;
}

.bridge-link--h.is-single::before {
  top: calc(50% - var(--gameplay-line-width) / 2);
}

.bridge-link--h.is-single::after {
  display: none;
}

.bridge-link--v {
  left: calc(var(--left) - 14px);
  top: var(--top);
  width: 28px;
  height: var(--height);
}

.bridge-link--v::before,
.bridge-link--v::after {
  top: 0;
  bottom: 0;
  width: var(--gameplay-line-width);
}

.bridge-link--v::before {
  left: 10px;
}

.bridge-link--v::after {
  right: 10px;
}

.bridge-link--v.is-single::before {
  left: calc(50% - var(--gameplay-line-width) / 2);
}

.bridge-link--v.is-single::after {
  display: none;
}

.bridge-island {
  position: absolute;
  z-index: 4;
  left: calc((var(--col) + 0.5) * 100% / var(--bridge-size));
  top: calc((var(--row) + 0.5) * 100% / var(--bridge-size));
  display: grid;
  place-items: center;
  width: clamp(32px, 10.8%, 58px);
  aspect-ratio: 1;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: clamp(18px, 4.8vw, 34px);
  font-weight: 700;
  transform: translate(-50%, -50%);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.bridge-island.is-satisfied {
  color: var(--text-secondary);
  text-decoration: line-through;
  text-decoration-thickness: 0.08em;
}

.bridge-island.is-error {
  border-color: var(--accent-error);
  color: var(--accent-error);
}

.node,
.island {
  position: relative;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.node {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.island {
  width: min(62%, 58px);
  aspect-ratio: 1;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--text-primary);
}

.node:hover,
.island:hover {
  transform: scale(1.08);
}

.tool-shelf {
  position: sticky;
  top: calc(var(--header-height) + var(--space-4));
  display: grid;
  flex: 0 1 var(--right-shelf-width);
  gap: 0;
  width: var(--right-shelf-width);
  min-width: min(236px, 100%);
  max-height: calc(100vh - var(--header-height) - var(--space-6));
  max-height: calc(100svh - var(--header-height) - var(--space-6));
  overflow: auto;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-panel);
  scrollbar-width: thin;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.shelf-section {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: var(--border-thickness) solid var(--border-subtle);
}

.shelf-section:last-child {
  border-bottom: 0;
}

.shelf-section h2 {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.puzzle-list {
  display: grid;
  gap: var(--space-1);
}

.daily-set-list {
  display: grid;
  gap: var(--space-1);
}

.daily-set-list button {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding-inline: var(--space-3);
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-control);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.daily-set-list button:hover {
  border-color: var(--accent-glowing);
}

.daily-set-list .is-active {
  border-color: color-mix(in srgb, var(--accent-glowing) 70%, var(--border-subtle));
  background: color-mix(in srgb, var(--accent-glowing) 12%, var(--surface-control));
}

.daily-set-list .is-complete {
  color: var(--text-secondary);
}

.daily-mode-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.preferred-games-panel {
  display: grid;
  gap: var(--space-2);
}

.preferred-games-label {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.preferred-game {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 28px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

.puzzle-list button,
.segmented-control button,
.button {
  min-height: 36px;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-control);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.puzzle-list button {
  display: flex;
  align-items: center;
  padding-inline: var(--space-3);
  text-align: left;
}

.puzzle-list button:hover,
.segmented-control button:hover,
.button:hover {
  border-color: var(--accent-glowing);
}

.segmented-control button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.segmented-control button:disabled:hover,
.button:disabled:hover {
  border-color: var(--border-subtle);
}

.puzzle-list .is-active,
.segmented-control .is-selected,
.button-primary {
  border-color: color-mix(in srgb, var(--accent-glowing) 70%, var(--border-subtle));
  background: color-mix(in srgb, var(--accent-glowing) 12%, var(--surface-control));
  color: var(--text-primary);
}

.stats-grid div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.stats-grid span,
.instructions p {
  color: var(--text-secondary);
}

.stats-grid strong,
.instructions p {
  margin: 0;
}

.hint-status {
  min-height: 40px;
  padding: var(--space-2);
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-control);
  font-size: 13px;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.hint-status.is-active {
  border-color: color-mix(in srgb, var(--accent-glowing) 70%, var(--border-subtle));
  color: var(--text-primary);
}

.hint-status.is-error {
  border-color: var(--accent-error);
  color: var(--accent-error);
}

.learn-links a,
.footer-links a,
.guide-link-list a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent-glowing) 62%, transparent);
  text-underline-offset: 3px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.learn-links {
  gap: var(--space-2);
}

.learn-links a {
  color: var(--text-secondary);
  font-size: 13px;
}

.learn-links a:hover,
.footer-links a:hover,
.guide-link-list a:hover {
  color: var(--text-primary);
  text-decoration-color: var(--accent-glowing);
}

.guide-link-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.segmented-control,
.tool-actions,
.completion-actions,
.mobile-tools__row {
  display: flex;
  gap: var(--space-2);
}

.tool-actions {
  flex-wrap: wrap;
}

.segmented-control button,
.tool-actions .button,
.completion-actions .button {
  flex: 1 1 0;
  padding-inline: var(--space-3);
}

.tool-actions .button {
  flex-basis: 72px;
}

.completion-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius-minimal);
  background: color-mix(in srgb, var(--surface-page) 74%, transparent);
  backdrop-filter: blur(5px);
  animation: overlay-fade 0.28s ease both;
}

.completion-overlay[hidden] {
  display: none;
}

.completion-dialog {
  position: relative;
  z-index: 2;
  display: grid;
  gap: var(--space-3);
  width: min(88%, 360px);
  padding: var(--space-5);
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-raised);
  box-shadow: 0 18px 52px var(--shadow-subtle);
  text-align: center;
  max-height: calc(100% - var(--space-4));
  overflow: auto;
  animation: dialog-pop 0.24s ease both;
}

.completion-kicker,
.completion-meta {
  margin: 0;
  color: var(--text-secondary);
}

.completion-dialog h1,
.completion-dialog h2 {
  margin: 0;
  font-size: clamp(26px, 6vw, 38px);
  line-height: 1.05;
}

.share-status {
  min-height: 18px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.share-status.is-active {
  color: var(--text-primary);
}

.share-status.is-error {
  color: var(--accent-error);
}

.share-preview {
  width: 100%;
  max-width: 100%;
  min-height: 84px;
  max-height: 132px;
  padding: var(--space-2);
  overflow: auto;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-control);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.35;
  resize: none;
}

.share-preview:focus {
  border-color: color-mix(in srgb, var(--accent-glowing) 70%, var(--border-subtle));
}

.h5-interstitial-slot {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: var(--border-thickness) dashed var(--border-subtle);
  border-radius: var(--radius-minimal);
  color: var(--text-secondary);
  font-size: 12px;
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.particle {
  position: absolute;
  top: 42%;
  left: 50%;
  width: 7px;
  height: 12px;
  background: var(--accent-glowing);
  opacity: 0;
  animation: confetti-pop 900ms ease-out forwards;
}

.particle-b,
.particle-e {
  background: var(--accent-marker);
}

.particle-c,
.particle-f {
  background: var(--accent-error);
}

.particle-a { --x: -130px; --y: -118px; --r: 18deg; }
.particle-b { --x: 118px; --y: -112px; --r: 54deg; animation-delay: 50ms; }
.particle-c { --x: -86px; --y: 124px; --r: 92deg; animation-delay: 80ms; }
.particle-d { --x: 94px; --y: 118px; --r: 132deg; animation-delay: 110ms; }
.particle-e { --x: -12px; --y: -148px; --r: 210deg; animation-delay: 130ms; }
.particle-f { --x: 18px; --y: 146px; --r: 280deg; animation-delay: 160ms; }

.mobile-tools {
  display: none;
}

.seo-overview,
.site-footer,
.guide-page {
  background: var(--surface-page);
  color: var(--text-primary);
}

.seo-overview {
  padding: var(--space-6) var(--page-gutter) calc(var(--space-6) * 1.5);
}

.seo-overview__inner,
.guide-layout,
.footer-inner {
  width: min(100%, 920px);
  margin-inline: auto;
}

.seo-overview__inner {
  display: grid;
  gap: var(--space-4);
}

.guide-kicker {
  margin: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.seo-overview h1,
.guide-hero h1 {
  margin: 0;
  color: var(--text-primary);
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.08;
}

.seo-overview p,
.guide-hero p,
.guide-section p,
.guide-section li,
.site-footer {
  color: var(--text-secondary);
}

.seo-overview p,
.guide-hero p,
.guide-section p,
.guide-section li {
  max-width: 68ch;
}

.seo-link-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
}

.seo-link-grid a,
.guide-panel {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-4);
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: var(--radius-minimal);
  background: var(--surface-panel);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.seo-link-grid a:hover,
.guide-panel:hover {
  border-color: color-mix(in srgb, var(--accent-glowing) 64%, var(--border-subtle));
}

.seo-link-grid strong,
.guide-panel strong {
  color: var(--text-primary);
}

.seo-link-grid span,
.guide-panel span {
  color: var(--text-secondary);
  font-size: 13px;
}

.site-footer {
  padding: var(--space-5) var(--page-gutter);
  border-top: var(--border-thickness) solid var(--border-subtle);
  font-size: 13px;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.guide-page {
  min-height: 100vh;
  min-height: 100svh;
}

.guide-layout {
  display: grid;
  gap: var(--space-6);
  padding: var(--space-6) var(--page-gutter) calc(var(--space-6) * 1.5);
}

.guide-hero {
  display: grid;
  gap: var(--space-3);
  padding-block: var(--space-4);
}

.guide-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.guide-actions .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  padding-inline: var(--space-4);
}

.guide-section {
  display: grid;
  gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: var(--border-thickness) solid var(--border-subtle);
}

.guide-section h2,
.guide-section h3 {
  margin: 0;
  color: var(--text-primary);
  line-height: 1.18;
}

.guide-section h2 {
  font-size: 22px;
}

.guide-section h3 {
  font-size: 16px;
}

.guide-section p {
  margin: 0;
}

.guide-section ol,
.guide-section ul {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding-left: var(--space-5);
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.guide-grid--compact {
  gap: var(--space-2);
}

.guide-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.guide-feature {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: var(--space-5);
  align-items: center;
}

.guide-feature__copy,
.guide-example {
  display: grid;
  gap: var(--space-3);
}

.guide-example {
  justify-items: center;
}

.guide-mini-caption {
  max-width: 28ch;
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

.guide-panel--focus {
  border-color: color-mix(in srgb, var(--accent-glowing) 36%, var(--border-subtle));
  background: color-mix(in srgb, var(--accent-glowing) 7%, var(--surface-panel));
}

.mini-board {
  display: grid;
  width: min(100%, 260px);
  aspect-ratio: 1;
  border: var(--border-thickness) solid var(--grid-line);
  background: var(--surface-control);
}

.mini-board--fences {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
}

.mini-board--bridges,
.mini-board--pearls {
  position: relative;
  background-image:
    linear-gradient(to right, var(--grid-line) var(--border-thickness), transparent var(--border-thickness)),
    linear-gradient(to bottom, var(--grid-line) var(--border-thickness), transparent var(--border-thickness));
  background-size: 25% 25%;
}

.mini-cell {
  display: grid;
  place-items: center;
  border-right: var(--border-thickness) solid var(--grid-line);
  border-bottom: var(--border-thickness) solid var(--grid-line);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.mini-cell.is-muted {
  color: var(--text-secondary);
}

.mini-island,
.mini-bridge,
.mini-pearl,
.mini-pearl-line {
  position: absolute;
}

.mini-island {
  display: grid;
  place-items: center;
  width: 42px;
  aspect-ratio: 1;
  border: var(--border-thickness) solid var(--border-subtle);
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 700;
  transform: translate(-50%, -50%);
}

.mini-bridge,
.mini-pearl-line {
  height: var(--gameplay-line-width);
  border-radius: 999px;
  background: var(--accent-glowing);
  transform-origin: left center;
}

.mini-pearl {
  width: 24px;
  aspect-ratio: 1;
  border: 2px solid var(--text-primary);
  border-radius: 50%;
  background: var(--surface-raised);
  transform: translate(-50%, -50%);
}

.mini-pearl--black {
  background: var(--text-primary);
}
@keyframes overlay-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes dialog-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes confetti-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1) rotate(var(--r));
  }
}

@media (max-width: 860px) {
  :root {
    --game-max: min(94vw, calc(100vh - var(--header-height) - var(--mobile-ad-height) - var(--bottom-bar-height) - 48px));
  }

  @supports (height: 1svh) {
    :root {
      --game-max: min(94vw, calc(100svh - var(--header-height) - var(--mobile-ad-height) - var(--bottom-bar-height) - 48px));
    }
  }

  body {
    padding-bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom));
  }

  .mobile-ad {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    height: var(--mobile-ad-height);
    border-bottom: var(--border-thickness) solid var(--border-subtle);
    background: var(--surface-panel);
    color: var(--text-secondary);
    font-size: 12px;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  }

  body.ads-mobile-collapsed {
    --mobile-ad-height: 0px;
  }

  body.ads-mobile-collapsed .mobile-ad {
    display: none;
  }

  .site-header {
    top: var(--mobile-ad-height);
  }

  .portal-layout {
    display: block;
    min-height: auto;
    padding: var(--space-3) var(--page-gutter) var(--space-4);
  }

  .desktop-ad,
  .tool-shelf {
    display: none;
  }

  .game-status-strip {
    min-height: 32px;
    padding-inline: 0;
  }

  .game-square {
    width: var(--game-max);
    max-width: 100%;
  }

  .cell-clue {
    font-size: clamp(18px, 7.6vw, 34px);
  }

  .mobile-tools {
    position: fixed;
    right: var(--page-gutter);
    bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
    left: var(--page-gutter);
    z-index: 40;
    display: grid;
    border: var(--border-thickness) solid var(--border-subtle);
    border-radius: var(--radius-minimal);
    background: var(--surface-panel);
    box-shadow: 0 12px 32px var(--shadow-subtle);
    transition: background 0.2s ease, border-color 0.2s ease;
  }

  .mobile-tools summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding-inline: var(--space-3);
    color: var(--text-primary);
    cursor: pointer;
    list-style: none;
  }

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

  .mobile-tools__row {
    overflow-x: auto;
    padding: 0 var(--space-3) var(--space-3);
    scrollbar-width: none;
  }

  .mobile-tools__row::-webkit-scrollbar {
    display: none;
  }

  .mobile-tools__row .button {
    flex: 0 0 auto;
    min-width: 86px;
    padding-inline: var(--space-3);
  }
}

@media (max-width: 860px) {
  .seo-link-grid,
  .guide-grid,
  .guide-grid--three,
  .guide-feature {
    grid-template-columns: 1fr;
  }

  .footer-inner {
    align-items: flex-start;
    flex-direction: column;
  }
}
@media (max-width: 440px) {
  .brand span:last-child {
    max-width: 178px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .language-picker select {
    min-width: 104px;
  }

  .theme-toggle {
    width: 48px;
  }

  .game-frame {
    padding: 8px;
  }

  .completion-dialog {
    gap: var(--space-2);
    width: min(94%, 360px);
    padding: var(--space-4);
  }

  .share-preview {
    min-height: 64px;
    max-height: 84px;
    font-size: 11px;
  }

  .h5-interstitial-slot {
    min-height: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
