:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #1d2530;
  --muted: #697386;
  --line: #d9e1ec;
  --accent: #1b8a7a;
  --accent-strong: #0f6e62;
  --warn: #d95f3d;
  --key: #ffffff;
  --key-shadow: #b7c4d4;
  --left-index: #4f80ff;
  --left-middle: #7b61ff;
  --left-ring: #b45ad4;
  --left-pinky: #c1488b;
  --right-index: #19a974;
  --right-middle: #e0a300;
  --right-ring: #e56b6f;
  --right-pinky: #2b9fd8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1160px, calc(100vw - 32px));
  height: 100svh;
  margin: 0 auto;
  padding: 14px 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 10px;
}

.topbar,
.practice-panel,
.stats-row,
.keyboard-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(35, 54, 82, 0.08);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 14px 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 2.6vw, 1.9rem);
}

.lesson-picker {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

#modeSelect {
  min-width: 260px;
  height: 40px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #e8f7f4;
  color: var(--accent-strong);
  cursor: pointer;
  padding: 0 12px;
  font-weight: 800;
}

.secondary-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
  color: var(--ink);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 700;
}

.secondary-button:hover {
  border-color: var(--accent);
  background: #e8f7f4;
  color: var(--accent-strong);
}

.practice-panel {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  padding: 16px 20px;
}

.prompt-area {
  min-width: 0;
}

.prompt-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.95rem;
}

.prompt {
  min-height: 92px;
  display: grid;
  place-items: center;
  font-size: clamp(3.4rem, 8vw, 6rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  overflow-wrap: anywhere;
}

.prompt.sequence {
  align-content: center;
  font-size: clamp(1.7rem, 3.6vw, 3.2rem);
  line-height: 1.2;
}

.roman {
  min-height: 36px;
  color: var(--accent-strong);
  font-size: 1.65rem;
  font-weight: 900;
  text-align: center;
  overflow-wrap: anywhere;
}

.roman .done {
  color: #95a1b2;
}

.roman .next {
  color: var(--warn);
  text-decoration: underline;
  text-underline-offset: 6px;
}

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

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 120ms ease;
}

.input-area {
  align-self: center;
}

.input-area label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 800;
}

#typingInput {
  width: 100%;
  height: 46px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  font-size: 1.25rem;
  font-weight: 800;
  outline: none;
}

#typingInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(27, 138, 122, 0.14);
}

.feedback {
  min-height: 24px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.feedback.good {
  color: var(--accent-strong);
  font-weight: 800;
}

.feedback.bad {
  color: var(--warn);
  font-weight: 800;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  align-items: stretch;
  gap: 10px;
  padding: 10px;
}

.stat {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  background: #fbfcff;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 1px;
  font-size: 1.35rem;
}

.keyboard-section {
  min-height: 0;
  padding: 14px 20px 12px;
  overflow: hidden;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 10px;
}

.section-head h2 {
  font-size: 1.25rem;
}

.section-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.88rem;
}

