/* ==========================================================================
   PA Cycle Study Website — Styling
   Dark theme by default (trading-friendly)
   ========================================================================== */

:root {
  --bg-0: #0f172a;
  --bg-1: #1e293b;
  --bg-2: #334155;
  --bg-3: #475569;
  --txt-0: #f1f5f9;
  --txt-1: #cbd5e1;
  --txt-2: #94a3b8;
  --txt-3: #64748b;
  --bull: #22c55e;
  --bear: #ef4444;
  --accent: #fbbf24;
  --accent-2: #a78bfa;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  --border: rgba(148, 163, 184, 0.15);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background: var(--bg-0);
  color: var(--txt-0);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

/* ===== FOUC prevention: hide body until i18n ready ===== */
body { visibility: hidden; }
body.i18n-ready { visibility: visible; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: #fcd34d; }

/* ===== Top nav ===== */
.topnav {
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.topnav .logo {
  font-weight: 700;
  font-size: 17px;
  color: var(--accent);
  margin-right: auto;
}
.topnav .logo .small { color: var(--txt-2); font-weight: 400; font-size: 13px; margin-left: 8px; }
.topnav nav { display: flex; gap: 16px; }
.topnav nav a {
  color: var(--txt-1);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.topnav nav a:hover {
  background: var(--bg-2);
  color: var(--txt-0);
}
.topnav nav a.active {
  background: var(--accent);
  color: var(--bg-0);
}
.topnav nav a.disabled {
  color: var(--txt-3);
  cursor: not-allowed;
  font-style: italic;
}
.topnav nav a.disabled:hover { background: transparent; }

/* ===== Language switcher ===== */
.lang-switch {
  display: flex;
  gap: 2px;
  margin-left: 16px;
  padding-left: 16px;
  border-left: 1px solid var(--border);
  align-items: center;
}
.lang-btn {
  padding: 5px 11px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--txt-2);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.lang-btn:hover { color: var(--txt-0); background: var(--bg-2); }
.lang-btn.active {
  color: var(--bg-0);
  background: var(--accent);
  font-weight: 700;
}
.lang-divider {
  color: var(--txt-3);
  font-size: 12px;
  margin: 0 2px;
}

/* ===== Main container ===== */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.page-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.page-header h1 {
  font-size: 23px;
  font-weight: 700;
  margin-bottom: 6px;
}
.page-header .subtitle {
  color: var(--txt-2);
  font-size: 14px;
}

/* ===== Pattern Atlas Matrix (Module 1) ===== */
.matrix-wrap {
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.matrix {
  display: grid;
  grid-template-columns: 140px repeat(5, 1fr);
  gap: 4px;
  min-width: 800px;
}
.mx-cell {
  padding: 14px 8px;
  border-radius: 6px;
  text-align: center;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.mx-cell.header {
  background: var(--bg-2);
  font-weight: 600;
  color: var(--txt-0);
}
.mx-cell.header.row {
  align-items: flex-start;
  text-align: left;
  padding-left: 12px;
}
.mx-cell.header .pat-cn { font-size: 15px; font-weight: 700; }
.mx-cell.header .pat-en { font-size: 11px; color: var(--txt-2); font-weight: 400; }
.mx-cell.header .pat-icon { font-size: 19px; margin-bottom: 2px; }
.mx-cell.cat-name {
  background: var(--bg-2);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
}
.mx-cell.cat-name .icon { font-size: 22px; line-height: 1; }
.mx-cell.data {
  background: var(--bg-2);
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  position: relative;
}
.mx-cell.data:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.mx-cell.data.active {
  background: var(--accent);
  color: var(--bg-0);
}
.mx-cell.data .count {
  font-size: 23px;
  font-weight: 700;
  line-height: 1;
}
.mx-cell.data .count.zero { color: var(--txt-3); font-weight: 400; }
.mx-cell.data .count-label {
  font-size: 11px;
  color: var(--txt-2);
}
.mx-cell.data.active .count-label { color: var(--bg-0); }

.heat-0 { background: rgba(51, 65, 85, 0.4); }
.heat-1 { background: rgba(251, 191, 36, 0.10); }
.heat-2 { background: rgba(251, 191, 36, 0.18); }
.heat-3 { background: rgba(251, 191, 36, 0.30); }
.heat-4 { background: rgba(251, 191, 36, 0.45); }

/* ===== Filter pill bar ===== */
.pillbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.pill {
  background: var(--bg-2);
  color: var(--txt-1);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  user-select: none;
}
.pill:hover { background: var(--bg-3); }
.pill.active {
  background: var(--accent);
  color: var(--bg-0);
  font-weight: 600;
}

/* ===== Card grid (legacy single-column-fill) ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

/* ===== Paired card grid (bull|bear side-by-side) ===== */
.pair-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(720px, 1fr));
  gap: 20px;
  margin-top: 16px;
}
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: stretch;
}
.pair.single {
  grid-template-columns: 1fr;
  /* keep width consistent with paired rows for visual rhythm */
}
@media (max-width: 760px) {
  .pair {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 1100px) {
  .pair-grid {
    grid-template-columns: 1fr;
  }
}

.feature-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
}
.feature-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.feature-card.dir-bull { border-left: 3px solid var(--bull); }
.feature-card.dir-bear { border-left: 3px solid var(--bear); }

.fc-head {
  padding: 10px 14px;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  flex-wrap: wrap;
}
.fc-head .pat-tag {
  background: var(--bg-3);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12px;
}
.fc-head .pat-tag.sb { background: rgba(67, 160, 71, 0.25); color: #86efac; }
.fc-head .pat-tag.wb { background: rgba(229, 57, 53, 0.25); color: #fca5a5; }
.fc-head .pat-tag.trend { background: rgba(30, 136, 229, 0.25); color: #93c5fd; }
.fc-head .pat-tag.rb { background: rgba(251, 140, 0, 0.25); color: #fdba74; }
.fc-head .pat-tag.sr { background: rgba(142, 36, 170, 0.25); color: #d8b4fe; }
.fc-head .dir-tag {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.fc-head .dir-tag.bull { background: rgba(34, 197, 94, 0.2); color: var(--bull); }
.fc-head .dir-tag.bear { background: rgba(239, 68, 68, 0.2); color: var(--bear); }
.fc-head .marker {
  margin-left: auto;
  font-size: 12px;
  color: var(--txt-2);
}
.fc-head .no-tag {
  background: var(--bg-3);
  color: var(--txt-1);
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
}

.fc-concept {
  padding: 8px 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}
.fc-concept .concept-cn {
  font-weight: 600;
  font-size: 14px;
  color: var(--txt-0);
}
.fc-concept .concept-en {
  font-size: 12px;
  color: var(--txt-2);
  font-style: italic;
  margin-top: 2px;
}

.fc-chart {
  padding: 12px;
  background: var(--bg-0);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pa-chart {
  width: 100%;
  max-width: 320px;
  height: auto;
  display: block;
}

.fc-text {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--txt-1);
  border-top: 1px solid var(--border);
  flex-grow: 1;
}
.fc-text .brooks-quote {
  font-family: 'Georgia', 'Source Serif Pro', serif;
  color: var(--txt-0);
}

.fc-notes {
  padding: 10px 14px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
}
.fc-notes label {
  display: block;
  font-size: 12px;
  color: var(--txt-2);
  margin-bottom: 4px;
}
.fc-notes textarea {
  width: 100%;
  min-height: 40px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--txt-0);
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  transition: border 0.15s;
}
.fc-notes textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.fc-notes .saved-tick {
  font-size: 11px;
  color: var(--bull);
  margin-left: 6px;
  opacity: 0;
  transition: opacity 0.3s;
}
.fc-notes .saved-tick.show { opacity: 1; }

/* ===== Pattern Deep Dive (Module 2) ===== */
.deep-dive-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  margin-top: 16px;
}
.deep-dive-main { min-width: 0; }
.deep-dive-sidebar {
  position: sticky;
  top: 80px;
  align-self: start;
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.deep-dive-sidebar h3 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--accent);
}
.deep-dive-sidebar .mnemonic-list {
  list-style: none;
}
.deep-dive-sidebar .mnemonic-list li {
  padding: 8px 0;
  font-size: 14px;
  color: var(--txt-1);
  border-bottom: 1px solid var(--border);
  position: relative;
  padding-left: 20px;
}
.deep-dive-sidebar .mnemonic-list li:last-child { border-bottom: none; }
.deep-dive-sidebar .mnemonic-list li::before {
  content: '✦';
  color: var(--accent);
  position: absolute;
  left: 0;
}
.deep-dive-sidebar .stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.deep-dive-sidebar .stat-row:last-child { border-bottom: none; }
.deep-dive-sidebar .stat-label { color: var(--txt-2); }
.deep-dive-sidebar .stat-value { color: var(--txt-0); font-weight: 600; }

.cat-section {
  margin-bottom: 24px;
}
.cat-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-radius: var(--radius);
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.15s;
  /* Sticky: pin just below the top nav while scrolling through this category's cards */
  position: sticky;
  top: 56px;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.cat-section-header:hover {
  background: var(--bg-3);
}
.cat-section-header .cat-icon { font-size: 25px; }
.cat-section-header .cat-name {
  font-size: 17px;
  font-weight: 700;
}
.cat-section-header .cat-count {
  margin-left: auto;
  background: var(--accent);
  color: var(--bg-0);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.cat-section-header .toggle-chevron {
  margin-left: 8px;
  font-size: 15px;
  color: var(--txt-2);
  transition: transform 0.2s;
}
.cat-section.collapsed .toggle-chevron { transform: rotate(-90deg); }
.cat-section.collapsed .cat-section-content { display: none; }

/* ===== Pattern selector ===== */
.pattern-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.pattern-btn {
  background: var(--bg-2);
  color: var(--txt-1);
  padding: 12px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
  font-size: 15px;
}
.pattern-btn:hover { background: var(--bg-3); }
.pattern-btn.active {
  border-color: var(--accent);
  background: rgba(251, 191, 36, 0.15);
}
.pattern-btn .icon { font-size: 23px; }
.pattern-btn .name { font-weight: 600; }
.pattern-btn .name-en { font-size: 12px; color: var(--txt-3); }

/* ===== Empty state ===== */
.empty-state {
  background: var(--bg-1);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 60px 20px;
  text-align: center;
  color: var(--txt-2);
  font-size: 15px;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal-backdrop.show { display: flex; }
.modal-content {
  background: var(--bg-0);
  border-radius: var(--radius);
  max-width: 1100px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  background: var(--bg-0);
  z-index: 1;
}
.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
}
.modal-header .close-btn {
  margin-left: auto;
  background: var(--bg-2);
  border: none;
  color: var(--txt-0);
  width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-header .close-btn:hover { background: var(--bg-3); }
.modal-body {
  padding: 20px;
}

/* ===== Footer ===== */
footer {
  margin-top: 40px;
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--txt-3);
  border-top: 1px solid var(--border);
}

/* ===== Concept clickable area ===== */
.fc-concept-clickable {
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.fc-concept-clickable:hover {
  background: rgba(251, 191, 36, 0.08);
}
.fc-concept .compare-icon {
  font-size: 12px;
  margin-left: 4px;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.fc-concept-clickable:hover .compare-icon {
  opacity: 1;
}

/* ===== Sibling concept distribution bar ===== */
.fc-concept-bar {
  display: flex;
  gap: 4px;
  padding: 6px 14px 10px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}
.csb-segment {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 0;
  border-radius: 4px;
  font-size: 15px;
  cursor: default;
  transition: all 0.15s;
  border: 1.5px solid transparent;
  user-select: none;
  min-height: 24px;
}
.csb-segment.csb-active {
  cursor: pointer;
}
.csb-segment.csb-active:hover {
  filter: brightness(1.4);
  transform: translateY(-1px);
}
.csb-segment.csb-sb { background: rgba(67, 160, 71, 0.30); }
.csb-segment.csb-wb { background: rgba(229, 57, 53, 0.30); }
.csb-segment.csb-trend { background: rgba(30, 136, 229, 0.30); }
.csb-segment.csb-rb { background: rgba(251, 140, 0, 0.30); }
.csb-segment.csb-sr { background: rgba(142, 36, 170, 0.30); }
.csb-segment.csb-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), inset 0 0 0 1px rgba(251, 191, 36, 0.3);
}
.csb-segment.csb-empty {
  background: transparent;
  border: 1px dashed rgba(148, 163, 184, 0.3);
  color: var(--txt-3);
  cursor: not-allowed;
  font-size: 13px;
}

/* ===== Detailed-reading button + popover ===== */
.fc-interp-btn,
.cl-interp-btn {
  background: rgba(251, 191, 36, 0.14);
  color: var(--accent);
  border: 1px solid rgba(251, 191, 36, 0.35);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 6px;
  vertical-align: baseline;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}
.fc-interp-btn:hover,
.cl-interp-btn:hover {
  background: rgba(251, 191, 36, 0.28);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.cl-interp-btn { font-size: 10px; padding: 2px 7px; }

.interp-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 320;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.interp-backdrop.show { display: flex; }
.interp-popover {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: interp-pop-in 0.18s ease-out;
}
@keyframes interp-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.interp-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-1);
  border-radius: 8px 8px 0 0;
}
.interp-header h3 {
  margin: 0;
  font-size: 15px;
  color: var(--accent);
}
.interp-meta {
  flex-grow: 1;
  font-size: 12px;
  color: var(--txt-2);
  font-style: italic;
  text-align: right;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.interp-close {
  background: var(--bg-2);
  border: none;
  color: var(--txt-0);
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.interp-close:hover { background: var(--bg-3); }
.interp-body {
  padding: 18px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.78;
  color: var(--txt-0);
  flex-grow: 1;
}
.interp-source {
  padding: 9px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  font-size: 11px;
  color: var(--txt-3);
  font-style: italic;
  border-radius: 0 0 8px 8px;
}
.interp-source:empty { display: none; }

@media (max-width: 640px) {
  .interp-backdrop { padding: 10px; }
  .interp-popover { max-height: 92vh; }
  .interp-header { padding: 11px 14px; }
  .interp-header h3 { font-size: 14px; }
  .interp-meta { font-size: 11px; }
  .interp-body { padding: 14px; font-size: 13px; line-height: 1.72; }
  .interp-source { padding: 8px 14px; font-size: 10px; }
}

/* ===== Instant tooltip (replaces native title=, no delay) ===== */
.instant-tooltip {
  position: absolute;
  z-index: 310;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  line-height: 1.6;
  color: var(--txt-1);
  font-family: Georgia, 'Source Serif Pro', serif;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  /* No transition delay — pop in instantly */
}
.instant-tooltip.show {
  opacity: 1;
  visibility: visible;
}

/* ===== Tooltip ===== */
.csb-tooltip {
  position: absolute;
  z-index: 300;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  min-width: 280px;
  max-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
}
.csb-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}
.csb-tip-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.csb-tip-line {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: flex-start;
}
.csb-tip-line:last-child { margin-bottom: 0; }
.csb-tip-dir {
  flex-shrink: 0;
  font-size: 12px;
}
.csb-tip-text {
  color: var(--txt-1);
  line-height: 1.5;
  font-family: Georgia, 'Source Serif Pro', serif;
}

/* ===== Comparison drawer ===== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 240;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.drawer-backdrop.show {
  opacity: 1;
  pointer-events: all;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 92vw;
  max-width: 1240px;
  background: var(--bg-0);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.6);
  z-index: 250;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}
.drawer.show { transform: translateX(0); }
.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}
.drawer-header > div:first-child {
  flex-grow: 1;
  min-width: 0;
}
.drawer-header h2 {
  font-size: 17px;
  margin: 0;
  color: var(--txt-0);
}
.drawer-title-en {
  color: var(--txt-2);
  font-size: 13px;
  font-style: italic;
  margin-top: 2px;
}
.drawer-marker {
  background: var(--bg-2);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--txt-1);
  flex-shrink: 0;
}
.drawer-close {
  background: var(--bg-2);
  border: none;
  color: var(--txt-0);
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 23px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.drawer-close:hover { background: var(--bg-3); }
.drawer-body {
  padding: 20px;
  overflow-y: auto;
  flex-grow: 1;
}
.drawer-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
}
.drawer-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.drawer-col-empty .drawer-empty-note {
  background: var(--bg-1);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 30px 12px;
  text-align: center;
  color: var(--txt-3);
  font-size: 12px;
  flex-grow: 1;
}
.drawer-col-header {
  padding: 8px 10px;
  border-radius: 6px;
  font-weight: 700;
  text-align: center;
  font-size: 13px;
}
.drawer-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.drawer-card.dir-bull { border-left: 3px solid var(--bull); }
.drawer-card.dir-bear { border-left: 3px solid var(--bear); }
.drawer-card-head {
  display: flex;
  gap: 4px;
  font-size: 11px;
  align-items: center;
  flex-wrap: wrap;
}
.drawer-card-chart {
  background: var(--bg-0);
  padding: 4px;
  border-radius: 4px;
}
.drawer-card-chart .pa-chart {
  width: 100%;
  height: auto;
  display: block;
}
.drawer-card-text {
  font-size: 12px;
  line-height: 1.5;
  color: var(--txt-1);
  font-family: Georgia, 'Source Serif Pro', serif;
}

/* ===== Concept Lens ===== */
.cl-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  background: var(--bg-1);
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.cl-toolgroup {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  color: var(--txt-1);
}
.cl-toolgroup select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--txt-0);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 14px;
}
.cl-toolgroup .checkbox-label {
  display: flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.cl-stats {
  margin-left: auto;
  font-size: 13px;
  color: var(--txt-2);
}
.cl-stats b { color: var(--accent); }

.concept-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.cl-row {
  background: var(--bg-1);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.cl-row-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-left: 4px solid var(--accent);
  cursor: pointer;
  transition: background 0.15s;
  flex-wrap: wrap;
}
.cl-row-header:hover { background: var(--bg-3); }

/* Drag-and-drop handle */
.cl-row-drag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  font-size: 14px;
  color: var(--txt-3);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  letter-spacing: -2px;
  transition: color 0.12s;
}
.cl-row-drag:hover { color: var(--accent); }
.cl-row-drag:active { cursor: grabbing; }
.cl-row.cl-row-dragging {
  opacity: 0.4;
  outline: 2px dashed var(--accent);
}
.cl-row.cl-row-drag-over .cl-row-header {
  background: rgba(251, 191, 36, 0.15);
  box-shadow: inset 0 -3px 0 var(--accent);
}

/* Reset-order button in toolbar */
.cl-reset-btn {
  background: var(--bg-2);
  color: var(--txt-1);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.cl-reset-btn:hover {
  background: var(--bg-3);
  color: var(--txt-0);
  border-color: var(--accent);
}

.cl-row-marker {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.cl-row-titles {
  flex-grow: 1;
  min-width: 0;
}
.cl-row-cn {
  font-weight: 700;
  font-size: 15px;
  color: var(--txt-0);
}
.cl-row-en {
  font-size: 12px;
  color: var(--txt-2);
  font-style: italic;
  margin-top: 2px;
}
.cat-tag {
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.cl-row-expand {
  background: var(--accent);
  color: var(--bg-0);
  border: none;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.cl-row-expand:hover { background: #fcd34d; }

.cl-row-body {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  padding: 0;
}
.cl-cell {
  padding: 10px 8px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.cl-cell:last-child { border-right: none; }
.cl-cell-empty {
  padding: 8px;
  background: transparent;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.cl-cell-empty-note {
  background: var(--bg-1);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 30px 12px;
  text-align: center;
  color: var(--txt-3);
  font-size: 12px;
  font-style: italic;
  flex-grow: 1;
}
.cl-cell-pat {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}
.cl-mini-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 3px solid var(--neutralBar, #64748b);
}
.cl-mini-card.dir-bull { border-left-color: var(--bull); }
.cl-mini-card.dir-bear { border-left-color: var(--bear); }
.cl-mini-head {
  display: flex;
  gap: 4px;
  font-size: 11px;
  align-items: center;
}
.cl-mini-head .dir-tag {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.cl-mini-head .dir-tag.bull { background: rgba(34,197,94,0.2); color: var(--bull); }
.cl-mini-head .dir-tag.bear { background: rgba(239,68,68,0.2); color: var(--bear); }
.cl-mini-head .no-tag {
  background: var(--bg-2);
  color: var(--txt-1);
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.cl-mini-chart {
  background: var(--bg-1);
  padding: 2px;
  border-radius: 3px;
}
.cl-mini-chart .pa-chart {
  width: 100%;
  height: auto;
  display: block;
}
.cl-mini-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--txt-1);
  font-family: Georgia, 'Source Serif Pro', serif;
}

/* ===== Live Scan ===== */
.scan-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
}
.scan-checklist {
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}
.scan-cat-section {
  margin-bottom: 12px;
}
.scan-cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-2);
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}
.scan-cat-header .toggle-chev {
  margin-left: auto;
  transition: transform 0.2s;
  font-size: 12px;
  color: var(--txt-2);
}
.scan-cat-section.collapsed .toggle-chev { transform: rotate(-90deg); }
.scan-cat-section.collapsed .scan-cat-items { display: none; }
.scan-cat-items {
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.scan-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  line-height: 1.4;
  transition: background 0.1s;
}
.scan-item:hover { background: var(--bg-2); }
.scan-item input { margin-top: 3px; cursor: pointer; flex-shrink: 0; }
.scan-item-text {
  color: var(--txt-1);
}
.scan-item-text .cn { font-weight: 600; color: var(--txt-0); }
.scan-item-text .en { font-size: 11px; color: var(--txt-3); font-style: italic; margin-left: 6px; }
.scan-item.checked .scan-item-text .cn { color: var(--accent); }
.scan-item-spread {
  margin-left: auto;
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.scan-item-spread .ic {
  font-size: 13px;
  opacity: 1;
}
.scan-item-spread .ic.dim {
  opacity: 0.08;
  filter: grayscale(100%);
}

.scan-panel {
  background: var(--bg-1);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  position: sticky;
  top: 80px;
  align-self: start;
}
.scan-panel h3 {
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--accent);
}
.scan-summary {
  font-size: 13px;
  color: var(--txt-2);
  margin-bottom: 14px;
  padding: 8px;
  background: var(--bg-2);
  border-radius: 4px;
}
.scan-summary b { color: var(--accent); }
.scan-rank {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.scan-rank-item {
  background: var(--bg-2);
  border-radius: 6px;
  padding: 10px;
  border-left: 3px solid var(--neutralBar, #64748b);
}
.scan-rank-item.top {
  border-left-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(251,191,36,0.3);
}
.scan-rank-item.sb { border-left-color: var(--bull); }
.scan-rank-item.wb { border-left-color: var(--bear); }
.scan-rank-item.trend { border-left-color: #1E88E5; }
.scan-rank-item.rb { border-left-color: #FB8C00; }
.scan-rank-item.sr { border-left-color: #8E24AA; }
.scan-rank-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
}
.scan-rank-pct {
  margin-left: auto;
  font-size: 14px;
  color: var(--accent);
  font-weight: 700;
}
.scan-rank-bar {
  height: 6px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}
.scan-rank-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}
.scan-rank-detail {
  font-size: 12px;
  color: var(--txt-2);
}
.scan-actions {
  margin-top: 14px;
  display: flex;
  gap: 8px;
}
.scan-btn {
  flex-grow: 1;
  background: var(--bg-2);
  color: var(--txt-0);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.scan-btn:hover { background: var(--bg-3); }
.scan-btn.primary { background: var(--accent); color: var(--bg-0); border-color: var(--accent); font-weight: 700; }

/* ==========================================================================
   FLASH DRILL
   ========================================================================== */

.drill-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.drill-mode-tab {
  background: var(--bg-1);
  border: 2px solid var(--border);
  color: var(--txt-1);
  padding: 14px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.15s;
  font-family: inherit;
}
.drill-mode-tab:hover {
  border-color: var(--bg-3);
  background: var(--bg-2);
}
.drill-mode-tab.active {
  border-color: var(--accent);
  background: rgba(251, 191, 36, 0.08);
}
.drill-mode-tab .m-icon {
  font-size: 23px;
}
.drill-mode-tab .m-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--txt-0);
}
.drill-mode-tab .m-desc {
  font-size: 12px;
  color: var(--txt-2);
}

.drill-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.ds-block {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}
.ds-num {
  font-size: 23px;
  font-weight: 700;
  color: var(--accent);
}
.ds-label {
  font-size: 12px;
  color: var(--txt-2);
  margin-top: 2px;
}

.drill-card-area {
  margin-bottom: 16px;
}
.drill-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 760px;
  margin: 0 auto;
}
.drill-card.revealed { border-color: var(--accent); }

.dc-prompt {
  text-align: center;
  font-size: 15px;
  color: var(--txt-1);
  margin-bottom: 18px;
}
.dc-chart-large {
  background: var(--bg-0);
  border-radius: 6px;
  padding: 16px;
  display: flex;
  justify-content: center;
  margin: 0 auto 16px;
}
.dc-chart-large .pa-chart {
  width: 100%;
  max-width: 560px;
  height: auto;
}
.dc-hint {
  text-align: center;
  font-size: 13px;
  color: var(--txt-3);
  font-style: italic;
}
.dc-result {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 14px;
  background: var(--bg-2);
}
.dc-result.correct {
  background: rgba(34, 197, 94, 0.15);
  color: var(--bull);
  border: 1px solid rgba(34, 197, 94, 0.3);
}
.dc-result.wrong {
  background: rgba(239, 68, 68, 0.15);
  color: var(--bear);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.dc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12px;
}
.dc-meta .marker {
  background: var(--bg-2);
  color: var(--txt-2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.dc-concept-revealed {
  background: rgba(251, 191, 36, 0.05);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 12px;
}
.dc-concept-revealed .cn {
  font-weight: 700;
  color: var(--txt-0);
  font-size: 15px;
}
.dc-concept-revealed .en {
  font-size: 12px;
  font-style: italic;
  color: var(--txt-2);
  margin-top: 2px;
}
.dc-text-revealed {
  background: var(--bg-0);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--txt-1);
  font-family: Georgia, 'Source Serif Pro', serif;
}
.dc-concept-front {
  text-align: center;
  padding: 30px 16px;
  background: var(--bg-0);
  border-radius: 6px;
  margin-bottom: 16px;
}
.dc-concept-pat {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.dc-concept-front .cn-large {
  font-size: 23px;
  font-weight: 700;
  color: var(--txt-0);
  margin-bottom: 6px;
}
.dc-concept-front .en-large {
  font-size: 14px;
  font-style: italic;
  color: var(--txt-2);
}
.dc-text-front {
  background: var(--bg-0);
  padding: 24px 20px;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1.8;
  color: var(--txt-0);
  font-family: Georgia, 'Source Serif Pro', serif;
  margin-bottom: 16px;
}

.drill-action-area {
  margin-bottom: 16px;
}
.drill-choices {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
}
.drill-choices.choices-8 {
  grid-template-columns: repeat(4, 1fr);
}
.drill-choice-btn {
  background: var(--bg-1);
  border: 2px solid var(--border);
  color: var(--txt-0);
  padding: 14px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
  position: relative;
  font-size: 14px;
}
.drill-choice-btn:hover {
  border-color: var(--accent);
  background: var(--bg-2);
  transform: translateY(-1px);
}
.drill-choice-btn .m-icon {
  font-size: 23px;
}

.drill-rating {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 760px;
  margin: 0 auto;
}
.dr-label {
  color: var(--txt-2);
  font-size: 14px;
  font-weight: 600;
}
.drill-rate-btn {
  background: var(--bg-1);
  border: 2px solid var(--border);
  color: var(--txt-0);
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.drill-rate-btn:hover { transform: translateY(-1px); }
.drill-rate-btn.rate-red {
  border-color: rgba(239, 68, 68, 0.5);
}
.drill-rate-btn.rate-red:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--bear);
}
.drill-rate-btn.rate-yellow {
  border-color: rgba(251, 191, 36, 0.5);
}
.drill-rate-btn.rate-yellow:hover {
  background: rgba(251, 191, 36, 0.15);
  border-color: var(--accent);
}
.drill-rate-btn.rate-green {
  border-color: rgba(34, 197, 94, 0.5);
}
.drill-rate-btn.rate-green:hover {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--bull);
}

.kbd {
  background: var(--bg-3);
  color: var(--txt-1);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0,0,0,0.4);
  min-width: 16px;
  text-align: center;
  display: inline-block;
}

.drill-btn {
  background: var(--bg-2);
  color: var(--txt-0);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.drill-btn:hover { background: var(--bg-3); color: var(--txt-0); }
.drill-btn.primary {
  background: var(--accent);
  color: var(--bg-0);
  border-color: var(--accent);
  font-weight: 700;
}
.drill-btn.primary:hover {
  background: #fcd34d;
  color: var(--bg-0);
}
.drill-btn-sm {
  background: var(--bg-2);
  color: var(--txt-0);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.drill-btn-sm:hover { background: var(--bg-3); }

.drill-session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--txt-1);
  margin-bottom: 16px;
}

.drill-end-state {
  text-align: center;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  margin-top: 20px;
}
.drill-end-state h2 {
  color: var(--accent);
  font-size: 21px;
  margin-bottom: 6px;
}
.drill-end-state .drill-btn {
  margin: 0 6px;
}

/* ==========================================================================
   TRACKER
   ========================================================================== */

.tracker-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.sc-icon { font-size: 29px; }
.sc-num {
  font-size: 23px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}
.sc-label {
  font-size: 12px;
  color: var(--txt-2);
  margin-top: 4px;
}

.tracker-section {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}
.ts-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--txt-0);
  margin-bottom: 4px;
}
.ts-subtitle {
  font-size: 13px;
  color: var(--txt-2);
  margin-bottom: 16px;
}

.heatmap-wrap {
  overflow-x: auto;
}
.heatmap-grid {
  display: grid;
  grid-template-columns: 140px repeat(5, minmax(140px, 1fr));
  gap: 4px;
  min-width: 800px;
}
.hm-cell {
  padding: 10px 6px;
  border-radius: 6px;
  text-align: center;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 56px;
}
.hm-corner {
  background: transparent;
}
.hm-header {
  background: var(--bg-2);
  color: var(--txt-0);
  font-weight: 700;
}
.hm-header .m-icon { font-size: 19px; margin-bottom: 2px; }
.hm-row-label {
  background: var(--bg-2);
  color: var(--txt-0);
  font-weight: 700;
  flex-direction: row;
  justify-content: flex-start;
  padding-left: 12px;
  text-align: left;
}
.hm-row-label .m-icon { font-size: 19px; margin-right: 4px; }
.hm-cell[data-cat] {
  cursor: pointer;
  transition: all 0.12s;
  border: 1.5px solid transparent;
}
.hm-cell[data-cat]:hover {
  transform: scale(1.05);
  border-color: var(--accent);
}
.hm-cell-num {
  font-size: 19px;
  font-weight: 700;
}
.hm-cell-frac {
  font-size: 11px;
  opacity: 0.85;
}

.hl-empty {
  background: rgba(51, 65, 85, 0.3);
  color: var(--txt-3);
  font-size: 17px;
}
.hl-0 { background: rgba(100, 116, 139, 0.3); color: var(--txt-2); }
.hl-1 { background: rgba(239, 68, 68, 0.5); color: #ffffff; }
.hl-2 { background: rgba(251, 146, 60, 0.5); color: #ffffff; }
.hl-3 { background: rgba(251, 191, 36, 0.5); color: #1a202c; }
.hl-4 { background: rgba(34, 197, 94, 0.65); color: #ffffff; }

.heatmap-legend {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--txt-2);
  flex-wrap: wrap;
}
.heatmap-legend .hl-cell {
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.session-row {
  display: grid;
  grid-template-columns: 100px 1.5fr 1fr 100px;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-2);
  border-radius: 6px;
  font-size: 14px;
}
.sr-time {
  color: var(--txt-2);
  font-family: ui-monospace, monospace;
  font-size: 13px;
}
.sr-mode { color: var(--txt-0); }
.sr-counts { display: flex; gap: 12px; font-size: 13px; }
.sr-acc {
  text-align: right;
  font-weight: 700;
}
.sr-acc-num { color: var(--accent); font-size: 16px; }
.sr-total { color: var(--txt-3); font-size: 12px; margin-left: 4px; }

.weak-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.weak-item {
  display: grid;
  grid-template-columns: 50px 1fr;
  gap: 12px;
  background: var(--bg-2);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.weak-item:hover {
  background: var(--bg-3);
  transform: translateX(2px);
}
.wi-rank {
  font-size: 19px;
  font-weight: 700;
  color: var(--accent);
  align-self: center;
  text-align: center;
}
.wi-content { min-width: 0; }
.wi-header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}
.wi-level {
  margin-left: auto;
  letter-spacing: 1px;
  color: var(--accent);
  font-size: 13px;
}
.wi-concept {
  font-size: 14px;
  font-weight: 600;
  color: var(--txt-0);
  margin-bottom: 4px;
}
.wi-text {
  font-size: 12px;
  color: var(--txt-1);
  line-height: 1.5;
  font-family: Georgia, serif;
  margin-bottom: 6px;
}
.wi-stats {
  font-size: 12px;
  color: var(--txt-3);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .deep-dive-layout {
    grid-template-columns: 1fr;
  }
  .deep-dive-sidebar {
    position: static;
  }
  .matrix {
    grid-template-columns: 100px repeat(5, 1fr);
  }
  .drawer-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .scan-layout {
    grid-template-columns: 1fr;
  }
  .scan-panel {
    position: static;
  }
  .cl-row-body {
    grid-template-columns: 1fr;
  }
  .cl-cell { border-right: none; border-bottom: 1px solid var(--border); }
  .drill-mode-tabs { grid-template-columns: 1fr; }
  .drill-choices { grid-template-columns: repeat(2, 1fr); }
  .drill-choices.choices-8 { grid-template-columns: repeat(2, 1fr); }
  .session-row {
    grid-template-columns: 80px 1fr;
    grid-template-rows: auto auto;
    gap: 4px;
  }
  .sr-counts, .sr-acc { grid-column: 2; }
}
@media (max-width: 1200px) {
  .drawer-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ==========================================================================
   MOBILE PORTRAIT (≤640px) — phone screens, single-column flow
   ========================================================================== */
@media (max-width: 640px) {
  html, body { font-size: 14px; }

  /* ---- Top nav: stack into 2 rows so all 6 modules stay accessible ---- */
  .topnav {
    padding: 10px 12px;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
  }
  .topnav .logo {
    font-size: 15px;
    margin-right: 0;
    flex: 1 1 auto;
  }
  .topnav .logo .small { display: none; }
  .lang-switch {
    margin-left: auto;
    padding-left: 12px;
    flex-shrink: 0;
  }
  .lang-btn { padding: 4px 8px; font-size: 12px; }
  /* nav links: full-width row that scrolls horizontally if needed */
  .topnav nav {
    order: 3;
    flex-basis: 100%;
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .topnav nav::-webkit-scrollbar { display: none; }
  .topnav nav a {
    padding: 5px 9px;
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ---- Main container ---- */
  main { padding: 14px 12px; }
  .page-header { margin-bottom: 16px; padding-bottom: 12px; }
  .page-header h1 { font-size: 19px; }
  .page-header .subtitle { font-size: 13px; }

  /* ---- Pattern Atlas: keep horizontal scroll, tighten cells ---- */
  .matrix-wrap { padding: 10px; }
  .matrix {
    grid-template-columns: 90px repeat(5, minmax(70px, 1fr));
    min-width: 540px;
    gap: 3px;
  }
  .mx-cell { padding: 9px 4px; font-size: 12px; }
  .mx-cell.header .pat-cn { font-size: 13px; }
  .mx-cell.header .pat-en { font-size: 10px; }
  .mx-cell.header .pat-icon { font-size: 16px; }
  .mx-cell.cat-name { font-size: 13px; }
  .mx-cell.data .count { font-size: 19px; }
  .mx-cell.data .count-label { font-size: 10px; }

  /* ---- Pillbar / pattern selector ---- */
  .pillbar { gap: 6px; margin-bottom: 12px; }
  .pill { padding: 5px 11px; font-size: 12px; }
  .pattern-selector { gap: 6px; margin-bottom: 18px; }
  .pattern-btn { padding: 9px 12px; font-size: 13px; gap: 6px; }
  .pattern-btn .icon { font-size: 19px; }
  .pattern-btn .name-en { font-size: 11px; }

  /* ---- Card grid (single column) ---- */
  .card-grid { grid-template-columns: 1fr; gap: 12px; }
  .pair-grid { gap: 14px; }
  .pair { gap: 10px; }
  .pa-chart { max-width: 100%; }
  .fc-head { padding: 8px 11px; font-size: 12px; gap: 6px; }
  .fc-head .pat-tag,
  .fc-head .dir-tag,
  .fc-head .no-tag { font-size: 11px; padding: 1px 6px; }
  .fc-concept { padding: 7px 11px; }
  .fc-concept .concept-cn { font-size: 13px; }
  .fc-concept .concept-en { font-size: 11px; }
  .fc-chart { padding: 9px; }
  .fc-text { padding: 10px 11px; font-size: 12px; line-height: 1.55; }
  .fc-notes { padding: 8px 11px; }
  .fc-notes textarea { font-size: 12px; }

  /* ---- Deep dive: ensure category headers wrap nicely ---- */
  .cat-section-header { padding: 9px 12px; gap: 9px; top: 92px; }  /* taller stacked mobile nav */
  .cat-section-header .cat-icon { font-size: 21px; }
  .cat-section-header .cat-name { font-size: 14px; }
  .cat-section-header .cat-count { font-size: 11px; padding: 1px 8px; }
  .deep-dive-sidebar { padding: 14px; }
  .deep-dive-sidebar h3 { font-size: 14px; }
  .deep-dive-sidebar .mnemonic-list li { font-size: 13px; padding: 6px 0 6px 18px; }

  /* ---- Drawer (concept comparison) ---- */
  .drawer {
    width: 100vw;
    border-left: none;
  }
  .drawer-header { padding: 12px 14px; gap: 10px; }
  .drawer-header h2 { font-size: 14px; }
  .drawer-title-en { font-size: 11px; }
  .drawer-marker { padding: 3px 8px; font-size: 11px; }
  .drawer-close { width: 30px; height: 30px; font-size: 19px; }
  .drawer-body { padding: 12px; }
  .drawer-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .drawer-card-text { font-size: 11px; line-height: 1.45; }

  /* ---- Concept Lens ---- */
  .cl-toolbar { padding: 10px 12px; gap: 10px; }
  .cl-toolgroup { font-size: 13px; }
  .cl-toolgroup select { font-size: 13px; padding: 4px 8px; }
  .cl-stats { margin-left: 0; flex-basis: 100%; }
  .cl-row-header { padding: 10px 12px; gap: 9px; }
  .cl-row-cn { font-size: 14px; }
  .cl-row-en { font-size: 11px; }
  .cl-cell { padding: 9px 7px; }
  .cl-mini-card { padding: 5px; }
  .cl-mini-text { font-size: 12px; line-height: 1.5; }

  /* ---- Live Scan ---- */
  .scan-checklist, .scan-panel { padding: 12px; }
  .scan-cat-header { font-size: 13px; padding: 6px 9px; }
  .scan-item { font-size: 12px; }
  .scan-item-text .en { display: none; } /* drop EN translation on phones to save room */
  .scan-summary { font-size: 12px; padding: 7px; }
  .scan-rank-name { font-size: 13px; gap: 6px; }
  .scan-rank-pct { font-size: 13px; }
  .scan-rank-detail { font-size: 11px; }

  /* ---- Flash Drill ---- */
  .drill-mode-tab { padding: 11px 12px; }
  .drill-mode-tab .m-icon { font-size: 19px; }
  .drill-mode-tab .m-name { font-size: 14px; }
  .drill-mode-tab .m-desc { font-size: 11px; }
  .drill-stats { gap: 8px; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
  .ds-block { padding: 10px 11px; }
  .ds-num { font-size: 19px; }
  .ds-label { font-size: 11px; }
  .drill-card { padding: 16px 14px; }
  .dc-prompt { font-size: 14px; margin-bottom: 14px; }
  .dc-chart-large { padding: 10px; }
  .dc-chart-large .pa-chart { max-width: 100%; }
  .dc-text-front { padding: 16px 14px; font-size: 14px; line-height: 1.65; }
  .dc-text-revealed { padding: 10px 12px; font-size: 13px; line-height: 1.6; }
  .dc-concept-front .cn-large { font-size: 19px; }
  .drill-choices,
  .drill-choices.choices-8 { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .drill-choice-btn { padding: 11px 6px; font-size: 13px; }
  .drill-choice-btn .m-icon { font-size: 19px; }
  .drill-rate-btn { padding: 8px 14px; font-size: 13px; }
  .drill-session-bar { padding: 8px 12px; font-size: 13px; gap: 8px; flex-wrap: wrap; }
  .drill-end-state { padding: 28px 14px; }
  .drill-end-state h2 { font-size: 18px; }

  /* ---- Tracker ---- */
  .tracker-stats { gap: 10px; grid-template-columns: repeat(2, 1fr); }
  .stat-card { padding: 11px 12px; gap: 10px; }
  .sc-icon { font-size: 23px; }
  .sc-num { font-size: 19px; }
  .tracker-section { padding: 14px; }
  .ts-title { font-size: 15px; }
  .ts-subtitle { font-size: 12px; margin-bottom: 12px; }
  .heatmap-grid {
    grid-template-columns: 90px repeat(5, minmax(70px, 1fr));
    min-width: 540px;
  }
  .hm-cell { padding: 8px 4px; font-size: 12px; min-height: 48px; }
  .hm-cell-num { font-size: 16px; }
  .hm-cell-frac { font-size: 10px; }
  .hm-row-label { padding-left: 8px; font-size: 12px; }
  .hm-row-label .m-icon { font-size: 16px; }
  .heatmap-legend { font-size: 12px; gap: 6px; }
  .session-row { font-size: 13px; padding: 9px 12px; }
  .weak-item { padding: 10px 12px; gap: 10px; grid-template-columns: 36px 1fr; }
  .wi-rank { font-size: 16px; }
  .wi-concept { font-size: 13px; }
  .wi-text { font-size: 11px; }

  /* ---- Modals & tooltips ---- */
  .modal-backdrop { padding: 16px 8px; }
  .modal-content { max-height: calc(100vh - 32px); }
  .modal-header { padding: 12px 14px; }
  .modal-header h2 { font-size: 15px; }
  .modal-body { padding: 14px; }
  .csb-tooltip,
  .instant-tooltip {
    max-width: calc(100vw - 24px);
    font-size: 12px;
  }

  /* ---- Footer ---- */
  footer { padding: 18px 12px; font-size: 12px; }
}

/* ==========================================================================
   SMALL PHONES (≤400px) — extra-tight tweaks
   ========================================================================== */
@media (max-width: 400px) {
  .topnav { padding: 9px 10px; gap: 8px; }
  .topnav .logo { font-size: 14px; }
  .topnav nav a { padding: 4px 8px; font-size: 12px; }
  .lang-btn { padding: 3px 6px; font-size: 11px; }
  main { padding: 12px 10px; }
  .page-header h1 { font-size: 17px; }
  .matrix {
    grid-template-columns: 80px repeat(5, minmax(58px, 1fr));
    min-width: 460px;
  }
  .heatmap-grid {
    grid-template-columns: 80px repeat(5, minmax(58px, 1fr));
    min-width: 460px;
  }
  .pattern-btn { padding: 8px 10px; font-size: 12px; }
  .pattern-btn .icon { font-size: 17px; }
  .tracker-stats { grid-template-columns: 1fr 1fr; }
  .drill-mode-tab .m-name { font-size: 13px; }
}
