:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --text: #1d1b2e;
  --muted: #8f8c9e;
  --faint: #c9c7d3;
  --line: #e6e4ee;
  --accent: #5b4fd6;
  --accent-soft: #ecebfd;
  --on-accent: #ffffff;
  --key-bg: #eceaf2;
  --key-text: #2a2840;
  --overlay: rgba(250, 250, 247, 0.7);
  --shadow: 0 10px 40px rgba(29, 27, 46, 0.14);
  --toast-bg: #1d1b2e;
  --toast-text: #ffffff;
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131219;
    --surface: #1c1b25;
    --text: #f2f1f7;
    --muted: #8d8a9c;
    --faint: #4a4859;
    --line: #2c2a38;
    --accent: #a59cf5;
    --accent-soft: #2a2650;
    --on-accent: #16142a;
    --key-bg: #262433;
    --key-text: #eceaf5;
    --overlay: rgba(19, 18, 25, 0.75);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --toast-bg: #f2f1f7;
    --toast-text: #131219;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
button { font-family: inherit; }

/* ---------- Header ---------- */
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 64px;
  padding: 0 14px;
  flex-shrink: 0;
}
.topbar-side { display: flex; gap: 2px; }
.topbar-side.right { justify-content: flex-end; }
.brand { text-align: center; line-height: 1; }
.brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.02em;
}
.brand .dot { color: var(--accent); }
.subtitle {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.icon-btn {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px;
  cursor: pointer;
  border-radius: 999px;
  display: grid;
  place-items: center;
  transition: background-color 150ms, color 150ms;
}
.icon-btn:hover { background: var(--key-bg); color: var(--text); }

/* ---------- Board ---------- */
.game {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  padding: 0 16px;
}
.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 460px;
}

/* Breadcrumb trail of past words */
.trail {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px 6px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 26px;
}
.trail .sep { color: var(--faint); font-weight: 700; }
.trail .crumb.current { color: var(--text); }
.trail .crumb.target {
  color: var(--accent);
  border: 1.5px dashed var(--accent);
  border-radius: 999px;
  padding: 1px 9px;
}
.trail .crumb.current.target { border-style: solid; }

/* The one big word */
.word {
  display: flex;
  gap: 0.14em;
  font-size: clamp(64px, 20vw, 108px);
  font-weight: 900;
  line-height: 1;
  margin-top: 26px;
}
.slot {
  position: relative;
  width: 0.8em;
  padding: 0 0 0.1em;
  background: none;
  border: 0;
  border-bottom: 5px solid var(--line);
  border-radius: 0;
  font: inherit;
  color: var(--text);
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  justify-content: center;
  transition: border-color 160ms, transform 200ms cubic-bezier(.2, 1.3, .4, 1);
}
.slot:disabled { cursor: default; color: var(--text); }
.slot:not(:disabled):hover { border-color: var(--faint); }
.slot .ch { display: inline-block; }
.slot .old {
  position: absolute;
  top: -0.42em;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.26em;
  font-weight: 800;
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.slot.selected { border-color: var(--accent); transform: translateY(-8px); }
.slot.selected:hover { border-color: var(--accent); }
.slot.selected .ch { color: var(--accent); }
.slot .ch.placeholder { opacity: 0.4; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.18; } }
.word.picking .slot:not(.selected) .ch { color: var(--muted); }

.word.won .slot { border-color: var(--accent); }
.word.won .ch { color: var(--accent); }
.word.lost .ch { color: var(--muted); }

.fall {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--faint);
  animation: fall 460ms ease-in forwards;
  pointer-events: none;
}
.ch.drop { animation: drop 460ms cubic-bezier(.2, 1.35, .4, 1); }
.ch.pop { animation: pop 160ms ease-out; }
.ch.bounce { animation: bounce 900ms; }
.word.shake { animation: shake 450ms; }

.hint {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  min-height: 20px;
  text-align: center;
}

