@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;
  --line: #d2d2d7;
  --line-soft: rgba(0, 0, 0, 0.08);
  --surface: #ffffff;
  --surface-alt: #f5f5f7;
  --brand: #005EA2;
  --brand-soft: rgba(0, 94, 162, 0.08);
  --good: #1d8a4d;
  --graph-accent: #ff7a1a;
  --graph-accent-soft: rgba(255, 122, 26, 0.1);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --panel-left-width: 270px;
  --panel-right-width: 350px;
  --topbar-height: 68px;
  --chiprow-height: 60px;
  --statusbar-height: 42px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body.is-resizing { cursor: col-resize; user-select: none; }

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-height);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--line-soft);
}

.topbar-title {
  font-family: var(--font);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}

.topbar-subtitle {
  font-size: 0.8125rem;
  letter-spacing: -0.005em;
  color: var(--muted);
  margin: 0.2rem 0 0;
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-ghost {
  font-family: var(--font);
  font-size: 0.84375rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  color: var(--ink);
  background: var(--surface-alt);
  border: 1px solid transparent;
  border-radius: 980px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-ghost:hover { background: #ebebef; }
.btn-ghost:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-ghost[aria-pressed="true"] {
  background: var(--brand);
  color: #ffffff;
}
.btn-ghost[aria-pressed="true"]:hover { background: #00548f; }

/* ---------- Chip row + search ---------- */
.chiprow-wrap {
  flex-shrink: 0;
  border-bottom: 1px solid var(--line-soft);
  padding: 1.1rem 1.5rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chiprow-topics {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chiprow-label {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.chip-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.chip {
  font-family: var(--font);
  font-size: 0.84375rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  padding: 0.5rem 1rem;
  border-radius: 980px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.chip:hover { border-color: var(--chip-color, var(--brand)); color: var(--ink); }
.chip[aria-pressed="true"] {
  background: var(--chip-color, var(--brand));
  border-color: var(--chip-color, var(--brand));
  color: #ffffff;
}

.chiprow-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.search-input {
  flex-shrink: 0;
  width: 220px;
  font-family: var(--font);
  font-size: 0.875rem;
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  color: var(--ink);
}
.search-input::placeholder { color: var(--faint); }
.search-input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

@media (max-width: 900px) {
  .chiprow-actions { margin-left: 0; width: 100%; }
  .search-input { width: 100%; max-width: 360px; }
}

/* ---------- Explorer body (3 resizable panes) ---------- */
.explorer {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--panel-left-width) 1px 1fr 1px var(--panel-right-width);
}

/* Nothing to browse yet (no category, term, search, or review active) —
   collapse the empty left panel and its divider so the graph gets that
   width back instead of framing blank space. Zeroing the panel's own box
   (rather than grid-template-columns alone) also collapses it on the
   mobile layout below, where the grid runs in rows instead of columns.
   visibility, not display: none — a display:none grid item drops out of
   the auto-placement flow entirely, which re-numbers every track after it
   (panel-center would slide into column 1, panel-right into panel-center's
   column...). visibility:hidden hides it (and its resize-handle pseudo-
   elements) while leaving its column/row slot intact. */
.explorer.is-left-collapsed {
  grid-template-columns: 0px 0px 1fr 1px var(--panel-right-width);
}
.explorer.is-left-collapsed .panel-left,
.explorer.is-left-collapsed [data-resize-handle="left"] {
  visibility: hidden;
}
.explorer.is-left-collapsed .panel-left {
  max-height: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
}

.panel {
  min-height: 0;
  overflow-y: auto;
}

.panel-left {
  border-right: 1px solid rgba(0, 94, 162, 0.14);
  background: var(--surface-alt);
  padding: 1.25rem 1.1rem;
}

.panel-right {
  border-left: 1px solid rgba(0, 94, 162, 0.14);
  padding: 1.4rem 1.5rem;
}

.resize-handle {
  cursor: col-resize;
  position: relative;
  background: var(--line-soft);
}
.resize-handle::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: -6px;
  width: 13px;
}
/* Always-visible grip pill, so the divider reads as draggable at a glance
   instead of hiding that as a 1px line you'd only find by accident. */
.resize-handle::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 4px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: var(--line);
  box-shadow: 0 0 0 3px var(--surface);
  transition: background 0.15s ease, height 0.15s ease;
}
.resize-handle:hover,
.resize-handle:focus-visible {
  background: var(--brand);
}
.resize-handle:hover::before,
.resize-handle:focus-visible::before {
  background: var(--brand);
  height: 56px;
}

.panel-center {
  position: relative;
  border: 1px solid rgba(255, 122, 26, 0.4);
  border-top: 3px solid var(--graph-accent);
  background-color: var(--surface);
  background-image: radial-gradient(circle, rgba(0, 0, 0, 0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  overflow: hidden;
}

#graphCanvas { position: absolute; inset: 0; display: block; cursor: grab; touch-action: none; }

.graph-labels { position: absolute; inset: 0; pointer-events: none; }

.graph-label {
  position: absolute;
  top: 0; left: 0;
  transform: translate(-9999px, -9999px);
  translate: -50% calc(-100% - 10px);
  pointer-events: auto;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--line-soft);
  border-radius: 980px;
  padding: 0.22rem 0.6rem 0.22rem 0.45rem;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.32rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: opacity 0.2s ease, border-color 0.15s ease, color 0.15s ease;
}
.graph-label::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--dot-color, var(--brand));
  flex-shrink: 0;
}
.graph-label--category { font-weight: 600; font-size: 0.78rem; }
.graph-label--term { max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
.graph-label.is-hidden { opacity: 0; pointer-events: none; }
.graph-label.is-dim { opacity: 0.4; }
.graph-label.is-active {
  border-color: var(--dot-color, var(--brand));
  color: var(--ink);
  background: #ffffff;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
}
.graph-label:hover { border-color: var(--dot-color, var(--brand)); color: var(--ink); }

.map-key {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  font-size: 0.72rem;
  color: var(--muted);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}
.map-key-title { font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.64rem; color: var(--faint); margin-bottom: 0.4rem; }
.map-key-row { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.28rem; }
.map-key-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.map-key-hint {
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line-soft);
  font-size: 0.66rem;
  color: var(--faint);
}

.wholemap-btn {
  position: absolute;
  top: 1rem; right: 1rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

/* ---------- Left panel content ---------- */
.section-header { margin-bottom: 0.85rem; }
.section-header-step {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
}
.section-header-sub {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.empty-state {
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--faint);
}

.term-list { display: flex; flex-direction: column; gap: 0.25rem; }

.az-letter {
  margin: 0.9rem 0.2rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--brand);
}
.az-letter:first-child { margin-top: 0.1rem; }

.term-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.85rem;
  letter-spacing: -0.005em;
  color: var(--ink);
  transition: background 0.12s ease, border-color 0.12s ease;
}
.term-row:hover { background: var(--surface); border-color: var(--line-soft); }
.term-row.is-active { background: var(--surface); border-color: var(--brand); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05); }

.term-row-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot-color, var(--brand)); flex-shrink: 0; }
.term-row-label { flex: 1; }
.term-row-check { color: var(--good); font-size: 0.8rem; }

