:root {
  color-scheme: light;
  --ink: #17191f;
  --muted: #74757a;
  --canvas: #f1eee8;
  --paper: #fbfaf7;
  --line: #cbc6bd;
  --primary: #24324a;
  --accent: #d94d3f;
  --gold: #b48418;
  --track: #d8d3ca;
  --placeholder: #9a9790;
  --subtle-line: #ddd8cf;
  --button-bg: #24324a;
  --button-fg: #ffffff;
  --button-hover: #33496f;
  --error: #bd3f35;
  --success: #2f527f;
  --particle-color: #44516a;
}

:root[data-theme="dark"] {
  --ink: #f2efe8;
  --muted: #aaa8a3;
  --canvas: #11151d;
  --paper: #171c26;
  --line: #353b48;
  --primary: #aebddd;
  --accent: #ff7468;
  --gold: #e7bd5c;
  --track: #343a47;
  --placeholder: #777c87;
  --subtle-line: #303642;
  --button-bg: #d8dfed;
  --button-fg: #151922;
  --button-hover: #ffffff;
  --error: #ff7468;
  --success: #9abbe8;
  --particle-color: #8fa3cc;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}

#particle-canvas {
  position: fixed;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; }
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.shell {
  position: relative;
  z-index: 1;
  width: min(100% - 36px, 760px);
  margin: 0 auto;
}

.topbar {
  position: relative;
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand {
  display: flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark,
.topbar-note,
.intro,
.card-topline,
.sidebar,
footer {
  display: none;
}

.brand-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(27px, 5vw, 38px);
  font-weight: 700;
  letter-spacing: -.045em;
  line-height: 1;
  text-align: center;
}

.brand-name small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font: 800 9px/1 Arial, sans-serif;
  letter-spacing: .28em;
}

.theme-toggle {
  position: absolute;
  top: 44px;
  right: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: color-mix(in srgb, var(--canvas) 84%, transparent);
  color: var(--ink);
  font-size: 18px;
  backdrop-filter: blur(8px);
}

.theme-toggle:hover { border-color: var(--muted); }

main,
.layout,
.game-card {
  width: 100%;
}

.layout { display: block; }

.game-card {
  min-height: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.stats {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 38px;
  padding: 0 0 18px;
}

body.game-active:not(.game-ended) .stats { display: flex; }

.stat {
  min-width: 82px;
  padding: 0;
  border: 0;
  text-align: center;
}

.stat:nth-child(3) { display: none; }

.stat-label,
.micro-heading,
.input-label,
.leaderboard-subhead,
.leaderboard-foot,
.round-footer,
.small-note {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.stat-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
}

.stat strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 29px;
  line-height: 1;
}

.stat strong small { display: none; }
.stat .urgent { color: var(--accent); }

.timer-track {
  display: none;
  width: min(100%, 520px);
  height: 2px;
  margin: 0 auto;
  overflow: hidden;
  background: var(--track);
}

body.game-active:not(.game-ended) .timer-track { display: block; }
.timer-track div {
  width: 100%;
  height: 100%;
  background: var(--primary);
  transition: width .1s linear;
}
.timer-track div.urgent-fill { background: var(--accent); }

.start-panel {
  width: min(100%, 500px);
  margin: 16vh auto 0;
  padding: 0;
}

.start-panel > .micro-heading,
.start-panel > p,
.rules-row,
.start-panel .input-label {
  display: none;
}

.start-actions,
.word-entry {
  display: flex;
  gap: 10px;
}

.start-panel > .name-feedback {
  min-height: 18px;
  display: block;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.start-panel > .name-feedback.error { color: var(--error); }

input {
  min-width: 0;
  height: 58px;
  flex: 1;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
  scroll-margin-block: 25vh;
}

input::placeholder { color: var(--placeholder); }
input:focus { border-color: var(--accent); }
input[aria-invalid="true"] {
  border-color: var(--error);
}

input.wrong-word {
  animation: wrong-word-shake .32s ease-in-out;
}

#player-name[aria-invalid="true"] {
  animation: wrong-word-shake .32s ease-in-out;
}

@keyframes wrong-word-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

@media (prefers-reduced-motion: reduce) {
  input.wrong-word,
  #player-name[aria-invalid="true"] {
    animation-duration: .01ms;
  }
}

.primary-button {
  min-width: 124px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 18px;
  border: 0;
  border-radius: 0;
  background: var(--button-bg);
  color: var(--button-fg);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .12em;
}

.primary-button:hover { background: var(--button-hover); }
.primary-button:disabled { cursor: wait; opacity: .58; }
.primary-button span { font-size: 18px; }

.play-panel {
  width: 100%;
  padding: clamp(42px, 8vh, 82px) 0 0;
  text-align: center;
}

