:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --ink: #202124;
  --muted: #6d675f;
  --line: #d9d1c3;
  --panel: #fffaf1;
  --accent: #24786d;
  --accent-dark: #155b53;
  --plum: #8b4762;
  --gold: #c48424;
  --mist: #dde9e5;
  --wrong: #b34545;
  --right: #24786d;
  --shadow: 0 18px 45px rgba(43, 35, 22, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(145deg, rgba(36, 120, 109, 0.12), transparent 38%),
    linear-gradient(315deg, rgba(196, 132, 36, 0.13), transparent 42%),
    var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100svh;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
}

.screen {
  display: none;
  min-height: calc(100svh - 40px);
}

.screen.is-active {
  display: flex;
}

.screen-menu {
  flex-direction: column;
  gap: 22px;
  justify-content: space-between;
}

.brand-row,
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-row {
  padding-top: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 560px;
  margin-bottom: 0;
  font-size: clamp(2.25rem, 12vw, 4.9rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.score-pill,
.timer {
  min-width: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.78);
  padding: 10px 12px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(43, 35, 22, 0.08);
}

.score-pill span,
.stat-row span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.score-pill strong,
.timer {
  font-size: 1.34rem;
  font-weight: 900;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.mode-card {
  display: grid;
  min-height: 248px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.78), rgba(255, 250, 241, 0.92)),
    var(--panel);
  color: var(--ink);
  padding: 20px;
  text-align: left;
  box-shadow: var(--shadow);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.mode-card:active {
  transform: scale(0.98);
}

.mode-card:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.icon-button:focus-visible,
.choice-button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 120, 109, 0.38);
  outline-offset: 3px;
}

.mode-kana {
  align-self: start;
  color: var(--plum);
  font-size: clamp(3.8rem, 20vw, 8.4rem);
  font-weight: 900;
  line-height: 0.85;
}

.mode-title {
  align-self: end;
  font-size: 1.2rem;
  font-weight: 900;
}

.mode-meta {
  align-self: end;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.study-band {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.7);
  padding: 10px;
}

.study-strip {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
}

.study-tile {
  min-width: 0;
  border-radius: 6px;
  background: rgba(221, 233, 229, 0.76);
  padding: 8px 2px;
  text-align: center;
}

.study-tile b {
  display: block;
  font-size: 1.2rem;
  line-height: 1;
}

.study-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
}

.screen-game {
  flex-direction: column;
  gap: 16px;
}

.game-header {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -2px -18px 0;
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  background: rgba(247, 243, 234, 0.92);
  backdrop-filter: blur(18px);
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 2.2rem;
  line-height: 1;
}

.game-title-block {
  min-width: 0;
  flex: 1;
}

.game-title-block h2 {
  margin-bottom: 0;
  overflow: hidden;
  font-size: 1.32rem;
  line-height: 1.08;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timer {
  min-width: 76px;
  background: var(--ink);
  color: white;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat-row > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.72);
  padding: 10px;
  text-align: center;
}

.stat-row strong {
  display: block;
  margin-top: 2px;
  font-size: 1.45rem;
  line-height: 1;
}

.play-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  justify-content: center;
}

.prompt-card {
  display: grid;
  min-height: 230px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.prompt {
  color: var(--plum);
  font-size: clamp(5.8rem, 34vw, 14rem);
  font-weight: 950;
  line-height: 0.88;
}

.prompt-sub {
  align-self: start;
  min-height: 24px;
  margin-top: -22px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 900;
}

.answer-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.answer-form[hidden],
.choice-grid[hidden] {
  display: none;
}

input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 16px;
  font-size: 1.35rem;
  font-weight: 800;
}

.primary-button,
.secondary-button {
  min-height: 54px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.choice-button {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-size: clamp(1.55rem, 8vw, 2.7rem);
  font-weight: 900;
  box-shadow: 0 8px 20px rgba(43, 35, 22, 0.07);
  transition:
    transform 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.choice-button:active {
  transform: scale(0.95);
}

.choice-button.is-right {
  background: var(--right);
  color: white;
}

.choice-button.is-wrong {
  background: var(--wrong);
  color: white;
}

.feedback {
  min-height: 28px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.feedback.is-right {
  color: var(--right);
}

.feedback.is-wrong {
  color: var(--wrong);
}

.screen-result {
  align-items: center;
  justify-content: center;
}

.result-card {
  width: min(100%, 430px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: var(--shadow);
}

.result-card h2 {
  margin-bottom: 8px;
  font-size: 3rem;
  line-height: 0.95;
}

.result-copy {
  color: var(--muted);
  font-weight: 800;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

@media (max-width: 620px) {
  .app-shell {
    padding-inline: 14px;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }

  .mode-card {
    min-height: 172px;
  }

  .study-strip {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 390px) {
  .answer-form {
    grid-template-columns: 1fr;
  }

  .choice-grid {
    gap: 6px;
  }

  .game-title-block h2 {
    font-size: 1.08rem;
  }
}
