* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.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;
}

:root {
  --serif: Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

/* Dark theme (original look) */
body {
  --bg: #0c1420;
  --text: #e8edf4;
  --muted: rgba(232, 237, 244, 0.5);
  --faint: rgba(232, 237, 244, 0.28);
  --btn-bg: rgba(255, 255, 255, 0.05);
  --btn-border: rgba(255, 255, 255, 0.16);
  --btn-text: rgba(232, 237, 244, 0.6);
  --btn-active-bg: rgba(255, 255, 255, 0.16);
  --btn-active-border: rgba(255, 255, 255, 0.5);
  --btn-active-text: #ffffff;
  --hint-text: #f0c85a;
  --hint-bg: rgba(240, 200, 90, 0.08);
  --hint-border: rgba(240, 200, 90, 0.35);
  --overlay-bg: rgba(9, 14, 22, 0.85);
  --over-title: #e05a7a;
  --card-bg: #131d2b;
  --card-border: rgba(255, 255, 255, 0.12);
  --menu-hover: rgba(255, 255, 255, 0.07);
  --key-bg: rgba(255, 255, 255, 0.09);
  --key-border: rgba(255, 255, 255, 0.16);
}

/* Light theme — editorial, NYT-games-style */
body.theme-light {
  --bg: #fafaf5;
  --text: #121212;
  --muted: rgba(18, 18, 18, 0.55);
  --faint: rgba(18, 18, 18, 0.38);
  --btn-bg: transparent;
  --btn-border: rgba(18, 18, 18, 0.35);
  --btn-text: rgba(18, 18, 18, 0.78);
  --btn-active-bg: #121212;
  --btn-active-border: #121212;
  --btn-active-text: #ffffff;
  --hint-text: #8a6d1a;
  --hint-bg: rgba(201, 180, 88, 0.14);
  --hint-border: rgba(138, 109, 26, 0.45);
  --overlay-bg: rgba(250, 250, 245, 0.93);
  --over-title: #121212;
  --card-bg: #ffffff;
  --card-border: rgba(18, 18, 18, 0.14);
  --menu-hover: rgba(18, 18, 18, 0.05);
  --key-bg: #e6e6e0;
  --key-border: rgba(18, 18, 18, 0.1);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--sans);
  color: var(--text);
  user-select: none;
}

button:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 3px;
}

.tutorial-active #mode-dd,
.tutorial-active #hint-btn,
.tutorial-active #daily-info {
  display: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;   /* fallback; JS sets exact px, and dvh tracks iOS chrome */
  height: 100dvh;
  touch-action: none;
}

html, body {
  overscroll-behavior: none;
}

#brand {
  position: fixed;
  top: 20px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 8px;
  text-indent: 8px;
  color: var(--text);
  pointer-events: none;
}

#hud {
  position: fixed;
  top: 22px;
  left: 26px;
  display: flex;
  gap: 30px;
  pointer-events: none;
}

#hud .stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#hud .label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2.5px;
  color: var(--muted);
}

#hud .value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

body:not(.mode-shape) #hud .shape-stat {
  display: none;
}

body.mode-shape #hud .classic-stat {
  display: none;
}

body:not(.mode-arcade) #hud .arcade-stat {
  display: none;
}

/* spill tray: every off-shape cell lands here, GitHub-contributions style */
#spill-tray {
  position: fixed;
  top: 88px;
  left: 26px;
  display: none;
  flex-wrap: wrap;
  gap: 3px;
  max-width: 160px;
  pointer-events: none;
}

body.mode-shape #spill-tray {
  display: flex;
}

#spill-tray .spill-cell {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  animation: spill-pop 0.35s ease;
}

@keyframes spill-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

@media (max-width: 480px) {
  #spill-tray {
    top: 68px;
    left: 16px;
  }
}

#mode-ui {
  position: fixed;
  top: 22px;
  right: 26px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 600;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--btn-active-border);
  color: var(--text);
}

