/* Spellotic Daily — dark by default. There is no theme switcher: the game is
   played once a day, often at night, and the design is built for the dark
   ground. Light-preferring users get the dark theme too, deliberately. */

:root {
  --bg: #0b0e14;
  --bg-2: #10141d;
  --surface: #161c28;
  --surface-2: #1d2534;
  --line: #27303f;
  --ink: #e9eef7;
  --muted: #8a97ad;
  --faint: #5d6779;
  --accent: #7c6cff;
  --correct: #34d399;
  --present: #fbbf24;
  --absent: #414c5e;
  --danger: #fb7185;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-word: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  /* minmax(0,1fr) rather than an auto column — an auto column sizes to the
     shell's min-content, which overflows a narrow phone viewport. */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
  justify-items: center;
  gap: 1.5rem;
  padding: 1.5rem 1rem 3rem;
  font-family: var(--font);
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(124, 108, 255, 0.2), transparent 65%),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

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

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------ the card */

.shell {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 1.1rem 1.4rem 1.6rem;
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.85);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

header h1 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

header h1 span {
  color: var(--ink);
}

/* One pip per word — position in the run, without a "Word 3 of 5" line. */
#puzzle-pips {
  display: flex;
  gap: 0.35rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

#puzzle-pips li {
  width: 1.35rem;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  transition: background 0.25s;
}

#puzzle-pips li.solved {
  background: var(--correct);
}

#puzzle-pips li.failed {
  background: var(--absent);
}

#puzzle-pips li.current {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

#puzzle-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}

#help-btn {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

#help-btn:hover {
  color: var(--ink);
  border-color: var(--accent);
}

main {
  text-align: center;
}

#loading-message {
  padding: 3rem 0;
  color: var(--muted);
}

/* ------------------------------------------------------- listen + clue */

.listen {
  padding: 1.6rem 0 0;
}

#replay-audio-btn {
  position: relative;
  width: 5.75rem;
  height: 5.75rem;
  border-radius: 50%;
  border: 1px solid rgba(124, 108, 255, 0.5);
  background: radial-gradient(circle at 35% 30%, #8f80ff, #5b4bd6 70%);
  color: #fff;
  font-size: 1.9rem;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 14px 34px -12px rgba(124, 108, 255, 0.8);
  transition: transform 0.15s;
}

#replay-audio-btn:active {
  transform: scale(0.95);
}

/* The button had an infinitely repeating ring to read as "press me". It was
   removed: the "tap to hear it again" label below already says that, and a
   pulse that never stops sits in the corner of the eye for the whole round,
   competing with the word the player is trying to spell. */

.listen-hint {
  display: block;
  margin-top: 0.65rem;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

#definition {
  margin: 1.25rem auto 0;
  max-width: 21rem;
  font-size: 0.95rem;
  line-height: 1.5;
  font-style: italic;
  color: var(--muted);
  min-height: 2.8em;
}

/* --------------------------------------------------------- guess input */

#guess-form {
  margin: 0;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0.5rem;
  transition: border-color 0.2s;
}

.input-row:focus-within {
  border-bottom-color: var(--accent);
}

#guess-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--font-word);
  font-size: 1.85rem;
  letter-spacing: 0.04em;
  padding: 0.25rem 0.1rem;
}

#guess-input::placeholder {
  color: var(--faint);
  opacity: 0.45;
  font-size: 1.35rem;
}

.enter-hint {
  font-size: 0.68rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.25rem 0.5rem;
  white-space: nowrap;
  transition: opacity 0.16s;
}

/* While the call is up the guess reads as committed — but it is *styled*
   locked, not `readonly`: readonly collapses the phone keyboard. The caret
   goes because the input still holds focus and a blinking caret would invite
   typing. Kept after :focus-within so it wins on equal specificity. */
.input-row.committed {
  border-bottom-color: var(--line);
}

.input-row.committed #guess-input {
  color: var(--muted);
  caret-color: transparent;
}

.input-row.committed .enter-hint {
  opacity: 0;
}

/* ------------------------------------------------------------- the call
   The row under the input is empty while typing and becomes the prompt on
   Enter — an in-place morph, not an overlay. It is centred under the guess so
   the question reads as being asked of the word above it. */

.meta-row {
  margin-top: 0.75rem;
  min-height: 2rem;
}

#call-prompt:not(:empty) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  padding-top: 0.35rem;
  animation: call-in 0.14s ease-out;
}

@keyframes call-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.call-question {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.call-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.call-actions button {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  /* Comfortably tappable: this is the one control a phone player hits five
     times a game, twice per word. */
  min-height: 2.6rem;
  padding: 0 1.15rem;
  cursor: pointer;
  transition: border-color 0.16s, color 0.16s, background 0.16s;
}

.call-actions button:hover,
.call-actions button:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

/* Yes carries the stake, and it is the only number on the play screen — it is
   what shows a player that the call gets cheaper after a wrong go. */
.call-actions [data-call="yes"] {
  color: var(--ink);
}

.call-actions [data-call="yes"] b {
  margin-left: 0.4rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.call-actions [data-call="back"] {
  color: var(--faint);
}

/* ----------------------------------------------------- letter feedback */

#diff-feedback {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem;
  padding: 0;
  margin: 1.35rem 0 0;
  min-height: 2.4rem;
}

#diff-feedback li {
  width: 2.15rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 800;
  font-size: 1rem;
  text-transform: uppercase;
  color: #08111c;
  animation: pop 0.22s backwards;
}

