:root {
  --bg: #f3eee4;
  --paper: #fffaf2;
  --ink: #1c1814;
  --muted: #6d645a;
  --line: #e4d9ca;
  --accent: #0f6e62;
  --accent-2: #144f48;
  --soft: #dceee9;
  --danger: #b42318;
  --good: #2f7d4a;
  --shadow: 0 18px 50px rgba(40, 28, 16, 0.08);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: Outfit, ui-sans-serif, system-ui, sans-serif;
  --serif: Fraunces, "Iowan Old Style", Georgia, serif;
  --lp: #7c3aed;
  --lr: #2563eb;
  --lm: #0891b2;
  --li: #16a34a;
  --th: #78716c;
  --ri: #ca8a04;
  --rm: #ea580c;
  --rr: #e11d48;
  --rp: #db2777;
  --mark-glow: #173a52;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100dvh;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #efe4cf 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #d9ebe4 0%, transparent 50%),
    var(--bg);
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}

.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: var(--paper);
  padding: 8px 12px;
}

.top {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 1.25rem;
  align-items: center;
  padding: 0.65rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.mark {
  width: 2.65rem;
  height: 2.65rem;
  display: block;
  border-radius: 0.85rem;
  overflow: hidden;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--mark-glow) 28%, transparent);
  flex-shrink: 0;
  object-fit: cover;
  background: var(--mark-glow);
}

