:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --surface: #fbfdfc;
  --surface-strong: #ffffff;
  --ink: #20302f;
  --muted: #66716f;
  --line: #d8ddd6;
  --teal: #137c72;
  --blue: #285f9f;
  --amber: #e9b949;
  --coral: #d95f52;
  --green: #4d8d5a;
  --body-gradient-start: rgba(255, 255, 255, 0.74);
  --body-gradient-end: rgba(244, 247, 246, 0.94);
  --active-bg: #e8f4f1;
  --mode-bg: #eef5f3;
  --mode-toggle-bg: #dfe9e5;
  --target-border: #cfd8d3;
  --input-bg: #ffffff;
  --progress-track-bg: #dfe5df;
  --score-bg: linear-gradient(180deg, #ffffff, #eef6ff);
  --key-bg: #ffffff;
  --key-border: #c9d3cf;
  --key-shadow: inset 0 -3px 0 rgba(32, 48, 47, 0.08);
  --home-bg: #e8f4f1;
  --correct-bg: rgba(77, 141, 90, 0.1);
  --wrong-bg: rgba(217, 95, 82, 0.16);
  --current-bg: rgba(233, 185, 73, 0.26);
  --key-current-bg: #ffe19b;
  --key-current-border: #b98611;
  --focus-ring: rgba(40, 95, 159, 0.28);
  --shadow: 0 10px 28px rgba(32, 48, 47, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111614;
  --surface: #18201d;
  --surface-strong: #202a26;
  --ink: #eef5f2;
  --muted: #a9b7b2;
  --line: #34423d;
  --teal: #53c2b5;
  --blue: #83b9f2;
  --amber: #f0c85a;
  --coral: #ff8b80;
  --green: #8bd19b;
  --body-gradient-start: rgba(41, 52, 48, 0.68);
  --body-gradient-end: rgba(17, 22, 20, 0.95);
  --active-bg: #1d3b36;
  --mode-bg: #202b27;
  --mode-toggle-bg: #121916;
  --target-border: #40504a;
  --input-bg: #111816;
  --progress-track-bg: #2c3834;
  --score-bg: linear-gradient(180deg, #202a26, #172433);
  --key-bg: #222c29;
  --key-border: #3b4944;
  --key-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
  --home-bg: #193a34;
  --correct-bg: rgba(139, 209, 155, 0.16);
  --wrong-bg: rgba(255, 139, 128, 0.18);
  --current-bg: rgba(240, 200, 90, 0.22);
  --key-current-bg: #5a4518;
  --key-current-border: #f0c85a;
  --focus-ring: rgba(131, 185, 242, 0.32);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.26);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--body-gradient-start), var(--body-gradient-end)),
    var(--bg);
}

button,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1320px, calc(100% - 28px));
  margin: 0 auto;
  padding: 14px 0 18px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.82rem;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.phase-badge,
.saved-status,
.theme-button,
.home-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.home-link {
  color: var(--text);
  text-decoration: none;
}

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

.theme-button {
  cursor: pointer;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(210px, 0.72fr) minmax(470px, 1.85fr) minmax(260px, 0.86fr);
  gap: 10px;
  align-items: stretch;
}

.lesson-panel,
.practice-panel,
.stats-panel,
.keyboard-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lesson-panel,
.stats-panel {
  padding: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.saved-status {
  min-height: 22px;
  padding: 0 7px;
  font-size: 0.68rem;
}

.lesson-list {
  display: grid;
  gap: 6px;
}

.lesson-button {
  width: 100%;
  min-height: 43px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.lesson-button strong,
.lesson-button span {
  display: block;
}

.lesson-button strong {
  font-size: 0.84rem;
  line-height: 1.2;
}

.lesson-button span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.7rem;
}

.lesson-button.active {
  border-color: var(--teal);
  background: var(--active-bg);
}

.lesson-button.completed {
  border-color: rgba(77, 141, 90, 0.55);
}

.practice-panel {
  display: grid;
  grid-template-rows: auto auto minmax(118px, auto) auto auto;
  gap: 9px;
  padding: 12px;
}

.practice-meta,
.mode-row,
.practice-footer,
.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.practice-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.mode-row {
  min-height: 34px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--mode-bg);
}

.mode-label {
  padding-left: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.mode-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  gap: 4px;
  padding: 2px;
  border-radius: 8px;
  background: var(--mode-toggle-bg);
}

