/*
 * marcela-shell.css
 * Persistent application shell: left rail, context bar, content region, action zone.
 * Platform target: iPadOS landscape (1024 × 768). Scales to desktop.
 */

/* =============================================
   DESIGN TOKENS
   Shared with marcela-learning-page.css via :root
   ============================================= */
:root {
  /* Color */
  --ink:              #1a1c20;
  --ink-soft:         #4c525b;
  --ink-faint:        #8b9099;
  --line:             #2b2f36;
  --rule:             #c6cbd2;
  --rule-light:       #e4e7ec;
  --paper:            #ffffff;
  --bg:               #f0f2f5;
  --focus-bg:         #eef1f7;
  --focus-bg-strong:  #e4e9f3;
  --accent:           #3f5d86;
  --accent-deep:      #2f486b;
  --accent-light:     #d4dff0;
  --peer-bg:          #fbfbfc;

  /* Source status */
  --status-clear:     #1e6b3e;
  --status-caution:   #8b5c00;
  --status-blocked:   #8b2500;
  --status-return:    #5c2d91;
  --status-clear-bg:  #e8f5ee;
  --status-caution-bg: #fef3e2;
  --status-blocked-bg: #fdf0eb;
  --status-return-bg: #f1ebfb;

  /* Shell dimensions */
  --rail-w:           72px;
  --ctx-h:            48px;
  --action-h:         52px;
  --seg-tab-h:        44px;

  /* Typography */
  --font-sans: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(20,24,32,.07);
  --shadow-md: 0 2px 8px rgba(20,24,32,.10);
  --shadow-lg: 0 6px 24px rgba(20,24,32,.13);
}

/* =============================================
   RESET
   ============================================= */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, [role="button"] {
  font-family: var(--font-sans);
  touch-action: manipulation;
}

/* =============================================
   APP SHELL
   ============================================= */
.app {
  display: flex;
  width: 100vw;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

/* =============================================
   LEFT RAIL
   ============================================= */
.left-rail {
  width: var(--rail-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  overflow: hidden;
  z-index: 10;
}

.rail-brand {
  height: var(--ctx-h);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.rail-brand-mark {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: .1em;
  color: rgba(255,255,255,.5);
  user-select: none;
}

.rail-nav {
  flex: 1;
  list-style: none;
  padding: 8px 0;
  overflow: hidden;
}

.rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 9px 4px;
  cursor: pointer;
  border-left: 3px solid transparent;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s, border-color .12s;
  min-height: 54px;
  user-select: none;
}

.rail-item:hover {
  background: rgba(255,255,255,.07);
}

.rail-item.active {
  background: rgba(63,93,134,.28);
  border-left-color: var(--accent);
}

.rail-icon {
  width: 20px;
  height: 20px;
  color: rgba(255,255,255,.45);
  flex-shrink: 0;
  transition: color .12s;
}

.rail-item.active .rail-icon {
  color: #fff;
}

.rail-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: rgba(255,255,255,.58);
  text-align: center;
  line-height: 1.08;
  font-weight: 500;
  transition: color .12s;
}

.rail-item.active .rail-label {
  color: rgba(255,255,255,.92);
}

/* =============================================
   APP RIGHT (context bar + content + actions)
   ============================================= */
.app-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* =============================================
   CONTEXT BAR
   ============================================= */
.context-bar {
  height: var(--ctx-h);
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--rule-light);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 0;
  overflow: hidden;
}

.cb-area {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-faint);
  letter-spacing: .04em;
  white-space: nowrap;
  flex-shrink: 0;
}

.cb-sep {
  width: 1px;
  height: 14px;
  background: var(--rule);
  margin: 0 11px;
  flex-shrink: 0;
}

