:root {
  --paper: #f5f3ee;
  --ink: #1d1d1b;
  --muted: #85847f;
  --line: #dedcd5;
  --lime: #c8f36a;
  --coral: #ff765e;
  --dark: #282825;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #d8d6cf;
  color: var(--ink);
  font-family: Arial, sans-serif;
}
.app-shell {
  max-width: 460px;
  min-height: 100vh;
  margin: auto;
  background: var(--paper);
  padding: 0 22px 26px;
}
button {
  font: inherit;
  border: 0;
  cursor: pointer;
  color: inherit;
  background: none;
}
header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: bold;
  letter-spacing: 2px;
}
.brand b {
  display: inline-grid;
  place-items: center;
  background: var(--ink);
  color: var(--lime);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-style: italic;
}
.avatar {
  background: #8ac7df;
  border-radius: 50%;
  height: 35px;
  width: 35px;
  font-size: 11px;
}
.screen {
  display: none;
  padding-top: 35px;
}
.screen.active {
  display: block;
}
.eyebrow {
  font: 11px monospace;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}
.coral,
em {
  color: var(--coral);
  font-style: normal;
}
h1 {
  font-size: 52px;
  line-height: 0.95;
  letter-spacing: -4px;
  margin: 20px 0;
}
h2 {
  font-size: 17px;
  margin: 28px 0 12px;
}
.subcopy {
  color: #6f6e69;
  line-height: 1.55;
  max-width: 335px;
}
.actions {
  display: grid;
  gap: 10px;
  margin: 28px 0 33px;
}
.primary,
.secondary {
  height: 54px;
  padding: 0 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  border-radius: 3px;
}
.primary {
  background: var(--ink);
  color: var(--lime);
}
.secondary {
  border: 1px solid #c9c7bf;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-block: 1px solid var(--line);
  padding: 17px 0;
}
.stats div {
  border-right: 1px solid var(--line);
  padding-left: 12px;
}
.stats div:first-child {
  padding-left: 0;
}
.stats div:last-child {
  border: 0;
}
.stats b {
  display: block;
  font-size: 23px;
}
.stats small,
.room small,
.chips small,
.achievement small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 4px;
}
.room {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  padding: 13px;
}
.room i {
  background: var(--lime);
  border-radius: 50%;
  font-size: 22px;
  font-style: normal;
  padding: 7px;
}
.room div {
  flex: 1;
}
.round {
  background: var(--ink);
  color: var(--lime);
  border-radius: 50%;
  width: 32px;
  height: 32px;
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-title button {
  font-size: 11px;
  color: var(--muted);
}
.chips {
  display: flex;
  gap: 9px;
  overflow: hidden;
}
.chips article {
  min-width: 128px;
  border: 1px solid var(--line);
  padding: 13px;
  background: #efede7;
}
.chips strong {
  display: block;
  color: var(--coral);
  font-size: 22px;
  margin-bottom: 8px;
}
.chips b {
  display: block;
  font-size: 12px;
}
.game-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.game-head div {
  flex: 1;
}
.game-head button {
  font-size: 24px;
  color: var(--muted);
}
.game-head h2,
.game-head h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -1px;
}
.game-head h1 {
  font-size: 29px;
}
.game-meta {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  justify-content: stretch;
  align-items: end;
  margin: 30px 0 17px;
}
.game-meta small,
.game-meta p {
  font: 10px monospace;
  color: var(--muted);
  line-height: 1.8;
}
.game-meta strong {
  display: block;
  font-size: 34px;
}
#gameScore {
  color: var(--coral);
}
.preview {
  height: 45px;
  background: #ebe9e2;
  display: grid;
  place-items: center;
  font: 13px monospace;
  color: #999;
  margin-bottom: 14px;
}
.preview.found {
  background: var(--lime);
  color: var(--ink);
  font-size: 21px;
}
.board {
  background: var(--dark);
  padding: 8px;
  touch-action: none;
}
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.tile {
  aspect-ratio: 1;
  background: #f8f6f0;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: bold;
  user-select: none;
}
.tile.selected {
  background: var(--coral);
  color: white;
}
.game-foot {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  color: var(--muted);
  font: 11px monospace;
}
.game-foot button {
  color: var(--coral);
}
.result {
  text-align: center;
  border-block: 1px solid var(--line);
  padding: 20px;
}
.result small {
  display: block;
  font: 10px monospace;
  color: var(--muted);
}
.result strong {
  display: block;
  font-size: 64px;
}
.leader p {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  font-size: 13px;
}
.achievement {
  display: flex;
  gap: 12px;
  align-items: center;
  background: #eceae3;
  padding: 13px;
  margin: 20px 0;
}
.achievement > div {
  flex: 1;
}
.achievement:first-letter {
  color: var(--coral);
  font-size: 28px;
}
.progress {
  margin: 33px 0 23px;
  color: var(--muted);
}
.progress b {
  font-size: 28px;
  color: var(--ink);
}
.progress i {
  display: block;
  height: 5px;
  background: linear-gradient(90deg, var(--coral) 33%, #e1dfd8 33%);
  margin-top: 12px;
}
.achievement-list {
  display: grid;
  gap: 9px;
}
.achievement-list article {
  display: flex;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  padding: 13px;
  font-size: 22px;
  color: var(--coral);
}
.achievement-list article div {
  flex: 1;
}
.achievement-list b,
.achievement-list small {
  display: block;
  color: var(--ink);
  font-size: 13px;
}
.achievement-list small {
  color: var(--muted);
  font-size: 10px;
  margin-top: 4px;
}
.achievement-list em {
  font: 9px monospace;
  color: #86a43f;
}
nav {
  position: relative;
  width: 100%;
  height: 72px;
  background: var(--paper);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  padding-top: 9px;
  margin-top: 38px;
}
nav button {
  font-size: 20px;
  color: var(--muted);
  min-width: 80px;
}
nav button.active {
  color: var(--coral);
}
nav small {
  display: block;
  font: 10px monospace;
  color: var(--muted);
  margin-top: 4px;
}
#toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 11px 17px;
  font: 11px monospace;
  opacity: 0;
  transition: 0.2s;
}
#toast.show {
  opacity: 1;
}
.site-footer {
  margin: 28px 0 0;
  padding: 16px 0 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
}
@media (min-width: 600px) {
  .app-shell {
    margin: 20px auto;
    min-height: calc(100vh - 40px);
    box-shadow: 0 12px 50px #7775;
    border-radius: 8px;
  }
  nav {
    border-radius: 0 0 8px 8px;
  }
}

