:root {
  color-scheme: light;
  --bg: #f6f5fa;
  --surface: #fff;
  --panel: #eeebf7;
  --line: #dedbe9;
  --ink: #231d37;
  --muted: #5c566b;
  --accent: #5c3bb3;
  --banner: linear-gradient(115deg, #28429c, #4c33a2 53%, #713c9c);
  --card-shadow: #2d24581a;
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161323;
  --surface: #201b31;
  --panel: #2d2544;
  --line: #413858;
  --ink: #f5efff;
  --muted: #c8bdd9;
  --accent: #cab5ff;
  --banner: linear-gradient(115deg, #212f69, #362575 53%, #532779);
  --card-shadow: #08061166;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}
a { color: inherit; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.shell { width: min(1120px, calc(100% - 96px)); margin-inline: auto; }
.skip {
  position: fixed;
  z-index: 6;
  top: .75rem;
  left: .75rem;
  padding: .5rem 1rem;
  background: var(--bg);
  transform: translateY(-200%);
}
.skip:focus { transform: none; }

.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.header-inner, .footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.header-inner { min-height: 68px; }
.header-inner a, .footer-inner a { font-size: .875rem; }
.header-brand { display: flex; align-items: center; gap: .25rem; }
.brand { min-width: 44px; margin-inline-start: -9px; }
.theme-switch {
  display: grid;
  place-items: center;
  width: 72px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.theme-switch[hidden] { display: none; }
.theme-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-track {
  position: relative;
  width: 66px;
  height: 30px;
  border: 1px solid #788daa;
  border-radius: 999px;
  background: #c9e0f6;
  transition: background-color 180ms ease, border-color 180ms ease;
}
.theme-track::before, .theme-track::after {
  content: "";
  position: absolute;
}
.theme-track::before {
  top: 9px;
  right: 7px;
  width: 20px;
  height: 12px;
  background: #fffaf0;
  clip-path: polygon(0 50%, 20% 50%, 20% 33.33%, 40% 33.33%, 40% 0, 70% 0,
    70% 33.33%, 80% 33.33%, 80% 50%, 100% 50%, 100% 83.33%, 90% 83.33%,
    90% 100%, 10% 100%, 10% 83.33%, 0 83.33%);
}
.theme-track::after {
  top: 8px;
  left: 12px;
  width: 2px;
  height: 2px;
  background: #f3e5ff;
  box-shadow: 0 -2px #f3e5ff, 0 2px #f3e5ff, 2px 0 #f3e5ff, -2px 0 #f3e5ff,
    11px 8px #cdbaf7, -4px 12px #cdbaf7;
  opacity: 0;
}
.theme-track::before, .theme-track::after { transition: opacity 140ms ease; }
.theme-thumb {
  position: absolute;
  z-index: 1;
  top: 3px;
  left: 3px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid #aa7034;
  border-radius: 7px;
  background: #ffce76;
  transition: transform 220ms cubic-bezier(.2, .73, .34, 1), background-color 180ms ease, border-color 180ms ease;
}
.theme-thumb::before, .theme-thumb::after {
  content: "";
  grid-area: 1 / 1;
  width: 2px;
  height: 2px;
  transition: opacity 100ms ease;
}
.theme-thumb::before {
  background: #74431c;
  box-shadow: -2px 0 #74431c, 2px 0 #74431c, 0 -2px #74431c, 0 2px #74431c,
    -2px -2px #74431c, 2px -2px #74431c, -2px 2px #74431c, 2px 2px #74431c,
    0 -6px #74431c, 0 6px #74431c, -6px 0 #74431c, 6px 0 #74431c,
    -4px -4px #74431c, 4px -4px #74431c, -4px 4px #74431c, 4px 4px #74431c;
}
.theme-thumb::after {
  width: 12px;
  height: 14px;
  background: #49327a;
  clip-path: polygon(33.33% 0, 66.67% 0, 66.67% 14.29%, 50% 14.29%, 50% 28.57%,
    33.33% 28.57%, 33.33% 57.14%, 50% 57.14%, 50% 71.43%, 83.33% 71.43%,
    83.33% 57.14%, 100% 57.14%, 100% 85.71%, 83.33% 85.71%, 83.33% 100%,
    33.33% 100%, 33.33% 85.71%, 16.67% 85.71%, 16.67% 71.43%, 0 71.43%,
    0 28.57%, 16.67% 28.57%, 16.67% 14.29%, 33.33% 14.29%);
  opacity: 0;
}
.theme-switch[aria-checked="true"] .theme-track {
  border-color: #766792;
  background: #2e284b;
}
.theme-switch[aria-checked="true"] .theme-thumb {
  transform: translateX(36px);
  border-color: #ad91e4;
  background: #dfd2ff;
}
.theme-switch[aria-checked="true"] :is(.theme-track, .theme-thumb)::before { opacity: 0; }
.theme-switch[aria-checked="true"] :is(.theme-track, .theme-thumb)::after { opacity: 1; }
@media (hover: hover) {
  .theme-switch:hover .theme-track { border-color: var(--accent); }
}
nav .motion-face {
  justify-content: center;
  min-height: 36px;
  padding-inline: .85rem;
  border-radius: 6px;
  font-weight: 630;
}
nav [aria-current="page"] .motion-face { background: var(--panel); color: var(--accent); }

.home { flex: 1; padding-bottom: clamp(2.5rem, 5vw, 4.5rem); }
.page-banner {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  min-height: clamp(9.5rem, 20vw, 14rem);
  padding: 2rem 1rem;
  overflow: hidden;
  background: var(--banner);
  color: #fff;
  text-align: center;
}
.page-banner h1 {
  font-size: clamp(2.8rem, 6.5vw, 5rem);
  font-weight: 760;
  letter-spacing: -.062em;
  line-height: 1;
  text-wrap: balance;
}
.page-banner::before, .page-banner::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: clamp(12rem, 28vw, 28rem);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
}
.page-banner::before {
  top: -80%;
  right: max(65%, calc(50% + 17rem));
  border: 2px solid #ffffff38;
  background: repeating-radial-gradient(circle, #ffffff0d 0 16px, transparent 17px 30px);
}
.page-banner::after {
  bottom: -63%;
  left: max(71%, calc(50% + 17rem));
  border: clamp(20px, 4vw, 58px) solid #f1a5ed2d;
  box-shadow: 0 0 0 1px #ffffff34, inset 0 0 0 1px #ffffff34;
}
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(1rem, 2.6vw, 2rem);
  max-width: 1000px;
  margin-top: clamp(1.5rem, 4vw, 3rem);
  scroll-margin-top: 1rem;
}
.game-card {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--card-bg);
  color: #fff;
  box-shadow: 0 5px 16px var(--card-shadow);
}
.drill-card { --card-bg: #4042a5; }
.pool-card { --card-bg: #176b57; }
[data-theme="dark"] .drill-card { --card-bg: #323477; }
[data-theme="dark"] .pool-card { --card-bg: #1b5145; }
.game-art {
  width: 100%;
  height: auto;
  aspect-ratio: 1.67;
  object-fit: cover;
  border-radius: 14px 14px 0 0;
  background: var(--panel);
}
.game-summary {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: clamp(1.05rem, 2.5vw, 1.55rem);
}
.game-summary h2 {
  font-size: clamp(1.3rem, 2.5vw, 1.8rem);
  font-weight: 720;
  letter-spacing: -.043em;
  line-height: 1.15;
}
.game-summary p {
  max-width: 41ch;
  margin: .65rem 0 1.15rem;
  color: #fff;
}
.profile {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(1rem, 3vw, 1.75rem);
  max-width: 640px;
  margin-top: clamp(1.5rem, 4vw, 3rem);
  padding: clamp(1.2rem, 4vw, 2.5rem);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.profile img {
  width: clamp(2.75rem, 8vw, 4rem);
  height: auto;
}
.profile p {
  max-width: 40ch;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.2rem);
}
.site-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; }
.footer-inner { min-height: 62px; justify-content: flex-end; }

[data-motion] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.motion-face {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  pointer-events: none;
  transition: scale 150ms ease-out, translate 150ms ease-out, color 120ms ease-out,
    background-color 120ms ease-out, box-shadow 120ms ease-out;
}
.is-highlighted .motion-face {
  scale: var(--hover-scale-x, 1.025) var(--hover-scale-y, 1.045);
  color: var(--ink);
  transition-timing-function: cubic-bezier(.2, .78, .28, 1.14), ease-out, ease-out, ease-out, ease-out;
  transition-duration: 170ms, 150ms, 120ms, 120ms, 120ms;
}
.play .motion-face, .text-link .motion-face {
  min-height: 44px;
  justify-content: center;
  gap: .65rem;
  padding-inline: .95rem;
  border-radius: inherit;
  font-size: .875rem;
  font-weight: 650;
}
.game-summary .play {
  align-self: center;
  margin-top: auto;
  border-radius: 999px;
}
.play .motion-face {
  min-width: 108px;
  background: #fff;
  color: var(--card-bg);
}
.play:is(.is-highlighted, :focus-visible) .motion-face { background: #efedf9; }
.play:focus-visible { outline-color: #fff; }
.back .motion-face span { font-size: 1.1em; line-height: 1; }
.text-link .motion-face { border: 1px solid var(--line); color: var(--ink); }
.text-link:is(.is-highlighted, :focus-visible) .motion-face { background: var(--panel); }
.is-pressed .motion-face {
  scale: .985 .91;
  translate: 0 3px;
  transition-duration: 65ms;
  transition-timing-function: ease-out;
}
.is-releasing .motion-face {
  transition-timing-function: cubic-bezier(.25, .7, .32, 1.35), cubic-bezier(.25, .7, .32, 1.35),
    ease-out, ease-out, ease-out;
  transition-duration: 170ms;
}
.play .motion-face { animation: play-entrance 190ms cubic-bezier(.22, .61, .36, 1) 36ms both; }
.game-card:nth-child(2) .play .motion-face { animation-delay: 72ms; }
.play:is(:focus-visible, .is-highlighted, .is-pressed, .is-releasing) .motion-face { animation: none; }
@keyframes play-entrance {
  from { opacity: .52; transform: translateY(6px) scale(.955); }
  to { opacity: 1; transform: none; }
}
.button-ripple {
  position: fixed;
  z-index: 5;
  width: 58px;
  height: 58px;
  border: 1px solid #d78b61;
  border-radius: 50%;
  pointer-events: none;
  animation: button-ripple 240ms cubic-bezier(.16, .6, .3, 1) both;
}
@keyframes button-ripple {
  from { opacity: .95; transform: translate(-50%, -50%) scale(.23); border-width: 9px; }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

.back { color: var(--ink); }
.play-layout {
  display: grid;
  grid-template-columns: auto minmax(220px, 300px);
  align-items: start;
  justify-content: center;
  gap: clamp(1.5rem, 5vw, 4rem);
  padding-block: 1.5rem 2.5rem;
}
.game-stage {
  width: auto;
  max-width: 100%;
  height: min(840px, calc(100vh - 112px));
  height: min(840px, calc(100dvh - 112px));
  overflow: hidden;
  aspect-ratio: 9 / 16;
  border-radius: 8px;
  background: #090f1c;
}
.game-stage iframe { display: block; width: 100%; height: 100%; border: 0; }
.pool-layout { grid-template-columns: minmax(0, 1fr) minmax(175px, 230px); gap: clamp(1.25rem, 3vw, 2.5rem); }
.pool-stage { width: 100%; height: auto; aspect-ratio: 4 / 3; }
.game-guide { padding-block: 1rem; color: var(--muted); }
.game-guide h1, .text-page h1 {
  color: var(--ink);
  font-size: clamp(2rem, 4vw, 3.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -.065em;
}
.game-guide h1 { margin-bottom: 1rem; }
.game-guide h2 { margin: 1.3rem 0 .35rem; color: var(--ink); font-size: 1rem; }
.game-guide h1 + h2 { margin-top: 0; }
.game-guide dl { margin-block: .6rem 1.25rem; }
.game-guide dt { color: var(--ink); font-weight: 640; }
.game-guide dd { margin: .25rem 0 .85rem; }
kbd {
  display: inline-block;
  min-width: 1.35em;
  padding-inline: .23em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  text-align: center;
}
.text-link { margin-top: 1.05rem; }
.text-page { max-width: 640px; padding-block: clamp(2.5rem, 6vw, 5rem); }
.text-page h1 { margin-bottom: 2rem; }
.text-page h2 { margin-bottom: .45rem; font-size: 1.15rem; }
.text-page p { margin-bottom: 1.5rem; color: var(--muted); }
.text-page p a { color: var(--accent); text-underline-offset: .2em; }

@media (max-width: 820px) {
  .shell { width: calc(100% - 56px); }
}
@media (max-width: 680px) {
  .shell { width: calc(100% - 40px); }
  .header-inner { min-height: 58px; }
  nav .motion-face { padding-inline: .6rem; }
  .play-header .header-inner { min-height: 49px; }
  .play-layout { display: flex; flex-direction: column; align-items: center; gap: 0; width: 100%; padding-top: 0; }
  .game-stage { width: 100%; max-width: 450px; height: auto; max-height: calc(100dvh - 50px); border-radius: 0; }
  .pool-stage { max-width: none; }
  .game-guide { width: min(100% - 40px, 450px); padding-top: 1.6rem; }
}
/* Compact three-across game cards on phones only; desktop stays unchanged. */
@media (max-width: 620px) {
  .home .game-grid {
    width: calc(100% - 24px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .home .game-card { min-width: 0; border-radius: 10px; }
  .home .game-art { aspect-ratio: 1; border-radius: 10px 10px 0 0; }
  .home .game-summary { min-width: 0; padding: 10px 6px 6px; }
  .home .game-summary h2 {
    min-height: 3.6em;
    font-size: clamp(.75rem, 3.2vw, .95rem);
    line-height: 1.2;
    letter-spacing: -.025em;
    overflow-wrap: anywhere;
    text-align: center;
  }
  .home .game-summary p { display: none; }
  .home .game-summary .play { align-self: stretch; min-width: 44px; margin-top: 8px; }
  .home .play .motion-face {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding-inline: 4px;
    font-size: .8125rem;
  }
}
@media (max-width: 340px) {
  .shell { width: calc(100% - 32px); }
  .play-layout { width: 100%; }
  .header-inner a { font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) {
  [data-motion] .motion-face {
    scale: none;
    rotate: none;
    translate: none;
    animation: none;
    transition: none;
  }
  .button-ripple { display: none; }
  .theme-track, .theme-thumb, .theme-track::before, .theme-track::after,
  .theme-thumb::before, .theme-thumb::after { transition: none; }
}