.cb-block {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--ink-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

.cb-unit {
  font-size: 11px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cb-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cb-spacer {
  flex: 1;
  min-width: 8px;
}

/* Source status badge */
.cb-source {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: var(--bg);
  flex-shrink: 0;
}

.cs-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cb-source[data-status="clear"]   { border-color: #a3c9a8; background: var(--status-clear-bg); }
.cb-source[data-status="caution"] { border-color: #e0bb7a; background: var(--status-caution-bg); }
.cb-source[data-status="blocked"] { border-color: #f0b0a0; background: var(--status-blocked-bg); }
.cb-source[data-status="return"]  { border-color: #bca8e8; background: var(--status-return-bg); }

.cb-source[data-status="clear"]   .cs-dot { background: var(--status-clear); }
.cb-source[data-status="caution"] .cs-dot { background: var(--status-caution); }
.cb-source[data-status="blocked"] .cs-dot { background: var(--status-blocked); }
.cb-source[data-status="return"]  .cs-dot { background: var(--status-return); }

/* =============================================
   CONTENT REGION
   ============================================= */
.content-region {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Area panels (Home, Learn, Topics, etc.) */
.area-panel {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 28px;
}

.area-panel.active {
  display: block;
}

/* Learning page panel */
.page-panel {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
}

.page-panel.active {
  display: flex;
}

/* ---- Segment tabs (within page panel) ---- */
.segment-tabs {
  height: var(--seg-tab-h);
  flex-shrink: 0;
  background: var(--paper);
  border-bottom: 1px solid var(--rule-light);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 3px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.segment-tabs::-webkit-scrollbar { display: none; }

.seg-btn {
  display: inline-flex;
  align-items: center;
  padding: 0 13px;
  height: 30px;
  min-height: 30px;
  min-width: 44px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .12s, background .12s;
}

.seg-btn:hover {
  background: var(--rule-light);
  color: var(--ink);
}

.seg-btn.active {
  background: var(--accent-light);
  color: var(--accent-deep);
  font-weight: 600;
}

/* ---- Segment content ---- */
.seg-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.seg-panel {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.seg-panel.active {
  display: block;
}

/* Visual segment: scrollable content zone */
#seg-visual {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

#seg-visual.active {
  display: block;
}

/* =============================================
   ACTION ZONE
   ============================================= */
.action-zone {
  height: var(--action-h);
  flex-shrink: 0;
  background: var(--paper);
  border-top: 1.5px solid var(--rule);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.action-zone::-webkit-scrollbar { display: none; }

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  padding: 0 16px;
  height: 44px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: 1.2px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  white-space: nowrap;
  transition: border-color .12s, color .12s, background .12s;
  flex-shrink: 0;
}

.action-btn:disabled {
  opacity: .46;
  cursor: not-allowed;
  box-shadow: none;
}

.action-btn:disabled:hover {
  border-color: var(--rule-light);
  color: var(--ink-faint);
  background: var(--paper);
}

.action-btn:hover {
  border-color: var(--accent-light);
  color: var(--ink);
}

.action-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.action-btn.primary:hover {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.action-btn.dim {
  color: var(--ink-faint);
  border-color: var(--rule-light);
}

.action-btn .btn-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.action-sep {
  width: 1px;
  height: 20px;
  background: var(--rule-light);
  flex-shrink: 0;
}

.action-spacer { flex: 1; }

.az-area-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* =============================================
   AREA PANEL COMPONENTS
   ============================================= */

/* --- HOME --- */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 4px;
}

.home-block-card {
  grid-column: 1 / -1;
  background: var(--paper);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: var(--shadow-md);
}

.home-block-card .hbc-eyebrow {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 5px;
}

.home-block-card .hbc-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
  margin-bottom: 6px;
}

.home-block-card .hbc-desc {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.home-next-card {
  grid-column: 1 / -1;
  background: var(--focus-bg);
  border: 1.5px solid var(--accent-light);
  border-radius: 8px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s, border-color .12s;
}

.home-next-card:hover {
  background: var(--focus-bg-strong);
  border-color: var(--accent);
}

.home-next-card .hnc-meta .hnc-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 4px;
}

.home-next-card .hnc-meta .hnc-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.home-next-card .hnc-meta .hnc-unit {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.home-next-card .hnc-cta {
  padding: 9px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.home-stat-card {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.home-stat-card .hsc-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 500;
  margin-bottom: 8px;
}

.home-stat-card .hsc-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
  margin-bottom: 2px;
}

.home-stat-card .hsc-sub {
  font-size: 12px;
  color: var(--ink-soft);
}

/* --- LEARN (block list) --- */
.learn-header {
  margin-bottom: 16px;
}

.learn-header h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--ink);
  margin-bottom: 4px;
}

.learn-header p {
  font-size: 13px;
  color: var(--ink-soft);
}

.block-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block-row {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color .12s, box-shadow .12s, background .12s;
}

.block-row.active { border-color: var(--accent-light); }

.block-row.expanded {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 1px rgba(63, 93, 134, .06), var(--shadow-sm);
}

.block-row.expanded .block-header {
  background: var(--focus-bg);
  border-bottom: 1px solid var(--rule-light);
}

.block-row.placeholder {
  opacity: .55;
  border-style: dashed;
  box-shadow: none;
}

.block-row.placeholder .block-header {
  cursor: default;
}

.block-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.block-badge {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--rule-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
}

.block-row.active .block-badge {
  background: var(--accent);
  color: #fff;
}

.block-meta .block-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 3px;
}

.block-row.active .block-meta .block-label { color: var(--accent); }

.block-meta {
  min-width: 0;
}

.block-meta .block-title {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
}

.block-row.placeholder .block-meta .block-title {
  color: var(--ink-soft);
  font-weight: 600;
}

.block-chevron {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--rule-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  transition: transform .15s, background .12s, color .12s;
}

.block-row.active .block-chevron,
.block-row.expanded .block-chevron {
  background: var(--accent-light);
  color: var(--accent-deep);
}

.block-row.expanded .block-chevron { transform: rotate(90deg); }

/* Unit list */
.unit-list {
  border-top: 1px solid var(--rule-light);
  background: var(--focus-bg);
  padding: 10px 0 12px;
}

.unit-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 12px 6px 16px;
  padding: 11px 14px 11px 12px;
  border: 1px solid var(--rule-light);
  border-left: 3px solid var(--rule-light);
  border-radius: 7px;
  background: var(--paper);
  min-height: 46px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, border-color .1s, box-shadow .1s;
}

.unit-item:last-child { margin-bottom: 0; }
.unit-item:hover {
  background: var(--focus-bg-strong);
  border-color: var(--accent-light);
}

.unit-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rule);
  flex-shrink: 0;
}

.unit-item.has-pages {
  border-left-color: var(--accent-light);
}

.unit-item.has-pages .unit-dot { background: var(--accent-light); }
.unit-item.active-unit {
  background: var(--focus-bg-strong);
  border-color: var(--accent-light);
  border-left-color: var(--accent);
}

.unit-item.active-unit .unit-dot { background: var(--accent); }

.unit-label {
  min-width: 0;
  font-size: 13.25px;
  line-height: 1.25;
  font-weight: 600;
  color: var(--ink-soft);
  flex: 1;
}

.unit-item.active-unit .unit-label { font-weight: 700; color: var(--ink); }

.unit-item > span:last-child {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-light);
  border: 1px solid var(--accent-light);
  color: var(--accent-deep) !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  line-height: 1;
  letter-spacing: .02em;
  white-space: nowrap;
}

/* Page links inside unit */
.page-link-list {
  margin: 0 12px 10px 28px;
  border: 1px solid var(--rule-light);
  border-left: 3px solid var(--accent-light);
  border-radius: 0 7px 7px 7px;
  background: var(--paper);
  overflow: hidden;
  padding: 4px 0;
}

.page-link-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 16px;
  border-bottom: 1px solid var(--rule-light);
  min-height: 42px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, color .1s;
}