.hero-art {
  height: 126px;
  margin: -10px -22px 24px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  position: relative;
  background: linear-gradient(125deg, #30264f, #d85f78 52%, #f6c85f);
  transform: rotate(-1deg);
  box-shadow: inset 0 -8px 0 #1d1d1b33;
}
.hero-art span,
.hero-art b {
  display: grid;
  place-items: center;
  width: 38px;
  height: 48px;
  border: 2px solid #fff9f0;
  border-radius: 8px;
  background: #fff9f0;
  color: #30264f;
  font: 900 24px monospace;
  box-shadow: 0 5px 0 #211a36;
  transform: rotate(var(--tilt, 0deg));
  animation: hero-tile-float 3.5s ease-in-out infinite;
}
.hero-art span:nth-child(2n) { --tilt: 4deg; animation-delay: -0.8s; }
.hero-art span:nth-child(3n) { --tilt: -5deg; animation-delay: -1.7s; }
.hero-art b {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--lime);
  color: #30264f;
  font-size: 17px;
  animation-delay: -2.4s;
}
@keyframes hero-tile-float {
  0%, 100% { transform: translateY(2px) rotate(var(--tilt, 0deg)); }
  50% { transform: translateY(-6px) rotate(var(--tilt, 0deg)); }
}
.mode-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  background: #ebe9e2;
  padding: 14px;
  margin: 20px 0 28px;
}
.mode-panel div {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.mode-panel small {
  font: 10px monospace;
  color: var(--coral);
  letter-spacing: 1px;
}
.mode-panel strong {
  font-size: 13px;
}
.mode-panel span {
  font-size: 11px;
  color: var(--muted);
}
.mode-panel button {
  font-size: 25px;
  color: var(--coral);
}
.random-start {
  font: 700 11px monospace;
  color: var(--ink) !important;
  background: var(--lime);
  padding: 9px 11px !important;
  white-space: nowrap;
}
.mode-panel {
  gap: 8px;
}
.mode-panel button:hover {
  transform: none;
}

.game-mode-stack {
  display: grid;
  gap: 12px;
  margin: 14px 0 28px;
}
.game-mode-card {
  position: relative;
  width: 100%;
  min-height: 88px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 16px;
  text-align: left;
  color: #201a34;
  border: 2px solid var(--mode-edge, #fff8cc);
  border-radius: 18px;
  background: linear-gradient(120deg, var(--mode-start), var(--mode-end));
  box-shadow: 0 6px 0 var(--mode-shadow, #5c4b7d);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.game-mode-card:hover,
.game-mode-card:focus-visible {
  transform: translateY(-3px) rotate(-0.3deg);
  box-shadow: 0 9px 0 var(--mode-shadow, #5c4b7d);
}
.game-mode-card:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--mode-shadow, #5c4b7d);
}
.game-mode-card > span {
  width: 42px;
  font-size: 32px;
  text-align: center;
  filter: drop-shadow(0 2px 0 #ffffff99);
}
.game-mode-card > div {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}
.game-mode-card small {
  font: 900 10px monospace;
  letter-spacing: 0.12em;
}
.game-mode-card strong {
  font-size: 16px;
}
.game-mode-card em {
  color: inherit;
  font-size: 12px;
  font-style: normal;
  opacity: 0.78;
}
.game-mode-card > b {
  font-size: 26px;
}
.mode-classic { --mode-start: #b7f5ff; --mode-end: #80b9ff; --mode-edge: #e7fbff; --mode-shadow: #5682bb; }
.mode-random { --mode-start: #e2ff84; --mode-end: #7fe5a6; --mode-edge: #f6ffc4; --mode-shadow: #48956b; }
.mode-random.is-featured {
  min-height: 104px;
  border-width: 3px;
  box-shadow: 0 8px 0 var(--mode-shadow);
}
.mode-random.is-featured::before {
  content: "★ FEATURED";
  position: absolute;
  top: 8px;
  right: 64px;
  color: #326448;
  font: 900 9px monospace;
  letter-spacing: 0.12em;
}
.mode-sudden { --mode-start: #ffe16b; --mode-end: #ff9f65; --mode-edge: #fff3af; --mode-shadow: #c9743d; }
.mode-dirty { --mode-start: #e9b7ff; --mode-end: #d77bc7; --mode-edge: #f8dbff; --mode-shadow: #985184; }
.mode-race { --mode-start: #ffb0bc; --mode-end: #ff6f81; --mode-edge: #ffe0e5; --mode-shadow: #bd4b60; }
.mode-minimum { --mode-start: #b7f0d0; --mode-end: #67d5cf; --mode-edge: #ddfff1; --mode-shadow: #459c9a; }
.mode-blitz { --mode-start: #fff16b; --mode-end: #ff8d67; --mode-edge: #fff8bd; --mode-shadow: #c75d42; }
.mode-longhaul { --mode-start: #d5c4ff; --mode-end: #9a83e8; --mode-edge: #eee7ff; --mode-shadow: #6650ae; }
.mode-storm { --mode-start: #bde9ff; --mode-end: #6ab9ed; --mode-edge: #e0f7ff; --mode-shadow: #4780ad; }
.mode-scoreattack { --mode-start: #ffd0a3; --mode-end: #ff8f72; --mode-edge: #ffebd5; --mode-shadow: #bb5f4c; }
.mode-chain { --mode-start: #b9f2dc; --mode-end: #68c9b3; --mode-edge: #e2fff4; --mode-shadow: #458c7d; }
.mode-custom { --mode-start: #c3c8ff; --mode-end: #8e93f5; --mode-edge: #ebecff; --mode-shadow: #6368b9; }
.mode-dictionary { --mode-start: #ffd3a8; --mode-end: #f7a568; --mode-edge: #ffebd6; --mode-shadow: #bd7140; }
.mode-random #reroll {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: #ffffff80;
  color: inherit;
  font-size: 24px;
}
@media (max-width: 380px) {
  .hero-art { gap: 3px; }
  .hero-art span { width: 28px; height: 38px; font-size: 18px; }
  .hero-art b { width: 24px; height: 24px; font-size: 13px; }
  .game-mode-card { min-height: 80px; padding: 12px; }
  .game-mode-card > span { width: 34px; font-size: 27px; }
  .game-mode-card strong { font-size: 14px; }
}

.round-intro-screen {
  min-height: calc(100svh - 86px);
  padding-top: 22px;
  text-align: center;
  overflow: hidden;
}
.intro-orbit {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  min-height: 112px;
  margin: 0 -10px 8px;
  position: relative;
}
.intro-orbit i,
.intro-orbit b {
  display: grid;
  place-items: center;
  width: 32px;
  height: 42px;
  border-radius: 7px;
  background: var(--ink);
  color: var(--lime);
  font: 900 20px monospace;
  font-style: normal;
  box-shadow: 0 5px 0 var(--coral);
  animation: intro-letter-bob 1.8s ease-in-out infinite;
}
.intro-orbit i:nth-child(2n) { animation-delay: -0.35s; transform: rotate(6deg); }
.intro-orbit i:nth-child(3n) { animation-delay: -0.7s; transform: rotate(-7deg); }
.intro-orbit b {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--coral);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  animation-delay: -1s;
}
@keyframes intro-letter-bob {
  0%, 100% { translate: 0 4px; }
  50% { translate: 0 -8px; }
}
.round-intro-screen h1 {
  margin: 14px 0 20px;
  font-size: clamp(38px, 12vw, 58px);
  letter-spacing: -3px;
}
.intro-rule-card {
  margin: 0 auto;
  padding: 20px 16px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: linear-gradient(135deg, #fff9f0, #e6f6d0);
  box-shadow: 0 7px 0 var(--ink);
  animation: intro-card-pop 0.5s ease both;
}
.intro-rule-card small,
.intro-auto {
  color: var(--muted);
  font: 10px monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.intro-rule-card h2 {
  margin: 9px 0 6px;
  font-size: 22px;
  line-height: 1.1;
}
.intro-rule-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.intro-countdown {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  margin: 27px auto 15px;
  border: 3px solid var(--coral);
  border-radius: 50%;
  color: var(--coral);
  font: 900 30px monospace;
  animation: intro-countdown-pulse 1s ease-in-out infinite;
}
.intro-start {
  width: 100%;
  justify-content: center;
  border: 0;
  font-size: 15px;
}
.intro-auto {
  display: block;
  margin-top: 12px;
  letter-spacing: 0;
  text-transform: none;
}
@keyframes intro-card-pop {
  from { opacity: 0; transform: translateY(12px) rotate(1deg); }
  to { opacity: 1; transform: translateY(0) rotate(0); }
}
@keyframes intro-countdown-pulse {
  0%, 100% { transform: scale(0.96); }
  50% { transform: scale(1.06); }
}
html[data-theme="dark"] .intro-rule-card {
  background: linear-gradient(135deg, #292e28, #39482f);
}

:root {
  color-scheme: light dark;
}
html[data-theme="light"] {
  color-scheme: light;
}
html[data-theme="dark"] {
  color-scheme: dark;
}
html[data-theme="dark"] body {
  background: #111311;
  color: #f3f1ea;
}
html[data-theme="dark"] .app-shell {
  background: #1b1d1a;
  --paper: #1b1d1a;
  --ink: #f3f1ea;
  --muted: #aaa99f;
  --line: #393d37;
  --dark: #0e100e;
}
html[data-theme="dark"] .subcopy,
html[data-theme="dark"] .stats small,
html[data-theme="dark"] .room small,
html[data-theme="dark"] .chips small,
html[data-theme="dark"] .achievement small {
  color: #aaa99f;
}
html[data-theme="dark"] .secondary {
  border-color: #555b53;
}
html[data-theme="dark"] .room,
html[data-theme="dark"] .chips article {
  background: #242823;
  border-color: #3b4239;
}
html[data-theme="dark"] .mode-panel,
html[data-theme="dark"] .preview {
  background: #292e28;
}
html[data-theme="dark"] .tile {
  background: #e8e5da;
  color: #181a17;
}
html[data-theme="dark"] .achievement {
  background: #292e28;
}
html[data-theme="dark"] .hero-art {
  background: #292e28;
}
html[data-theme="dark"] nav {
  background: rgba(27, 29, 26, 0.97);
}
.theme-toggle {
  font-size: 21px;
  color: var(--muted);
  padding: 4px 9px;
}
.theme-toggle:hover {
  color: var(--coral);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) body {
    background: #111311;
    color: #f3f1ea;
  }
  html:not([data-theme="light"]) .app-shell {
    background: #1b1d1a;
    --paper: #1b1d1a;
    --ink: #f3f1ea;
    --muted: #aaa99f;
    --line: #393d37;
    --dark: #0e100e;
  }
  html:not([data-theme="light"]) .subcopy,
  html:not([data-theme="light"]) .stats small,
  html:not([data-theme="light"]) .room small,
  html:not([data-theme="light"]) .chips small,
  html:not([data-theme="light"]) .achievement small {
    color: #aaa99f;
  }
  html:not([data-theme="light"]) .secondary {
    border-color: #555b53;
  }
  html:not([data-theme="light"]) .room,
  html:not([data-theme="light"]) .chips article {
    background: #242823;
    border-color: #3b4239;
  }
  html:not([data-theme="light"]) .mode-panel,
  html:not([data-theme="light"]) .preview {
    background: #292e28;
  }
  html:not([data-theme="light"]) .tile {
    background: #e8e5da;
    color: #181a17;
  }
  html:not([data-theme="light"]) .achievement {
    background: #292e28;
  }
  html:not([data-theme="light"]) nav {
    background: rgba(27, 29, 26, 0.97);
  }
}

#gameScreen.active {
  height: calc(100svh - 182px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: 22px;
}
.game-head,
.rule-banner,
.game-meta,
.preview,
.game-foot {
  flex: none;
}
.board {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.grid {
  width: min(100%, calc(100svh - 370px));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  position: relative;
  z-index: 1;
}
.trace-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
  /*
   * Deliberately hidden for now: app.js still records and smooths trace paths
   * so the visual trail can be restored without rebuilding input handling.
   * Use visibility (rather than display) to preserve the SVG's dimensions.
   */
  visibility: hidden;
}
.trace-layer path {
  fill: none;
  stroke: var(--coral);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 2px #0003);
  opacity: 0.92;
}
.board .tile {
  touch-action: none;
}
.tile.selected {
  transform: scale(0.94);
  transition: transform 0.08s ease;
}
.game-foot {
  padding-bottom: 4px;
}
@media (max-height: 650px) {
  #gameScreen.active {
    height: calc(100svh - 162px);
    padding-top: 8px;
  }
  .game-head h2 {
    font-size: 17px;
  }
  .game-meta {
    margin: 8px 0 6px;
  }
  .game-meta strong {
    font-size: 27px;
  }
  .preview {
    height: 32px;
    margin-bottom: 6px;
  }
  .grid {
    width: min(100%, calc(100svh - 370px));
  }
}
@media (min-width: 600px) {
  #gameScreen.active {
    height: calc(100svh - 202px);
  }
}

/* The play surface owns the viewport on phones. */
body:has(#gameScreen.active) nav {
  display: none;
}
body:has(#gameScreen.active) .app-shell {
  padding-bottom: 0;
}
#gameScreen.active {
  height: calc(100svh - 76px);
  padding-top: 12px;
}
.game-head div {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.game-head .eyebrow {
  margin: 0;
  white-space: nowrap;
}
.game-head h2 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-meta {
  margin: 12px 0 10px;
  gap: 12px;
}
.game-meta > div:first-child,
.game-meta > div:nth-child(2) {
  min-width: 58px;
}
.game-meta strong {
  font-size: 32px;
}
.preview {
  height: 42px;
  font-size: 24px;
  font-weight: bold;
  color: var(--ink);
  margin-bottom: 8px;
}
.preview.found {
  font-size: 24px;
}
.board {
  padding: 6px;
}
.grid {
  width: min(100%, calc(100svh - 200px), calc(100vw - 56px));
  height: auto;
  aspect-ratio: 1/1;
  flex: 0 0 auto;
  max-height: none;
}
.tile {
  background: #f7dfe4;
}
body[data-mode="classic"] .tile {
  background: #dcecf7;
}
body[data-mode="minimum"] .tile {
  background: #e6def8;
}
body[data-mode="sudden"] .tile {
  background: #ffe1d2;
}
body[data-mode="race"] .tile {
  background: #dcefdc;
}
body[data-mode="dirty"] .tile {
  background: #f8e2bc;
}
body[data-mode="blitz"] .tile {
  background: #fff0c4;
}
body[data-mode="longhaul"] .tile {
  background: #e6def8;
}
body[data-mode="storm"] .tile {
  background: #d9effb;
}
body[data-mode="scoreattack"] .tile {
  background: #ffe2d1;
}
body[data-mode="chain"] .tile {
  background: #d9f2e7;
}
@media (max-height: 650px) {
  #gameScreen.active {
    height: calc(100svh - 76px);
    padding-top: 6px;
  }
  .game-head h2 {
    font-size: 17px;
  }
  .game-meta {
    margin: 6px 0 5px;
  }
  .game-meta strong {
    font-size: 28px;
  }
  .preview {
    height: 34px;
    font-size: 21px;
    margin-bottom: 5px;
  }
  .preview.found {
    font-size: 21px;
  }
  .game-foot {
    padding-top: 6px;
  }
}
@media (min-width: 600px) {
  #gameScreen.active {
    height: calc(100svh - 116px);
  }
}

.avatar {
  display: grid;
  place-items: center;
  font-size: 20px;
}
.live-players {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  max-width: none;
  overflow-x: auto;
}
.live-player {
  display: grid;
  grid-template-columns: 20px minmax(42px, auto);
  grid-template-rows: auto auto;
  gap: 2px 5px;
  align-items: center;
  background: #ebe9e2;
  padding: 4px 7px;
  font-size: 11px;
  flex: none;
  min-width: 88px;
}
.player-avatar {
  font-size: 16px;
}
.player-name {
  max-width: 82px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-player b {
  grid-column: 1 / -1;
  color: var(--coral);
  font-family: monospace;
  font-size: 32px;
  line-height: 1;
  text-align: right;
}
.live-player.is-you {
  outline: 1px solid var(--coral);
}
.live-player.is-opponent {
  outline: 1px solid #5268c7;
}
.live-player.is-opponent b {
  color: #5268c7;
}
@media (max-height: 650px) {
  .live-player b {
    font-size: 28px;
  }
}
dialog {
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 0;
  max-width: 340px;
  width: calc(100% - 36px);
  box-shadow: 0 20px 80px #0008;
}
dialog::backdrop {
  background: #1118;
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 20px 8px;
}
.dialog-head h2 {
  margin: 0;
}
.dialog-head button {
  font-size: 26px;
  color: var(--muted);
}
#profileForm {
  padding-bottom: 20px;
}
#profileForm label,
#profileForm input,
#profileForm .avatar-label {
  display: block;
  margin-left: 20px;
  margin-right: 20px;
}
#profileForm label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
}
#profileName {
  width: calc(100% - 40px);
  margin-top: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  border-radius: 3px;
}
.avatar-label {
  margin-top: 20px !important;
}
.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 20px;
}
.avatar-picker button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 22px;
  background: transparent;
}
.avatar-picker button.chosen {
  border: 2px solid var(--coral);
  background: var(--lime);
}
.dialog-save {
  width: calc(100% - 40px);
  margin: 0 20px;
  justify-content: center;
}

html[data-theme="dark"] .primary {
  background: var(--lime);
  color: #1d1d1b;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .primary {
    background: var(--lime);
    color: #1d1d1b;
  }
}

.tile {
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}
.tile.selected {
  animation: tile-selected 0.38s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  transform: scale(1);
  background-color: #45f27d;
  color: #1d1d1b;
}
html[data-theme="dark"] .tile.selected {
  color: #181a17;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .tile.selected {
    color: #181a17;
  }
}
@keyframes tile-selected {
  0% {
    transform: scale(1);
    box-shadow: 0 3px 0 #1e9f58;
  }
  52% {
    transform: scale(1.18) rotate(-3deg);
    box-shadow: 0 10px 20px #45f27db3;
  }
  100% {
    transform: scale(1);
    box-shadow: 0 5px 12px #45f27d88;
  }
}
.tile.word-correct {
  animation: word-correct 0.65s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  background-color: #36ef78;
  color: var(--ink);
}
@keyframes word-correct {
  0% {
    transform: scale(1);
    background-color: #36ef78;
    box-shadow: 0 3px 0 #1c9c4e;
  }
  42% {
    transform: scale(1.25) rotate(-5deg);
    background-color: #c5ff35;
    box-shadow: 0 13px 24px #9cff3db3;
  }
  70% {
    transform: scale(1.13) rotate(5deg);
    background-color: #00e68a;
  }
  100% {
    transform: scale(1);
    background-color: #36ef78;
    box-shadow: 0 4px 0 #1c9c4e;
  }
}
.tile.word-incorrect {
  animation: word-incorrect 1.05s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  background-color: #ff345e;
  color: #fff;
  outline: 4px solid #ff174e;
  outline-offset: 2px;
}
@keyframes word-incorrect {
  0% {
    transform: scale(1);
    background-color: #ff174e;
    box-shadow: 0 3px 0 #b51f42;
  }
  25% {
    transform: scale(1.24) rotate(8deg);
    background-color: #ff003d;
    box-shadow: 0 0 0 7px #ff174e66, 0 14px 28px #ff345ecc;
  }
  45% {
    transform: scale(1.08) rotate(-8deg);
    background-color: #ff633f;
    box-shadow: 0 0 0 4px #ff174e55, 0 8px 18px #ff345eaa;
  }
  65% {
    transform: scale(1.18) rotate(5deg);
    background-color: #ff174e;
  }
  100% {
    transform: scale(1);
    background-color: #ff345e;
    box-shadow: 0 4px 0 #b51f42;
  }
}
.tile.word-duplicate {
  animation: word-duplicate .48s ease-in-out;
  background-color: #f6c85f;
  color: #2c1c37;
}
@keyframes word-duplicate {
  0%, 100% { transform: scale(1); }
  30% { transform: scale(1.08) rotate(-2deg); box-shadow: 0 0 0 4px #f6c85f66; }
  60% { transform: scale(.96) rotate(2deg); }
}

/* A bright, candy-like board makes scanning letters feel more playful. */
.board {
  background:
    radial-gradient(circle at 10% 8%, #5f4b9b 0 2px, transparent 3px),
    radial-gradient(circle at 88% 18%, #2dd4bf 0 2px, transparent 3px),
    linear-gradient(135deg, #25234c, #3c2a67 52%, #1d4d67);
  border-radius: 20px;
  padding: 10px;
}
#grid .tile {
  position: relative;
  background-image: linear-gradient(145deg, #ffffff6b, transparent 60%);
  border: 1px solid #ffffffa8;
  border-radius: 22px !important;
  box-shadow:
    inset 0 1px 0 #ffffffa8,
    0 3px 0 #17233c40;
  overflow: hidden;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}
#grid .tile:nth-child(4n + 1) {
  background-color: #ffd2ad;
}
#grid .tile:nth-child(4n + 2) {
  background-color: #b9e6ff;
}
#grid .tile:nth-child(4n + 3) {
  background-color: #d8c4ff;
}
#grid .tile:nth-child(4n) {
  background-color: #ffc4d5;
}
#grid .tile.selected {
  background-color: #45f27d;
  box-shadow:
    inset 0 1px 0 #ffffffb8,
    0 5px 14px #45f27d99;
}
#grid .tile.word-correct {
  background-color: #36ef78;
  box-shadow:
    inset 0 1px 0 #ffffffb8,
    0 6px 18px #36ef78aa;
}
#grid .tile.word-incorrect {
  background-color: #ff345e;
  box-shadow:
    inset 0 1px 0 #ffffffb8,
    0 6px 18px #ff345eaa;
}
#grid .tile.word-duplicate {
  background-color: #f6c85f;
  box-shadow:
    inset 0 1px 0 #ffffffb8,
    0 4px 12px #f6c85f99;
}
@media (prefers-reduced-motion: reduce) {
  #grid .tile,
  #grid .tile.selected,
  #grid .tile.word-correct,
  #grid .tile.word-incorrect {
    animation-duration: 0.01ms;
    transition-duration: 0.01ms;
  }
}

body:has(#gameScreen.active) header {
  display: none;
}
body:has(#gameScreen.active) .app-shell {
  padding-bottom: 0;
}
#gameScreen.active {
  height: 100svh;
  padding-top: 8px;
}
#gameScreen.active .game-head {
  margin-bottom: 2px;
}
#gameScreen.active #gameMode {
  font-size: 14px;
  letter-spacing: 0.5px;
}
#gameScreen.active #gameTitle {
  font-size: 18px;
}
#gameScreen.active .rule-banner {
  font-size: 12px;
  padding-block: 9px;
  margin-block: 12px 10px;
}
#gameScreen.active .game-meta {
  margin-block: 8px 7px;
}
#gameScreen.active .game-meta strong {
  font-size: 32px;
}
#gameScreen.active .preview {
  font-size: 24px;
  height: 42px;
  margin-bottom: 7px;
}
@media (max-height: 650px) {
  #gameScreen.active {
    padding-top: 4px;
  }
  #gameScreen.active .rule-banner {
    margin-block: 7px 5px;
    padding-block: 7px;
  }
  #gameScreen.active .game-meta strong,
  #gameScreen.active .live-player b {
    font-size: 28px;
  }
  #gameScreen.active .preview {
    font-size: 21px;
    height: 34px;
  }
  #gameScreen.active .game-meta {
    margin-block: 5px;
  }
  #gameScreen.active .preview {
    height: 34px;
    font-size: 21px;
    margin-bottom: 4px;
  }
}

