/* =========================================================
   2048 · Number Lab
   A warm, editorial take on the sliding-number classic.
   ========================================================= */

:root {
  --paper: #f2ecdf;
  --paper-deep: #e9e1d2;
  --paper-bright: #faf6ec;
  --ink: #1d2a23;
  --ink-soft: #5d6a60;
  --ink-faint: #889187;
  --line: rgba(29, 42, 35, 0.13);
  --line-strong: rgba(29, 42, 35, 0.22);
  --accent: #df5a35;
  --accent-deep: #c44725;
  --accent-soft: #f0c7b7;
  --gold: #e0b55c;
  --forest: #22372a;
  --forest-deep: #19291f;
  --cream: #f7f1e5;
  --cream-muted: rgba(247, 241, 229, 0.58);
  --board-cell: rgba(247, 241, 229, 0.065);
  --gap: clamp(9px, 1.1vw, 13px);
  --pad: clamp(10px, 1.3vw, 15px);
  --radius-board: 26px;
  --radius-card: 24px;
  --slide-ms: 150ms;
  --ease-out: cubic-bezier(0.2, 0.78, 0.28, 1);
  --ease-spring: cubic-bezier(0.22, 1.1, 0.36, 1);
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia,
    "Times New Roman", serif;
  --mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
}

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

html {
  min-width: 320px;
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(900px 540px at 94% -8%, rgba(223, 90, 53, 0.13), transparent 64%),
    radial-gradient(820px 680px at -14% 42%, rgba(53, 87, 65, 0.1), transparent 68%),
    linear-gradient(180deg, #f4eee2 0%, var(--paper) 56%, #efe8da 100%);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body.has-overlay {
  overflow: hidden;
}

body::before {
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.45;
  background-image: radial-gradient(rgba(29, 42, 35, 0.12) 0.55px, transparent 0.55px);
  background-size: 18px 18px;
  mask-image: linear-gradient(to bottom, #000 0%, transparent 58%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, transparent 58%);
}

::selection {
  color: var(--paper-bright);
  background: var(--accent);
}

button {
  color: inherit;
  font: inherit;
}

button,
.switch,
.speed-option {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
.switch:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

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

.page {
  position: relative;
  z-index: 1;
  width: min(calc(100% - 64px), 1050px);
  margin: 0 auto;
  padding: 30px 0 26px;
}

/* ---------- Masthead ---------- */

.masthead {
  border-bottom: 1px solid var(--line);
  padding-bottom: 32px;
}

.utility-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  color: var(--cream);
  background: var(--ink);
  border-radius: 50%;
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: -0.02em;
  place-items: center;
}

.brand-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.08em;
}

.brand-name small {
  color: var(--ink-faint);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.19em;
}

.utility-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
}