.mark svg,
.intro-mark svg,
.mark img,
.intro-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.name {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tag,
.kicker,
.hint-line,
.kb-note,
.fine {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.progress-block {
  min-width: 0;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.rail {
  height: 0.4rem;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.rail i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
}

.live-stats {
  display: flex;
  gap: 1rem;
  flex-shrink: 0;
}

.live-stats div {
  text-align: right;
  min-width: 4.6rem;
}

.live-stats span {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.live-stats strong {
  display: inline-block;
  min-width: 4.5ch;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: min(1080px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0.75rem 0 1rem;
}

.lesson-head {
  flex-shrink: 0;
}

.lesson-head h1 {
  font-family: var(--serif);
  font-size: clamp(1.45rem, 2.2vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  margin: 0.1rem 0 0.3rem;
}

.tip {
  max-width: 46rem;
  line-height: 1.45;
  color: var(--muted);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.trainer {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0.7rem 0;
  padding: 0.9rem 1.25rem 0.8rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.finger-hint {
  min-height: 1.35rem;
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.finger-hint i {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 99px;
  display: inline-block;
}

.text {
  font-family: var(--mono);
  font-size: clamp(1.15rem, 2vw, 1.5rem);
  line-height: 1.75;
  margin: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  outline: none;
}

.text.flash {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--danger) 55%, white);
  border-radius: 0.6rem;
}

.text span {
  border-radius: 0.2rem;
}

.text .sp {
  display: inline-block;
  width: 1ch;
}

.text .ok {
  color: color-mix(in srgb, var(--ink) 55%, var(--good));
}

.text .wait {
  color: color-mix(in srgb, var(--ink) 38%, var(--bg));
}

.text .now {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.hint-line {
  margin-top: 0.65rem;
  flex-shrink: 0;
}

.nav-row,
.kb-tools,
.dialog-actions {
  display: flex;
  gap: 0.7rem;
  flex-wrap: wrap;
  align-items: center;
}

.nav-row {
  justify-content: space-between;
  margin-top: 0.85rem;
  flex-shrink: 0;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.primary,
.ghost,
.icon-btn {
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.primary {
  background: var(--accent);
  color: #fff;
}

.primary:hover {
  background: var(--accent-2);
}

.ghost,
.icon-btn {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.layout-switch {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.layout-switch select {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
}

.icon-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.ghost:hover,
.icon-btn:hover {
  background: var(--paper);
}

.ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ghost.danger {
  color: var(--danger);
  width: calc(100% - 1.5rem);
  margin: 0.5rem 0.75rem 1rem;
}

.kb-section {
  margin-top: 0.7rem;
  flex-shrink: 0;
}

.kb-tools {
  justify-content: space-between;
  margin-bottom: 0.45rem;
  width: 100%;
}

.keyboard-wrap {
  overflow-x: auto;
  padding-bottom: 0.4rem;
}

.keyboard {
  user-select: none;
  width: 100%;
  margin: 0 auto;
  background:
    linear-gradient(180deg, #efe6d8 0%, #e2d6c6 100%);
  border: 1px solid color-mix(in srgb, var(--line) 70%, #c4b8a6);
  border-radius: 1.15rem;
  padding: 0.55rem 0.55rem 0.6rem;
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    inset 0 -1px 0 rgba(40, 28, 16, 0.06);
}

.kb-row {
  display: flex;
  gap: 0.22rem;
  margin-bottom: 0.22rem;
}

.kb-row:last-child {
  margin-bottom: 0;
}

.key {
  position: relative;
  min-width: 0;
  height: clamp(1.9rem, 3.4vh, 2.45rem);
  border-radius: 0.45rem;
  background: linear-gradient(180deg, #fffefb 0%, #f6f0e6 100%);
  border: 1px solid color-mix(in srgb, var(--line) 80%, #cfc3b2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.08rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink);
  box-shadow:
    0 1px 0 rgba(40, 28, 16, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.key.dim {
  opacity: 0.38;
}

.key.mod,
.key.space {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.key .glyph {
  line-height: 1;
  pointer-events: none;
  font-size: 0.95rem;
  font-weight: 600;
}

.key.bump .dot {
  position: absolute;
  left: 50%;
  bottom: 0.18rem;
  width: 0.7rem;
  height: 0.18rem;
  border-radius: 99px;
  background: var(--ink);
  opacity: 0.85;
  transform: translateX(-50%);
}

.key.bump.active .dot {
  background: #fff;
  opacity: 1;
}

.key.home {
  box-shadow:
    inset 0 -2px 0 color-mix(in srgb, currentColor 20%, transparent),
    0 1px 0 rgba(40, 28, 16, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.key.active {
  transform: translateY(1px);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(15, 110, 98, 0.25);
}

.intro-mark {
  width: 3.4rem;
  height: 3.4rem;
  border-radius: 1rem;
  overflow: hidden;
  margin-bottom: 0.85rem;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--mark-glow) 28%, transparent);
  object-fit: cover;
  display: block;
  background: var(--mark-glow);
}

.key.f-lp.active,
.key[data-finger="lp"].active { background: var(--lp); }
.key.f-lr.active,
.key[data-finger="lr"].active { background: var(--lr); }
.key.f-lm.active,
.key[data-finger="lm"].active { background: var(--lm); }
.key.f-li.active,
.key[data-finger="li"].active { background: var(--li); }
.key.f-th.active,
.key[data-finger="th"].active { background: var(--th); }
.key.f-ri.active,
.key[data-finger="ri"].active { background: var(--ri); }
.key.f-rm.active,
.key[data-finger="rm"].active { background: var(--rm); }
.key.f-rr.active,
.key[data-finger="rr"].active { background: var(--rr); }
.key.f-rp.active,
.key[data-finger="rp"].active { background: var(--rp); }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.38);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 10;
}

.overlay[hidden] {
  display: none;
}

.dialog {
  width: min(36rem, 100%);
  background: var(--paper);
  border-radius: 1.4rem;
  padding: 1.6rem 1.6rem 1.4rem;
  box-shadow: var(--shadow);
}

.dialog h2 {
  font-family: var(--serif);
  margin: 0.2rem 0 0.6rem;
  letter-spacing: -0.03em;
}

.lead {
  color: var(--muted);
  line-height: 1.55;
}

.steps {
  padding-left: 1.2rem;
  line-height: 1.55;
}

.steps li {
  margin: 0.4rem 0;
}

.dialog-actions {
  margin-top: 1.2rem;
  justify-content: flex-end;
}

.stars {
  margin: 0;
  color: var(--accent);
  letter-spacing: 0.2em;
  font-size: 1.2rem;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin: 1rem 0 0;
}

.result-stats div {
  background: var(--bg);
  border-radius: 0.8rem;
  padding: 0.7rem;
}

.result-stats dt {
  font-size: 0.75rem;
  color: var(--muted);
}

.result-stats dd {
  margin: 0.15rem 0 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.drawer {
  position: relative;
}

.drawer-backdrop {
  display: none;
}

.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(22rem, 92vw);
  background: var(--paper);
  border-left: 1px solid var(--line);
  transform: translateX(105%);
  transition: transform 0.22s ease;
  z-index: 8;
  overflow: auto;
}

.drawer.open .drawer-panel {
  transform: none;
}

.drawer.open .drawer-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(28, 24, 20, 0.25);
  z-index: 7;
}

.drawer-head {
  padding: 1.2rem 1.1rem 0.4rem;
}

.drawer-head h2 {
  margin: 0 0 0.3rem;
  font-family: var(--serif);
}

#lesson-list h3 {
  margin: 1rem 1.1rem 0.3rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.lesson-item {
  width: calc(100% - 1rem);
  margin: 0.15rem 0.5rem;
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0.6rem;
  padding: 0.45rem 0.5rem;
}

.lesson-item:hover,
.lesson-item.current {
  background: var(--soft);
}

.lesson-item .n {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lesson-item .s {
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.cookie-banner {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 15;
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0.9rem 1.1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow);
}

.cookie-banner[hidden] {
  display: none !important;
}

.cookie-copy {
  flex: 1 1 16rem;
}

.cookie-copy h2 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.cookie-banner p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.cookie-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .top {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "progress progress"
      "stats stats";
  }
  .brand { grid-area: brand; }
  .progress-block { grid-area: progress; }
  .live-stats { grid-area: stats; justify-content: space-between; }
  .header-actions { grid-area: actions; }
  .layout-label { display: none; }
  .key {
    height: 2.15rem;
    font-size: 0.68rem;
    border-radius: 0.38rem;
  }
  .key.mod,
  .key.space {
    font-size: 0.58rem;
  }
}

@media (max-width: 640px) {
  .keyboard {
    display: none;
  }
}

@media (max-height: 800px) {
  .hint-line {
    display: none;
  }
}

@media (max-height: 700px) {
  html,
  body {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }
  main {
    flex: none;
    padding-bottom: 1.5rem;
  }
  .trainer {
    flex: none;
  }
  .text {
    min-height: 6rem;
    overflow: visible;
  }
}