.page-link-item:last-child { border-bottom: none; }
.page-link-item:hover { background: var(--focus-bg); }

.pli-type {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .035em;
  text-transform: uppercase;
  color: var(--accent-deep);
  font-weight: 600;
  background: var(--accent-light);
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.pli-title {
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
  flex: 1;
}

.pli-arrow {
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* --- TOPICS --- */
.topics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.topic-card {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
  cursor: default;
  display: flex;
  flex-direction: column;
}

.topic-card.available {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-color: var(--accent-light);
  transition: background .12s, border-color .12s, box-shadow .12s;
}

.topic-card.available:hover {
  background: var(--focus-bg);
  border-color: var(--accent);
}

.topic-card .tc-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--rule-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 14px;
  flex-shrink: 0;
}

.topic-card.available .tc-icon { background: var(--accent-light); }

.topic-card .tc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 5px;
  line-height: 1.25;
}

.topic-card.placeholder .tc-name { color: var(--ink-soft); }

.topic-card .tc-terms {
  font-size: 11px;
  color: var(--ink-faint);
  line-height: 1.45;
  flex: 1;
  margin-bottom: 10px;
}

.topic-card.available .tc-terms { color: var(--ink-soft); }

.topic-card .tc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.topic-card .tc-count {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--ink-faint);
  letter-spacing: .03em;
}

