:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--charcoal);
  background: #f4f6ef;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --baltic: #336699;
  --sky: #86bbd8;
  --selected-blue: #dcebf4;
  --charcoal: #2f4858;
  --light-green: #9ee493;
  --mint: #daf7dc;
  --muted: var(--charcoal);
  --border: #e1e7df;
  --control-border: #718493;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 0%, #e7eee1 0, transparent 42%), #f4f6ef;
}

button, input { font: inherit; }
button, summary { touch-action: manipulation; }
button { cursor: pointer; }

.game {
  display: grid;
  gap: 12px;
  width: min(100%, 860px);
  margin: 0 auto;
}

.game > *, .game-card > *, .puzzle-heading > *, .found-heading > * {
  min-width: 0;
}

.page-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 12px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); letter-spacing: -0.06em; line-height: 1.15; }
h2 { font-size: 1.05rem; letter-spacing: -0.025em; }

.rules { color: var(--muted); font-size: 0.875rem; }
.rules summary {
  min-height: 44px;
  padding: 12px 4px;
  color: var(--baltic);
  font-weight: 600;
  cursor: pointer;
}
.rules[open] { grid-column: 1 / -1; }
.intro { max-width: 65ch; margin-bottom: 10px; line-height: 1.5; }

.game-card, .found-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(35 58 45 / 5%);
}

.game-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  align-content: start;
}

.puzzle-heading, .found-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
}

.eyebrow { color: var(--baltic); font-size: 0.8rem; font-weight: 700; }
.puzzle-badges { display: contents; }
.possible-count {
  padding: 5px 8px;
  border-radius: 999px;
  background: #edf5ee;
  color: var(--charcoal);
  font-size: 0.75rem;
  font-weight: 700;
}
.minimum { flex-basis: 100%; color: var(--muted); font-size: 0.75rem; }

.wheel-panel { text-align: center; }
.wheel {
  position: relative;
  width: min(100%, 260px);
  /* Short phones get a smaller wheel, without sacrificing tile hit areas. */
  width: min(100%, clamp(220px, 36svh, 300px));
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle, #fbfcf9 0 49%, #edf4f7 50% 100%);
}
.letter-ring { position: absolute; inset: 0; }
.letter-button, .centre-letter {
  position: absolute;
  top: var(--top);
  left: var(--left);
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: 50%;
  background: #fff;
  color: var(--charcoal);
  font-size: 1.125rem;
  font-weight: 700;
  box-shadow: 0 3px 9px rgb(35 58 45 / 7%);
  transform: translate(-50%, -50%);
}
.centre-letter {
  top: 50%;
  left: 50%;
  width: 72px;
  height: 72px;
  font-size: 1.875rem;
  font-weight: 800;
}
.letter-button.is-used, .centre-letter.is-used {
  border-color: var(--baltic);
  background: var(--baltic);
  color: #fff;
}
.wheel-hint { margin-top: 3px; color: var(--muted); font-size: 0.75rem; }

