/* ============================================================================
   chinese-lab.css  —  Section 08 · 学中文 · Hànzì Lab
   Matches the site's light cream + deep-teal hybrid. Uses the site's :root vars
   (--bg, --accent, --ink, --line, etc.) so it stays in sync automatically.
   All rules are scoped under #chinese / .cl-* to avoid touching site styles.
   ============================================================================ */

#chinese .cl-root { margin-top: 8px; }

#chinese code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 0.9em;
  font-weight: 500;
}

/* Chinese glyphs everywhere in the lab */
.cl-zh, .cl-hanzi, .cl-tile-zh, .cl-big-char {
  font-family: 'Noto Serif SC', 'Songti SC', serif;
}

/* ---------- XP bar ---------- */
.cl-xp-bar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 22px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 24px;
}
.cl-xp-level {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  color: var(--ink);
  font-size: 15px;
  white-space: nowrap;
}
.cl-xp-level b { color: var(--accent); }
.cl-xp-track {
  flex: 1;
  min-width: 180px;
  height: 8px;
  background: var(--bg-alt);
  border-radius: 999px;
  overflow: hidden;
}
.cl-xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  border-radius: 999px;
  transition: width .6s cubic-bezier(.2,.8,.2,1);
}
.cl-xp-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Tabs ---------- */
.cl-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}
.cl-tab {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .18s;
}
.cl-tab:hover { border-color: var(--accent); color: var(--accent); }
.cl-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Panels ---------- */
.cl-panel { display: none; }
.cl-panel.active { display: block; animation: clFade .3s ease; }
@keyframes clFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Generic toolbar / filters ---------- */
.cl-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}
.cl-input, .cl-select {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color .15s;
}
.cl-input:focus, .cl-select:focus { border-color: var(--accent); }
.cl-input { flex: 1; min-width: 200px; }
.cl-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: all .18s;
}
.cl-btn:hover { background: var(--accent); border-color: var(--accent); transform: translateY(-1px); }
.cl-btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.cl-btn.ghost:hover { color: var(--accent); border-color: var(--accent); background: transparent; }
.cl-btn.sm { padding: 6px 12px; font-size: 12px; }

.cl-progress-line {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
  letter-spacing: 0.04em;
}
.cl-progress-line b { color: var(--accent); }