/* ---------- Right panel content ---------- */
.detail-eyebrow {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.detail-eyebrow-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot-color, var(--brand)); }

.detail-title {
  font-family: var(--font);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.022em;
  line-height: 1.2;
  margin: 0 0 1rem;
  color: var(--ink);
}

.detail-intro { font-size: 0.925rem; letter-spacing: -0.008em; color: var(--muted); line-height: 1.6; }

.detail-block { margin-bottom: 1.1rem; }
.detail-block-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 0.4rem;
}
.detail-block-text { font-size: 0.9125rem; line-height: 1.62; letter-spacing: -0.006em; margin: 0; color: var(--ink); }

.detail-block--callout {
  background: var(--brand-soft);
  border: 1px solid rgba(0, 94, 162, 0.16);
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.detail-block--callout .detail-block-label { color: var(--brand); }

.detail-block--warn {
  background: #fff6ea;
  border: 1px solid #f3ddb2;
  border-radius: 12px;
  padding: 0.9rem 1rem;
}
.detail-block--warn .detail-block-label { color: #a15c00; }

.related-chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.related-chip {
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  padding: 0.4rem 0.8rem;
  border-radius: 980px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.related-chip::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--dot-color, var(--brand));
}
.related-chip:hover { border-color: var(--dot-color, var(--brand)); background: var(--surface-alt); }

/* ---------- Status bar ---------- */
.statusbar {
  height: var(--statusbar-height);
  flex-shrink: 0;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.3rem;
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--surface-alt);
}

.statusbar-reset {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 0.76rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 0;
}
.statusbar-reset:hover { text-decoration: underline; }

/* ---------- Status bar progress ---------- */
.statusbar-progress {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.statusbar-progress-track {
  width: 180px;
  height: 6px;
  border-radius: 999px;
  background: #e0e0e0;
  overflow: hidden;
  flex-shrink: 1;
}
.statusbar-progress-fill {
  height: 100%;
  width: 0;
  background: var(--brand);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* ---------- App buttons (tours / review) ---------- */
.btn-app {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-app:disabled { opacity: 0.45; cursor: default; }
.btn-app--primary { background: var(--brand); border-color: var(--brand); color: #ffffff; }
.btn-app--primary:hover:not(:disabled) { background: #00548f; }
.btn-app--ghost { background: var(--surface-alt); color: var(--ink); }
.btn-app--ghost:hover:not(:disabled) { background: #ebebef; }

/* ---------- Completion state (shared by flashcard review) ---------- */
.review-done { display: flex; flex-direction: column; align-items: flex-start; gap: 0.8rem; }
.tour-done-badge {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--good);
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tour-done-actions { display: flex; gap: 0.55rem; flex-wrap: wrap; margin-top: 0.3rem; }

/* ---------- Flashcard review ---------- */
.review-stats { margin-top: 0.7rem; }
.review-card { perspective: 1200px; min-height: 360px; }
.review-card-inner {
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.64, 1);
}
.review-card.is-flipped .review-card-inner { transform: rotateY(180deg); }
.review-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.07);
}
.review-face--front {
  width: 100%;
  min-height: 340px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.7rem;
  padding: 1.6rem;
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font);
  text-align: left;
}
.review-face--front:hover { border-color: var(--brand); }
.review-face--front:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.review-front-title { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); line-height: 1.15; }
.review-front-hint { font-size: 0.8rem; color: var(--faint); }
.review-face--back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  background: var(--surface);
  padding: 1.3rem 1.4rem;
  overflow-y: auto;
  max-height: 480px;
}
.review-actions { display: flex; gap: 0.55rem; margin-top: 1rem; }
.review-actions .btn-app { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  .review-card-inner { transition: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .statusbar { flex-wrap: wrap; gap: 0.4rem; padding: 0.5rem 1rem; height: auto; }
  .statusbar-progress-track { width: 100px; }
  .explorer {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .panel-left, .panel-right { max-height: 220px; }
  .resize-handle { display: none; }
  .panel-center { min-height: 300px; }
}
