:root {
  color-scheme: light;
  --ink: #253238;
  --muted: #68767c;
  --line: #dce6e8;
  --paper: #ffffff;
  --canvas: #f4f8f8;
  --teal: #36a88f;
  --teal-dark: #177861;
  --teal-soft: #e5f5f0;
  --blue: #4386c7;
  --blue-soft: #e8f2fb;
  --yellow: #f7c84b;
  --yellow-soft: #fff6d8;
  --coral: #ef725e;
  --coral-soft: #fff0ec;
  --brown: #704022;
  --shadow: 0 10px 30px rgba(37, 50, 56, 0.09);
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(67, 134, 199, 0.35);
  outline-offset: 3px;
}

.topbar {
  min-height: 72px;
  padding: 10px clamp(16px, 4vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 3px solid var(--brown);
  border-radius: 8px;
  color: var(--brown);
  background: var(--yellow);
  font-size: 24px;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-size: 20px;
}

.brand small {
  margin-top: 2px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.streak {
  min-height: 40px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #f2d57b;
  border-radius: 8px;
  background: var(--yellow-soft);
  color: #765a10;
  font-size: 13px;
  font-weight: 700;
}

.streak span {
  color: var(--yellow);
  -webkit-text-stroke: 1px #9f770d;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 21px;
  font-weight: 800;
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.icon-button.is-muted {
  color: #98a2a6;
  background: #eef2f3;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
}

.stage-panel {
  min-height: calc(100vh - 108px);
  padding: 28px 22px;
  background: #eef7f4;
  border-right: 1px solid #d5e6e1;
}

.panel-heading {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.panel-heading h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.4;
  letter-spacing: 0;
}

.stage-list {
  display: grid;
  gap: 10px;
}

.stage-button {
  width: 100%;
  min-height: 74px;
  padding: 10px;
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 10px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  text-align: left;
  cursor: pointer;
}

.stage-button:hover {
  border-color: #acd9cc;
  background: var(--paper);
}

.stage-button.is-active {
  border-color: var(--teal);
  background: var(--paper);
  box-shadow: 0 6px 18px rgba(23, 120, 97, 0.12);
}

.stage-number {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 17px;
  font-weight: 900;
}

.is-active .stage-number {
  background: var(--teal);
  color: white;
}

.stage-copy strong,
.stage-copy small {
  display: block;
  letter-spacing: 0;
}

.stage-copy strong {
  font-size: 16px;
}

.stage-copy small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stage-status {
  min-width: 40px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.small-record {
  margin-top: 26px;
  padding-top: 20px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid #cee1db;
}

.small-record h2 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0;
}

.record-detail {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
}

.record-detail strong {
  color: var(--teal-dark);
}

.small-record > strong {
  max-width: 92px;
  color: var(--blue);
  font-size: 19px;
  line-height: 1.25;
  text-align: right;
}

.practice-area {
  min-width: 0;
  padding: 24px clamp(18px, 4vw, 52px) 38px;
}

.progress-row {
  min-height: 46px;
  display: grid;
  grid-template-columns: minmax(180px, auto) minmax(180px, 1fr) 48px;
  align-items: center;
  gap: 18px;
}

.progress-row > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

#stage-label {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

#lesson-title {
  font-size: 18px;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 5px;
  background: #dae5e7;
}

.progress-track span {
  width: 0;
  height: 100%;
  display: block;
  background: var(--teal);
  transition: width 180ms ease;
}

#progress-text {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.lesson-band {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(300px, 1fr) minmax(120px, 160px);
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.coach {
  min-height: 330px;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  justify-content: end;
  background: var(--yellow-soft);
  border-radius: 8px 0 0 8px;
  overflow: hidden;
}

.coach img {
  width: min(190px, 100%);
  max-height: 185px;
  margin: 0 auto -8px;
  object-fit: contain;
}

.speech {
  position: relative;
  z-index: 1;
  min-height: 108px;
  padding: 14px;
  border: 2px solid #efd170;
  border-radius: 8px;
  background: white;
}

.speech-name {
  display: inline-block;
  color: #7d610e;
  font-size: 11px;
  font-weight: 900;
}

.speech p {
  margin: 6px 0 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.8;
}

.word-zone {
  min-height: 330px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.home-position-check {
  width: min(560px, 100%);
  margin-bottom: 18px;
  padding: 13px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 2px solid #efd170;
  border-bottom: 2px solid #efd170;
  background: var(--yellow-soft);
  text-align: left;
}

.home-position-check[hidden] {
  display: none;
}

.home-position-check strong {
  color: #72570d;
  font-size: 14px;
}

.home-position-check p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
}

.home-position-check kbd {
  min-width: 25px;
  padding: 2px 6px;
  display: inline-block;
  border: 1px solid #b9c4c8;
  border-bottom-width: 3px;
  border-radius: 5px;
  background: white;
  color: var(--ink);
  font-family: inherit;
  font-weight: 900;
  text-align: center;
}

.home-position-check button {
  min-width: 112px;
  min-height: 42px;
  padding: 8px 12px;
  border: 2px solid var(--teal-dark);
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-weight: 900;
  cursor: pointer;
}

.listen-button {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid #bed8ed;
  border-radius: 8px;
  background: var(--blue-soft);
  color: #235f97;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.listen-button:hover {
  border-color: var(--blue);
}

.prompt-label {
  margin: 20px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kana-word {
  min-height: 65px;
  font-size: 44px;
  font-weight: 900;
  line-height: 1.45;
  letter-spacing: 0;
}

.romaji-word {
  min-height: 46px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
}

.romaji-char {
  min-width: 20px;
  padding: 0 1px 4px;
  border-bottom: 3px solid #cfdadc;
  color: #9aa8ad;
}

.romaji-char.is-done {
  color: var(--teal-dark);
  border-bottom-color: var(--teal);
}

.romaji-char.is-current {
  color: var(--ink);
  border-bottom-color: var(--yellow);
  background: var(--yellow-soft);
}

.romaji-char.is-space {
  min-width: 28px;
  background: transparent;
}

.feedback {
  min-height: 26px;
  margin: 16px 0 0;
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
}

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

.feedback.is-success {
  color: var(--teal-dark);
}

.stats-strip {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  border-left: 1px solid var(--line);
}

.stats-strip div {
  min-height: 88px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.stats-strip div + div {
  border-top: 1px solid var(--line);
}

.stats-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stats-strip strong {
  font-size: 22px;
}

.key-guide {
  margin-top: 18px;
  padding: 18px;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.finger-guide {
  min-height: 166px;
  padding: 16px;
  display: grid;
  grid-template-columns: 68px 1fr;
  align-content: center;
  gap: 10px 14px;
  border-radius: 8px;
  background: var(--teal-soft);
}

.finger-guide .eyebrow {
  grid-column: 1 / -1;
}

.next-key {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border: 3px solid var(--teal-dark);
  border-radius: 8px;
  background: white;
  color: var(--teal-dark);
  font-size: 29px;
  font-weight: 900;
  box-shadow: 0 5px 0 #b9ded4;
}

.finger-guide h2 {
  margin: 4px 0;
  font-size: 17px;
  letter-spacing: 0;
}

.finger-guide p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.keyboard-wrap {
  min-width: 0;
  overflow-x: auto;
}

.keyboard-stage {
  width: 100%;
  min-width: 690px;
  min-height: 270px;
  position: relative;
  padding-top: 4px;
  overflow: hidden;
}

.keyboard {
  min-width: 690px;
  position: relative;
  z-index: 1;
  display: grid;
  gap: 6px;
}

.natural-hands {
  width: 690px;
  height: auto;
  position: absolute;
  z-index: 2;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0.64;
  pointer-events: none;
  user-select: none;
}

.hands-overlay {
  width: 690px;
  height: 250px;
  position: absolute;
  z-index: 2;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

.finger-route {
  fill: none;
  stroke: transparent;
  stroke-width: 24;
  stroke-linecap: round;
  transition: stroke 120ms ease, stroke-width 120ms ease;
}

.finger-route.is-active {
  stroke: rgba(239, 114, 94, 0.5);
  stroke-width: 26;
}

.thumb-route {
  stroke-width: 20;
}

.thumb-route.is-active {
  stroke-width: 23;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  width: 54px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid #c8d2d5;
  border-bottom-width: 4px;
  border-radius: 7px;
  background: white;
  color: #536166;
  font-size: 15px;
  font-weight: 800;
  transition: transform 80ms ease, background 80ms ease, color 80ms ease;
}

.key.home::after {
  content: "";
  width: 12px;
  height: 2px;
  position: absolute;
  margin-top: 25px;
  border-radius: 1px;
  background: #7f8e93;
}

.key.home {
  position: relative;
}

.key.is-target {
  position: relative;
  z-index: 3;
  border-color: var(--teal-dark);
  background: var(--teal);
  color: white;
  transform: translateY(2px);
  box-shadow: 0 0 0 4px rgba(54, 168, 143, 0.18);
}

.key.is-pressed {
  background: var(--yellow);
  color: #644c0b;
  transform: translateY(3px);
}

.key.is-wrong {
  border-color: var(--coral);
  background: var(--coral-soft);
  color: #a53626;
}

.completion {
  margin-top: 18px;
  min-height: 164px;
  padding: 18px 22px;
  display: grid;
  grid-template-columns: 100px minmax(210px, 1fr) 180px auto;
  align-items: center;
  gap: 18px;
  border: 2px solid #efd170;
  border-radius: 8px;
  background: var(--yellow-soft);
}

.completion[hidden] {
  display: none;
}

.completion img {
  width: 100px;
  height: 100px;
  object-fit: contain;
}

.completion h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 0;
}

.completion p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.completion .next-goal {
  margin-top: 8px;
  color: var(--teal-dark);
  font-size: 13px;
}

.score-result {
  min-height: 124px;
  display: grid;
  place-items: center;
  align-content: center;
  border-left: 1px solid #e4ca69;
  border-right: 1px solid #e4ca69;
}

.score-result span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.score-result > strong {
  margin-top: 2px;
  color: var(--teal-dark);
  font-size: 32px;
  line-height: 1.1;
}

.score-result b {
  margin-top: 4px;
  color: var(--blue);
  font-size: 18px;
}

.score-result em {
  margin-top: 4px;
  color: #a53626;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
}

.completion-actions {
  display: grid;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  border: 2px solid var(--teal-dark);
  background: var(--teal);
  color: white;
}

.secondary-button {
  border: 2px solid var(--blue);
  background: white;
  color: #235f97;
}

footer {
  min-height: 36px;
  padding: 9px 20px;
  border-top: 1px solid var(--line);
  background: white;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .stage-panel {
    padding: 24px 14px;
  }

  .lesson-band {
    grid-template-columns: 180px minmax(280px, 1fr);
  }

  .stats-strip {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .stats-strip div {
    min-height: 68px;
  }

  .stats-strip div + div {
    border-top: 0;
    border-left: 1px solid var(--line);
  }

  .key-guide {
    grid-template-columns: 1fr;
  }

  .finger-guide {
    min-height: auto;
    grid-template-columns: 68px 1fr;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
  }

  .streak {
    display: none;
  }

  .app-shell {
    display: block;
  }

  .stage-panel {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid #d5e6e1;
  }

  .panel-heading {
    margin-bottom: 14px;
  }

  .stage-list {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    overflow-x: auto;
  }

  .stage-button {
    grid-template-columns: 36px 1fr;
  }

  .stage-status {
    display: none;
  }

  .small-record {
    display: none;
  }

  .practice-area {
    padding: 18px 14px 30px;
  }

  .progress-row {
    grid-template-columns: 1fr 44px;
  }

  .progress-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .lesson-band {
    grid-template-columns: 1fr;
  }

  .coach {
    min-height: 150px;
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: end;
    border-radius: 8px 8px 0 0;
  }

  .coach img {
    width: 105px;
    margin: 0;
  }

  .speech {
    min-height: 105px;
  }

  .word-zone {
    min-height: 280px;
  }

  .home-position-check {
    align-items: stretch;
    flex-direction: column;
  }

  .home-position-check button {
    width: 100%;
  }

  .kana-word {
    font-size: 38px;
  }

  .completion {
    grid-template-columns: 80px 1fr;
  }

  .completion img {
    width: 76px;
    height: 76px;
  }

  .score-result,
  .completion-actions {
    grid-column: 1 / -1;
  }

  .score-result {
    min-height: 112px;
    border-top: 1px solid #e4ca69;
    border-right: 0;
    border-bottom: 1px solid #e4ca69;
    border-left: 0;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}
