:root {
  color-scheme: light;
  --ink: #1d2433;
  --muted: #657087;
  --line: #d9dee8;
  --panel: #ffffff;
  --canvas: #f3f5f8;
  --accent: #1f6f5c;
  --accent-2: #9b2f3f;
  --gold: #bd8d2f;
  --green-soft: #e2f0eb;
  --amber-soft: #fbf1de;
  --red-soft: #f7e4e7;
  --shadow: 0 14px 40px rgba(29, 36, 51, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(31, 111, 92, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(155, 47, 63, 0.05) 1px, transparent 1px),
    var(--canvas);
  background-size: 32px 32px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1, .hero h2, .panel h3, .module h3 { margin: 0; letter-spacing: 0; }
.topbar h1 { font-size: 28px; line-height: 1.1; }

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

.topbar-meta {
  display: grid;
  gap: 4px;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  gap: 18px;
  padding: 18px;
}

.sidebar, .rightbar {
  display: grid;
  align-content: start;
  gap: 14px;
  position: sticky;
  top: 96px;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

.sidebar { grid-column: 1; }
.content { grid-column: 2; }
.rightbar { grid-column: 3; }

.panel, .module, .practice, .hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel { padding: 16px; }
.panel.tight { padding: 12px; }
.search-row input { width: 100%; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.filters button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font-weight: 700;
  font-size: 12px;
}
.filters button.active { border-color: var(--accent); background: var(--green-soft); }
.status-filters { margin-top: 8px; }

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

.unit-card {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 11px 12px;
  text-align: left;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.unit-card.active { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.unit-card .group-tag { color: var(--accent-2); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.unit-card small { color: var(--muted); line-height: 1.3; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badges span { border-radius: 999px; padding: 3px 7px; font-size: 10px; font-weight: 800; }
.badges span.unknown { background: var(--red-soft); color: var(--accent-2); }
.badges span.fuzzy { background: var(--amber-soft); color: #8a6414; }
.badges span.known { background: var(--green-soft); color: var(--accent); }

.content { display: grid; gap: 16px; min-width: 0; }

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 140px;
  padding: 26px;
  background: linear-gradient(135deg, rgba(31, 111, 92, 0.12), rgba(189, 141, 47, 0.12)), #fff;
}

.hero h2 { font-size: 44px; line-height: 1.1; margin: 6px 0; letter-spacing: 0.01em; }
.hero .phonetic { margin: 0 0 4px; color: var(--accent); font-size: 17px; font-weight: 700; font-family: "Cambria Math", Charis, Georgia, serif; }
.hero p:last-child { max-width: 760px; margin: 0; color: #465064; font-size: 15px; }

.card-nav { display: grid; justify-items: center; gap: 8px; }
.card-nav button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 8px 12px;
  font-weight: 700;
}
.card-nav span { color: var(--muted); font-size: 12px; font-weight: 800; }

.reveal-card { padding: 26px; display: grid; gap: 16px; justify-items: center; text-align: center; }

.reveal-btn {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 14px 28px;
  font-weight: 800;
  font-size: 15px;
}

#revealContent { width: 100%; display: grid; gap: 14px; text-align: left; }

.def-block { border-top: 1px solid var(--line); padding-top: 10px; }
.def-block h4 { margin: 0 0 4px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.def-block p { margin: 0; color: #3f4859; line-height: 1.6; }

.status-actions { padding: 18px; }
.status-buttons { display: flex; gap: 10px; justify-content: center; }
.status-btn {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  font-weight: 800;
  background: #fff;
}
.status-btn.unknown { border-color: var(--accent-2); color: var(--accent-2); }
.status-btn.unknown.active { background: var(--red-soft); }
.status-btn.fuzzy { border-color: var(--gold); color: #8a6414; }
.status-btn.fuzzy.active { background: var(--amber-soft); }
.status-btn.known { border-color: var(--accent); color: var(--accent); }
.status-btn.known.active { background: var(--green-soft); }

.section-title h3, .section-title span { margin: 0; }

.progress-panel { display: grid; grid-template-columns: 88px 1fr; gap: 14px; align-items: center; }
.ring {
  display: grid;
  place-items: center;
  width: 88px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at center, #fff 0 58%, transparent 59%), conic-gradient(var(--accent) var(--progress, 0deg), #e7ebf1 0);
  color: var(--ink);
  font-weight: 900;
  font-size: 20px;
}

.stats-list { display: grid; gap: 10px; margin: 0; }
.stats-list div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: baseline; padding-top: 8px; border-top: 1px solid var(--line); }
.stats-list dt { color: var(--muted); font-size: 12px; font-weight: 800; }
.stats-list dd { margin: 0; font-weight: 800; }

.concepts-nav-btn {
  width: 100%;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: #fdf6e6;
  color: #6b4f14;
  padding: 12px;
  font-weight: 800;
  text-align: left;
}
.concepts-nav-btn.active { background: var(--gold); color: #fff; }

.small, .empty { color: var(--muted); line-height: 1.55; margin: 0; }

#typingHeading { font-size: 24px; }

.typing-stage {
  padding: 32px 26px;
  display: grid;
  gap: 18px;
  justify-items: center;
  text-align: center;
}

.typing-prompt { display: grid; gap: 4px; justify-items: center; }
.typing-cluster { color: var(--accent-2); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.typing-zh { font-size: 22px; font-weight: 700; margin: 0; }
.typing-phonetic { margin: 0; color: var(--muted); font-family: "Cambria Math", Charis, Georgia, serif; font-size: 14px; }

.typing-letters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.type-letter {
  min-width: 26px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 26px;
  font-weight: 700;
  border-bottom: 3px solid var(--line);
  color: var(--muted);
  padding: 0 2px;
}

.type-letter.correct { color: var(--accent); border-bottom-color: var(--accent); }
.type-letter.current { color: var(--ink); border-bottom-color: var(--gold); border-bottom-width: 4px; }
.type-letter.wrong { color: var(--accent-2); border-bottom-color: var(--accent-2); background: var(--red-soft); }
.type-letter.space { min-width: 14px; border-bottom: none; }

.typing-letters.shake { animation: typing-shake 0.28s; }
@keyframes typing-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.typing-capture {
  width: 320px;
  max-width: 100%;
  text-align: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  caret-color: var(--accent);
  background: #fbfcfe;
}
.typing-capture::placeholder { color: var(--muted); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-weight: 400; font-size: 14px; }
.typing-capture:focus { outline: none; border-color: var(--accent); background: #fff; }

.typing-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.typing-stats .stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.typing-stats .stat-card strong { display: block; font-size: 22px; color: var(--accent); }
.typing-stats .stat-card span { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr); }
  .rightbar { grid-column: 1 / -1; position: static; max-height: none; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
  .topbar, .hero { align-items: stretch; grid-template-columns: 1fr; }
  .topbar { position: static; }
  .topbar-meta { text-align: left; }
  .layout, .rightbar { grid-template-columns: 1fr; }
  .sidebar, .content, .rightbar { grid-column: 1; }
  .sidebar, .rightbar { position: static; max-height: none; }
  .hero h2 { font-size: 32px; }
  .status-buttons { flex-direction: column; }
  .typing-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
