:root {
  color-scheme: light;
  --bg: #f3f4ef;
  --surface: #fffefb;
  --surface-soft: #f7f8f4;
  --text: #1e2722;
  --muted: #7d857f;
  --faint: #c5cac6;
  --line: #e2e6e1;
  --accent: #2d7f5c;
  --accent-soft: #e6f3ec;
  --danger: #d45d4d;
  --danger-soft: #ffebe7;
  --shadow: 0 22px 65px rgba(30, 45, 36, 0.09);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141815;
  --surface: #1c221e;
  --surface-soft: #202722;
  --text: #edf2ee;
  --muted: #99a29b;
  --faint: #515a53;
  --line: #303832;
  --accent: #69c99a;
  --accent-soft: #263e33;
  --danger: #ff8c7b;
  --danger-soft: #462d29;
  --shadow: 0 22px 65px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 12% 10%, rgba(61, 146, 106, 0.07), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea {
  font: inherit;
}

.home-link {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 5;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  backdrop-filter: blur(8px);
}

.home-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.keyboard-toggle {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 5;
  display: inline-flex;
  min-height: 34px;
  gap: 7px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  backdrop-filter: blur(8px);
}

.keyboard-toggle:hover,
.keyboard-toggle:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.keyboard-toggle b {
  font-size: inherit;
}

.focus-shell {
  display: grid;
  width: 100%;
  min-height: 100dvh;
  padding: clamp(10px, 2.2vw, 24px);
  place-items: center;
}

.practice-card {
  display: flex;
  width: min(100%, 980px);
  height: min(720px, calc(100dvh - clamp(20px, 4.4vw, 48px)));
  min-height: 570px;
  overflow: hidden;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.typing-panel {
  position: relative;
  min-height: 0;
  flex: 1 1 33.333%;
}

.typing-area {
  position: relative;
  display: flex;
  height: 100%;
  min-height: 0;
  align-items: center;
  padding: clamp(24px, 4vh, 38px) clamp(28px, 7vw, 76px);
  cursor: text;
  outline: none;
}

.typing-area:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.prompt {
  width: 100%;
  margin: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(21px, 2.7vw, 28px);
  line-height: 1.75;
  letter-spacing: 0.012em;
}

.char {
  border-radius: 3px;
  color: var(--faint);
  transition: color 80ms ease, background-color 80ms ease;
}

.char.correct {
  color: var(--text);
}

.char.incorrect {
  background: var(--danger-soft);
  color: var(--danger);
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.char.current {
  position: relative;
}

.char.current::after {
  position: absolute;
  right: 0;
  bottom: -4px;
  left: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  content: "";
  animation: blink 1s steps(2, jump-none) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.start-hint {
  position: absolute;
  right: 0;
  bottom: 14px;
  left: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 11px;
  transition: opacity 150ms ease;
}

.start-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

.key-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-soft);
  font-size: 10px;
}

.result[hidden] {
  display: none;
}

.result {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.keyboard-panel {
  min-height: 0;
  flex: 2 1 66.667%;
  padding: 18px clamp(16px, 4vw, 38px) 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.finger-guide {
  display: flex;
  min-height: 52px;
  gap: 12px;
  align-items: center;
  width: min(100%, 820px);
  margin: 0 auto 16px;
}

.next-key {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--accent);
  border-bottom-width: 3px;
  border-radius: 9px;
  background: var(--surface);
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
}

.guide-copy {
  display: flex;
  min-width: 96px;
  flex-direction: column;
}

.guide-copy span {
  color: var(--muted);
  font-size: 9px;
}

.guide-copy strong {
  font-size: 13px;
}

.guide-arrow {
  color: var(--accent);
}

.guide-home {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.keyboard-status {
  overflow: hidden;
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keyboard-status.error {
  color: var(--danger);
  font-weight: 700;
}

.virtual-keyboard {
  display: flex;
  width: min(100%, 820px);
  flex-direction: column;
  gap: 8px;
  margin: 0 auto;
}

.keyboard-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.keyboard-row:nth-child(2) {
  padding: 0 20px;
}

.keyboard-row:nth-child(3) {
  padding: 0 52px;
}

.virtual-key {
  position: relative;
  display: grid;
  height: 48px;
  flex: 1 1 0;
  place-items: center;
  border: 1px solid var(--line);
  border-top-color: var(--finger-color, var(--line));
  border-bottom-width: 2px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--finger-color, var(--surface)) 6%, var(--surface));
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  transition: 100ms ease;
}

.virtual-key.home::after {
  position: absolute;
  bottom: 4px;
  width: 9px;
  height: 1px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  opacity: 0.45;
}

.virtual-key.space {
  max-width: 350px;
  flex-basis: 350px;
  text-transform: none;
}

.virtual-key.target {
  z-index: 1;
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent);
  color: #fff;
  transform: translateY(-2px);
}

.virtual-key.wrong {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  animation: key-wrong 180ms ease 2;
}

@keyframes key-wrong {
  50% { transform: translateY(2px); }
}

.finger-group-left-pinky { --finger-color: #df6c62; }
.finger-group-left-ring { --finger-color: #e5944c; }
.finger-group-left-middle { --finger-color: #b89a3c; }
.finger-group-left-index { --finger-color: #5fa66c; }
.finger-group-right-index { --finger-color: #3d9b91; }
.finger-group-right-middle { --finger-color: #4c8fc5; }
.finger-group-right-ring { --finger-color: #716fc2; }
.finger-group-right-pinky { --finger-color: #a56db2; }
.finger-group-thumb { --finger-color: var(--accent); }

.compact-hands {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  gap: 14px;
  align-items: center;
  width: min(100%, 820px);
  margin: 18px auto 0;
}

.hand-strip {
  display: flex;
  gap: 6px;
  align-items: end;
}

.left-strip {
  justify-content: flex-end;
}

.right-strip {
  justify-content: flex-start;
}

.hand-name {
  align-self: center;
  padding: 0 3px;
  color: var(--muted);
  font-size: 10px;
}

.finger-marker {
  display: flex;
  width: 39px;
  height: 50px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--finger-color);
  border-radius: 17px 17px 8px 8px;
  background: color-mix(in srgb, var(--finger-color) 12%, var(--surface));
  color: color-mix(in srgb, var(--finger-color) 80%, var(--text));
  transition: 120ms ease;
}

.finger-marker.index { height: 58px; }
.finger-marker.middle { height: 64px; }
.finger-marker.ring { height: 58px; }
.finger-marker.pinky { height: 50px; }
.finger-marker.thumb {
  width: 50px;
  height: 40px;
  border-radius: 17px;
}

.finger-marker b {
  font-size: 10px;
}

.finger-marker small {
  margin-top: 2px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 7px;
}

.finger-marker.active {
  z-index: 2;
  background: var(--finger-color);
  box-shadow: 0 5px 12px color-mix(in srgb, var(--finger-color) 35%, transparent);
  color: #fff;
  transform: translateY(-5px);
}

.mapping-center {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.mapping-center strong {
  font-size: 11px;
}

.mapping-center i {
  color: var(--accent);
  font-size: 13px;
  font-style: normal;
}

.mapping-center > b {
  display: grid;
  min-width: 44px;
  height: 34px;
  padding: 0 7px;
  place-items: center;
  border: 1px solid var(--accent);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 10px;
}

.typing-input {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

@media (max-width: 720px) {
  .home-link {
    top: 10px;
    left: 10px;
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
  }

  .home-link span {
    display: none;
  }

  .keyboard-toggle {
    top: 10px;
    right: 10px;
    min-height: 34px;
  }

  .focus-shell {
    display: block;
    padding: 0;
  }

  .practice-card {
    width: 100%;
    height: 100dvh;
    min-height: 560px;
    border: 0;
    border-radius: 0;
  }

  .typing-area {
    padding: 28px 22px 42px;
  }

  .prompt {
    font-size: clamp(18px, 5vw, 23px);
    line-height: 1.65;
  }

  .keyboard-panel {
    overflow-x: auto;
    padding-right: 12px;
    padding-left: 12px;
  }

  .finger-guide,
  .virtual-keyboard,
  .compact-hands {
    min-width: 560px;
  }

  .keyboard-status {
    display: none;
  }
}

@media (max-height: 650px) and (min-width: 721px) {
  .practice-card {
    min-height: 540px;
  }

  .typing-area {
    min-height: 190px;
    padding-top: 26px;
    padding-bottom: 38px;
  }

  .prompt {
    font-size: 21px;
    line-height: 1.6;
  }

  .virtual-key {
    height: 31px;
  }

  .finger-marker {
    height: 34px;
  }

  .finger-marker.index,
  .finger-marker.ring { height: 39px; }
  .finger-marker.middle { height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
