:root {
  color-scheme: light;
  --paper: #FFF9EF;
  --ink: #4B392F;
  --peach: #FFB38A;
  --mint: #9EDBC4;
  --sky: #8DCDF4;
  --sun: #FFD55C;
  --coral: #FA9381;
  --white: #fffefa;
  --line: #4B392F;
  --shadow: 0 7px 0 var(--ink);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input { font: inherit; }

button { cursor: pointer; }

button:focus-visible,
input:focus-visible,
.keyboard-scroll:focus-visible {
  outline: 4px solid var(--ink);
  outline-offset: 3px;
}

.sky-decor { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.cloud { position: absolute; width: 126px; height: 35px; border: 3px solid var(--ink); border-radius: 99px; background: var(--white); box-shadow: 0 4px 0 rgba(75, 57, 47, .12); }
.cloud::before,
.cloud::after { position: absolute; bottom: -3px; content: ""; border: 3px solid var(--ink); border-bottom: 0; background: var(--white); }
.cloud::before { left: 20px; width: 46px; height: 45px; border-radius: 45px 45px 0 0; }
.cloud::after { right: 16px; width: 54px; height: 58px; border-radius: 54px 54px 0 0; }
.cloud-one { top: 64px; left: -18px; transform: rotate(-4deg); }
.cloud-two { top: 190px; right: -30px; transform: rotate(3deg) scale(.72); }
.sparkle { position: absolute; color: var(--sun); font-size: 2rem; text-shadow: 2px 2px 0 var(--ink); animation: twinkle 2.4s ease-in-out infinite; }
.sparkle-one { top: 104px; right: 10%; }
.sparkle-two { top: 48%; left: 5%; font-size: 1.35rem; animation-delay: .6s; }
.dot { position: absolute; width: 18px; height: 18px; border: 3px solid var(--ink); border-radius: 50%; background: var(--mint); }
.dot-one { top: 36%; right: 7%; }
.dot-two { bottom: 12%; left: 8%; background: var(--peach); }

.adventure { width: min(100% - 32px, 960px); margin: 0 auto; padding: 32px 0 48px; }
.hero { margin-bottom: 28px; }
.eyebrow,
.round-label { margin: 0 0 7px; color: var(--ink); font-weight: 900; letter-spacing: .08em; }
.hero-copy { display: grid; grid-template-columns: 1fr minmax(140px, 220px); align-items: center; gap: 18px; }
h1,
h2,
h3,
p { overflow-wrap: anywhere; }
h1 { max-width: 13ch; margin: 0; font-size: clamp(2.35rem, 7vw, 4.4rem); line-height: 1; letter-spacing: -.055em; }
.hero-copy > div > p:last-child { max-width: 38rem; margin: 14px 0 0; font-size: clamp(1rem, 2.3vw, 1.2rem); font-weight: 700; line-height: 1.7; }
.mascot-stage { position: relative; min-height: 174px; }
.mascot { position: absolute; right: 0; bottom: -15px; width: min(100%, 220px); height: auto; filter: drop-shadow(0 8px 0 rgba(75, 57, 47, .14)); animation: bob 2.7s ease-in-out infinite; }

.game-card,
.target-panel,
.keyboard-panel,
.typing-field { border: 3px solid var(--line); border-radius: 28px; background: var(--white); box-shadow: var(--shadow); }
.game-card { padding: clamp(18px, 3vw, 28px); }
.game-card > h2 { margin: 0 0 17px; font-size: clamp(1.35rem, 3vw, 1.75rem); }

.mode-picker,
.level-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mode-button,
.level-button,
.primary-action,
.secondary-action { border: 3px solid var(--line); border-radius: 18px; color: var(--ink); font-weight: 900; box-shadow: 0 4px 0 var(--ink); transition: transform .16s ease, box-shadow .16s ease, background-color .16s ease; }
.mode-button { display: grid; min-height: 112px; padding: 13px; background: var(--peach); text-align: left; }
.mode-button:nth-child(2) { background: var(--sky); }
.mode-button span { color: rgba(75, 57, 47, .66); font-size: .78rem; font-weight: 900; letter-spacing: .08em; }
.mode-button strong { font-size: clamp(1.22rem, 3vw, 1.55rem); }
.mode-button small { font-size: .85rem; }
.mode-button.is-selected,
.level-button.is-selected { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); background: var(--sun); }
.mode-button:hover,
.level-button:hover,
.primary-action:hover,
.secondary-action:hover { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.level-picker { margin-top: 21px; }
.level-picker h3 { margin: 0 0 10px; font-size: 1rem; }
.level-button { min-height: 77px; padding: 9px; background: var(--mint); }
.level-button strong,
.level-button span { display: block; }
.level-button span { margin-top: 5px; font-size: .78rem; font-weight: 700; }

.selection-layout,
.practice-layout { display: grid; gap: 12px; }
.selection-layout .level-picker { margin-top: 0; }
.practice-layout > * { min-width: 0; }
.practice-layout .target-panel { grid-area: target; }
.practice-layout .typing-field { grid-area: typing; margin-top: 0; }
.practice-layout .stats { grid-area: stats; margin: 0; }
.practice-layout .status { grid-area: status; margin: 0; }
.practice-layout .keyboard-panel { grid-area: keyboard; margin-top: 0; }

.practice-area { margin-top: 28px; }
.round-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.progress-value { margin: 0; font-size: 1.28rem; font-weight: 900; }
.target-panel { padding: 16px; background: var(--peach); text-align: center; }
.target-label { margin: 0; font-size: .9rem; font-weight: 900; }
.current-target { min-height: 1.25em; margin: 5px 0; font-size: clamp(2.35rem, 8vw, 4.9rem); font-weight: 900; letter-spacing: .08em; line-height: 1.2; }
.next-key { margin: 0; font-weight: 800; }
kbd { display: inline-block; min-width: 2em; padding: 2px 8px; border: 2px solid var(--line); border-radius: 8px; background: var(--white); box-shadow: 0 2px 0 var(--ink); font-family: inherit; font-weight: 900; }

.keyboard-panel,
.typing-field { margin-top: 18px; padding: 14px; }
.keyboard-panel { background: var(--sky); }
.keyboard-title { margin: 0 0 12px; font-weight: 900; }
.keyboard-scroll { overflow-x: auto; padding: 3px 3px 8px; border-radius: 15px; }
.keyboard { display: grid; min-width: 620px; gap: 7px; }
.keyboard-row { display: flex; justify-content: center; gap: 7px; }
.keyboard-key { display: grid; place-items: center; width: 46px; min-width: 46px; min-height: 46px; padding: 3px; border: 2px solid var(--line); border-radius: 10px; background: var(--white); box-shadow: 0 3px 0 rgba(75, 57, 47, .64); text-align: center; }
.keyboard-key strong { font-size: 1.05rem; line-height: 1; }
.keyboard-key small { margin-top: 3px; color: var(--ink); font-size: .67rem; font-weight: 800; }
.keyboard-key.is-expected { border-color: var(--line); background: var(--sun); box-shadow: 0 0 0 4px var(--coral), 0 3px 0 var(--ink); animation: pulse 1s ease-in-out infinite; }
.typing-field { background: var(--mint); }
.typing-field label { display: block; margin-bottom: 8px; font-weight: 900; }
.typing-field input { width: 100%; min-height: 48px; padding: 0 12px; border: 3px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--white); font-size: 1rem; font-weight: 700; }
.field-help { margin: 8px 0 0; font-size: .86rem; font-weight: 700; line-height: 1.55; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin: 18px 0 0; }
.stat { padding: 13px 15px; border: 3px solid var(--line); border-radius: 19px; background: var(--white); box-shadow: 0 4px 0 var(--ink); }
.stat-correct { background: var(--mint); }
.stat-error { background: #ffd6cb; }
.stat dt { font-size: .85rem; font-weight: 800; }
.stat dd { margin: 2px 0 0; font-size: 1.65rem; font-weight: 900; }
.status { min-height: 1.5em; margin: 20px 0 0; padding: 12px 15px; border: 3px solid var(--line); border-radius: 16px; background: var(--paper); font-weight: 900; line-height: 1.5; }

.primary-action,
.secondary-action { min-height: 52px; padding: 10px 16px; }
.primary-action { width: 100%; background: var(--coral); }
.secondary-action { background: var(--white); }
button:disabled,
button:disabled:hover { cursor: not-allowed; opacity: .62; transform: none; box-shadow: 0 4px 0 var(--ink); }

@keyframes bob { 50% { transform: translateY(-7px) rotate(-2deg); } }
@keyframes twinkle { 50% { transform: scale(1.14) rotate(8deg); } }
@keyframes pulse { 50% { transform: translateY(-2px); } }

body.is-practicing .hero { margin-bottom: 14px; }
body.is-practicing .hero-copy { gap: 10px; }
body.is-practicing .mascot-stage { min-height: 104px; }
body.is-practicing .hero-copy > div > p:last-child { margin-top: 8px; line-height: 1.45; }

@media (min-width: 621px) and (max-width: 959.99px) {
  .adventure { width: min(100% - 28px, 960px); padding: 28px 0 44px; }
  .selection-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .practice-layout { grid-template-columns: minmax(190px, .8fr) minmax(0, 1.2fr); grid-template-areas: "target typing" "target stats" "target status" "keyboard keyboard"; }
  .game-card { padding: 20px; }
}

@media (min-width: 960px) {
  .adventure { width: min(100% - 40px, 1120px); padding: 24px 0 40px; }
  .selection-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .practice-area { margin-top: 18px; }
  .practice-layout { grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); grid-template-areas: "target typing" "target stats" "target status" "keyboard keyboard"; }
  .game-card { padding: 22px; }

  body.is-practicing .hero { margin-bottom: 8px; }
  body.is-practicing .hero-copy { grid-template-columns: 1fr 150px; gap: 6px; }
  body.is-practicing h1 { font-size: clamp(2rem, 4vw, 3.2rem); }
  body.is-practicing .hero-copy > div > p:last-child { margin-top: 4px; max-width: 28rem; font-size: .78rem; line-height: 1.2; }
  body.is-practicing .mascot-stage { min-height: 48px; }
  body.is-practicing .mascot { width: min(100%, 110px); bottom: -6px; }
  body.is-practicing .game-card { padding: 14px 16px; }
  body.is-practicing #practice-view > h2 { margin-bottom: 8px; font-size: 1.4rem; }
  body.is-practicing .practice-area { margin-top: 8px; }
  body.is-practicing .round-heading { gap: 8px; margin-bottom: 8px; }
  body.is-practicing .secondary-action { min-height: 44px; padding: 7px 12px; }
  body.is-practicing .practice-layout { gap: 8px; }
  body.is-practicing .target-panel { padding: 10px; }
  body.is-practicing .current-target { margin: 4px 0; font-size: clamp(2rem, 6vw, 3.4rem); }
  body.is-practicing .typing-field { padding: 10px 12px; }
  body.is-practicing .keyboard-panel { padding: 9px 12px; }
  body.is-practicing .typing-field label { margin-bottom: 4px; line-height: 1.2; }
  body.is-practicing .typing-field input { min-height: 42px; padding: 0 10px; }
  body.is-practicing .field-help { margin-top: 5px; font-size: .78rem; line-height: 1.25; }
  body.is-practicing .stats { gap: 8px; }
  body.is-practicing .stat { padding: 8px 12px; }
  body.is-practicing .stat dd { font-size: 1.45rem; }
  body.is-practicing .status { min-height: 0; padding: 8px 12px; line-height: 1.25; }
  body.is-practicing .keyboard-title { margin-bottom: 6px; line-height: 1.2; }
  body.is-practicing .keyboard-scroll { padding-bottom: 4px; }
  body.is-practicing .keyboard { gap: 5px; }
  body.is-practicing .keyboard-row { gap: 5px; }
  body.is-practicing .keyboard-key { width: 40px; min-width: 40px; min-height: 40px; padding: 2px; border-radius: 8px; }
  body.is-practicing .keyboard-key strong { font-size: .95rem; }
  body.is-practicing .keyboard-key small { margin-top: 2px; font-size: .6rem; }
}

@media (max-width: 620px) {
  .cloud-one { display: none; }
  .adventure { width: min(100% - 22px, 960px); padding-top: 27px; }
  .hero-copy { grid-template-columns: 1fr 118px; gap: 8px; }
  .mascot-stage { min-height: 114px; }
  .mascot { bottom: -8px; }
  .mode-picker,
  .level-buttons { grid-template-columns: 1fr; }
  .selection-layout,
  .practice-layout { grid-template-columns: 1fr; }
  .practice-layout { grid-template-areas: "target" "typing" "stats" "status" "keyboard"; gap: 10px; }
  .mode-button { min-height: 86px; }
  .round-heading { align-items: flex-start; flex-direction: column; }
  .current-target { font-size: clamp(2rem, 15vw, 3.5rem); }
  .game-card { padding: 17px; border-radius: 23px; }
  .keyboard-panel,
  .typing-field { padding: 14px; border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
