:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #1a1e22;
  --panel-2: #22282d;
  --line: #364049;
  --text: #f4f7f5;
  --muted: #9eaaa5;
  --green: #70d083;
  --teal: #5ec9c3;
  --yellow: #f2bf62;
  --red: #ef6f6c;
  --ink: #0d1012;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 8%, rgba(94, 201, 195, 0.18), transparent 28%),
    linear-gradient(135deg, #101214 0%, #182024 52%, #111315 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.stage-panel,
.coach-panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(26, 30, 34, 0.88);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.stage-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  overflow: hidden;
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 52px);
  line-height: 0.95;
}

h2 {
  margin-bottom: 0;
  font-size: 24px;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(88px, 1fr));
  gap: 8px;
  min-width: 470px;
}

.stats div {
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #15191c;
}

.stats span,
.lesson-card span,
.target-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.stats strong {
  display: block;
  font-size: 18px;
}

.battlefield-wrap {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, #182226 0%, #101315 100%);
  background-size: 32px 32px, 32px 32px, auto;
}

#battlefield {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
}

.base {
  position: absolute;
  left: 20px;
  top: 50%;
  display: grid;
  gap: 8px;
  transform: translateY(-50%);
  pointer-events: none;
}

.base-core {
  width: 58px;
  height: 110px;
  border: 2px solid rgba(112, 208, 131, 0.8);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(112, 208, 131, 0.35), rgba(94, 201, 195, 0.1));
  box-shadow: 0 0 30px rgba(112, 208, 131, 0.28);
}

.base-label {
  max-width: 112px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.pause-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(10, 12, 14, 0.68);
  backdrop-filter: blur(8px);
}

.pause-overlay.hidden {
  display: none;
}

.pause-overlay h2 {
  font-size: clamp(28px, 5vw, 58px);
  line-height: 1;
}

.pause-overlay p {
  max-width: 560px;
  margin: 0 auto;
  color: #c5d0cc;
  line-height: 1.7;
}

.primary {
  width: max-content;
  min-width: 150px;
  margin: 4px auto 0;
  padding: 13px 20px;
  border-radius: 8px;
  background: var(--green);
  color: var(--ink);
  font-weight: 900;
}

.typing-panel {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #15191c;
}

.target-card,
.input-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #20262b;
}

.target-card {
  min-height: 82px;
  padding: 12px;
}

.target-card strong {
  display: block;
  font-size: 25px;
}

.target-card small {
  color: var(--yellow);
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 82px;
  padding: 0 18px;
  overflow: hidden;
  font-size: clamp(25px, 3.2vw, 44px);
  font-weight: 900;
}

.input-wrap input {
  position: absolute;
  inset: 0;
  width: 100%;
  border: 0;
  opacity: 0;
}

#typedPrefix {
  color: var(--green);
}

#typedRest {
  color: #5f6b66;
}

.input-wrap.wrong {
  border-color: rgba(239, 111, 108, 0.9);
  box-shadow: inset 0 0 0 1px rgba(239, 111, 108, 0.45);
}

.actions {
  display: grid;
  grid-template-columns: repeat(2, 54px);
  gap: 8px;
}

.actions button {
  border-radius: 8px;
  background: #283037;
  color: var(--text);
  font-size: 30px;
  font-weight: 800;
}

.coach-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  border-radius: 8px;
  padding: 20px;
}

.coach-header {
  padding-bottom: 8px;
}

.module-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111416;
}

.module-switch button {
  min-width: 0;
  padding: 10px 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.module-switch button.active {
  background: var(--green);
  color: var(--ink);
}

.module-switch button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.lesson-card,
.habit-card,
.level-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171b1f;
}

.lesson-card {
  padding: 16px;
}

.lesson-card strong {
  display: block;
  margin-bottom: 10px;
  font-size: 18px;
}

.lesson-card p,
.habit-card p {
  margin-bottom: 0;
  color: #c7d0cc;
  line-height: 1.65;
}

.keyboard {
  display: grid;
  width: 100%;
  max-width: 100%;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111416;
}

.key-row {
  display: grid;
  grid-template-columns: repeat(var(--count), minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}

.key-row.narrow {
  width: 72%;
}

.key {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  max-height: 34px;
  border: 1px solid #303941;
  border-radius: 6px;
  background: #242a30;
  color: #d6dedb;
  font-size: 12px;
  font-weight: 800;
}

.key-row.narrow .key {
  max-height: 32px;
}

.key.home {
  border-color: rgba(112, 208, 131, 0.8);
}

.key.active {
  background: var(--yellow);
  color: #15110b;
  transform: translateY(2px);
}

.key.next {
  background: var(--green);
  color: var(--ink);
  box-shadow: 0 0 18px rgba(112, 208, 131, 0.38);
}

.level-list {
  display: grid;
  gap: 8px;
}

.level-item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  color: var(--text);
  text-align: left;
}

.level-item:disabled {
  cursor: not-allowed;
}

.level-item .badge {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: #283037;
  color: var(--teal);
  font-weight: 900;
}

.level-item strong {
  display: block;
  margin-bottom: 2px;
}

.level-item span {
  color: var(--muted);
  font-size: 12px;
}

.level-item.current {
  border-color: rgba(112, 208, 131, 0.75);
  background: #202820;
}

.level-item.complete .badge {
  background: rgba(112, 208, 131, 0.18);
  color: var(--green);
}

.level-item.locked {
  opacity: 0.5;
}

.habit-card {
  padding: 16px;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stats {
    min-width: 0;
  }

  .coach-panel {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .typing-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .typing-panel {
    display: grid;
  }

  .actions {
    grid-template-columns: repeat(2, 1fr);
  }

  #battlefield,
  .battlefield-wrap {
    min-height: 360px;
  }

  .key-row {
    gap: 4px;
  }

  .keyboard {
    padding: 10px;
  }
}