.utility-item {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.live-pin {
  display: block;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(223, 90, 53, 0.11);
  animation: breathe 3s ease-in-out infinite;
}

.utility-rule {
  width: 24px;
  height: 1px;
  background: var(--line-strong);
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 36px;
  padding-top: 48px;
}

.hero-copy {
  min-width: 0;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.eyebrow-line {
  display: inline-block;
  width: 28px;
  height: 1px;
  background: var(--accent);
}

h1 {
  margin: 15px 0 16px;
  font-family: var(--serif);
  font-size: clamp(88px, 8.8vw, 126px);
  font-weight: 400;
  letter-spacing: -0.075em;
  line-height: 0.76;
}

.title-dot {
  color: var(--accent);
  padding-left: 0.02em;
}

.hero-copy p {
  max-width: 390px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  letter-spacing: 0.01em;
  line-height: 1.8;
}

.score-panel {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  padding-bottom: 3px;
}

.score-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 148px;
  min-height: 119px;
  padding: 16px 18px 14px;
  overflow: hidden;
  background: rgba(255, 252, 244, 0.58);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 14px 28px -24px rgba(29, 42, 35, 0.45);
  isolation: isolate;
}

.score-card--accent {
  color: #fff7ed;
  background:
    radial-gradient(150% 130% at 100% 0%, rgba(255, 200, 159, 0.27), transparent 48%),
    var(--accent);
  border-color: transparent;
  box-shadow: 0 20px 34px -22px rgba(196, 71, 37, 0.75);
}

.score-card--accent::after {
  position: absolute;
  top: -44px;
  right: -38px;
  width: 110px;
  height: 110px;
  content: "";
  border: 1px solid rgba(255, 246, 236, 0.22);
  border-radius: 50%;
}

.score-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.score-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.score-english {
  color: var(--ink-faint);
  font-family: var(--mono);
  font-size: 7px;
  letter-spacing: 0.15em;
}

.score-card--accent .score-english {
  color: rgba(255, 247, 237, 0.56);
}

.score-value {
  margin-top: auto;
  padding-top: 10px;
  font-family: var(--serif);
  font-size: clamp(34px, 3.4vw, 43px);
  font-weight: 400;
  letter-spacing: -0.045em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.score-value.is-bumping {
  animation: score-bump 360ms var(--ease-spring);
}

.score-value.is-compact {
  font-size: clamp(27px, 2.9vw, 34px);
  letter-spacing: -0.055em;
}

.score-value.is-tiny {
  font-size: clamp(21px, 2.35vw, 27px);
  letter-spacing: -0.06em;
}

.score-gain {
  position: absolute;
  top: 38px;
  right: 15px;
  color: rgba(255, 247, 237, 0.86);
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0;
}

.score-gain.is-visible {
  animation: gain-rise 780ms var(--ease-out) both;
}

.score-card.is-record {
  border-color: rgba(223, 90, 53, 0.32);
}

.score-card.is-record .score-value {
  color: var(--accent-deep);
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(310px, 0.88fr);
  gap: clamp(36px, 5vw, 64px);
  align-items: start;
  padding-top: 32px;
}

.play-area {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

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

.play-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 13px;
}

.turn-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.turn-light {
  position: relative;
  display: block;
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  background: var(--forest);
  border-radius: 50%;
  transition: background 220ms ease;
}

.turn-light::after {
  position: absolute;
  inset: -4px;
  content: "";
  border: 1px solid transparent;
  border-radius: 50%;
  transition: border-color 220ms ease;
}

.turn-copy {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.turn-copy strong {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.turn-copy small {
  overflow: hidden;
  max-width: 250px;
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.turn-status[data-mode="ai"] .turn-light {
  background: var(--accent);
}

.turn-status[data-mode="ai"] .turn-light::after {
  border-color: rgba(223, 90, 53, 0.28);
  animation: pulse-ring 2s ease-out infinite;
}

.turn-status[data-mode="thinking"] .turn-light {
  background: var(--gold);
}

.turn-status[data-mode="over"] .turn-light {
  background: var(--ink-faint);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.text-button,
.solid-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    color 180ms ease,
    background 180ms ease,
    border-color 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.text-button svg,
.solid-button svg {
  width: 15px;
  height: 15px;
}

.text-button {
  color: var(--ink-soft);
  background: transparent;
  border-color: var(--line);
}

.text-button:hover:not(:disabled) {
  color: var(--ink);
  background: rgba(255, 252, 244, 0.55);
  border-color: var(--line-strong);
}

.text-button:active:not(:disabled),
.solid-button:active:not(:disabled) {
  transform: translateY(1px);
}

.text-button:disabled {
  color: rgba(93, 106, 96, 0.42);
  border-color: rgba(29, 42, 35, 0.08);
  cursor: default;
}

.solid-button {
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 9px 20px -12px rgba(29, 42, 35, 0.72);
}

.solid-button:hover {
  background: #2a3c31;
  transform: translateY(-1px);
  box-shadow: 0 13px 24px -13px rgba(29, 42, 35, 0.76);
}

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

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

.board {
  position: relative;
  width: 100%;
  padding: var(--pad);
  background:
    radial-gradient(120% 100% at 10% -10%, rgba(255, 255, 255, 0.08), transparent 38%),
    linear-gradient(148deg, #2a4133 0%, var(--forest) 44%, #1a2b21 100%);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-board);
  box-shadow:
    0 44px 80px -38px rgba(20, 34, 25, 0.7),
    0 16px 30px -26px rgba(20, 34, 25, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.board-surface {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.board-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
}

.board-cell {
  display: block;
  min-width: 0;
  min-height: 0;
  background: var(--board-cell);
  border: 1px solid rgba(247, 241, 229, 0.025);
  border-radius: clamp(8px, 1.25vw, 13px);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.13);
}

.tile-layer {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}

.tile {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  pointer-events: none;
  will-change: transform;
  transition: transform var(--slide-ms) var(--ease-out);
}

.tile.is-settled {
  transition: none;
}

.tile-inner {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: var(--cream);
  border-radius: clamp(8px, 1.25vw, 13px);
  box-shadow:
    0 7px 16px -8px rgba(5, 16, 10, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.52),
    inset 0 -1px 0 rgba(64, 44, 25, 0.08);
  font-family: var(--sans);
  font-size: var(--tile-font-size, 36px);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.055em;
  line-height: 1;
  place-items: center;
  transform-origin: center;
  backface-visibility: hidden;
}

.tile-inner::after {
  position: absolute;
  inset: 0;
  content: "";
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: inherit;
  pointer-events: none;
}

.tile-inner.is-appearing {
  animation: tile-appear 240ms var(--ease-spring) both;
}

.tile-inner.is-merging {
  animation: tile-merge 300ms var(--ease-spring) both;
}

/* Tile palette --------------------------------------------------------- */

.tile[data-value="2"] .tile-inner {
  color: #334237;
  background: linear-gradient(145deg, #fdf9ef 0%, #f2eadb 100%);
}

.tile[data-value="4"] .tile-inner {
  color: #354236;
  background: linear-gradient(145deg, #f1e7d1 0%, #e7dbc2 100%);
}

.tile[data-value="8"] .tile-inner {
  color: #442c16;
  background: linear-gradient(145deg, #f7ce8d 0%, #efb772 100%);
}

.tile[data-value="16"] .tile-inner {
  color: #482810;
  background: linear-gradient(145deg, #f5b66d 0%, #e99b55 100%);
}

.tile[data-value="32"] .tile-inner {
  color: #fff8ef;
  background: linear-gradient(145deg, #ee9258 0%, #df7040 100%);
  text-shadow: 0 1px 1px rgba(94, 42, 18, 0.19);
}

.tile[data-value="64"] .tile-inner {
  color: #fff9f0;
  background: linear-gradient(145deg, #e77445 0%, #cd512a 100%);
  text-shadow: 0 1px 2px rgba(84, 28, 12, 0.22);
}

.tile[data-value="128"] .tile-inner {
  color: #32230c;
  background: linear-gradient(145deg, #f0d585 0%, #dfb954 100%);
  box-shadow:
    0 8px 18px -9px rgba(5, 16, 10, 0.55),
    0 0 22px -8px rgba(224, 181, 92, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.tile[data-value="256"] .tile-inner {
  color: #35240b;
  background: linear-gradient(145deg, #eccd72 0%, #d7ad43 100%);
  box-shadow:
    0 8px 18px -9px rgba(5, 16, 10, 0.55),
    0 0 24px -8px rgba(224, 181, 92, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.tile[data-value="512"] .tile-inner {
  color: #fff9ea;
  background: linear-gradient(145deg, #d9b04d 0%, #bd8a29 100%);
  text-shadow: 0 1px 1px rgba(79, 52, 5, 0.22);
  box-shadow:
    0 8px 18px -9px rgba(5, 16, 10, 0.6),
    0 0 24px -8px rgba(224, 181, 92, 0.48),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.tile[data-value="1024"] .tile-inner {
  color: #fff7e4;
  background: linear-gradient(145deg, #d09d34 0%, #a87417 100%);
  text-shadow: 0 1px 2px rgba(58, 38, 3, 0.28);
  box-shadow:
    0 8px 18px -9px rgba(5, 16, 10, 0.6),
    0 0 27px -8px rgba(224, 181, 92, 0.54),
    inset 0 1px 0 rgba(255, 255, 255, 0.36);
}

.tile[data-value="2048"] .tile-inner {
  color: #2b210d;
  background:
    radial-gradient(110% 100% at 20% 0%, rgba(255, 255, 255, 0.6), transparent 45%),
    linear-gradient(145deg, #f4dc8e 0%, #e6bd54 56%, #cf9b2f 100%);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow:
    0 8px 24px -8px rgba(5, 16, 10, 0.62),
    0 0 36px -5px rgba(236, 196, 92, 0.72),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.tile[data-value="2048"] .tile-inner::before {
  position: absolute;
  width: 72%;
  height: 150%;
  content: "";
  background: linear-gradient(
    110deg,
    transparent 25%,
    rgba(255, 255, 255, 0.36) 48%,
    transparent 66%
  );
  transform: translateX(-120%) rotate(12deg);
  animation: tile-shine 4.2s ease-in-out infinite;
}

.tile[data-value="4096"] .tile-inner {
  color: #f8f2e4;
  background: linear-gradient(145deg, #4e715b 0%, #2b4937 100%);
  box-shadow:
    0 8px 22px -8px rgba(5, 16, 10, 0.62),
    0 0 28px -10px rgba(139, 184, 153, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.tile[data-value="8192"] .tile-inner,
.tile[data-value="16384"] .tile-inner,
.tile[data-value="32768"] .tile-inner,
.tile[data-value="65536"] .tile-inner {
  color: #f4ead5;
  background:
    radial-gradient(100% 100% at 20% 0%, rgba(223, 90, 53, 0.48), transparent 52%),
    linear-gradient(145deg, #2d4234 0%, #17271e 100%);
  box-shadow:
    0 8px 22px -8px rgba(5, 16, 10, 0.72),
    0 0 28px -8px rgba(223, 90, 53, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.11);
}

.board-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 12px;
  padding: 0 3px;
}

.key-hints {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.keycap {
  display: inline-grid;
  width: 19px;
  height: 19px;
  margin-right: 1px;
  color: var(--ink-soft);
  background: rgba(255, 252, 244, 0.44);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 9px;
  line-height: 1;
  place-items: center;
}

.caption-text {
  margin-left: 6px;
}

.next-target {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.next-target strong {
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.board.is-nudged {
  animation: board-nudge 240ms ease;
}

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

.board-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  padding: 24px;
  overflow: hidden;
  background: rgba(13, 25, 18, 0.64);
  border-radius: calc(var(--radius-board) - var(--pad) - 1px);
  -webkit-backdrop-filter: blur(12px) saturate(0.8);
  backdrop-filter: blur(12px) saturate(0.8);
  place-items: center;
}

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

.board-overlay::before {
  position: absolute;
  top: -25%;
  right: -20%;
  width: 70%;
  aspect-ratio: 1;
  content: "";
  background: radial-gradient(circle, rgba(223, 90, 53, 0.23), transparent 66%);
  pointer-events: none;
}

.overlay-card {
  position: relative;
  width: min(100%, 390px);
  padding: 30px 30px 25px;
  color: var(--ink);
  background:
    radial-gradient(110% 100% at 100% 0%, rgba(223, 90, 53, 0.08), transparent 50%),
    var(--paper-bright);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 22px;
  box-shadow: 0 30px 70px -28px rgba(0, 0, 0, 0.64);
  text-align: center;
  animation: overlay-in 420ms var(--ease-spring) both;
}

.overlay-kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

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

.overlay-card h2 {
  margin: 12px 0 8px;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1.1;
}

.overlay-card > p {
  max-width: 280px;
  margin: 0 auto 18px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.7;
}

.overlay-result {
  display: flex;
  justify-content: center;
  gap: 34px;
  margin-bottom: 20px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

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

.overlay-stat span {
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.overlay-stat strong {
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 400;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    transform 180ms ease;
}

.overlay-button:active {
  transform: translateY(1px);
}

.overlay-button--primary {
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 10px 20px -13px rgba(29, 42, 35, 0.72);
}

.overlay-button--primary:hover {
  background: #2e4235;
}

.overlay-button--secondary {
  color: var(--ink);
  background: transparent;
  border-color: var(--line-strong);
}

.overlay-button--secondary:hover {
  background: rgba(29, 42, 35, 0.045);
}

.overlay-button--ghost {
  min-height: 32px;
  padding: 0;
  color: var(--ink-faint);
  background: transparent;
  border: none;
  font-size: 10px;
  font-weight: 550;
  text-decoration: underline;
  text-decoration-color: rgba(29, 42, 35, 0.2);
  text-underline-offset: 3px;
}

.overlay-button--ghost:hover {
  color: var(--ink);
}

/* ---------- AI panel ---------- */

.ai-panel {
  position: relative;
  overflow: hidden;
  padding: 24px;
  color: var(--cream);
  background:
    radial-gradient(100% 120% at 108% -8%, rgba(223, 90, 53, 0.3), transparent 44%),
    radial-gradient(80% 70% at -10% 115%, rgba(224, 181, 92, 0.08), transparent 56%),
    linear-gradient(152deg, #263d2e 0%, var(--forest) 36%, #18281f 100%);
  border: 1px solid rgba(255, 255, 255, 0.055);
  border-radius: var(--radius-card);
  box-shadow:
    0 28px 54px -32px rgba(16, 29, 20, 0.66),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.ai-panel::before {
  position: absolute;
  top: -150px;
  right: -105px;
  width: 280px;
  height: 280px;
  content: "";
  border: 1px solid rgba(247, 241, 229, 0.06);
  border-radius: 50%;
  box-shadow:
    0 0 0 30px rgba(247, 241, 229, 0.016),
    0 0 0 64px rgba(247, 241, 229, 0.012);
  pointer-events: none;
}

.ai-panel > * {
  position: relative;
  z-index: 1;
}

.ai-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.panel-eyebrow {
  color: rgba(247, 241, 229, 0.46);
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.16em;
}

.panel-eyebrow.dark {
  color: var(--ink-faint);
}

.ai-panel h2 {
  margin: 7px 0 0;
  color: var(--cream);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.switch {
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.switch-track {
  position: relative;
  display: block;
  width: 48px;
  height: 28px;
  background: rgba(247, 241, 229, 0.12);
  border: 1px solid rgba(247, 241, 229, 0.14);
  border-radius: inherit;
  transition:
    background 200ms ease,
    border-color 200ms ease,
    box-shadow 200ms ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: rgba(247, 241, 229, 0.82);
  border-radius: 50%;
  transition:
    transform 240ms var(--ease-spring),
    background 200ms ease;
}

.switch:hover .switch-track {
  border-color: rgba(247, 241, 229, 0.28);
}

.switch[aria-checked="true"] .switch-track {
  background: var(--accent);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 0 0 4px rgba(223, 90, 53, 0.1);
}

.switch[aria-checked="true"] .switch-thumb {
  background: #fff9f0;
  transform: translateX(20px);
}

.ai-copy {
  max-width: 290px;
  margin: 11px 0 18px;
  color: rgba(247, 241, 229, 0.62);
  font-size: 11px;
  letter-spacing: 0.01em;
  line-height: 1.7;
}

.ai-status {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 64px;
  padding: 12px 13px;
  background: rgba(5, 14, 9, 0.2);
  border: 1px solid rgba(247, 241, 229, 0.07);
  border-radius: 15px;
}

.status-orb {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  background: rgba(247, 241, 229, 0.06);
  border: 1px solid rgba(247, 241, 229, 0.14);
  border-radius: 50%;
  place-items: center;
}

.status-orb::before {
  position: absolute;
  inset: 4px;
  content: "";
  border: 1px solid rgba(247, 241, 229, 0.08);
  border-radius: 50%;
}

.status-orb > span {
  position: relative;
  width: 7px;
  height: 7px;
  background: rgba(247, 241, 229, 0.58);
  border-radius: 50%;
  transition: background 200ms ease;
}

.ai-panel[data-state="active"] .status-orb > span {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(223, 90, 53, 0.13);
}

.ai-panel[data-state="active"] .status-orb {
  border-color: rgba(223, 90, 53, 0.35);
}

.ai-panel[data-state="thinking"] .status-orb {
  border-color: rgba(224, 181, 92, 0.45);
  animation: orb-pulse 1.25s ease-in-out infinite;
}

.ai-panel[data-state="thinking"] .status-orb > span {
  background: var(--gold);
}

.ai-panel[data-state="error"] .status-orb > span {
  background: #e77c5d;
}

.status-text {
  min-width: 0;
  flex: 1;
}

.status-text strong {
  display: block;
  overflow: hidden;
  color: var(--cream);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-text span {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: rgba(247, 241, 229, 0.56);
  font-size: 9px;
  letter-spacing: 0.025em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-arrow {
  flex: 0 0 auto;
  min-width: 20px;
  color: rgba(247, 241, 229, 0.42);
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1;
  text-align: center;
  transition:
    color 180ms ease,
    transform 180ms ease;
}

.status-arrow.is-direction {
  color: var(--gold);
  animation: arrow-in 280ms var(--ease-spring);
}

.speed-block {
  margin-top: 17px;
}

.speed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
  color: rgba(247, 241, 229, 0.42);
  font-size: 9px;
  letter-spacing: 0.06em;
}

.speed-head strong {
  color: rgba(247, 241, 229, 0.72);
  font-size: 9px;
  font-weight: 500;
}

.speed-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 3px;
  background: rgba(5, 14, 9, 0.22);
  border: 1px solid rgba(247, 241, 229, 0.06);
  border-radius: 10px;
}

.speed-option {
  min-height: 28px;
  padding: 5px 2px;
  color: rgba(247, 241, 229, 0.45);
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 10px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

.speed-option:hover {
  color: rgba(247, 241, 229, 0.8);
}

.speed-option[aria-checked="true"] {
  color: var(--forest-deep);
  background: rgba(247, 241, 229, 0.92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
  font-weight: 650;
}

.ai-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 17px;
  padding-top: 14px;
  border-top: 1px solid rgba(247, 241, 229, 0.08);
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 0 11px;
  border-left: 1px solid rgba(247, 241, 229, 0.08);
}

.metric:first-child {
  padding-left: 0;
  border-left: 0;
}

.metric span {
  color: rgba(247, 241, 229, 0.5);
  font-size: 8px;
  letter-spacing: 0.09em;
}

.metric strong {
  overflow: hidden;
  color: rgba(247, 241, 229, 0.82);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-step {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 39px;
  margin-top: 16px;
  color: rgba(247, 241, 229, 0.78);
  background: rgba(247, 241, 229, 0.045);
  border: 1px solid rgba(247, 241, 229, 0.13);
  border-radius: 10px;
  font-size: 10px;
  font-weight: 550;
  letter-spacing: 0.025em;
  cursor: pointer;
  transition:
    color 180ms ease,
    background 180ms ease,
    border-color 180ms ease;
}

.ai-step svg {
  width: 13px;
  height: 13px;
  stroke-width: 1.25;
}

.ai-step:hover:not(:disabled) {
  color: var(--cream);
  background: rgba(247, 241, 229, 0.09);
  border-color: rgba(247, 241, 229, 0.23);
}

.ai-step:disabled {
  color: rgba(247, 241, 229, 0.26);
  border-color: rgba(247, 241, 229, 0.07);
  cursor: default;
}

/* ---------- Run panel ---------- */

.run-panel {
  padding: 21px;
  background:
    radial-gradient(120% 100% at 100% 0%, rgba(255, 255, 255, 0.3), transparent 50%),
    rgba(250, 246, 238, 0.5);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow:
    0 18px 38px -32px rgba(29, 42, 35, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.48);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.run-meta {
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.02em;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 15px;
  border-top: 1px solid var(--line);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 0 12px;
  border-bottom: 1px solid var(--line);
}

.stat:nth-child(odd) {
  padding-right: 12px;
  border-right: 1px solid var(--line);
}

.stat:nth-child(even) {
  padding-left: 16px;
}

.stat:nth-last-child(-n + 2) {
  padding-bottom: 8px;
  border-bottom: 0;
}

.stat span {
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.04em;
}

.stat strong {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.025em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.target-block {
  margin-top: 13px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.target-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-faint);
  font-size: 9px;
  letter-spacing: 0.035em;
}

.target-head b {
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
}

.target-head > span:last-child {
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 9px;
}

.target-track {
  height: 5px;
  margin: 9px 0 10px;
  overflow: hidden;
  background: rgba(29, 42, 35, 0.1);
  border-radius: 999px;
}

.target-fill {
  position: relative;
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #e6b35c);
  border-radius: inherit;
  transition: width 520ms var(--ease-out);
}

.target-fill::after {
  position: absolute;
  top: 0;
  right: 0;
  width: 18px;
  height: 100%;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55));
}

.target-block p {
  margin: 0;
  color: var(--ink-faint);
  font-size: 10px;
  line-height: 1.65;
}

/* ---------- Footer ---------- */

.mastfoot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 48px;
  padding-top: 19px;
  color: var(--ink-faint);
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.footer-note {
  color: rgba(136, 145, 135, 0.8);
}

.footer-keys {
  text-align: right;
}

/* ---------- Toast & confetti ---------- */

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 15px;
  color: var(--cream);
  background: rgba(24, 38, 29, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  box-shadow: 0 16px 36px -16px rgba(9, 19, 13, 0.65);
  font-size: 11px;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 220ms ease,
    transform 280ms var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error .toast-mark {
  background: #e77c5d;
}

.toast-mark {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  background: var(--gold);
  border-radius: 50%;
}

.confetti {
  position: fixed;
  z-index: 90;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -24px;
  width: 7px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall var(--duration, 2.4s) var(--delay, 0s) cubic-bezier(0.16, 0.65, 0.35, 1) forwards;
}

/* ---------- Animations ---------- */

@keyframes breathe {
  0%,
  100% {
    box-shadow: 0 0 0 4px rgba(223, 90, 53, 0.09);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(223, 90, 53, 0.02);
  }
}

@keyframes pulse-ring {
  0% {
    opacity: 0.9;
    transform: scale(0.8);
  }
  70% {
    opacity: 0;
    transform: scale(1.6);
  }
  100% {
    opacity: 0;
    transform: scale(1.6);
  }
}

@keyframes orb-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(224, 181, 92, 0.02);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(224, 181, 92, 0.08);
  }
}

@keyframes score-bump {
  0% {
    transform: translateY(0) scale(1);
  }
  35% {
    transform: translateY(-3px) scale(1.055);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes gain-rise {
  0% {
    opacity: 0;
    transform: translateY(5px);
  }
  18% {
    opacity: 1;
    transform: translateY(0);
  }
  72% {
    opacity: 1;
    transform: translateY(-5px);
  }
  100% {
    opacity: 0;
    transform: translateY(-10px);
  }
}

@keyframes tile-appear {
  0% {
    opacity: 0;
    transform: scale(0.42);
  }
  64% {
    opacity: 1;
    transform: scale(1.06);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes tile-merge {
  0% {
    opacity: 0.25;
    transform: scale(0.58);
  }
  55% {
    opacity: 1;
    transform: scale(1.13);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes tile-shine {
  0%,
  42% {
    transform: translateX(-140%) rotate(12deg);
  }
  62%,
  100% {
    transform: translateX(160%) rotate(12deg);
  }
}

@keyframes board-nudge {
  0% {
    transform: translateX(0);
  }
  24% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
  100% {
    transform: translateX(0);
  }
}

@keyframes overlay-in {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes arrow-in {
  0% {
    opacity: 0;
    transform: translateY(3px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes confetti-fall {
  0% {
    opacity: 1;
    transform: translate3d(0, -10px, 0) rotate(0deg);
  }
  100% {
    opacity: 0.2;
    transform: translate3d(var(--drift, 40px), 108vh, 0)
      rotate(var(--spin, 540deg));
  }
}

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

@media (max-width: 980px) {
  .page {
    width: min(calc(100% - 48px), 760px);
  }

  .hero {
    padding-top: 42px;
  }

  h1 {
    font-size: clamp(84px, 15vw, 112px);
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 30px;
    padding-top: 28px;
  }

  .play-area {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
  }

  .sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    gap: 16px;
    align-items: stretch;
  }

  .ai-panel,
  .run-panel {
    height: 100%;
  }

  .run-panel {
    display: flex;
    flex-direction: column;
  }

  .run-panel .stat-grid {
    flex: 1;
  }

  .mastfoot {
    margin-top: 36px;
  }
}

@media (max-width: 760px) {
  .page {
    width: calc(100% - 32px);
    padding-top: 20px;
  }

  .utility-meta {
    display: none;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  .masthead {
    padding-bottom: 24px;
  }

  .hero {
    display: block;
    padding-top: 34px;
  }

  .hero-copy {
    max-width: 100%;
  }

  h1 {
    margin: 13px 0 13px;
    font-size: clamp(82px, 22vw, 106px);
  }

  .hero-copy p {
    max-width: 100%;
    font-size: 12px;
    line-height: 1.75;
  }

  .desktop-break {
    display: none;
  }

  .score-panel {
    width: 100%;
    padding-top: 24px;
  }

  .score-card {
    flex: 1;
    min-width: 0;
    min-height: 96px;
    padding: 13px 15px;
  }

  .score-value {
    font-size: 32px;
  }

  .score-gain {
    top: 34px;
    right: 13px;
  }

  .layout {
    padding-top: 22px;
    gap: 22px;
  }

  .play-toolbar {
    margin-bottom: 10px;
  }

  .turn-copy {
    display: block;
  }

  .turn-copy small {
    display: block;
    max-width: 190px;
    margin-top: 2px;
    font-size: 9px;
  }

  .toolbar-actions {
    gap: 5px;
  }

  .text-button,
  .solid-button {
    height: 35px;
    padding: 0 10px;
    font-size: 10px;
  }

  .text-button svg,
  .solid-button svg {
    width: 14px;
    height: 14px;
  }

  .board {
    border-radius: 21px;
  }

  .board-cell {
    border-radius: 9px;
  }

  .tile-inner {
    border-radius: 9px;
  }

  .board-caption {
    margin-top: 10px;
  }

  .caption-text {
    display: none;
  }

  .sidebar {
    grid-template-columns: minmax(0, 1fr);
    gap: 13px;
  }

  .ai-panel {
    padding: 20px;
    border-radius: 21px;
  }

  .run-panel {
    padding: 19px;
    border-radius: 21px;
  }

  .ai-copy {
    margin-bottom: 15px;
  }

  .mastfoot {
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-top: 28px;
    padding-top: 16px;
    font-size: 7.5px;
  }

  .footer-note {
    order: 3;
    width: 100%;
  }

  .board-overlay {
    position: fixed;
    z-index: 80;
    inset: 0;
    padding: 20px;
    overflow-y: auto;
    background: rgba(13, 25, 18, 0.79);
    border-radius: 0;
    -webkit-backdrop-filter: blur(14px) saturate(0.8);
    backdrop-filter: blur(14px) saturate(0.8);
    overscroll-behavior: contain;
  }

  .overlay-card {
    padding: 24px 22px 20px;
    margin: auto;
  }

  .overlay-card h2 {
    font-size: 30px;
  }

  .overlay-card > p {
    margin-bottom: 15px;
  }

  .overlay-result {
    gap: 28px;
    margin-bottom: 16px;
    padding: 10px 0;
  }

  .overlay-actions {
    gap: 7px;
  }

  .overlay-button {
    min-height: 40px;
  }
}

@media (max-width: 420px) {
  .page {
    width: calc(100% - 24px);
  }

  h1 {
    font-size: 86px;
  }

  .eyebrow {
    font-size: 9px;
    letter-spacing: 0.1em;
  }

  .score-card {
    min-height: 88px;
    padding: 11px 13px;
  }

  .score-english {
    font-size: 6px;
  }

  .score-value {
    font-size: 29px;
  }

  .score-gain {
    top: 31px;
    right: 11px;
    font-size: 8px;
  }

  .text-button span,
  .solid-button span {
    font-size: 9px;
  }

  .turn-copy small {
    max-width: 140px;
  }

  .key-hints {
    gap: 2px;
  }

  .keycap {
    width: 17px;
    height: 17px;
  }

  .next-target {
    font-size: 8px;
  }

  .board-caption {
    padding: 0;
  }

  .overlay-result {
    gap: 24px;
  }

  .overlay-card h2 {
    font-size: 27px;
  }

  .overlay-card > p {
    font-size: 11px;
  }

  .overlay-button {
    min-height: 42px;
  }

  .speed-option {
    font-size: 9px;
  }

  .ai-panel h2 {
    font-size: 20px;
  }

  .status-text strong {
    font-size: 11px;
  }

  .status-text span {
    font-size: 8.5px;
  }

  .metric {
    padding: 0 8px;
  }

  .metric strong {
    font-size: 10px;
  }
}

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

  .tile {
    transition: none !important;
  }
}