.scoreboard-button {
  width: 100%;
  margin-top: 12px;
  justify-content: space-between;
}
.scoreboard-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  margin: 18px 0 10px;
}
.scoreboard-tabs button {
  flex: 1;
  padding: 12px 8px;
  color: var(--muted);
  font: 11px monospace;
  border-bottom: 2px solid transparent;
}
.scoreboard-tabs button.active {
  color: var(--coral);
  border-color: var(--coral);
}
.scoreboard-list {
  display: grid;
  gap: 7px;
}
.scoreboard-row {
  display: grid;
  grid-template-columns: 24px 34px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 12px 9px;
  text-align: left;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
}
.scoreboard-row:hover {
  border-color: var(--coral);
  transform: translateY(-1px);
}
.scoreboard-rank {
  font: 12px monospace;
  color: var(--muted);
}
.scoreboard-avatar {
  font-size: 24px;
  text-align: center;
}
.scoreboard-player {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scoreboard-row b {
  font: 14px monospace;
}
.scoreboard-empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 10px;
  font: 11px monospace;
}
.leaderboard-profile {
  padding: 0 20px 22px;
}
.profile-score {
  text-align: center;
  border-block: 1px solid var(--line);
  padding: 16px;
  margin-bottom: 14px;
}
.profile-score strong {
  display: block;
  font-size: 38px;
}
.profile-score small,
.profile-stat-grid small {
  display: block;
  color: var(--muted);
  font: 10px monospace;
  margin-top: 4px;
}
.profile-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}
.profile-stat-grid span {
  border: 1px solid var(--line);
  padding: 11px;
}
.profile-stat-grid b {
  font-size: 20px;
}
html[data-theme="dark"] .scoreboard-row {
  background: #242823;
  border-color: #3b4239;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .scoreboard-row {
    background: #242823;
    border-color: #3b4239;
  }
}