#mode-dd {
  position: relative;
}

#mode-dd-btn,
#hint-btn {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  padding: 11px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#mode-dd-btn {
  color: var(--btn-active-text);
  background: var(--btn-active-bg);
  border: 1px solid var(--btn-active-border);
}

#mode-dd-btn .caret {
  font-size: 9px;
  opacity: 0.7;
}

#mode-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 250px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  padding: 6px;
  z-index: 30;
}

#mode-menu.hidden {
  display: none;
}

#mode-menu button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  cursor: pointer;
}

#mode-menu button:hover {
  background: var(--menu-hover);
}

#mode-menu button.active b::after {
  content: ' ✓';
}

#mode-menu button b {
  font-size: 12px;
  letter-spacing: 1.5px;
}

#mode-menu button span {
  font-size: 11px;
  color: var(--muted);
}

.labs-label {
  margin: 6px 10px 2px;
  padding-top: 8px;
  border-top: 1px solid var(--card-border);
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
}

#hint-btn {
  color: var(--hint-text);
  background: var(--hint-bg);
  border: 1px solid var(--hint-border);
}

#hint-btn:hover {
  border-color: var(--hint-text);
}

body:not(.mode-shape) #hint-btn {
  display: none;
}

#daily-info {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--muted);
}

body:not(.mode-shape) #daily-info {
  display: none;
}

@media (max-width: 980px) {
  #brand {
    display: none;
  }
}

@media (max-width: 480px) {
  #mode-ui {
    top: 16px;
    right: 12px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  #mode-dd-btn,
  #hint-btn {
    padding: 9px 12px;
    font-size: 10px;
    letter-spacing: 1px;
  }

  #hud {
    top: 16px;
    left: 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(42px, auto));
    column-gap: 16px;
    row-gap: 6px;
  }

  #hud .value {
    font-size: 20px;
  }

  #hud .label {
    font-size: 9px;
    letter-spacing: 1.8px;
  }
}

@media (max-width: 360px) {
  #mode-ui {
    top: 82px;
  }
}

#controls-hint {
  position: fixed;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 1.2px;
  color: var(--faint);
  pointer-events: none;
}

#tutorial-coach {
  position: fixed;
  left: 50%;
  top: 82px;
  z-index: 24;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--text);
}

#tutorial-coach.hidden {
  display: none;
}

#tutorial-step {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
}

#tutorial-prompt {
  white-space: normal;
  text-align: center;
  font-size: 11px;
  letter-spacing: 1.2px;
}

#tutorial-skip {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 700 10px var(--sans);
  cursor: pointer;
}

/* --- touch control pad (Wordle-keyboard style) ------------------------------- */

#pad {
  position: fixed;
  left: auto;
  right: 0;
  transform: none;
  bottom: 0;
  z-index: 20;
  display: none;
  /*  .   ←   →
      ↻  DROP DROP  */
  grid-template-areas:
    '.  left right'
    'cw drop drop';
  grid-template-columns: 76px 76px 76px;
  grid-auto-rows: 54px;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}

body.touch-device #pad {
  display: grid;
}

body.touch-device #controls-hint {
  display: none;
}

body.overlay-open #pad {
  display: none;
}

#pad button {
  border-radius: 10px;
  font-family: var(--sans);
  font-size: 21px;
  font-weight: 700;
  color: var(--text);
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#pad [data-act="left"]  { grid-area: left; }
#pad [data-act="right"] { grid-area: right; }
#pad [data-act="cw"]    { grid-area: cw; }
#pad #pad-drop          { grid-area: drop; }

#pad button:active {
  transform: scale(0.95);
}

#pad #pad-drop {
  font-size: 12px;
  letter-spacing: 2.5px;
  color: var(--btn-active-text);
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--overlay-bg);
  backdrop-filter: blur(3px);
  text-align: center;
  transition: opacity 0.3s ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#overlay h1 {
  font-family: var(--serif);
  font-size: 42px;
  letter-spacing: 6px;
  color: var(--over-title);
}