#word-form { display: grid; gap: 6px; align-content: center; scroll-margin-block: 12px; }
.entry-row { display: flex; gap: 8px; }
#word-input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  background: #fff;
  color: var(--charcoal);
  /* At least 16px avoids automatic input zoom on iOS. */
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
#word-input::placeholder { color: var(--charcoal); font-weight: 400; letter-spacing: normal; }
.submit-button {
  flex: 0 0 auto;
  min-height: 46px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--baltic);
  color: #fff;
  font-weight: 700;
}
.action-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.edit-button {
  min-height: 44px;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: #fff;
  color: var(--charcoal);
  font-size: 0.875rem;
  font-weight: 600;
}
.message {
  min-height: 2.8em;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.message.is-error { color: #a43229; }
.message.is-success {
  color: var(--charcoal);
  background: var(--mint);
  border-radius: 8px;
  padding: 6px 8px;
  font-weight: 700;
}

.found-section { align-self: start; padding: 12px; }
.found-heading { margin-bottom: 10px; }
.found-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.word-count { color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.solution-button {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: #fff;
  color: var(--charcoal);
  font-size: 0.8125rem;
  font-weight: 600;
}
.found-words {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.word-slot {
  display: flex;
  min-width: 0;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 5px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f9f5;
  color: var(--charcoal);
  font-size: 0.8125rem;
  font-weight: 600;
}
.word-slot.is-found { background: var(--mint); border-color: var(--light-green); }
.word-answer { overflow-wrap: anywhere; text-transform: capitalize; }
.word-slot.is-nine-letter .word-answer { text-transform: uppercase; }
.word-slot.is-missed { border-color: #c98780; background: #fff1ef; color: #a43229; }
.game-footer { color: var(--muted); font-size: 0.75rem; line-height: 1.5; text-align: center; }
.game-footer a { color: var(--charcoal); }

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--charcoal);
  outline-offset: 3px;
}
button:disabled, input:disabled { opacity: 0.65; cursor: not-allowed; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (hover: hover) {
  .letter-button:not(:disabled):hover { border-color: var(--charcoal); box-shadow: 0 0 0 2px var(--charcoal); }
  .submit-button:not(:disabled):hover { background: var(--charcoal); }
  .edit-button:not(:disabled):hover { background: var(--selected-blue); }
  .solution-button:not(:disabled):hover { background: var(--selected-blue); }
}

/* Tablets and wide, short phone viewports: keep the entry beside the wheel. */
@media (min-width: 560px) and (max-width: 959px),
       (min-width: 560px) and (max-height: 540px) {
  .game-card { grid-template-columns: minmax(220px, 1fr) minmax(0, 1fr); gap: 12px 20px; }
  .puzzle-heading { grid-column: 1 / -1; }
  #word-form { align-self: center; }
  .wheel-hint { display: none; }
}

/* Desktop: answers sit alongside the play area rather than far below it. */
@media (min-width: 960px) and (min-height: 541px) {
  body { padding: 24px; }
  .game { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
  .page-header, .game-footer, .save-status { grid-column: 1 / -1; }
  .game-card, .found-section { padding: 18px; }
  .game-card { gap: 12px; align-self: start; }
  .wheel { width: 244px; }
  .letter-button { width: 52px; height: 52px; font-size: 1.25rem; }
  #word-form { width: min(100%, 340px); margin-inline: auto; gap: 8px; }
  #word-input { text-align: center; }
  .wheel-hint { margin-top: 6px; }
}

@media (max-height: 540px) and (min-width: 560px) {
  body { padding-top: max(4px, env(safe-area-inset-top)); }
  .game { gap: 6px; }
  .game-card { padding: 8px 12px; gap: 6px 16px; }
  .minimum { flex-basis: auto; }
  .wheel { width: min(100%, clamp(200px, 55svh, 240px)); }
  .letter-button { width: 44px; height: 44px; }
  .centre-letter { width: 64px; height: 64px; font-size: 1.75rem; }
}

/* A keyboard may leave too little height for both wheel and input. Let the
   document scroll normally; never clip content or lock it to a viewport height. */
@media (max-width: 559px) and (max-height: 620px) {
  .game { gap: 8px; }
  .game-card { gap: 6px; }
  .wheel-hint { display: none; }
}

.save-status { margin: 0; color: var(--muted); font-size: 0.75rem; line-height: 1.5; text-align: center; }
.save-status.is-error { color: #a43229; }

/* A durable result/new-day notice, separate from transient word feedback. */
.daily-status {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid var(--control-border);
  border-radius: 10px;
  background: #edf4f7;
  color: var(--charcoal);
  font-size: 0.875rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.daily-status h2 { margin-bottom: 4px; }
.daily-status p + p { margin-top: 8px; }
.daily-status .submit-button { margin-top: 12px; width: 100%; }

.statistics { grid-column: 1 / -1; font-size: 0.875rem; }
.statistics summary { cursor: pointer; min-height: 44px; padding: 12px; color: var(--baltic); font-weight: 600; }
.statistics-body { padding: 12px; background: #fff; border: 1px solid var(--border); border-radius: 12px; }
.statistics select { font: inherit; min-height: 44px; margin: 0 0 12px 8px; max-width: 100%; }
.stats-note { color: var(--muted); font-size: 0.75rem; line-height: 1.5; }
.statistics-body > p { margin-bottom: 10px; }
.stats-history { list-style: none; padding: 0; margin: 12px 0; max-height: 360px; overflow: auto; }
.stats-history li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.stats-history p { line-height: 1.5; }
.daily-progress { margin-bottom: 12px; }
#progress-label { font-size: 0.875rem; font-weight: 600; }
progress { display: block; width: 100%; height: 8px; margin: 7px 0; border: 0; border-radius: 8px; overflow: hidden; background: #edf4f7; accent-color: var(--baltic); }
progress::-webkit-progress-bar { background: #edf4f7; }
progress::-webkit-progress-value { background: var(--baltic); }
progress::-moz-progress-bar { background: var(--baltic); }