/* Keep the results actions together and let Play Again follow the active theme. */
#resultsScreen > .primary,
#resultsScreen > .secondary {
  display: inline-flex;
  width: calc(33.333% - 6px);
  justify-content: center;
  padding: 0 8px;
  font-size: 12px;
  vertical-align: top;
  margin-top: 20px;
}
#resultsScreen > #stopRushResults[hidden] {
  display: none;
}
#resultsScreen:not(:has(#stopRushResults:not([hidden]))) > .primary,
#resultsScreen:not(:has(#stopRushResults:not([hidden]))) > .secondary {
  width: calc(50% - 5px);
}
#resultsScreen > #again {
  background: var(--coral);
  color: #1d1d1b;
  border-color: var(--coral);
}
html[data-theme="dark"] #resultsScreen > #again {
  background: var(--lime);
  color: #1d1d1b;
  border-color: var(--lime);
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #resultsScreen > #again {
    background: var(--lime);
    color: #1d1d1b;
    border-color: var(--lime);
  }
}
/* Achievement notifications stay readable in either theme and out of the board. */
#toast {
  width: min(420px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 13px 20px;
  text-align: center;
  line-height: 1.35;
  border: 1px solid var(--toast-border, #4b4b46);
  border-radius: 4px;
  background: var(--toast-bg, #282825);
  color: var(--toast-fg, #fff);
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 0.25s,
    transform 0.25s;
}
#toast.show {
  transform: translate(-50%, 0);
}
#toast.toast-duplicate {
  border: 2px solid #2c1c37;
  background: #f6c85f;
  color: #2c1c37;
  font-weight: 900;
}
#toast.toast-wrong {
  border: 2px solid #fff;
  background: #dd2857;
  color: #fff;
  font-size: 1rem;
  font-weight: 950;
  box-shadow: 0 4px 0 #7b1737;
  animation: wrong-toast-shake .42s ease-in-out;
}
@keyframes wrong-toast-shake {
  0%, 100% { transform: translate(-50%, 0); }
  25% { transform: translate(calc(-50% - 7px), 0) rotate(-1deg); }
  75% { transform: translate(calc(-50% + 7px), 0) rotate(1deg); }
}
body:has(#gameScreen.active) #toast {
  top: 10px;
  bottom: auto;
}
html[data-theme="dark"] #toast {
  --toast-bg: #f3f1ea;
  --toast-fg: #1b1d1a;
  --toast-border: #aaa99f;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) #toast {
    --toast-bg: #f3f1ea;
    --toast-fg: #1b1d1a;
    --toast-border: #aaa99f;
  }
}
.analytics-consent {
  position: fixed;
  z-index: 1200;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 36px));
  max-width: calc(100vw - 36px);
  margin: 0;
  padding: 22px;
  border: 2px solid #2c1c37;
  border-radius: 8px;
  background: linear-gradient(180deg, #fffdf7, #fff0d6);
  color: #2c1c37;
  box-shadow: 0 8px 0 #2c1c37, 0 24px 70px #0009;
  transform: translate(-50%, -50%);
  text-align: left;
}
.analytics-consent::backdrop {
  background: #171121cc;
  backdrop-filter: blur(3px);
}
.analytics-consent[open] {
  display: grid;
  gap: 14px;
}
.analytics-consent strong {
  font-size: 20px;
  line-height: 1.1;
}
.analytics-consent p {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
}
.analytics-consent div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}
.analytics-consent button {
  justify-content: center;
  white-space: normal;
}
.analytics-preferences {
  width: 100%;
  justify-content: center;
  margin: 10px 0 0;
}
html[data-theme="dark"] .analytics-consent {
  border-color: #f6c85f;
  background: linear-gradient(180deg, #2b2235, #1c1723);
  color: #fff9f0;
  box-shadow: 0 7px 0 #f6c85f, 0 18px 50px #0009;
}
@media (max-width: 540px) {
  .analytics-consent { padding: 18px; }
  .analytics-consent div { grid-template-columns: 1fr; }
}