#overlay #over-reason {
  font-size: 14px;
  color: var(--muted);
}

#overlay .final {
  font-size: 17px;
  font-weight: 600;
  margin-top: 10px;
  color: var(--text);
}

#overlay .restart {
  font-size: 13px;
  color: var(--muted);
  margin-top: 18px;
}

#overlay .restart b {
  color: var(--text);
}

#result-card {
  width: min(360px, 86vw);
  height: auto;
  max-height: 38vh;
  border: 1px solid var(--card-border);
  border-radius: 14px;
  background: var(--card-bg);
}

#result-card.hidden,
#result-actions.hidden {
  display: none;
}

#result-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

#result-actions button {
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  font: 700 11px var(--sans);
  letter-spacing: 1.3px;
  cursor: pointer;
}

#result-actions #share-btn {
  color: var(--btn-active-text);
  background: var(--btn-active-bg);
  border-color: var(--btn-active-border);
}

/* --- start screen ---------------------------------------------------------- */

#start-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  background: var(--bg);
  transition: opacity 0.35s ease;
}

#start-screen.hidden {
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.start-hero {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.start-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
}

.scroll-cue {
  margin-top: 6px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-decoration: none;
}

.scroll-cue:hover {
  color: var(--muted);
}

/* --- crawlable About / FAQ content (below the fold) ------------------------ */

.about-panel {
  padding: 8px 24px 72px;
}

.about-inner {
  width: min(680px, 100%);
  margin: 0 auto;
  padding-top: 32px;
  border-top: 1px solid var(--card-border);
}

.about-inner h2 {
  margin: 40px 0 14px;
  font: 700 26px var(--serif);
  letter-spacing: 1px;
  color: var(--text);
}

.about-inner h2:first-child {
  margin-top: 8px;
}

.about-inner h3 {
  margin: 22px 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.about-inner p,
.about-inner li {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
}

.about-inner p + p {
  margin-top: 12px;
}

.about-inner strong {
  color: var(--text);
  font-weight: 700;
}

.about-steps,
.about-modes {
  margin: 4px 0 0 22px;
}

.about-steps li,
.about-modes li {
  margin-bottom: 6px;
}

.about-controls kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 5px;
  background: var(--key-bg);
  border: 1px solid var(--key-border);
  color: var(--text);
  font: 600 12px var(--sans);
}

.about-faq h3:first-child {
  margin-top: 8px;
}

.about-inner a {
  color: var(--text);
}

.about-cta {
  margin-top: 40px;
  text-align: center;
}

.about-cta a {
  display: inline-block;
  padding: 12px 28px;
  border-radius: 999px;
  border: 1px solid var(--btn-active-border);
  background: var(--btn-active-bg);
  color: var(--btn-active-text);
  font: 700 12px var(--sans);
  letter-spacing: 2px;
  text-decoration: none;
}

#site-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 0 16px calc(20px + env(safe-area-inset-bottom, 0px));
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.5px;
}

#site-footer a {
  color: var(--muted);
  text-decoration: none;
}

#site-footer a:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

#site-footer a:focus-visible {
  border-radius: 2px;
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.start-card h1 {
  font-family: var(--serif);
  font-size: 52px;
  font-weight: 700;
  letter-spacing: 10px;
  text-indent: 10px;
  color: var(--text);
}

.start-card .tagline {
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted);
}

#play-btn {
  margin-top: 10px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 16px 64px;
  border-radius: 999px;
  color: var(--btn-active-text);
  background: var(--btn-active-bg);
  border: 1px solid var(--btn-active-border);
  cursor: pointer;
  transition: transform 0.12s ease;
}

#play-btn:hover {
  transform: scale(1.04);
}

#endless-btn,
#start-howto {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  padding: 12px 28px;
  border-radius: 999px;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  cursor: pointer;
}

#endless-btn:hover,
#start-howto:hover {
  border-color: var(--btn-active-border);
  color: var(--text);
}