.mode-button {
  min-height: 26px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.mode-button.active {
  background: var(--surface-strong);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(32, 48, 47, 0.12);
}

.target-text {
  min-height: 118px;
  padding: 12px;
  border: 1px solid var(--target-border);
  border-radius: 8px;
  background: var(--surface-strong);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 1.55rem;
  line-height: 1.42;
  outline: none;
}

.target-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0.64em;
  margin: 1px 0;
  border-bottom: 3px solid transparent;
  border-radius: 4px;
}

.target-char.space {
  min-width: 0.74em;
}

.target-char.correct {
  color: var(--green);
  background: var(--correct-bg);
}

.target-char.wrong {
  color: var(--coral);
  background: var(--wrong-bg);
  border-bottom-color: var(--coral);
}

.target-char.current {
  color: var(--ink);
  background: var(--current-bg);
  border-bottom-color: var(--amber);
}

.typing-input {
  width: 100%;
  min-height: 54px;
  max-height: 82px;
  resize: vertical;
  padding: 9px 12px;
  border: 1px solid var(--target-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.32;
  outline: none;
}

.typing-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(19, 124, 114, 0.16);
}

.feedback {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.feedback.good {
  color: var(--green);
}

.feedback.warn {
  color: var(--coral);
}

.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  max-width: min(420px, calc(100vw - 32px));
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 12px 30px rgba(32, 48, 47, 0.18);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.25;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 0s linear 160ms;
  visibility: hidden;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  visibility: visible;
}

.toast.good {
  border-left-color: var(--green);
}

.toast.warn {
  border-left-color: var(--coral);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 22, 20, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 22px 50px rgba(17, 22, 20, 0.28);
}

.modal h2 {
  margin: 0;
  font-size: 1.08rem;
}

.modal p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
  cursor: pointer;
}

.button.primary {
  background: var(--teal);
  color: #ffffff;
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface-strong);
  color: var(--ink);
}

.button.danger {
  border-color: rgba(210, 80, 65, 0.45);
  background: rgba(210, 80, 65, 0.12);
  color: var(--coral);
}

.button:focus-visible,
.lesson-button:focus-visible,
.mode-button:focus-visible,
.theme-button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.stat-block {
  min-height: 58px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

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

.stat-block strong {
  display: block;
  margin-top: 4px;
  font-size: 1.16rem;
  line-height: 1.1;
}

.score-block {
  border-color: rgba(40, 95, 159, 0.28);
  background: var(--score-bg);
}

.score-block strong {
  color: var(--blue);
}

.progress-block {
  grid-column: 1 / -1;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  font-size: 0.76rem;
  font-weight: 800;
}

.progress-track {
  height: 9px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--progress-track-bg);
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--blue);
  transition: width 180ms ease;
}

.level-progress-bar {
  background: var(--teal);
}

.keyboard-panel {
  margin-top: 10px;
  padding: 10px;
}

.keyboard {
  display: grid;
  gap: 6px;
  justify-items: center;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  width: 100%;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 34px;
  border: 1px solid var(--key-border);
  border-radius: 8px;
  background: var(--key-bg);
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-weight: 800;
  box-shadow: var(--key-shadow);
}

.key.home {
  border-color: rgba(19, 124, 114, 0.45);
  background: var(--home-bg);
}

.key.current {
  border-color: var(--key-current-border);
  background: var(--key-current-bg);
  transform: translateY(-2px);
}

.key.space-key {
  width: min(280px, 60%);
}

.app-footer {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .lesson-panel,
  .stats-panel {
    min-height: auto;
  }

  .lesson-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 1.8rem;
  }

  .lesson-list {
    grid-template-columns: 1fr;
  }

  .practice-panel {
    padding: 14px;
  }

  .target-text {
    min-height: 116px;
    padding: 14px;
    font-size: 1.45rem;
  }

  .practice-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-row {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-label {
    padding: 0 4px;
  }

  .mode-toggle {
    width: 100%;
  }

  .actions {
    justify-content: stretch;
  }

  .button {
    flex: 1 1 120px;
  }

  .toast {
    bottom: 10px;
    right: 9px;
    left: 9px;
    max-width: none;
  }

  .modal {
    padding: 16px;
  }

  .modal-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .modal-actions .button {
    width: 100%;
  }

  .key-row {
    gap: 4px;
  }

  .key {
    width: clamp(24px, 8vw, 31px);
    height: 36px;
    font-size: 0.84rem;
  }

  .key.space-key {
    width: 62%;
  }
}