.layout-note {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.keyboard {
  position: relative;
  display: grid;
  gap: 7px;
  overflow-x: visible;
  padding-bottom: 4px;
  justify-content: center;
}

.key-row {
  display: flex;
  gap: 8px;
  min-width: 0;
  justify-content: center;
}

.key-row.home {
  padding-left: 48px;
}

.key-row.bottom {
  padding-left: 56px;
}

.key {
  position: relative;
  z-index: 2;
  flex: 0 0 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-bottom: 4px solid var(--key-shadow);
  border-radius: 8px;
  background: var(--key);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-size: 1.08rem;
  font-weight: 900;
  transition: transform 80ms ease, background 80ms ease, border-color 80ms ease;
}

.keyboard-boundaries {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: visible;
}

.keyboard-boundary {
  fill: none;
  stroke: #ff1f1f;
  stroke-width: 3;
  stroke-linecap: square;
  stroke-linejoin: miter;
  vector-effect: non-scaling-stroke;
}

.key.wide {
  flex-basis: 78px;
}

.key.space {
  flex-basis: 286px;
}

.key::after {
  content: attr(data-finger);
  position: absolute;
  bottom: 4px;
  font-size: 0.5rem;
  color: var(--muted);
  font-weight: 800;
}

.key.rest::before {
  content: "";
  position: absolute;
  top: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.key.active {
  transform: translateY(3px);
  border-bottom-width: 1px;
  background: #fff7e8;
  border-color: #f2b84b;
}

.key.correct {
  background: #e8f7f4;
  border-color: var(--accent);
}

.key.dormant,
.key.kana-muted {
  visibility: visible;
  opacity: 0.28;
  filter: grayscale(0.25);
}

.key.lesson-key,
.key.chord-key,
.key.target {
  opacity: 1;
  filter: none;
}

.key.left-index,
.finger.left-index {
  color: var(--left-index);
}

.key.left-index {
  background: color-mix(in srgb, var(--left-index) 16%, white);
  border-color: color-mix(in srgb, var(--left-index) 45%, var(--line));
}

.key.left-middle,
.finger.left-middle {
  color: var(--left-middle);
}

.key.left-middle {
  background: color-mix(in srgb, var(--left-middle) 16%, white);
  border-color: color-mix(in srgb, var(--left-middle) 45%, var(--line));
}

.key.left-ring,
.finger.left-ring {
  color: var(--left-ring);
}

.key.left-ring {
  background: color-mix(in srgb, var(--left-ring) 16%, white);
  border-color: color-mix(in srgb, var(--left-ring) 45%, var(--line));
}

.key.left-pinky,
.finger.left-pinky {
  color: var(--left-pinky);
}

.key.left-pinky {
  background: color-mix(in srgb, var(--left-pinky) 16%, white);
  border-color: color-mix(in srgb, var(--left-pinky) 45%, var(--line));
}

.key.right-index,
.finger.right-index {
  color: var(--right-index);
}

.key.right-index {
  background: color-mix(in srgb, var(--right-index) 16%, white);
  border-color: color-mix(in srgb, var(--right-index) 45%, var(--line));
}

.key.right-middle,
.finger.right-middle {
  color: var(--right-middle);
}

.key.right-middle {
  background: color-mix(in srgb, var(--right-middle) 18%, white);
  border-color: color-mix(in srgb, var(--right-middle) 45%, var(--line));
}

.key.right-ring,
.finger.right-ring {
  color: var(--right-ring);
}

.key.right-ring {
  background: color-mix(in srgb, var(--right-ring) 16%, white);
  border-color: color-mix(in srgb, var(--right-ring) 45%, var(--line));
}

.key.right-pinky,
.finger.right-pinky {
  color: var(--right-pinky);
}

.key.right-pinky {
  background: color-mix(in srgb, var(--right-pinky) 16%, white);
  border-color: color-mix(in srgb, var(--right-pinky) 45%, var(--line));
}

.key.target {
  z-index: 4;
  outline: 5px solid rgba(255, 212, 74, 0.55);
  border-color: #ff6b2b;
  background: #fff2a8;
  box-shadow:
    0 0 0 3px rgba(255, 107, 43, 0.22),
    0 0 18px rgba(255, 196, 0, 0.65),
    0 8px 18px rgba(35, 54, 82, 0.14);
  transform: translateY(-2px);
}

.key.chord-key {
  z-index: 3;
  outline: 3px solid rgba(255, 212, 74, 0.42);
  border-color: #f5b936;
  background: #fff8c8;
  box-shadow: 0 0 14px rgba(255, 210, 58, 0.5);
}

.key.current-key::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 4px solid #ff3b30;
  border-radius: 999px;
  z-index: 2;
  pointer-events: none;
}

.key.rest.current-key::before {
  inset: 6px;
  width: auto;
  height: auto;
  background: transparent;
}

.finger-legend {
  display: none;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

@media (min-height: 900px) {
  .finger-legend {
    display: flex;
  }
}

.finger-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.finger {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100svh;
  }

  .topbar,
  .section-head {
    display: block;
  }

  .lesson-picker {
    margin-top: 12px;
  }

  #modeSelect {
    width: 100%;
    min-width: 0;
  }

  .practice-panel {
    grid-template-columns: 1fr;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .secondary-button {
    grid-column: 1 / -1;
  }

  .layout-note {
    margin-top: 12px;
  }
}

@media (max-height: 820px) and (min-width: 861px) {
  .app-shell {
    width: min(1120px, calc(100vw - 24px));
    padding: 8px 0;
    gap: 8px;
  }

  .topbar {
    padding: 10px 16px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.45rem;
  }

  .practice-panel {
    padding: 12px 16px;
  }

  .prompt {
    min-height: 70px;
    font-size: 4.3rem;
  }

  .roman {
    min-height: 30px;
    font-size: 1.35rem;
  }

  .stats-row {
    padding: 8px;
  }

  .stat {
    min-height: 48px;
  }

  .keyboard-section {
    padding: 10px 16px;
  }

  .section-head {
    margin-bottom: 8px;
  }

  .section-head p,
  .finger-legend {
    display: none;
  }

  .key-row {
    min-width: 0;
  }

  .key.wide {
    flex-basis: 78px;
  }

  .key.space {
    flex-basis: 280px;
  }
}