/* animated mark: three blocks whirling around the anchor in 90° steps */
.start-mark {
  position: relative;
  width: 84px;
  height: 84px;
  margin-bottom: 6px;
  animation: whirl 4.8s cubic-bezier(0.34, 1.4, 0.64, 1) infinite;
}

.sm {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 6px;
}

.sm-anchor {
  left: 29px;
  top: 29px;
  background: var(--card-bg);
  border: 2px solid var(--text);
}

.sm-anchor::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--text);
}

.sm-a { left: 29px; top: 1px;  background: #6aaa64; }
.sm-b { left: 57px; top: 29px; background: #e3a344; }
.sm-c { left: 57px; top: 1px;  background: #9d7bd8; }

@keyframes whirl {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(0deg); }
  25%  { transform: rotate(90deg); }
  45%  { transform: rotate(90deg); }
  50%  { transform: rotate(180deg); }
  70%  { transform: rotate(180deg); }
  75%  { transform: rotate(270deg); }
  95%  { transform: rotate(270deg); }
  100% { transform: rotate(360deg); }
}

/* --- how to play modal ------------------------------------------------------ */

#howto {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--overlay-bg);
  backdrop-filter: blur(3px);
}

#howto.hidden {
  display: none;
}

.howto-card {
  position: relative;
  width: min(400px, 92vw);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  padding: 26px 26px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

#howto-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

#howto-close:hover {
  color: var(--text);
}

.howto-card h2 {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 3px;
  color: var(--text);
}

#howto-canvas {
  width: 320px;
  height: 200px;
  max-width: 100%;
}

#howto-text {
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  min-height: 84px;
}

.howto-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.howto-nav button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.howto-nav button:hover {
  border-color: var(--btn-active-border);
}

#howto-dots {
  display: flex;
  gap: 8px;
}

#howto-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--btn-border);
}

#howto-dots .dot.on {
  background: var(--text);
}

/* --- legal page ------------------------------------------------------------ */

html.legal-page {
  width: 100%;
  height: auto;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  overscroll-behavior: auto;
  background: #fafaf5;
  scroll-padding-top: 64px;
  /* this page is light-only: stop any browser dark-mode auto-rendering */
  color-scheme: light;
}

body.legal-page {
  --bg: #fafaf5;
  --text: #121212;
  --muted: rgba(18, 18, 18, 0.62);
  --faint: rgba(18, 18, 18, 0.42);
  --card-border: rgba(18, 18, 18, 0.14);
  width: 100%;
  height: auto;
  min-height: 100vh;
  overflow: visible;
  overscroll-behavior: auto;
  background: #fafaf5;
  color: #121212;
  padding: max(64px, calc(32px + env(safe-area-inset-top, 0px))) 24px 48px;
  user-select: text;
}

.legal-shell {
  width: min(680px, 100%);
  margin: 0 auto;
}

.legal-back {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-decoration: none;
}

.legal-back:hover {
  color: var(--text);
}

.legal-shell h1 {
  margin: 42px 0 8px;
  font: 700 40px var(--serif);
  letter-spacing: 5px;
}

.legal-updated {
  margin-bottom: 40px;
  color: var(--faint);
  font-size: 12px;
}

.legal-shell section {
  scroll-margin-top: 64px;
}

.legal-shell section + section {
  margin-top: 56px;
  padding-top: 48px;
  border-top: 1px solid var(--card-border);
}

.legal-shell h2 {
  margin-bottom: 18px;
  font: 700 26px var(--serif);
}

.legal-shell h3 {
  margin: 28px 0 8px;
  font-size: 14px;
}

.legal-shell p,
.legal-shell li {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.legal-shell p + p {
  margin-top: 12px;
}

.legal-shell ul {
  margin: 10px 0 0 20px;
}

.legal-shell a {
  color: var(--text);
}

.legal-footer {
  margin-top: 64px;
  color: var(--faint);
  font-size: 11px;
}

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