:root {
  --paper: #eef4fb;
  --ink: #22324a;
  --accent: #3f7fd6;
  --accent-soft: #dcebff;
  --danger: #d94d4d;
  --ok: #2b8a5c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 12% 16%, rgba(255, 255, 255, 0.9), transparent 42%),
    linear-gradient(150deg, var(--paper), #fdfaf3);
  color: var(--ink);
  font-family: 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
}

.stage {
  width: min(920px, 96vw);
  padding: 20px;
}

.screen {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(63, 127, 214, 0.2);
  border-radius: 18px;
  padding: clamp(18px, 4vw, 36px);
  box-shadow: 0 14px 36px rgba(34, 50, 74, 0.1);
}

.badge {
  display: inline-block;
  margin: 0 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  padding: 5px 14px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

h1 { margin: 4px 0 10px; font-size: clamp(26px, 5vw, 38px); }
.lead { margin: 0 0 8px; line-height: 1.8; color: #45566f; font-weight: 600; }
.keyboard-note { margin: 0 0 18px; color: #8a6d3b; font-size: 13px; font-weight: 700; }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.mode-card {
  border: 1px solid rgba(63, 127, 214, 0.22);
  border-radius: 14px;
  background: #fbfdff;
  padding: 16px 18px;
}

.mode-card h2 { margin: 0 0 6px; font-size: 19px; }
.mode-card p { margin: 0 0 12px; color: #5a6a82; font-size: 14px; font-weight: 600; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

button {
  border: 1px solid rgba(63, 127, 214, 0.4);
  border-radius: 10px;
  background: #fff;
  padding: 10px 16px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}

button:hover { background: var(--accent-soft); transform: translateY(-1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

#challenge-buttons button { flex: 1; min-width: 90px; }

.best-line { margin: 10px 0 0; font-size: 13px; color: #5a6a82; }

.lesson-list { display: grid; gap: 8px; }

.lesson-list button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  gap: 10px;
}

.lesson-list .stars { color: #e0a020; font-size: 14px; letter-spacing: 2px; }
.lesson-list .locked { color: #9aa8bc; }

.settings-row { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.sound-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: #5a6a82; }
.sound-toggle select {
  border: 1px solid rgba(63, 127, 214, 0.4);
  border-radius: 8px;
  background: #fff;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

/* ---- プレイ画面 ---- */
.hud {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.hud-box {
  display: grid;
  min-width: 86px;
  justify-items: center;
  border: 1px solid rgba(63, 127, 214, 0.22);
  border-radius: 12px;
  background: #fff;
  padding: 8px 12px;
}

.hud-label { color: #71809a; font-size: 11px; font-weight: 800; }
.hud-box strong { font-size: 22px; }

.hud-timer { display: flex; align-items: center; gap: 12px; }

.timer-bar {
  flex: 1;
  height: 14px;
  border: 1px solid rgba(63, 127, 214, 0.3);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #79c1ff, var(--accent));
  transition: width 0.15s linear;
}

.timer-num {
  min-width: 64px;
  text-align: center;
  border: 2px solid rgba(63, 127, 214, 0.35);
  border-radius: 12px;
  background: #fff;
  padding: 6px 10px;
  font-size: 28px;
}

.hud-timer.urgent .timer-fill { background: var(--danger); }
.hud-timer.urgent .timer-num {
  border-color: var(--danger);
  background: #ffecea;
  color: var(--danger);
  animation: pulse 0.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.progress-line { margin: -6px 0 12px; color: #5a6a82; font-weight: 700; font-size: 14px; }

.word-card {
  border: 1px solid rgba(63, 127, 214, 0.24);
  border-radius: 16px;
  background: #fff;
  padding: clamp(18px, 4vw, 30px);
  text-align: center;
  min-height: 190px;
  display: grid;
  align-content: center;
  gap: 8px;
}

.word-card.miss { animation: shake 0.18s ease; background: #fff3f2; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-6px); }
  70% { transform: translateX(6px); }
}

.word-kanji { margin: 0; font-size: clamp(24px, 5vw, 36px); font-weight: 900; overflow-wrap: anywhere; }
.word-kana { margin: 0; color: #5a6a82; font-size: clamp(15px, 3vw, 19px); font-weight: 700; overflow-wrap: anywhere; }

.word-romaji {
  margin: 6px 0 0;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: clamp(20px, 4.5vw, 30px);
  font-weight: 700;
  letter-spacing: 1px;
  overflow-wrap: anywhere;
}

.word-romaji .typed { color: var(--accent); }
.word-romaji .rest { color: #9aa8bc; }

.next-key { margin: 14px 0 0; text-align: center; color: #5a6a82; font-weight: 700; }
.next-key strong {
  display: inline-grid;
  place-items: center;
  min-width: 46px;
  height: 46px;
  margin-left: 6px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: var(--accent-soft);
  font-size: 24px;
  text-transform: uppercase;
}

.play-footer { margin-top: 18px; text-align: right; }
.play-footer button { font-size: 13px; padding: 8px 14px; }

/* ---- 結果画面 ---- */
#screen-result { text-align: center; }

.rank {
  margin: 4px 0;
  font-size: 84px;
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
}

#screen-result h2 { margin: 0 0 18px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.result-grid .cell {
  border: 1px solid rgba(63, 127, 214, 0.22);
  border-radius: 12px;
  background: #fbfdff;
  padding: 12px;
}

.result-grid .cell strong { display: block; font-size: 24px; }
.result-grid .cell small { color: #71809a; font-weight: 700; }

.miss-keys { margin: 0 0 18px; color: #5a6a82; font-weight: 700; }

#screen-result .button-row { justify-content: center; }

@media (max-width: 620px) {
  .hud { grid-template-columns: 1fr 1fr; }
  .hud-timer { grid-column: 1 / -1; order: -1; }
}