.topic-card.available .tc-count { color: var(--ink-faint); }

.topic-card .tc-cta {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

/* ---- Topic detail panel ---- */
.tc-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
  margin-bottom: 22px;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
  transition: color .12s;
}
.tc-back-btn:hover { color: var(--accent); }

.tc-detail-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.tc-detail-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.tc-detail-meta { min-width: 0; }

.tc-detail-name {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
  letter-spacing: -.02em;
  line-height: 1.15;
}

.tc-detail-desc {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  max-width: 560px;
}

.tc-detail-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 22px;
}

.tc-term-chip {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--accent-deep);
  background: var(--accent-light);
  padding: 3px 9px;
  border-radius: 999px;
}

.tc-pages-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
  margin-bottom: 8px;
}

.tc-page-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-width: 620px;
}

.tc-page-item {
  display: block;
  padding: 14px 16px;
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-left: 3px solid var(--accent-light);
  border-radius: 7px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, border-color .1s;
}

.tc-page-item:hover {
  background: var(--focus-bg);
  border-left-color: var(--accent);
  border-color: var(--accent-light);
}

.tc-page-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}

.tc-page-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
  flex: 1;
  min-width: 0;
}

.tc-page-desc {
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.4;
  margin-bottom: 10px;
}

.tc-page-facts {
  list-style: none;
  margin: 0;
  padding: 9px 12px;
  background: var(--bg);
  border-radius: 5px;
}

.tc-page-facts li {
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.4;
  padding-left: 14px;
  position: relative;
  margin-bottom: 5px;
}

.tc-page-facts li:last-child { margin-bottom: 0; }

.tc-page-facts li::before {
  content: '·';
  position: absolute;
  left: 2px;
  color: var(--accent);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.15;
}

.tc-page-facts strong { color: var(--ink); }

.tc-page-arrow {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
  white-space: nowrap;
}

/* --- PRACTICE --- */
.practice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.practice-card {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  opacity: .65;
}

.practice-card--available {
  opacity: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border-color: var(--accent-light);
  background: var(--focus-bg);
  transition: border-color .12s, background .12s, transform .12s, box-shadow .12s;
}

.practice-card--available:hover,
.practice-card--available:focus-visible {
  border-color: var(--accent);
  background: var(--focus-bg-strong);
  outline: none;
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.practice-card--available .pc-icon {
  background: var(--accent-light);
  color: var(--accent);
}

.practice-card .pc-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--rule-light);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--ink-faint);
}

.practice-card .pc-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
}

.practice-card .pc-desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin-bottom: 12px;
}

.practice-card .pc-state {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 500;
}

.pc-state--active {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--status-clear);
  background: var(--status-clear-bg);
  border: 1px solid rgba(30, 107, 62, 0.3);
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 600;
}

.pc-state--active::before {
  content: '';
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--status-clear);
  flex-shrink: 0;
}

.practice-note {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--focus-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

/* --- FLASHCARDS --- */
.flashcard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  max-width: 980px;
}

.flashcard-back-btn {
  height: 36px;
  padding: 0 13px;
  border: 1.2px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink-soft);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.flashcard-back-btn:hover,
.flashcard-back-btn:focus-visible {
  border-color: var(--accent);
  color: var(--accent-deep);
  outline: none;
}

.flashcard-set-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.flash-topic-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  max-width: 1040px;
}

.flash-topic-card {
  min-height: 166px;
  border: 1.2px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  text-align: left;
  padding: 18px 18px 16px;
  cursor: pointer;
  display: grid;
  align-content: start;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .12s, background .12s, transform .12s;
}

