:root {
  color-scheme: light;
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", Nunito, system-ui, sans-serif;
  background: #fff8ec;
  color: #27302e;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  min-height: 100dvh;
  overflow: hidden;
}

button { font: inherit; }

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  gap: clamp(10px, 1.8vh, 18px);
  background: radial-gradient(circle at 7% 4%, #fff 0 4.5rem, transparent 4.55rem), radial-gradient(circle at 94% 92%, #e8f5e9 0 9rem, transparent 9.1rem), #fff8ec;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(4px, 1vw, 12px);
}

.title-lockup { line-height: 1; }
.eyebrow { margin: 0 0 5px; color: #e07b50; font-size: clamp(.68rem, 1.55vh, .9rem); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; color: #2d564e; font-size: clamp(1.45rem, 3.5vh, 2.3rem); letter-spacing: -.04em; }

.case-switch {
  display: flex;
  padding: 5px;
  border: 2px solid #d9e7dc;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 0 #d9e7dc;
}

.case-button {
  min-width: clamp(62px, 9vw, 96px);
  min-height: clamp(42px, 7vh, 54px);
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #66736f;
  font-size: clamp(1rem, 2.3vh, 1.35rem);
  font-weight: 900;
  touch-action: manipulation;
}

.case-button.is-selected { background: #2d9382; color: #fff; box-shadow: 0 2px 0 #1f7467; }
.case-button:focus-visible, .letter-tile:focus-visible, .mode-button:focus-visible { outline: 4px solid #e79a54; outline-offset: 3px; }

.speech-controls { display: flex; align-items: end; gap: 6px; padding: 6px 8px; border: 2px solid #d9e7dc; border-radius: 14px; background: #fff; box-shadow: 0 3px 0 #d9e7dc; }
.speech-controls[hidden] { display: none; }
.speech-controls label { display: grid; gap: 2px; color: #76827f; font-size: clamp(.56rem, 1.25vh, .68rem); font-weight: 850; letter-spacing: .02em; text-transform: uppercase; }
.speech-controls select { min-width: 54px; min-height: 30px; padding: 0 17px 0 6px; border: 1px solid #d9e7dc; border-radius: 8px; background: #f9fcfa; color: #2d564e; font: inherit; font-size: clamp(.62rem, 1.45vh, .75rem); font-weight: 850; text-transform: none; touch-action: manipulation; }

.letters-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  padding: clamp(12px, 1.9vh, 18px);
  border: 2px solid #f4e2c4;
  border-radius: 28px;
  background: rgba(255, 255, 255, .76);
  box-shadow: 0 6px 0 #f4e2c4;
}

#learning-content { min-height: 0; height: 100%; }

.prompt {
  margin: 0 0 clamp(9px, 1.7vh, 15px);
  color: #76827f;
  font-size: clamp(.84rem, 2vh, 1.12rem);
  font-weight: 750;
  text-align: center;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(8px, 1.45vw, 16px);
  min-height: 0;
  height: 100%;
}

.digraph-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 1.8vw, 19px);
  min-height: 0;
  height: 100%;
}

.letter-tile {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 2px solid #dce9e5;
  border-radius: clamp(14px, 2vw, 22px);
  background: #fff;
  box-shadow: 0 5px 0 #c8ddd7;
  color: #284f47;
  cursor: pointer;
  font-size: clamp(2rem, 7.3vh, 4.2rem);
  font-weight: 900;
  line-height: 1;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 85ms ease, background-color 85ms ease, box-shadow 85ms ease, color 85ms ease;
}

.letter-tile:nth-child(4n + 1) { border-color: #f4c8ab; box-shadow: 0 5px 0 #eab18e; color: #b15d3c; }
.letter-tile:nth-child(4n + 2) { border-color: #c5dfef; box-shadow: 0 5px 0 #a8cadd; color: #397798; }
.letter-tile:nth-child(4n + 3) { border-color: #d3ddb0; box-shadow: 0 5px 0 #b9c68e; color: #63783a; }

.letter-tile.is-pressed, .letter-tile:active { transform: translateY(5px) scale(.98); background: #fff2dc; box-shadow: 0 0 0 transparent; }
.digraph-tile { font-size: clamp(1.8rem, 6vh, 3.4rem); }

.family-page { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; height: 100%; gap: clamp(10px, 1.5vh, 16px); }
.family-picker { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(7px, 1vw, 11px); }
.family-choice { min-height: clamp(42px, 6.5vh, 52px); border: 2px solid #d9e7dc; border-radius: 13px; background: #fff; box-shadow: 0 3px 0 #d9e7dc; color: #60706b; font-size: clamp(1rem, 2.3vh, 1.3rem); font-weight: 900; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.family-choice.is-selected { border-color: #a8cadd; background: #e8f5fb; box-shadow: 0 3px 0 #a8cadd; color: #397798; }
.family-choice:active { transform: translateY(3px); box-shadow: none; }
.finished-word { align-self: center; justify-self: center; min-width: clamp(220px, 38vw, 350px); min-height: clamp(88px, 17vh, 132px); border: 2px solid #d3ddb0; border-radius: 22px; background: #f7fbe9; box-shadow: 0 6px 0 #b9c68e; color: #63783a; font-size: clamp(2.7rem, 8.5vh, 5rem); font-weight: 900; line-height: .8; touch-action: manipulation; }
.finished-word span { display: block; margin-top: 7px; color: #839656; font-size: clamp(.65rem, 1.55vh, .84rem); letter-spacing: .04em; text-transform: uppercase; }
.finished-word.is-unavailable { border-color: #d8dcda; background: #f1f3f2; box-shadow: 0 6px 0 #c8cdca; color: #7b8380; }
.finished-word.is-unavailable span { color: #8e9693; }
.finished-word.is-pressed, .finished-word:active, .start-tile.is-pressed, .start-tile:active { transform: translateY(5px) scale(.98); box-shadow: 0 0 0 transparent; }
.start-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(56px, 1fr)); gap: clamp(8px, 1.3vw, 14px); align-items: end; }
.start-tile { min-height: clamp(48px, 8.5vh, 68px); border: 2px solid #dce9e5; border-radius: 15px; background: #fff; box-shadow: 0 4px 0 #c8ddd7; color: #284f47; font-size: clamp(1.35rem, 3.8vh, 2.2rem); font-weight: 900; touch-action: manipulation; }
.start-tile.is-selected { border-color: #f4c8ab; background: #fff2dc; box-shadow: 0 4px 0 #eab18e; color: #b15d3c; }

.mode-nav {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(8px, 1.4vw, 16px);
  padding: 0 clamp(2px, .8vw, 8px);
}

.mode-button {
  display: flex;
  min-height: clamp(52px, 10vh, 72px);
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 2px solid transparent;
  border-radius: 17px;
  background: transparent;
  color: #9ba39f;
  font-size: clamp(.7rem, 1.9vh, 1rem);
  font-weight: 800;
}

.mode-button.is-active { border-color: #cde4dc; background: #eaf6f1; color: #246f60; }
.mode-button:disabled { opacity: .64; }
.mode-icon { font-size: clamp(1rem, 2.7vh, 1.45rem); font-weight: 900; }

@media (max-width: 700px) and (orientation: portrait) {
  html, body { width: 100%; overflow-x: hidden; }
  body { overflow-y: auto; }
  .app-shell { width: 100%; min-width: 0; max-width: 100vw; min-height: 100svh; padding: 14px; gap: 12px; }
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; min-width: 0; padding: 0; gap: 10px; }
  .title-lockup { min-width: 0; }
  .case-switch { justify-self: end; }
  .speech-controls { grid-column: 1 / -1; width: 100%; min-width: 0; justify-content: center; }
  .speech-controls label { min-width: 0; flex: 1; }
  .speech-controls select { width: 100%; min-width: 0; }
  .letters-panel, #learning-content, .family-page, .family-picker, .start-row { min-width: 0; }
  .letter-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(64px, 1fr)); }
  .digraph-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(76px, 1fr)); }
  .family-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .finished-word { max-width: 100%; }
  .letter-tile { min-height: 64px; font-size: 2.25rem; }
  .mode-button { flex-direction: column; gap: 1px; min-height: 62px; }
  .mode-icon { line-height: 1; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-shell { padding-top: 9px; padding-bottom: 9px; gap: 8px; }
  .eyebrow, .prompt { display: none; }
  .letters-panel { padding: 9px; border-radius: 20px; }
  .letter-grid { gap: 7px; }
  .digraph-grid { gap: 7px; }
  .letter-tile { border-radius: 13px; box-shadow: 0 3px 0 #c8ddd7; }
  .mode-button { min-height: 42px; }
}