.round-head,
.word-instruction,
.play-panel .input-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.letter-display {
  --letter-size: clamp(82px, 15vw, 144px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(10px, 2vw, 22px);
  width: 100%;
  padding: 0;
}

.letter-tile {
  display: block;
  width: auto;
  height: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: var(--letter-size);
  font-weight: 700;
  line-height: .78;
}

.letter-tile:last-child {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}

.letter-gap {
  display: block;
  width: clamp(34px, 8vw, 78px);
  flex: 0 0 auto;
}

.minimum-cue {
  width: fit-content;
  margin: clamp(24px, 4vh, 36px) auto 0;
  padding: 10px 14px 9px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 76%, transparent);
  color: var(--ink);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .13em;
  box-shadow: 0 3px 14px color-mix(in srgb, var(--ink) 7%, transparent);
}

.minimum-cue strong {
  color: var(--accent);
  font-size: 15px;
}

#word-form {
  width: min(100%, 560px);
  margin: clamp(30px, 5vh, 48px) auto 0;
}

.word-entry input {
  height: 62px;
  padding: 0 4px;
  font-size: 24px;
  text-align: center;
}

.word-entry .primary-button {
  min-width: 72px;
  width: 72px;
  padding: 0;
  justify-content: center;
  overflow: hidden;
}

.word-entry .primary-button span {
  color: var(--button-fg);
  font-size: 23px;
}

.below-entry {
  width: min(100%, 560px);
  min-height: 52px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.feedback {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.feedback.error { color: var(--error); }
.feedback.success { color: var(--success); font-weight: 700; }

.text-button {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .1em;
  white-space: nowrap;
}

.text-button:hover { text-decoration: underline; }
.text-button span { font-size: 15px; }
.round-footer { display: none; }

.end-panel {
  width: min(100%, 520px);
  margin: 10vh auto 0;
  padding: 0;
  text-align: center;
}

.end-panel .micro-heading { color: var(--muted); }
.end-panel h2 {
  margin: 14px 0 10px;
  font: 700 clamp(42px, 8vw, 64px)/.95 Georgia, "Times New Roman", serif;
  letter-spacing: -.055em;
}
.end-panel p { color: var(--muted); }
.accent-dot { color: var(--accent); }

.final-score {
  margin: 34px auto;
  padding: 0;
  border: 0;
  background: transparent;
}
.final-score span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
}
.final-score strong {
  display: block;
  margin-top: 7px;
  color: var(--primary);
  font: 700 64px/1 Georgia, "Times New Roman", serif;
}
.end-panel .primary-button { margin: 0 auto; }

body.game-ended .layout { padding-bottom: 80px; }
body.game-ended .sidebar {
  width: min(100%, 520px);
  margin: 80px auto 0;
  display: block;
}
body.game-ended .tip-card { display: none; }

body:not(.game-active) .sidebar {
  width: min(100%, 500px);
  margin: 56px auto 80px;
  display: flex;
  flex-direction: column;
  gap: 38px;
}

body:not(.game-active) .tip-card { order: -1; }

.tip-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  padding: 24px 0 0;
  border-top: 1px solid var(--line);
}

.tip-icon {
  color: var(--accent);
  font-size: 15px;
  line-height: 1;
}

.tip-card .section-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .16em;
}

.tip-card > div { min-width: 0; }

.tip-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.leaderboard-card {
  padding-top: 28px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.aside-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.aside-heading .section-label,
.trophy { display: none; }
.aside-heading h2 {
  margin: 0;
  font: 700 28px Georgia, "Times New Roman", serif;
}
.leaderboard-subhead {
  display: flex;
  justify-content: space-between;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.leaderboard-list { min-height: 80px; margin: 0; padding: 0; list-style: none; }
.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid var(--subtle-line);
  font-size: 13px;
}
.leaderboard-row.leader { color: var(--primary); }
.leaderboard-player { display: flex; gap: 16px; }
.rank { color: var(--muted); font-size: 10px; font-weight: 800; }
.leaderboard-empty { padding: 24px 0; color: var(--muted); font-size: 13px; }
.leaderboard-foot { margin-top: 18px; color: var(--muted); text-align: center; }

@media (max-width: 610px) {
  .shell { width: min(100% - 32px, 760px); }
  .topbar { min-height: 100px; }
  .theme-toggle { top: 28px; }
  .start-panel { margin-top: 18vh; }
  .start-actions { flex-direction: column; gap: 14px; }
  .start-actions input { width: 100%; flex: none; text-align: center; }
  .start-actions .primary-button { width: 100%; }
  body:not(.game-active) .sidebar { margin-top: 44px; }
  .stats { gap: 20px; padding-bottom: 14px; }
  .play-panel { padding-top: clamp(38px, 7vh, 64px); }
  .letter-display { gap: 10px; }
  #word-form { margin-top: clamp(46px, 8vh, 68px); }
  .word-entry { gap: 8px; }
  .below-entry { flex-direction: column; gap: 0; padding-top: 8px; }
  .text-button { align-self: center; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .topbar { min-height: 64px; }
  .theme-toggle { top: 10px; }
  .brand-name { font-size: 25px; }
  .brand-name small { display: none; }
  .play-panel { padding-top: 18px; }
  #word-form { margin-top: 30px; }
}

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