.flash-topic-card:hover,
.flash-topic-card:focus-visible {
  border-color: var(--accent);
  background: var(--focus-bg);
  outline: none;
  transform: translateY(-1px);
}

.flash-topic-card.is-building,
.flash-topic-card:disabled {
  opacity: .58;
  cursor: default;
  transform: none;
}

.flash-topic-card.is-building:hover,
.flash-topic-card:disabled:hover {
  border-color: var(--rule);
  background: var(--paper);
}

.ft-status,
.ft-meta {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}

.ft-status--active {
  color: var(--status-clear);
}

.ft-title {
  display: block;
  font-size: 16px;
  line-height: 1.18;
  font-weight: 700;
  color: var(--ink);
}

.ft-desc {
  display: block;
  font-size: 12.5px;
  line-height: 1.42;
  color: var(--ink-soft);
}

.ft-meta {
  align-self: end;
  margin-top: 6px;
}

.flashcard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 980px;
}

.flashcard-card {
  min-height: 176px;
  border: 1.2px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  text-align: left;
  padding: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.flashcard-card:hover,
.flashcard-card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.fc-face {
  display: grid;
  align-content: center;
  gap: 12px;
  min-height: 176px;
  padding: 22px 24px;
  transition: opacity .14s, transform .14s;
}

.fc-back {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: translateY(8px);
  background: var(--focus-bg);
}

.flashcard-card.is-flipped .fc-front {
  opacity: 0;
  transform: translateY(-8px);
}

.flashcard-card.is-flipped .fc-back {
  opacity: 1;
  transform: translateY(0);
}

.fc-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent-deep);
  font-weight: 600;
}

.fc-prompt,
.fc-answer {
  display: block;
  font-size: 18px;
  line-height: 1.28;
  font-weight: 700;
}

.fc-answer {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

/* --- GLOSSARY --- */
.glossary-section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  max-width: 1040px;
}

.glossary-section-card {
  min-height: 164px;
  border: 1.2px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  text-align: left;
  padding: 18px 18px 16px;
  cursor: pointer;
  display: grid;
  align-content: start;
  gap: 8px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .12s, background .12s, transform .12s;
}

.glossary-section-card:hover,
.glossary-section-card:focus-visible {
  border-color: var(--accent);
  background: var(--focus-bg);
  outline: none;
  transform: translateY(-1px);
}

.glossary-section-card.is-building,
.glossary-section-card:disabled {
  opacity: .58;
  cursor: default;
  transform: none;
}

.glossary-section-card.is-building:hover,
.glossary-section-card:disabled:hover {
  border-color: var(--rule);
  background: var(--paper);
}

.gs-status,
.gs-meta {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}

.gs-status--active {
  color: var(--status-clear);
}

.gs-title {
  display: block;
  font-size: 16px;
  line-height: 1.18;
  font-weight: 700;
  color: var(--ink);
}

.gs-desc {
  display: block;
  font-size: 12.5px;
  line-height: 1.42;
  color: var(--ink-soft);
}

.gs-meta {
  align-self: end;
  margin-top: 6px;
}

.glossary-section-body {
  max-width: 1040px;
}

.glossary-jump-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 18px;
}

.glossary-jump-row a {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1.2px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}

.glossary-jump-row a:hover,
.glossary-jump-row a:focus-visible {
  border-color: var(--accent);
  color: var(--accent-deep);
  outline: none;
}

.glossary-category {
  max-width: 1040px;
  margin-bottom: 18px;
}

.glossary-category-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 10px;
}

.gc-eyebrow,
.glossary-category-head span {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}

.glossary-category-head h3 {
  font-size: 16px;
  line-height: 1.2;
  color: var(--ink);
  margin-top: 2px;
}

.glossary-entries {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.glossary-entries--single {
  grid-template-columns: minmax(0, 1fr);
  max-width: 680px;
}

.glossary-entry {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 6px;
  padding: 13px 15px;
  box-shadow: var(--shadow-sm);
  display: grid;
  align-content: start;
}

.ge-term {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent-deep);
  letter-spacing: .02em;
  margin-bottom: 2px;
}

.ge-expansion {
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.ge-def {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink);
}