/* Goal */
.goal {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.goal-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.goal-word {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  border: 2px dashed var(--accent);
  border-radius: 999px;
  padding: 4px 8px 4px 16px;
  transition: background-color 300ms, color 300ms;
}
.goal.reached .goal-word {
  background: var(--accent);
  color: var(--on-accent);
  border-style: solid;
}
.steps {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------- Keyboard ---------- */
.keyboard {
  padding: 0 8px 6px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  flex-shrink: 0;
  user-select: none;
}
.kb-row {
  display: flex;
  gap: 6px;
  margin-bottom: 7px;
  justify-content: center;
}
.kb-row .spacer { flex: 0.5; }
.key {
  flex: 1;
  height: 54px;
  border: 0;
  border-radius: 12px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 80ms, background-color 150ms;
}
.key:active { transform: scale(0.94); }
.key.wide { flex: 1.5; font-size: 13px; }
.key.enter { background: var(--accent); color: var(--on-accent); font-size: 12px; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  animation: toast-in 180ms ease-out;
  transition: opacity 300ms;
}
.toast.fade { opacity: 0; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative;
  background: var(--surface);
  color: var(--text);
  border-radius: 22px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 30px 26px 26px;
  animation: slide-in 220ms ease-out;
}
.close-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.modal-card h2 { margin: 0 0 6px; font-size: 26px; font-weight: 900; letter-spacing: -0.01em; }
.modal-card h3 {
  margin: 22px 0 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.modal-card p, .modal-card li { font-size: 16px; line-height: 1.5; }
.lede { font-size: 18px !important; font-weight: 700; margin-top: 0; }
.muted { color: var(--muted); font-size: 14px !important; }
.how { padding-left: 22px; margin: 8px 0; }
.how li::marker { color: var(--accent); font-weight: 900; }

.ex-ladder, .ladder {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ex-ladder .sep, .ladder .arrow { color: var(--faint); font-weight: 700; }
.ex-word b { color: var(--accent); font-weight: 900; }
.ladder .lw:last-child { color: var(--accent); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
  gap: 6px;
}
.stat-num { font-size: 32px; font-weight: 900; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 700; }

.dist { display: grid; gap: 6px; }
.dist-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; }
.dist-bar {
  background: var(--key-bg);
  color: var(--key-text);
  font-weight: 800;
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 999px;
  text-align: right;
  min-width: 28px;
}
.dist-bar.highlight { background: var(--accent); color: var(--on-accent); }

.footer-row { display: flex; align-items: center; gap: 14px; margin-top: 24px; }
.countdown { flex: 1; text-align: center; border-right: 1px solid var(--line); padding-right: 14px; }
.countdown .label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.countdown .time { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.btn {
  flex: 1;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 900;
  font-size: 16px;
  padding: 14px 18px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 80ms;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--key-bg); color: var(--key-text); }
.btn-col { display: grid; gap: 10px; margin-top: 18px; }

/* ---------- Animations ---------- */
@keyframes pop {
  from { transform: scale(0.6); opacity: 0.3; }
  60% { transform: scale(1.12); }
}
@keyframes drop {
  from { transform: translateY(-0.7em); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes fall {
  to { transform: translateY(0.9em) rotate(14deg); opacity: 0; }
}
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-0.28em); }
  60% { transform: translateY(0.04em); }
  80% { transform: translateY(-0.08em); }
}
@keyframes slide-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toast-in {
  from { transform: translateY(-8px); opacity: 0; }
}

@media (max-height: 700px) {
  .board { gap: 12px; }
  .word { font-size: clamp(56px, 16vw, 84px); margin-top: 20px; }
  .key { height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .ch.drop, .ch.pop, .ch.bounce, .fall, .word.shake, .modal-card, .toast, .slot .ch.placeholder { animation: none !important; }
}

/* ---------- Color themes (Reword+) ---------- */
[data-accent="purple"] { --accent: #5b4fd6; --accent-soft: #ecebfd; }
[data-accent="teal"]   { --accent: #0f7f64; --accent-soft: #e1f5ee; }
[data-accent="coral"]  { --accent: #c94d26; --accent-soft: #faece7; }
[data-accent="blue"]   { --accent: #2361c4; --accent-soft: #e6f1fb; }
[data-accent="pink"]   { --accent: #be3a6d; --accent-soft: #fbeaf0; }
[data-accent="amber"]  { --accent: #a8630a; --accent-soft: #faeeda; }
@media (prefers-color-scheme: dark) {
  [data-accent="purple"] { --accent: #a59cf5; --accent-soft: #2a2650; }
  [data-accent="teal"]   { --accent: #5dcaa5; --accent-soft: #0c3a2f; }
  [data-accent="coral"]  { --accent: #f0997b; --accent-soft: #4a1f10; }
  [data-accent="blue"]   { --accent: #85b7eb; --accent-soft: #0c2b4d; }
  [data-accent="pink"]   { --accent: #ed93b1; --accent-soft: #4b1528; }
  [data-accent="amber"]  { --accent: #efb04a; --accent-soft: #412402; }
}

/* ---------- Extra game UI ---------- */
.loading { color: var(--muted); font-weight: 700; text-align: center; line-height: 1.6; }

.hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 14px;
  cursor: pointer;
}
.hint-btn[hidden] { display: none; }
.hint-btn.locked::after {
  content: "+";
  font-weight: 900;
  margin-left: -2px;
}

.icon-btn { position: relative; }
.icon-btn.signed-in { color: var(--text); }
.icon-btn.plus::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- Modal extras ---------- */
.center { text-align: center; }
.fine { font-size: 13px !important; color: var(--muted); }
.fine a, .modal-card a { color: var(--accent); font-weight: 700; }
.countdown.solo { border-right: 0; padding-right: 0; }
.dist-track { min-width: 0; }
.dist-bar { width: 8%; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.busy { opacity: 0.6; }
.btn .save {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
}
.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  padding: 6px;
}
.link-btn:hover { color: var(--text); }

.callout {
  background: var(--accent-soft);
  border-radius: 16px;
  padding: 14px 16px;
  margin: 12px 0 4px;
}
.callout p { margin: 0 0 10px; }
.callout .btn { width: 100%; }

.plus-mark {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.plus-mark span { color: var(--accent); }
.perks { list-style: none; padding: 0; margin: 14px 0 6px; display: grid; gap: 8px; }
.perks li { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.perks li::before {
  content: "";
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}

.plan-card {
  background: var(--key-bg);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 15px;
}

.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 16px 0 6px; }
.form input {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 13px 16px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.form input:focus { border-color: var(--accent); }
#code-input { letter-spacing: 0.3em; text-align: center; font-size: 22px; }

/* Theme picker */
.themes { display: flex; gap: 10px; flex-wrap: wrap; }
.theme {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 3px;
  background: none;
  cursor: pointer;
}
.theme.on { border-color: var(--text); }
.theme .sw { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--accent); }
.theme .lock {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 1px var(--line);
}

/* Archive calendar */
.archive-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.day {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
}
.day:hover { border-color: var(--accent); }
.day.won { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.day.lost { border-color: var(--muted); color: var(--muted); }
.day.playing { border-color: var(--accent); color: var(--accent); }
.day.locked { color: var(--muted); }
.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 12px;
}
.legend-row .day { width: 14px; height: 14px; display: inline-block; margin-left: 8px; cursor: default; }
.legend-row .day:first-child { margin-left: 0; }

/* Make your own */
.make-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; }
.make-row input { text-align: center; font-weight: 900; font-size: 22px; letter-spacing: 4px; text-transform: uppercase; }
.make-row .sep { color: var(--muted); font-weight: 900; }
.make-msg { margin: 0; font-size: 14px; font-weight: 700; min-height: 1.4em; }
.make-msg.good { color: var(--accent); }
.make-msg.bad { color: #d64545; }

/* Domain shown on screen so classroom recordings and screenshots say where to play. */
.site-mark {
  flex-shrink: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  padding: 2px 0 calc(8px + env(safe-area-inset-bottom));
  letter-spacing: 0.2px;
}
.site-mark b { color: var(--accent); font-weight: 900; }
.modal .site-mark { padding: 14px 0 0; }
@media (min-width: 900px) { body > .site-mark { font-size: 17px; padding-bottom: 14px; } }