/* ---------- Module 1 · Character grid ---------- */
.cl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.cl-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s, transform .18s, box-shadow .18s;
  overflow: hidden;
  min-height: 140px;
}
.cl-card::after { /* subtle scan-line on hover */
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(31,93,82,0.05) 0 1px, transparent 1px 4px);
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.cl-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 14px 30px -18px rgba(26,32,48,0.25);
}
.cl-card:hover::after { opacity: 1; }
.cl-card .cl-hanzi { font-size: 34px; color: var(--ink); line-height: 1.2; }
.cl-card .cl-py { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--accent); margin-top: 6px; }
.cl-card .cl-en { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.cl-card .cl-hsk {
  position: absolute; top: 8px; right: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 600;
}
.cl-card .cl-status-pip {
  position: absolute; top: 10px; left: 10px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line-strong);
}
.cl-card[data-status="learning"] .cl-status-pip { background: #e0a82e; }
.cl-card[data-status="mastered"] .cl-status-pip { background: var(--accent-bright); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Expanded card detail */
.cl-detail {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 26px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 28px;
  align-items: start;
  animation: clFade .25s ease;
}
.cl-trace {
  text-align: center;
}
.cl-big-char {
  font-size: 130px;
  color: rgba(26,32,48,0.12);
  line-height: 1;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  padding: 14px 0;
}
.cl-trace .cl-radical {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}
.cl-detail h4 { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .1em; margin: 0 0 6px; }
.cl-detail .cl-ex-zh { font-family: 'Noto Serif SC', serif; font-size: 20px; color: var(--ink); margin-bottom: 4px; }
.cl-detail .cl-ex-py { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--accent); }
.cl-detail .cl-ex-en { font-size: 14px; color: var(--ink-soft); margin: 4px 0 16px; }
.cl-detail .cl-meta { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.cl-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cl-speak {
  border: 1px solid var(--line-strong);
  background: transparent;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
}
.cl-speak:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Flashcard overlay ---------- */
.cl-overlay {
  position: fixed; inset: 0;
  background: rgba(26,32,48,0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
}
.cl-overlay[hidden] { display: none; }
.cl-overlay-close {
  position: absolute; top: 22px; right: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.cl-overlay-close:hover { border-color: var(--accent); color: var(--accent); }
.cl-fc-wrap { width: min(440px, 92vw); text-align: center; }
.cl-fc {
  perspective: 1200px;
  height: 320px;
  margin-bottom: 22px;
  cursor: pointer;
}
.cl-fc-inner {
  position: relative;
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .6s;
}
.cl-fc.flipped .cl-fc-inner { transform: rotateY(180deg); }
.cl-fc-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
}
.cl-fc-face.back { transform: rotateY(180deg); border-color: var(--accent); }
.cl-fc-face .cl-hanzi { font-family: 'Noto Serif SC', serif; font-size: 84px; color: var(--ink); }
.cl-fc-face .cl-py { font-family: 'JetBrains Mono', monospace; font-size: 22px; color: var(--accent); }
.cl-fc-face .cl-en { font-size: 18px; color: var(--ink-soft); }
.cl-fc-hint { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); }
.cl-fc-actions { display: flex; gap: 12px; justify-content: center; }
.cl-fc-stats { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- Module 2 · Grammar ---------- */
.cl-grammar { display: grid; grid-template-columns: 280px 1fr; gap: 24px; align-items: start; }
.cl-g-list {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  max-height: 560px;
  overflow-y: auto;
}
.cl-g-cat {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 14px 16px 6px;
}
.cl-g-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background .15s;
}
.cl-g-item:hover { background: var(--bg-alt); }
.cl-g-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.cl-g-item .cl-g-dot { font-size: 12px; color: var(--line-strong); }
.cl-g-item[data-state="1"] .cl-g-dot { color: #e0a82e; }
.cl-g-item[data-state="2"] .cl-g-dot { color: var(--accent-bright); }
.cl-g-item .cl-g-name { font-family: 'Noto Serif SC', serif; font-size: 15px; color: var(--ink); }
.cl-g-item .cl-g-en { font-size: 11px; color: var(--muted); display: block; font-family: 'Inter', sans-serif; }

.cl-g-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 26px;
  min-height: 420px;
}
.cl-g-panel .cl-g-title { font-family: 'Noto Serif SC', serif; font-size: 30px; color: var(--ink); }
.cl-g-panel .cl-g-formula {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--accent);
  margin: 12px 0 18px;
  display: inline-block;
}
.cl-subtabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.cl-subtab {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  padding: 8px 14px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.cl-subtab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.cl-ex-row { padding: 12px 0; border-bottom: 1px dashed var(--line); }
.cl-ex-row:last-child { border-bottom: none; }
.cl-ex-row .cl-ex-zh { font-family: 'Noto Serif SC', serif; font-size: 19px; color: var(--ink); }
.cl-ex-row .cl-ex-py { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent); }
.cl-ex-row .cl-ex-en { font-size: 13px; color: var(--ink-soft); }

.cl-drill { margin-bottom: 16px; }
.cl-drill .cl-q { font-size: 14px; color: var(--ink); margin-bottom: 8px; }
.cl-drill .cl-q b { font-family: 'JetBrains Mono', monospace; color: var(--accent); }
.cl-drill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.cl-drill-feedback { font-family: 'JetBrains Mono', monospace; font-size: 13px; margin-top: 8px; }
.cl-ok { color: var(--accent-bright); }
.cl-no { color: #c0392b; }

.cl-correct { background: rgba(31,93,82,0.10) !important; border-color: var(--accent) !important; }
.cl-wrong { background: rgba(192,57,43,0.10) !important; border-color: #c0392b !important; }

/* ---------- Module 3 · Sentences ---------- */
.cl-mode-switch { display: flex; gap: 8px; margin-bottom: 22px; }
.cl-sent-prompt {
  font-size: 20px;
  color: var(--ink);
  background: var(--bg-alt);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.cl-build-area {
  min-height: 64px;
  border: 2px dashed var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--surface);
  transition: border-color .15s;
}
.cl-build-area.cl-dragover { border-color: var(--accent); background: var(--accent-soft); }
.cl-pool { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.cl-tile {
  font-family: 'Noto Serif SC', serif;
  font-size: 20px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: grab;
  user-select: none;
  text-align: center;
  transition: border-color .15s, transform .1s;
}
.cl-tile:hover { border-color: var(--accent); }
.cl-tile:active { cursor: grabbing; }
.cl-tile .cl-tile-py { display: block; font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted); margin-top: 2px; }
.cl-tile.dragging { opacity: .5; border: 1px dashed var(--accent); }
.cl-tile.placed-ok { background: rgba(31,93,82,0.10); border-color: var(--accent); }
.cl-tile.placed-no { background: rgba(192,57,43,0.10); border-color: #c0392b; }

.cl-choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.cl-choice {
  text-align: left;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: all .15s;
}
.cl-choice:hover { border-color: var(--accent); }
.cl-note {
  margin-top: 14px;
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink-soft);
  background: var(--bg-alt);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 6px;
}
.cl-pinyin-toggle { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent); cursor: pointer; border: 1px solid var(--line-strong); border-radius: 6px; padding: 4px 10px; background: transparent; }
.cl-timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Module 4 · Dashboard ---------- */
.cl-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 26px;
}
.cl-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.cl-stat .v { font-family: 'JetBrains Mono', monospace; font-size: 26px; color: var(--accent); font-weight: 600; }
.cl-stat .k { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }

.cl-section-h {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin: 24px 0 12px;
}
.cl-heatmap {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.cl-hm-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--accent);
}
.cl-hm-legend { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); margin-top: 8px; display: flex; gap: 6px; align-items: center; }

.cl-log {
  background: var(--ink);
  color: #cfe8e2;
  border-radius: 12px;
  padding: 18px 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.9;
  max-height: 220px;
  overflow-y: auto;
}
.cl-log .t { color: var(--accent-bright); }
.cl-log .xp { color: #e0c060; }

.cl-share-box {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.cl-share-text {
  flex: 1;
  min-width: 240px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
}

.cl-empty { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: 13px; padding: 30px; text-align: center; }
.cl-toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  padding: 12px 22px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: all .3s;
  z-index: 10000;
}
.cl-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .cl-grammar { grid-template-columns: 1fr; }
  .cl-g-list { max-height: 280px; }
  .cl-detail { grid-template-columns: 1fr; }
  .cl-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .cl-choice-grid { grid-template-columns: 1fr; }
  .cl-heatmap { grid-template-columns: repeat(10, 1fr); }
  .cl-big-char { font-size: 96px; }
}
