/* Spelling & Phonics Game — matches Free Homeschool Games style */

:root {
  --sky-top: #7ec8ea;
  --sky-mid: #c7ecfa;
  --sky-bottom: #f3fbff;
  --navy: #16324f;
  --navy-soft: #2a4a6b;
  --ink: #1a2b3c;
  --paper: #fffdf6;
  --gold: #ffd24a;
  --orange: #ff8a3d;
  --purple: #6c63ff;
  --teal: #1faf9a;
  --correct: #2db86a;
  --correct-dark: #1d8a4b;
  --shadow: 0 8px 0 rgba(22, 50, 79, 0.12);
  --font: "Trebuchet MS", "Segoe UI", "Avenir Next", "Avenir", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--sky-bottom) 100%);
  background-attachment: fixed;
}

body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button, input, textarea { font-family: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 820px;
  margin: 0 auto;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.home-link { display: grid; place-items: center; text-decoration: none; }
.site-mark { width: 44px; height: 44px; border-radius: 14px; display: block; }
.site-name { margin: 0; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.02em; }
.site-name a { color: var(--navy-soft); text-decoration: none; }
.brand h1 { font-size: clamp(1.15rem, 3vw, 1.55rem); color: var(--navy); letter-spacing: -0.02em; line-height: 1.1; }
.tagline { font-size: 0.9rem; color: var(--navy-soft); font-weight: 700; }

.toggle {
  border: 3px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: var(--shadow);
  min-height: 44px;
}
.toggle[aria-pressed="true"] { background: #e8ffe8; }

.screen { flex: 1; display: flex; flex-direction: column; }
.screen[hidden] { display: none !important; }

.start-card, .end-card, .play-card {
  background: var(--paper);
  border: 3px solid var(--navy);
  border-radius: 28px;
  padding: 22px 20px 24px;
  box-shadow: var(--shadow);
  width: 100%;
}

h2 { color: var(--navy); font-size: clamp(1.4rem, 3.5vw, 1.9rem); margin-bottom: 8px; }
.lead { font-size: 1.05rem; line-height: 1.45; font-weight: 600; margin-bottom: 16px; }

.label {
  display: block;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--navy-soft);
  margin: 14px 0 8px;
}

.player-row, .chip-row, .preset-row, .mode-row, .list-row, .choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.player-pill, .chip, .preset, .mode-btn, .choice {
  border: 3px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
  min-height: 44px;
  box-shadow: 0 4px 0 rgba(22, 50, 79, 0.1);
}

.player-pill[aria-pressed="true"],
.chip[aria-pressed="true"],
.preset[aria-pressed="true"],
.mode-btn[aria-pressed="true"],
.choice[aria-pressed="true"] { background: var(--gold); }

.player-pill .edit {
  border: 0; background: transparent; padding: 0 0 0 6px;
  min-height: 0; font-size: 1rem; box-shadow: none;
}
.add-player { background: #e8ffe8; }

.preset, .mode-btn, .choice { border-radius: 16px; }
.mode-btn { flex: 1; min-width: 170px; text-align: left; }
.mode-btn .mode-title { display: block; font-size: 1.08rem; }
.mode-btn .mode-desc { display: block; font-size: 0.86rem; font-weight: 700; opacity: 0.9; }

.summary { font-weight: 700; color: var(--navy-soft); margin: 10px 0 0; }

#custom-panel textarea {
  width: 100%;
  min-height: 110px;
  border: 3px solid var(--navy);
  border-radius: 16px;
  padding: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  resize: vertical;
  background: #fff;
  color: var(--navy);
}

.custom-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.link-btn {
  border: 3px solid var(--navy);
  background: var(--paper);
  color: var(--navy);
  border-radius: 14px;
  padding: 8px 12px;
  font-weight: 800;
  min-height: 44px;
}

.start-btn, .primary, .secondary {
  border: 3px solid var(--navy);
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 800;
  font-size: 1.08rem;
  min-height: 52px;
  box-shadow: var(--shadow);
}
.start-btn, .primary { background: var(--orange); color: #fff; width: 100%; margin-top: 16px; }
.secondary { background: var(--paper); color: var(--navy); }
.start-btn:disabled, .primary:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

.best-note { margin-top: 12px; font-weight: 700; color: var(--navy-soft); }

.hud {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}
.stat, .linkish, .speak-btn {
  background: var(--paper);
  border: 3px solid var(--navy);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px 12px;
}
.stat { min-width: 80px; text-align: center; }
.stat .label { margin: 0; }
.stat .value { font-size: 1.45rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat.timer.warn .value { color: #d97706; }
.stat.timer.danger .value { color: #dc2626; }
.linkish, .speak-btn { font-weight: 800; color: var(--navy); min-height: 64px; }
.speak-btn { background: #e7f6ff; }

.play-card { flex: 1; display: flex; flex-direction: column; gap: 12px; }

.prompt-tools { display: flex; justify-content: center; gap: 8px; }

.word-line {
  text-align: center;
  font-size: clamp(2.1rem, 9vw, 3.4rem);
  font-weight: 800;
  color: var(--navy);
  letter-spacing: 0.08em;
  line-height: 1.2;
  min-height: 1.3em;
  text-transform: lowercase;
}
.word-line.ok { color: var(--correct-dark); }
.word-line.copy { letter-spacing: 0.12em; }

.slots {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}
.slot {
  min-width: 1.15em;
  border-bottom: 4px solid var(--navy);
  text-align: center;
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  color: var(--navy);
  padding: 0 4px;
}
.slot.fixed { border-bottom-color: transparent; color: var(--navy-soft); }
.slot.blank { color: var(--teal); }

.answer-box {
  border: 3px solid var(--navy);
  border-radius: 18px;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.8rem, 7vw, 2.8rem);
  font-weight: 800;
  color: var(--navy);
  background: #fff;
  letter-spacing: 0.08em;
  text-transform: lowercase;
}
.answer-box.ok { background: #e8ffe8; border-color: var(--correct-dark); }
.answer-box.teach { background: #fff6d9; }

.feedback {
  min-height: 1.5em;
  text-align: center;
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--navy-soft);
}
.hint { font-size: 1rem; font-weight: 700; text-align: center; color: var(--navy); }

.tries { text-align: center; font-weight: 800; color: var(--navy-soft); font-size: 0.95rem; }

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
}
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
  border: 3px solid var(--navy);
  background: #fff;
  color: var(--navy);
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 800;
  min-height: 52px;
  min-width: 8.2%;
  flex: 1 1 0;
  max-width: 64px;
  box-shadow: 0 4px 0 rgba(22, 50, 79, 0.12);
  text-transform: lowercase;
}
.key:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(22, 50, 79, 0.12); }
.key.wide { max-width: 120px; flex: 1.6 1 0; font-size: 1rem; text-transform: none; }
.key.enter { background: var(--teal); color: #fff; max-width: 140px; }
.key.back { background: #f3efe4; }

.score-big {
  font-size: clamp(2.4rem, 8vw, 3.8rem);
  font-weight: 800;
  color: var(--navy);
  line-height: 1;
  margin: 8px 0 4px;
  text-align: center;
}
.end-card { text-align: center; }

.missed-box, .mastery-box {
  text-align: left;
  background: #fff7e8;
  border: 2px solid #f0d3a0;
  border-radius: 16px;
  padding: 12px 14px;
  margin: 14px 0 10px;
  max-height: 220px;
  overflow: auto;
}
.missed-box h3, .mastery-box h3 { margin: 0 0 8px; color: var(--navy); font-size: 1rem; }
.missed-box ul { margin: 0; padding: 0 0 0 18px; columns: 2; gap: 12px; }
.missed-box li { margin: 0 0 4px; font-weight: 700; break-inside: avoid; }

.end-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 12px; }
.end-actions .primary, .end-actions .secondary { width: auto; margin-top: 0; }

.site-foot { margin: 12px 0 0; text-align: center; font-weight: 700; color: var(--navy); font-size: 0.92rem; }
.site-foot a { color: var(--navy); }

.dialog-back {
  position: fixed; inset: 0; background: rgba(22, 50, 79, 0.35);
  display: grid; place-items: center; padding: 16px; z-index: 20;
}
.dialog-back[hidden] { display: none !important; }
.dialog {
  background: var(--paper); border: 3px solid var(--navy); border-radius: 24px;
  padding: 20px; width: min(420px, 100%); box-shadow: var(--shadow);
}
.dialog input {
  width: 100%; border: 3px solid var(--navy); border-radius: 12px;
  padding: 10px 12px; font-size: 1.15rem; font-weight: 700; margin-bottom: 12px;
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-actions .primary, .dialog-actions .secondary { min-height: 44px; padding: 8px 14px; font-size: 1rem; width: auto; margin-top: 0; }

#print-sheet { display: none; }

@media print {
  body { background: #fff; }
  .app, .dialog-back { display: none !important; }
  #print-sheet { display: block; padding: 24px; }
  #print-sheet h1 { font-size: 1.6rem; margin-bottom: 8px; }
  #print-sheet p { margin-bottom: 16px; }
  #print-sheet table { width: 100%; border-collapse: collapse; }
  #print-sheet td { border-bottom: 1px solid #333; padding: 10px 8px; font-size: 1.15rem; }
  #print-sheet .write { width: 60%; }
}

@media (max-width: 560px) {
  .hud { grid-template-columns: 1fr 1fr auto; }
  .stat.tries-stat { display: none; }
  .key { min-height: 46px; font-size: 1.05rem; }
  .missed-box ul { columns: 1; }
  .mode-btn { min-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .key, .start-btn { transition: none; }
}
