/* Kaan — chalk & earth. A school slate under a Sahel roof.
   Duun letters/words: Andika; French UI: Nunito. */

:root {
  --board: #241b14;
  --board-soft: #2f251b;
  --board-line: #443627;
  --chalk: #efe6d3;
  --chalk-dim: #b8ab92;
  --ochre: #d9a441;
  --laterite: #b6532f;
  --leaf: #7ea34f;
  --rose: #c96a50;
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html { height: 100%; }

body {
  min-height: 100%;
  background:
    repeating-linear-gradient(94deg, transparent 0 90px, rgba(239, 230, 211, 0.022) 90px 92px),
    repeating-linear-gradient(2deg, transparent 0 70px, rgba(0, 0, 0, 0.15) 70px 72px),
    linear-gradient(170deg, #2a2016, var(--board) 55%);
  color: var(--chalk);
  font-family: "Nunito", system-ui, sans-serif;
  padding-bottom: 56px;
}

[lang^="dux"] { font-family: "Andika", sans-serif; }

/* ---------- header + tabs ---------- */

#top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 18px 4px;
}

#top h1 { font-size: 2rem; color: var(--ochre); font-family: "Andika", sans-serif; }

#top h1 .sub {
  display: block;
  font-family: "Nunito", sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--chalk-dim);
}

#net-badge {
  margin-left: auto;
  border: 1.5px dashed var(--ochre);
  color: var(--ochre);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 800;
}

#tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 9px;
  padding: 12px 16px 4px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, var(--board) 70%, transparent);
}

.tab {
  border: 1.5px solid var(--board-line);
  background: var(--board-soft);
  color: var(--chalk-dim);
  border-radius: 16px;
  padding: 9px 4px 8px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  transition: transform 0.2s var(--bounce), background 0.2s, color 0.2s;
}

.tab .tab-glyph {
  display: block;
  font-size: 1.25rem;
  line-height: 1.2;
  color: var(--chalk);
}

.tab.active {
  background: var(--ochre);
  border-color: var(--ochre);
  color: #241b14;
  transform: translateY(-2px);
  box-shadow: 0 5px 16px rgba(217, 164, 65, 0.35);
}

.tab.active .tab-glyph { color: #241b14; }

.tab:active { transform: scale(0.94); }

/* ---------- view ---------- */

#view { padding: 14px 16px 30px; max-width: 560px; margin: 0 auto; }

.intro { color: var(--chalk-dim); font-weight: 700; font-size: 0.92rem; text-align: center; margin: 2px 0 14px; }

/* letters grid */
.letter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.letter-cell {
  position: relative;
  border: 1.5px solid var(--board-line);
  border-radius: 18px;
  background: var(--board-soft);
  color: var(--chalk);
  font-family: "Andika", sans-serif;
  font-size: 1.6rem;
  padding: 14px 2px 10px;
  text-align: center;
  transition: transform 0.2s var(--bounce), border-color 0.2s;
  animation: chalk-in 0.4s ease both;
  animation-delay: calc(var(--i) * 18ms);
}

@keyframes chalk-in { from { opacity: 0; transform: scale(0.85); } }

.letter-cell:active { transform: scale(0.9); }

.letter-cell.done::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 9px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--leaf);
}

.letter-cell .low { color: var(--chalk-dim); font-size: 1.1rem; margin-left: 3px; }

/* ---------- letter screen ---------- */

.back-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

.back-btn {
  border: 1.5px solid var(--board-line);
  background: var(--board-soft);
  color: var(--chalk);
  border-radius: 12px;
  padding: 8px 14px;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.9rem;
}

.letter-hero {
  text-align: center;
  font-family: "Andika", sans-serif;
  font-size: 5.2rem;
  line-height: 1.05;
  color: var(--chalk);
  text-shadow: 0 0 26px rgba(239, 230, 211, 0.25);
  margin: 4px 0 2px;
}

.letter-hero .low { color: var(--ochre); }

.letter-count { text-align: center; color: var(--chalk-dim); font-weight: 700; font-size: 0.85rem; margin-bottom: 12px; }

.word-chips { display: flex; flex-direction: column; gap: 9px; margin: 12px 0; }

.word-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px solid var(--board-line);
  background: var(--board-soft);
  border-radius: 16px;
  padding: 11px 14px;
  color: var(--chalk);
  font-family: inherit;
  text-align: left;
  transition: transform 0.15s, border-color 0.2s;
  animation: chalk-in 0.35s ease both;
  animation-delay: calc(var(--i) * 50ms);
}

.word-chip:active { transform: scale(0.97); border-color: var(--ochre); }

.word-chip .w { font-family: "Andika", sans-serif; font-size: 1.35rem; }
.word-chip .w em { font-style: normal; color: var(--ochre); }
.word-chip .g { color: var(--chalk-dim); font-size: 0.85rem; font-weight: 700; margin-left: auto; text-align: right; max-width: 45%; }

.word-chip .spk {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.6px solid var(--ochre);
  color: var(--ochre);
  display: grid;
  place-items: center;
  background: transparent;
}

.word-chip .spk svg { width: 14px; height: 14px; }
.word-chip .spk.playing { background: var(--ochre); color: var(--board); animation: throb 0.9s infinite; }

@keyframes throb { 50% { transform: scale(1.12); } }

.contains-note { color: var(--chalk-dim); font-size: 0.78rem; font-weight: 700; text-align: center; margin-top: -4px; }

