:root {
  color-scheme: light;
  --sky: #9ee2ff;
  --sky-deep: #6dc9f1;
  --cream: #fff9e9;
  --paper: #fffef9;
  --panel: #ffffff;
  --panel-2: #f2edff;
  --input: #fffdf6;
  --line: #594d78;
  --line-soft: #cfc5e6;
  --text: #342b4d;
  --soft: #62577c;
  --muted: #857a9c;
  --accent: #ff6f61;
  --accent-dark: #d9514d;
  --yellow: #ffd75e;
  --blue: #59bff2;
  --green: #55c99c;
  --purple: #9b7de3;
  --success: #34ad7e;
  --danger: #e95262;
  --shadow: 0 9px 0 rgba(89, 77, 120, .18), 0 18px 42px rgba(71, 61, 103, .13);
  --z-dialog: 20;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #a7e3fb; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 10% 13%, rgba(255,255,255,.9) 0 4%, transparent 4.2%),
    radial-gradient(circle at 16% 13%, rgba(255,255,255,.9) 0 6%, transparent 6.2%),
    radial-gradient(circle at 22% 13%, rgba(255,255,255,.9) 0 4.5%, transparent 4.7%),
    radial-gradient(circle at 82% 21%, rgba(255,255,255,.78) 0 5%, transparent 5.2%),
    radial-gradient(circle at 89% 21%, rgba(255,255,255,.78) 0 7%, transparent 7.2%),
    linear-gradient(180deg, var(--sky) 0%, #d9f4ff 42%, #fff0c7 100%);
  background-attachment: fixed;
}
body::before, body::after { content: ""; position: fixed; inset: 0; pointer-events: none; }
body::before {
  opacity: .36;
  background-image: radial-gradient(#fff 1.5px, transparent 1.8px), radial-gradient(#ffe56c 1.4px, transparent 1.7px);
  background-position: 0 0, 20px 19px;
  background-size: 39px 39px;
}
body::after {
  top: auto;
  height: 110px;
  background: linear-gradient(170deg, transparent 44%, rgba(101,194,133,.28) 45% 64%, rgba(67,163,105,.32) 65%);
}

button, textarea { font: inherit; }
button:not(:disabled) { cursor: pointer; }
button:focus-visible, textarea:focus-visible, a:focus-visible { outline: 4px solid rgba(255, 111, 97, .35); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }
.tabular { font-variant-numeric: tabular-nums; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100% - 28px));
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px 0 24px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 254, 249, .91);
  box-shadow: 0 6px 0 rgba(89,77,120,.2);
  backdrop-filter: blur(12px);
}
.brand { width: fit-content; display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 43px; height: 43px;
  border: 3px solid var(--line); border-radius: 14px;
  background: var(--yellow); box-shadow: inset 0 -5px 0 rgba(221,154,38,.25);
  font-size: 22px; transform: rotate(-4deg);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; font-weight: 950; letter-spacing: .04em; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 750; }