.ge-see {
  display: inline-flex;
  align-items: center;
  margin-top: 7px;
  min-height: 44px;
  font-size: 11.5px;
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}

.ge-see:hover { text-decoration: underline; }

@media (max-width: 1120px) {
  .glossary-section-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .glossary-entries--single {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .glossary-section-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .glossary-category-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .glossary-entries {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --- PROGRESS --- */
.progress-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.progress-stat {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.ps-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.ps-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.02em;
  line-height: 1;
  margin-bottom: 3px;
}

.ps-sub {
  font-size: 12px;
  color: var(--ink-soft);
}

.progress-block-row {
  background: var(--paper);
  border: 1.2px solid var(--rule);
  border-radius: 8px;
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
}

.pbr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.pbr-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.pbr-pct {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
}

.pbr-bar {
  height: 5px;
  background: var(--rule-light);
  border-radius: 3px;
  overflow: hidden;
}

.pbr-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}

/* --- SOURCES --- */
.source-page-entry {
  background: var(--paper);
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
  max-width: 760px;
}

.spe-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule-light);
}

.spe-meta .spe-id {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 3px;
}

.spe-meta .spe-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.spe-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

.spe-status[data-status="clear"] {
  background: var(--status-clear-bg);
  border: 1px solid #a3c9a8;
}

.spe-status .spe-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.spe-status[data-status="clear"] .spe-dot { background: var(--status-clear); }

.spe-status .spe-status-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .055em;
  text-transform: uppercase;
  font-weight: 600;
}

.spe-status[data-status="clear"] .spe-status-label { color: var(--status-clear); }

.spe-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.spe-table tr { border-bottom: 1px solid var(--rule-light); }
.spe-table tr:last-child { border-bottom: none; }

.spe-table td:first-child {
  padding: 7px 16px 7px 0;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .045em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 500;
  width: 30%;
  vertical-align: top;
}

.spe-table td:last-child {
  padding: 7px 0 7px 8px;
  color: var(--ink);
  line-height: 1.45;
}

/* =============================================
   AREA PANEL HEADINGS (shared)
   ============================================= */
.area-heading {
  margin-bottom: 20px;
}

.area-heading .ah-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .095em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.area-heading h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
  margin-bottom: 4px;
}

.area-heading p {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
}

/* =============================================
   RAIL SOURCE STATUS + THEME TOGGLE
   ============================================= */
.rail-source {
  flex-shrink: 0;
  padding: 0 0 12px;
  display: flex;
  justify-content: center;
}

.rail-source-pill {
  width: 44px;
  height: 44px;
  border-radius: 8px;
}

.rail-source-pill .cs-dot {
  width: 9px;
  height: 9px;
}

.rail-theme-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.42);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background .12s, border-color .12s, color .12s;
  min-width: 44px;
  min-height: 44px;
  font-family: inherit;
}

.rail-theme-btn:hover {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.22);
  color: rgba(255,255,255,.72);
}

.context-theme-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  background: var(--paper);
  border-color: var(--rule);
  color: var(--ink-soft);
  font-size: 17px;
}

.context-theme-btn:hover {
  background: var(--focus-bg);
  border-color: var(--accent);
  color: var(--accent-deep);
}

.theme-alien {
  display: block;
  line-height: 1;
  filter: grayscale(1) saturate(.15) brightness(1.55) contrast(.78);
  text-shadow: none;
  transform: translateY(.5px);
  transition: filter .16s ease, text-shadow .16s ease, transform .16s ease;
}

.context-theme-btn:hover .theme-alien {
  filter: grayscale(1) saturate(.2) brightness(1.75) contrast(.84);
}

html[data-theme="dark"] .theme-alien {
  filter: saturate(1.8) brightness(1.08) contrast(1.08);
  text-shadow:
    0 0 5px rgba(93, 255, 137, .72),
    0 0 13px rgba(93, 255, 137, .36);
}

html[data-theme="dark"] .context-theme-btn:hover .theme-alien {
  filter: saturate(2.1) brightness(1.18) contrast(1.1);
  text-shadow:
    0 0 6px rgba(93, 255, 137, .86),
    0 0 17px rgba(93, 255, 137, .48);
  transform: translateY(.5px) scale(1.04);
}