/* ---------- slate (tracing) ---------- */

.slate-wrap { margin-top: 16px; }

.slate-title {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ochre);
  margin-bottom: 8px;
  text-align: center;
}

.slate {
  position: relative;
  border-radius: 20px;
  border: 3px solid #4a3a26;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.4);
  background:
    radial-gradient(120% 100% at 30% 20%, rgba(239, 230, 211, 0.05), transparent 60%),
    #1c150e;
  overflow: hidden;
  touch-action: none;
}

.slate canvas { display: block; width: 100%; }

.slate .stencil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Andika", sans-serif;
  font-size: 11rem;
  color: transparent;
  -webkit-text-stroke: 2px rgba(239, 230, 211, 0.28);
  pointer-events: none;
  user-select: none;
}

.slate-tools { display: flex; justify-content: center; gap: 10px; margin-top: 10px; }

.tool-btn {
  border: 1.5px solid var(--board-line);
  background: var(--board-soft);
  color: var(--chalk);
  border-radius: 12px;
  padding: 9px 16px;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.88rem;
  transition: transform 0.15s;
}

.tool-btn:active { transform: scale(0.93); }
.tool-btn.gold { background: var(--ochre); border-color: var(--ochre); color: var(--board); }

/* ---------- tones ---------- */

.tone-stage { text-align: center; }

.tone-listen {
  margin: 10px auto 4px;
  border: 0;
  border-radius: 999px;
  background: var(--laterite);
  color: var(--chalk);
  width: 92px;
  height: 92px;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 0 #7c3820, 0 10px 30px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s var(--bounce);
}

.tone-listen:active { transform: scale(0.9); }
.tone-listen svg { width: 38px; height: 38px; }
.tone-listen.playing { animation: throb 0.9s infinite; }

.tone-q { color: var(--chalk-dim); font-weight: 700; margin: 10px 0 14px; }

.tone-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.tone-choices.three { grid-template-columns: 1fr 1fr 1fr; }

.tone-choice {
  border: 2px solid var(--board-line);
  background: var(--board-soft);
  color: var(--chalk);
  border-radius: 18px;
  padding: 16px 6px;
  font-family: "Andika", sans-serif;
  font-size: 2rem;
  transition: transform 0.2s var(--bounce), border-color 0.2s;
}

.tone-choice:active { transform: scale(0.93); }
.tone-choice.right { border-color: var(--leaf); background: rgba(126, 163, 79, 0.14); }
.tone-choice.wrong { border-color: var(--rose); animation: shake 0.4s ease; }

@keyframes shake {
  20% { transform: translateX(-8px); }
  45% { transform: translateX(7px); }
  70% { transform: translateX(-4px); }
  90% { transform: translateX(2px); }
}

.tone-reveal {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: chalk-in 0.4s ease both;
}

.tone-reveal .pair {
  display: flex;
  justify-content: center;
  gap: 8px;
  color: var(--chalk-dim);
  font-weight: 700;
  font-size: 0.95rem;
}

.tone-reveal .pair b { color: var(--ochre); font-family: "Andika", sans-serif; font-size: 1.05rem; font-weight: 400; }

.score-row { display: flex; justify-content: center; gap: 6px; margin: 14px 0 4px; }

.score-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--board-line); }
.score-dot.hit { background: var(--leaf); }
.score-dot.miss { background: var(--rose); }

/* ---------- spelling game ---------- */

.spell-target {
  text-align: center;
  margin-bottom: 10px;
}

.spell-gloss { color: var(--chalk-dim); font-weight: 700; margin-top: 6px; }

.spell-slots {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
  min-height: 64px;
}

.slot {
  min-width: 52px;
  height: 62px;
  border-bottom: 3px solid var(--board-line);
  display: grid;
  place-items: center;
  font-family: "Andika", sans-serif;
  font-size: 2rem;
  color: var(--chalk);
  padding: 0 6px;
}

.slot.filled { border-bottom-color: var(--ochre); animation: chalk-in 0.25s ease; }

.tile-tray { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }

.tile {
  min-width: 60px;
  height: 66px;
  border: 2px solid var(--board-line);
  border-radius: 14px;
  background: linear-gradient(160deg, #37291b, var(--board-soft));
  color: var(--chalk);
  font-family: "Andika", sans-serif;
  font-size: 1.9rem;
  padding: 0 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.4);
  transition: transform 0.15s var(--bounce), opacity 0.2s;
}

.tile:active { transform: scale(0.9); }
.tile.used { opacity: 0.18; pointer-events: none; }
.tile.bad { animation: shake 0.35s ease; border-color: var(--rose); }

.spell-win {
  text-align: center;
  margin-top: 16px;
  animation: chalk-in 0.4s var(--bounce) both;
}

.spell-win .word { font-family: "Andika", sans-serif; font-size: 2.4rem; color: var(--ochre); }
.spell-win p { color: var(--chalk-dim); font-weight: 700; margin: 4px 0 12px; }

.spell-actions { display: flex; justify-content: center; gap: 10px; margin-top: 12px; }

/* ---------- footer ---------- */

#foot {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 9px 18px calc(9px + env(safe-area-inset-bottom));
  background: rgba(36, 27, 20, 0.95);
  border-top: 1px solid var(--board-line);
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--chalk-dim);
}

#foot a { color: var(--ochre); text-decoration: none; }

button { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