@keyframes pop {
  from {
    transform: translateY(6px) scale(0.85);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.letter-correct {
  background: var(--correct);
}

.letter-present {
  background: var(--present);
}

.letter-absent {
  background: var(--absent);
  color: var(--ink);
}

#word-result-message {
  min-height: 1.4em;
  margin: 0.9rem 0 0;
  font-size: 0.9rem;
  font-weight: 600;
}

#word-result-message.solved {
  color: var(--correct);
}

#word-result-message.failed {
  color: var(--danger);
}

#word-result-message.retry {
  color: var(--muted);
}

/* -------------------------------------------------------------- modals */

#tutorial-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  padding: 1rem;
}

.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 11, 0.74);
  backdrop-filter: blur(7px);
  animation: fade-in 0.18s;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(18px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-content {
  position: relative;
  margin: auto;
  width: min(26.5rem, 100%);
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1.4rem 1.25rem 1.1rem;
  box-shadow: 0 36px 80px -28px rgba(0, 0, 0, 0.9);
  animation: sheet-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.modal-content:focus {
  outline: none;
}

.kicker {
  margin: 0;
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 700;
}

kbd {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05rem 0.3rem;
  font-family: inherit;
  font-size: 0.62rem;
}

/* The first-run splash. Deliberately one screen and three sentences: the
   game takes 90 seconds, so the tutorial gets seconds. See DESIGN.md
   "Onboarding" for what was rejected and why. */
.modal-content {
  width: min(24rem, 100%);
  padding: 2rem 1.6rem 1.4rem;
  text-align: center;
}

.modal-content h2 {
  margin: 0.6rem 0 1.6rem;
  font-family: var(--font-word);
  font-size: clamp(1.7rem, 8vw, 2.2rem);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

/* Headline and button stay centred; the rules read as left-aligned prose,
   which is what stops three sentences looking like a slogan wall. */
.tutorial-rules {
  display: grid;
  gap: 1.15rem;
  text-align: left;
  margin-bottom: 1.7rem;
}

.tutorial-rules p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--muted);
}

.tutorial-rules strong {
  color: var(--ink);
  font-weight: 700;
}

.tutorial-rules b {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tutorial-foot {
  margin: 0.85rem 0 0;
  font-size: 0.7rem;
  color: var(--faint);
}

.modal-content button {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* ------------------------------------------------------------- results */

/* Score is shown large and bare — no denominator, matching the share text.
   A fraction reads like a school spelling test; a bare number reads like
   something you beat. The grid below supplies the scale. */
#results-total {
  margin: 1.6rem 0 0;
  font-size: 4.25rem;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

#results-label {
  margin: 0.5rem 0 0;
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 700;
}

/* The same two rows the share text emits, as real tiles. */
#results-grid {
  max-width: 15rem;
  margin: 1.6rem auto 0;
  display: grid;
  gap: 0.5rem;
}

.results-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  justify-items: center;
  align-items: center;
}

.results-row .sq {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
}

.results-row .ci {
  width: 66%;
  aspect-ratio: 1;
  border-radius: 50%;
}

/* One legend, two rows: green best, yellow middle, blue neither, red gone. */
.tone-1 { background: var(--correct); }
.tone-2 { background: var(--present); }
.tone-3 { background: #4d80ff; }
.tone-x { background: var(--danger); }

#results-breakdown {
  list-style: none;
  text-align: left;
  padding: 0;
  margin: 1.5rem 0 0;
  display: grid;
  gap: 0.3rem;
}

#results-breakdown li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.85rem;
}

#results-breakdown .pts {
  width: 1.6rem;
  flex: none;
  text-align: right;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#results-breakdown li.failed .word,
#results-breakdown li.failed .pts {
  color: var(--faint);
}

#results-breakdown .mark {
  width: 1rem;
  flex: none;
  text-align: center;
}

#results-breakdown li.solved .mark {
  color: var(--correct);
}

#results-breakdown li.failed .mark {
  color: var(--danger);
}

#results-breakdown .word {
  font-family: var(--font-word);
  font-size: 1rem;
}

#results-breakdown .detail {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

#results-countdown {
  margin: 1.25rem 0 0.85rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#share-btn {
  width: 100%;
  padding: 0.8rem 1.5rem;
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

#share-status {
  white-space: pre-line;
  font-size: 0.8rem;
  color: var(--muted);
}

.cta {
  color: var(--faint);
  text-decoration: none;
  font-size: 0.8rem;
}

.cta:hover {
  color: var(--ink);
}

/* Low-water warning — for the curator, so it sits below the game and stays
   quiet enough that a player reads past it. See DESIGN.md "Out of content". */
#curator-warning {
  color: var(--faint);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 0;
}

/* -------------------------------------------------------------- mobile */

@media (max-width: 560px) {
  body {
    padding: 0.75rem 0.6rem 2rem;
    gap: 1rem;
  }

  .shell {
    padding: 0.9rem 1rem 1.25rem;
    border-radius: 20px;
  }

  .listen {
    padding-top: 1.1rem;
  }

  #replay-audio-btn {
    width: 4.75rem;
    height: 4.75rem;
    font-size: 1.55rem;
  }

  #definition {
    margin-top: 1rem;
    font-size: 0.9rem;
  }

  #guess-input {
    font-size: 1.6rem;
  }

  .call-actions {
    gap: 0.4rem;
  }

  .call-actions button {
    padding: 0 0.95rem;
  }

  .modal-content {
    padding: 1.6rem 1.2rem 1.2rem;
  }

  #results-total {
    font-size: 3.5rem;
  }

  #results-grid {
    max-width: 13.5rem;
  }

  #results-breakdown .detail {
    font-size: 0.68rem;
  }
}

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