.mode-switch { display: inline-flex; gap: 4px; padding: 5px; border: 2px solid var(--line-soft); border-radius: 18px; background: #ece7ff; }
.mode-button { min-width: 92px; min-height: 38px; padding: 0 14px; border: 0; border-radius: 13px; background: transparent; color: var(--soft); font-size: 12px; font-weight: 900; transition: transform 150ms ease, background 150ms ease; }
.mode-button:hover { transform: translateY(-2px); }
.mode-button.is-active { color: white; background: var(--purple); box-shadow: 0 4px 0 #6f55ae; }
.header-actions { display: flex; justify-content: flex-end; gap: 8px; }
.icon-button, .secondary-button, .primary-button {
  min-height: 38px; border: 2px solid var(--line); border-radius: 13px;
  color: var(--text); background: #fff; font-weight: 900;
  box-shadow: 0 4px 0 rgba(89,77,120,.22);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}
.icon-button:hover, .secondary-button:hover, .primary-button:hover { filter: brightness(1.03); transform: translateY(-1px); }
.icon-button:active, .secondary-button:active, .primary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(89,77,120,.2); }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; padding: 0; }
.icon-button svg { width: 19px; height: 19px; fill: currentColor; }
.icon-button[aria-pressed="true"] { color: #fff; border-color: var(--line); background: var(--accent); }
.secondary-button, .primary-button { padding: 0 14px; font-size: 11px; }
.primary-button { color: #fff; border-color: var(--line); background: var(--accent); box-shadow: 0 5px 0 var(--accent-dark); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: .45; filter: grayscale(.35); }

.practice-panel, .keyboard-panel { position: relative; border: 3px solid var(--line); border-radius: 27px; padding: 15px; box-shadow: var(--shadow); }
.practice-panel { background: rgba(255,254,249,.97); }
.keyboard-panel { min-height: 0; display: flex; flex-direction: column; background: rgba(229,255,242,.96); }
.practice-panel::before { content: "🦊"; position: absolute; z-index: 2; right: 21px; top: -31px; font-size: 43px; transform: rotate(8deg); filter: drop-shadow(0 4px 0 rgba(89,77,120,.2)); }
.keyboard-panel::before { content: "⭐"; position: absolute; right: 25px; bottom: 11px; font-size: 28px; transform: rotate(12deg); opacity: .8; }

.session-bar { display: grid; grid-template-columns: minmax(0,1fr) auto auto; align-items: center; gap: 18px; padding-right: 56px; }
.eyebrow { color: var(--purple); font: 950 9px/1 ui-monospace, monospace; letter-spacing: .1em; }
.session-title h1, .keyboard-heading h2 { margin: 4px 0 0; text-wrap: balance; font-size: 21px; line-height: 1.15; font-weight: 950; }
.session-title p { margin: 5px 0 0; color: var(--soft); font-size: 11px; font-weight: 650; text-wrap: pretty; }
.timer-block { min-width: 110px; padding: 8px 13px; border: 2px solid var(--line); border-radius: 17px; text-align: center; background: #fff4b8; box-shadow: inset 0 -5px 0 rgba(255,199,57,.18); }
.timer-block span { display: block; color: #77631e; font: 900 8px/1 ui-monospace, monospace; }
.timer-block strong { display: block; margin-top: 4px; color: var(--text); font: 950 27px/1 ui-monospace, monospace; }
.timer-block.is-running { animation: timerPulse 1.4s ease-in-out infinite; }
.timer-block.is-running strong { color: var(--danger); }
@keyframes timerPulse { 50% { transform: scale(1.035); } }
.session-actions { display: flex; gap: 8px; }

.course-strip { margin-top: 11px; min-height: 44px; display: grid; grid-template-columns: auto minmax(180px,1fr) auto auto; align-items: center; gap: 8px; padding: 7px; border: 2px dashed #9a86c7; border-radius: 16px; background: #f4efff; }
.course-strip[hidden] { display: none; }
.course-nav-button { min-width: 40px; padding-inline: 10px; }
.course-progress-wrap { min-width: 0; display: grid; grid-template-columns: minmax(100px,1fr) auto; align-items: center; gap: 10px; }
.course-progress-track { height: 10px; overflow: hidden; border: 2px solid var(--line); border-radius: 99px; background: #fff; }
.course-progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,var(--green),#8be2bd); }
.course-progress-wrap > span { color: var(--soft); font-size: 10px; font-weight: 850; white-space: nowrap; }

.sentence-card { min-height: 115px; margin-top: 12px; display: grid; grid-template-columns: 172px minmax(0,1fr); align-items: stretch; border: 3px solid var(--line); border-radius: 22px; background: var(--input); overflow: hidden; box-shadow: inset 0 -5px 0 rgba(89,77,120,.06); }
.sentence-meta { display: flex; flex-direction: column; justify-content: center; padding: 16px; border-right: 3px solid var(--line); background: linear-gradient(145deg,#ffd6d1,#ffe5a8); }
.speaker { color: #b83c49; font: 950 16px/1 ui-monospace, monospace; }
.scene { margin-top: 7px; color: #796150; font: 800 9px/1.45 ui-monospace, monospace; }
.sentence-copy { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.target-sentence { display: flex; flex-wrap: wrap; align-items: center; padding: 12px 20px 7px; color: var(--soft); font-size: clamp(21px,2.2vw,31px); font-weight: 800; line-height: 1.45; text-wrap: pretty; }
.sentence-translation { margin: 0; padding: 6px 20px 10px; border-top: 2px dashed #e1d9ed; color: var(--muted); font-size: 11px; font-weight: 650; line-height: 1.45; text-wrap: pretty; }
.target-char { border-radius: 5px; transition: transform 100ms ease, color 100ms ease, background 100ms ease; }
.target-char.is-correct { color: var(--success); }
.target-char.is-current { color: var(--text); background: var(--yellow); box-shadow: 0 3px 0 #d8a82d; transform: translateY(-2px); }
.target-char.is-wrong { color: #fff; background: var(--danger); animation: wrongShake 180ms ease; }
.target-char.is-pending { color: #9a90aa; }
@keyframes wrongShake { 33% { transform: translateX(-2px); } 66% { transform: translateX(2px); } }

.input-row { margin-top: 10px; display: grid; grid-template-columns: minmax(0,1fr) 200px; gap: 9px; }
.input-wrap { display: block; }
textarea { width: 100%; height: 50px; resize: none; overflow: hidden; border: 3px solid var(--line); border-radius: 16px; background: #fff; color: var(--text); padding: 10px 14px; font-size: 17px; font-weight: 750; line-height: 1.4; box-shadow: inset 0 -4px 0 rgba(89,77,120,.06); }
textarea::placeholder { color: #a69db3; }
textarea:disabled { opacity: .6; background: #eeeaf2; }
.input-status { min-height: 50px; display: flex; align-items: center; padding: 0 13px; border: 2px solid var(--line-soft); border-radius: 16px; color: var(--soft); background: #f3efff; font-size: 11px; font-weight: 800; }
.input-status.is-error { color: #b62d41; border-color: var(--danger); background: #ffe4e7; }
.input-status.is-success { color: #187b59; border-color: var(--success); background: #dcfaed; }

.metrics { margin-top: 10px; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)) minmax(220px,1.5fr); gap: 7px; }
.metrics > * { min-width: 0; padding: 9px 11px; border: 2px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 3px 0 rgba(89,77,120,.15); }
.metrics > *:nth-child(1) { background: #e5f5ff; }
.metrics > *:nth-child(2) { background: #fff0bc; }
.metrics > *:nth-child(3) { background: #def8eb; }
.metrics > *:nth-child(4) { background: #f1e7ff; }
.metrics span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; }
.metrics strong { display: block; margin-top: 2px; font-size: 18px; font-weight: 950; }
.metric-challenge { display: flex; flex-direction: column; justify-content: center; color: var(--text); text-decoration: none; background: #ffe0dc; }
.metric-challenge strong { color: #b83c49; font-size: 10px; line-height: 1.35; }
.metric-challenge:hover { transform: translateY(-1px); }

.speed-reference { margin-top: 9px; display: grid; grid-template-columns: minmax(0,1.8fr) minmax(260px,1fr); border: 2px dashed #9a86c7; border-radius: 15px; overflow: hidden; background: #f6f2ff; }
.speed-reference[hidden] { display: none; }
.speed-scale { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 13px; padding: 8px 11px; }
.speed-scale strong { width: 100%; color: var(--text); font-size: 9px; }
.speed-scale span { color: var(--soft); font-size: 9px; }
.speed-scale b { margin-right: 4px; color: var(--purple); }
.speed-reference p { margin: 0; display: flex; align-items: center; padding: 8px 11px; border-left: 2px dashed #c9bee3; color: var(--soft); background: #fff; font-size: 10px; font-weight: 700; line-height: 1.45; text-wrap: pretty; }
.speed-reference p.is-graduated { color: #187b59; background: #dcfaed; }

.keyboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.keyboard-heading h2 { font-size: 17px; }
.key-guide { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 9px; min-width: 216px; padding: 7px 11px; border: 2px solid var(--line); border-radius: 15px; background: #fff4b8; }
.key-guide span { color: #77631e; font-size: 9px; font-weight: 850; }
.key-guide strong { font-size: 19px; }
.key-guide small { grid-column: 1/-1; margin-top: 2px; color: var(--soft); font-size: 9px; font-weight: 700; }
.keyboard-stage { width: min(100%,1040px); min-height: 0; margin: auto; display: grid; grid-template-rows: auto minmax(90px,1fr); align-items: center; }
.keyboard { display: grid; gap: 5px; padding: 12px; border: 3px solid var(--line); border-radius: 23px; background: #d9d2ec; box-shadow: 0 7px 0 #9f92c1, inset 0 4px 0 rgba(255,255,255,.6); }
.key-row { display: flex; justify-content: center; gap: 5px; }
.key { flex: 0 1 56px; min-width: 29px; height: 36px; display: grid; place-items: center; border: 2px solid var(--line); border-bottom-width: 5px; border-radius: 9px; background: #fff; color: var(--text); font: 900 11px/1 ui-monospace, monospace; transition: transform 100ms ease, background 100ms ease, box-shadow 100ms ease; }
.key-row:nth-child(1) .key { background: #e4f4ff; }
.key-row:nth-child(2) .key { background: #fff2b9; }
.key-row:nth-child(3) .key { background: #dff8eb; }
.key-row:nth-child(4) .key { background: #ffe0dc; }
.key-row:nth-child(5) .key { background: #efe4ff; }
.key.is-target { color: #4d3810; border-color: #8d6815; background: var(--yellow) !important; box-shadow: 0 0 0 5px rgba(255,215,94,.42), 0 0 22px rgba(255,190,38,.6); transform: translateY(-2px); animation: keyBounce .8s ease-in-out infinite; }
.key.is-pressed { color: #fff; border-color: #96333c; background: var(--accent) !important; transform: translateY(3px); border-bottom-width: 2px; }
@keyframes keyBounce { 50% { transform: translateY(-5px); } }
.key.is-home::after { content: ""; width: 12px; height: 3px; margin-top: -8px; border-radius: 5px; background: var(--purple); }
.key-wide { flex-grow: 1.45; }
.key-space { flex-basis: 340px; max-width: 340px; }
.key-shift { flex-basis: 88px; }

.hands-guide { min-height: 0; display: flex; flex-direction: column; justify-content: center; }
.hands-guide svg { width: 100%; height: auto; overflow: visible; }
.hand .palm { fill: #ffcba7; stroke: #8a5970; stroke-width: 3; }
.hand .palm-detail { fill: none; stroke: #e39f83; stroke-width: 2; stroke-linecap: round; }
.hand .finger { fill: #ffd8b9; stroke: #8a5970; stroke-width: 2.5; transition: transform 140ms ease, opacity 140ms ease; }
.hand .finger.is-active { fill: var(--accent); stroke: #9f2e3a; filter: drop-shadow(0 0 7px rgba(255,111,97,.7)); }
.hands-guide p { margin: -3px 0 0; color: var(--soft); text-align: center; font-size: 10px; font-weight: 750; }

.result-dialog, .course-dialog { padding: 0; border: 3px solid var(--line); border-radius: 25px; background: var(--paper); color: var(--text); box-shadow: 0 12px 0 rgba(89,77,120,.24), 0 28px 70px rgba(50,39,79,.26); }
.result-dialog { width: min(520px,calc(100% - 28px)); }
.course-dialog { width: min(780px,calc(100% - 28px)); max-height: 82dvh; overflow: auto; }
.result-dialog::backdrop, .course-dialog::backdrop { background: rgba(73,61,105,.48); backdrop-filter: blur(7px); }
.result-head { padding: 24px; border-bottom: 2px dashed var(--line-soft); background: linear-gradient(135deg,#fff0b8,#ffd9d4); }
.result-head span, .course-dialog-head span { color: #b83c49; font: 900 9px/1 ui-monospace, monospace; }
.result-head h2 { margin: 6px 0 0; text-wrap: balance; font-size: 27px; }
.result-head p { margin: 8px 0 0; color: var(--soft); text-wrap: pretty; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 12px; }
.result-grid div { padding: 15px 18px; border: 2px solid var(--line); border-radius: 14px; background: #fff; }
.result-grid span { display: block; color: var(--muted); font-size: 9px; }
.result-grid strong { display: block; margin-top: 4px; font-size: 25px; }
.dialog-actions { display: flex; gap: 9px; padding: 10px 22px 22px; }
.course-dialog-head { position: sticky; top: 0; z-index: var(--z-dialog); display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 19px; border-bottom: 2px dashed var(--line-soft); background: #f1ecff; }
.course-dialog-head h2 { margin: 5px 0 0; font-size: 23px; text-wrap: balance; }
.course-dialog-head p { margin: 7px 0 0; color: var(--soft); font-size: 11px; text-wrap: pretty; }
.course-list { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 13px; }
.course-lesson { min-height: 86px; display: grid; grid-template-columns: 44px minmax(0,1fr) auto; align-items: center; gap: 10px; padding: 10px; border: 2px solid var(--line-soft); border-radius: 16px; background: #fff; color: var(--text); text-align: left; box-shadow: 0 3px 0 rgba(89,77,120,.1); }
.course-lesson:not(:disabled) { cursor: pointer; }
.course-lesson:hover:not(:disabled) { border-color: var(--purple); transform: translateY(-1px); }
.course-lesson.is-current { border-color: var(--accent); background: #fff1ef; }
.course-lesson.is-complete { border-color: var(--success); background: #e6faef; }
.course-lesson:disabled { opacity: .48; cursor: not-allowed; }
.lesson-number { display: grid; place-items: center; min-height: 40px; border: 2px solid var(--line); border-radius: 12px; color: var(--text); background: var(--yellow); font: 900 11px/1 ui-monospace, monospace; }
.lesson-copy { min-width: 0; }
.lesson-copy span { display: block; color: var(--muted); font-size: 8px; }
.lesson-copy strong { display: block; margin-top: 4px; font-size: 12px; }
.lesson-copy small { display: block; margin-top: 4px; color: var(--soft); font-size: 9px; line-height: 1.35; }
.lesson-status { color: var(--muted); font-size: 9px; white-space: nowrap; }
.course-lesson.is-complete .lesson-status { color: #187b59; }

@media (min-width: 781px) and (max-height: 800px) {
  .app-shell { gap: 9px; padding-top: 8px; }
  .topbar { min-height: 54px; padding-block: 5px; }
  .brand-mark { width: 37px; height: 37px; }
  .practice-panel, .keyboard-panel { padding: 10px 13px; }
  .practice-panel::before { font-size: 35px; top: -25px; }
  .sentence-card { min-height: 82px; margin-top: 7px; }
  .sentence-meta { padding-block: 10px; }
  .target-sentence { padding-block: 7px 4px; font-size: clamp(19px,1.8vw,25px); }
  .sentence-translation { padding-block: 3px 6px; }
  .input-row, .metrics, .speed-reference { margin-top: 6px; }
  textarea, .input-status { height: 39px; min-height: 39px; padding-block: 6px; }
  .metrics > * { padding-block: 6px; }
  .speed-scale, .speed-reference p { padding-block: 5px; }
  .keyboard-heading { margin-bottom: 5px; }
  .keyboard-stage { grid-template-rows: auto 74px; }
  .keyboard { gap: 2px; padding: 7px; }
  .key-row { gap: 3px; }
  .key { height: 28px; border-bottom-width: 3px; }
  .hands-guide svg { height: 61px; }
  .hands-guide p { margin-top: 0; }
}

@media (max-width: 780px) {
  body { background-attachment: scroll; }
  .app-shell { width: min(100% - 14px,1240px); display: block; padding-top: 8px; }
  .topbar { grid-template-columns: 1fr auto; gap: 9px; margin-bottom: 10px; border-radius: 20px; }
  .mode-switch { grid-row: 2; grid-column: 1/-1; justify-self: stretch; margin-bottom: 2px; }
  .mode-button { flex: 1; min-width: 0; padding-inline: 7px; }
  .brand small { display: none; }
  .practice-panel, .keyboard-panel { padding: 11px; margin-bottom: 10px; border-radius: 23px; }
  .practice-panel::before { right: 13px; top: -24px; font-size: 35px; }
  .session-bar { grid-template-columns: 1fr auto; gap: 10px; padding-right: 0; }
  .session-title { padding-right: 39px; }
  .session-actions { grid-column: 1/-1; }
  .session-actions > * { flex: 1; }
  .course-strip { grid-template-columns: auto minmax(0,1fr) auto; }
  .course-strip #courseCatalogButton { grid-row: 2; grid-column: 1/-1; }
  .course-progress-wrap { grid-template-columns: 1fr; gap: 5px; }
  .sentence-card { grid-template-columns: 1fr; }
  .sentence-meta { border-right: 0; border-bottom: 3px solid var(--line); padding: 10px 13px; }
  .target-sentence { min-height: 82px; padding: 11px 12px 7px; font-size: 20px; }
  .sentence-translation { padding: 6px 12px 9px; }
  .input-row { grid-template-columns: 1fr; }
  .input-status { min-height: 38px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-challenge { grid-column: 1/-1; }
  .speed-reference { grid-template-columns: 1fr; }
  .speed-reference p { border-left: 0; border-top: 2px dashed #c9bee3; }
  .keyboard-heading { align-items: flex-start; }
  .key-guide { min-width: 168px; }
  .keyboard { gap: 3px; padding: 6px; border-radius: 16px; }
  .key-row { gap: 2px; }
  .key { min-width: 19px; height: 35px; border-width: 1.5px; border-bottom-width: 4px; border-radius: 6px; font-size: 8px; }
  .key-space { flex-basis: 180px; }
  .key-shift { flex-basis: 50px; }
  .hands-guide svg { height: auto; max-height: none; }
  .course-list { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .brand strong { font-size: 14px; }
  .brand-mark { width: 37px; height: 37px; font-size: 18px; }
  .header-actions .secondary-button { padding-inline: 9px; }
  .timer-block { min-width: 94px; padding-inline: 8px; }
  .timer-block strong { font-size: 23px; }
  .session-title h1 { font-size: 18px; }
  .key-guide { min-width: 145px; }
  .key-guide small { max-width: 125px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
