:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #1e293b;
  --ink-soft: #56677d;
  --line: #dbe3ec;
  --accent: #2563eb;
  --accent-soft: #dbe9fe;
  --tag-bg: #e3eaf2;
  --tag-ink: #3d4b5f;
  --page-tag: #e2f3ef;
  --page-ink: #1f6f63;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(30, 41, 59, 0.06), 0 4px 14px rgba(30, 41, 59, 0.05);
  --success: #16a34a;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.app-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ---------- Header ---------- */

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.app-header-text { min-width: 0; }

.page-title { padding-left: 16px; }

.app-header h1 {
  font-size: 1.6rem;
  margin: 0 0 6px;
}

/* ---------- Language toggle ---------- */

.lang-toggle {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  background: var(--tag-bg);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--tag-ink);
  cursor: pointer;
}

.lang-btn.active {
  background: var(--accent);
  color: #fff;
}

@media (max-width: 480px) {
  .app-header { flex-wrap: wrap; }
}

.subtitle {
  color: var(--ink-soft);
  margin: 0;
  font-size: 0.95rem;
}

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

@media (max-width: 480px) {
  .top-row { flex-wrap: wrap; }
}

.global-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.global-nav-link {
  display: inline-block;
  background: none;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

a.global-nav-link:hover { background: var(--tag-bg); color: var(--ink); }

.global-nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  cursor: default;
}

.back-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding-left: 16px;
}
.back-link:hover { text-decoration: underline; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
}

.breadcrumb-sep {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.breadcrumb-link {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0;
}
.breadcrumb-link:hover { color: var(--accent); text-decoration: underline; }

/* ---------- Home grid ---------- */

.home-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .home-grid { grid-template-columns: repeat(3, 1fr); }
}

.home-card {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 20px 24px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.home-card:not(.disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(30, 41, 59, 0.09);
}

.home-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.home-card p {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.card-status {
  margin-top: auto;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}

.home-card.disabled {
  opacity: 0.55;
  cursor: default;
}
.home-card.disabled .card-status {
  color: var(--ink-soft);
}

.app-footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.app-footer a {
  color: var(--accent);
  font-weight: 600;
}
.app-footer a:hover { text-decoration: none; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 8px;
  margin: 6px 0 0 16px;
  flex-wrap: wrap;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 18px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}

.saved-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
}

.saved-count-badge:empty {
  display: none;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Search & filters ---------- */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 8px;
}

.search-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 11px 40px 11px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--panel);
  color: var(--ink);
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
}

.search-clear.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.search-clear:hover,
.search-clear:focus-visible {
  background: var(--tag-bg);
  color: var(--ink);
  outline: none;
}

.search-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.result-count {
  font-size: 0.82rem;
  color: var(--ink-soft);
  padding-left: 16px;
}

.fc-saved-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.fc-clear-saved-btn {
  background: var(--tag-bg);
  color: var(--tag-ink);
  border: none;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

.fc-clear-saved-btn:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  background: var(--tag-bg);
  color: var(--tag-ink);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 5px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.chip.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- A-Z nav ---------- */

.az-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 18px;
  padding-left: 8px;
}

.az-nav a {
  display: inline-block;
  width: 26px;
  height: 26px;
  line-height: 26px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  border-radius: 6px;
}
.az-nav a:hover { background: var(--accent-soft); }
.az-nav a.disabled {
  color: var(--line);
  pointer-events: none;
}

/* ---------- Definitions list ---------- */

.letter-group {
  margin-bottom: 26px;
}

.letter-heading {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  padding: 0 0 4px 16px;
  margin-bottom: 10px;
  scroll-margin-top: 16px;
}

.def-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.def-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.def-term {
  font-weight: 700;
  font-size: 0.98rem;
}

.def-body {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

/* ---------- Rule cards (numbers/time) ---------- */

.article-group {
  margin-bottom: 30px;
}

.article-heading {
  font-size: 1.02rem;
  font-weight: 800;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  padding: 0 0 4px 16px;
  margin-bottom: 12px;
  scroll-margin-top: 16px;
}

.rule-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.rule-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.rule-title {
  font-weight: 700;
  font-size: 0.98rem;
}

.rule-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 16px;
  border-radius: 999px;
  white-space: nowrap;
}

.tag-section {
  background: var(--tag-bg);
  color: var(--tag-ink);
}

.tag-page {
  background: var(--page-tag);
  color: var(--page-ink);
}

.rule-body {
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.rule-body strong {
  color: var(--ink);
}

.rule-body table {
  border-collapse: collapse;
  margin: 10px 0;
  width: 100%;
  font-size: 0.85rem;
}

.rule-body th, .rule-body td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}

.rule-body th {
  background: #f4f7fb;
  color: var(--ink);
}

/* Mobile only: put the section/page pills + bookmark on their own row at
   the top of the card (pills left, bookmark pushed right), with the title
   dropping to a row below. Desktop keeps the title-first layout.
   Uses flex-direction: column (not flex-wrap + flex-basis: 100%) so the gap
   between the two rows is an explicit, deterministic value -- relying on
   wrap-to-a-new-line behavior instead left the gap dependent on each card's
   content width, which rendered inconsistently between cards. */
@media (max-width: 480px) {
  .rule-card-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .rule-tags {
    order: 1;
    width: 100%;
  }

  .rule-tags .save-toggle {
    margin-left: auto;
  }

  .rule-title {
    order: 2;
  }
}

.no-results {
  color: var(--ink-soft);
  font-style: italic;
  padding: 30px 0;
  text-align: center;
}

/* ---------- Save / bookmark toggle ---------- */

.save-toggle {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.save-toggle:hover,
.save-toggle:focus-visible {
  color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.save-toggle svg {
  width: 17px;
  height: 17px;
}

.save-toggle svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
}

.save-toggle.is-saved {
  color: var(--accent);
}

.save-toggle.is-saved svg path {
  fill: currentColor;
}

/* ---------- Source-excerpt popover ---------- */

/* Trigger button: a small, quiet icon so it doesn't compete with the content */
.source-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  flex-shrink: 0;
}

.source-trigger svg {
  width: 16px;
  height: 16px;
}

.source-trigger svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.source-trigger:hover,
.source-trigger:focus-visible {
  background: var(--accent-soft);
  color: var(--accent);
  outline: none;
}

.source-trigger.is-open {
  background: var(--accent);
  color: #fff;
}

/* Wrapper needed so the popover can be positioned relative to its trigger */
.source-anchor {
  position: relative;
  display: inline-block;
}

.source-popover {
  position: absolute;
  z-index: 40;
  top: calc(100% + 8px);
  left: 0;
  width: min(360px, 86vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(30, 41, 59, 0.18);
  padding: 14px 16px;
  animation: pop-in 0.12s ease-out;
}

.source-popover::before {
  content: "";
  position: absolute;
  top: -7px;
  left: var(--arrow-left, 12px);
  width: 12px;
  height: 12px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  transform: rotate(45deg);
}

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.source-popover-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.source-popover-note {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin: -4px 0 10px;
}

.source-popover-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
}

.source-popover-close {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  flex-shrink: 0;
}
.source-popover-close:hover { background: var(--tag-bg); color: var(--ink); }

.source-excerpt {
  font-size: 0.86rem;
  font-weight: 400;
  color: var(--ink);
  border-left: 3px solid var(--accent-soft);
  padding-left: 10px;
  margin: 0 0 10px;
  font-style: normal;
}

.source-excerpt:last-child { margin-bottom: 0; }

.source-excerpt-cite {
  display: block;
  margin-top: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  font-style: normal;
  color: var(--ink-soft);
}

/* ---------- Back to top ---------- */

.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(30, 41, 59, 0.25);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover,
.back-to-top:focus-visible {
  filter: brightness(0.92);
  outline: none;
}

.back-to-top svg {
  width: 20px;
  height: 20px;
}

.back-to-top svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 480px) {
  .back-to-top {
    right: 14px;
    bottom: 14px;
    width: 40px;
    height: 40px;
  }
}

/* Popover position/arrow are computed and set inline by
   clampPopoverToViewport() in study-guide.js on every open, on every screen
   size -- it measures the actual rendered position (after this CSS's
   defaults apply) and corrects both the box and the arrow together, so
   there's no separate narrow-screen override to keep in sync here. */

/* ---------- Flashcards ---------- */

.fc-section-heading {
  font-size: 1rem;
  font-weight: 800;
  color: var(--ink);
  padding-left: 16px;
  margin: 0 0 14px;
}

.fc-source-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.fc-source-option {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  margin-left: 16px;
}

.fc-source-option.is-disabled {
  opacity: 0.55;
  cursor: default;
}

.fc-source-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}

.fc-source-option.is-disabled input[type="checkbox"] { cursor: default; }

.fc-source-option-label {
  flex: 1;
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--ink);
}

.fc-source-option-hint {
  display: block;
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 2px;
}

.fc-count-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  margin-left: 16px;
}

.fc-count-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.94rem;
  color: var(--ink);
}

.fc-count-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.fc-count-option.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.fc-deck-count {
  font-size: 0.85rem;
  color: var(--ink-soft);
  padding-left: 16px;
  margin-bottom: 16px;
}

.fc-primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.fc-primary-btn:hover { filter: brightness(0.94); }

.fc-primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

.fc-secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.fc-secondary-btn:hover { background: var(--tag-bg); }

/* Progress line above the card */
.fc-progress-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 14px;
}

.fc-progress {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.fc-nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: var(--radius);
}

.fc-nav-btn:hover:not(:disabled) { background: var(--tag-bg); }

.fc-nav-btn:disabled {
  color: var(--line);
  cursor: default;
}

.fc-card.is-reviewing {
  opacity: 0.55;
}

/* Card flip */
.fc-card-stage {
  position: relative;
  perspective: 1400px;
  margin-bottom: 20px;
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

/* Changing to a different card: fan the old one away, then slide the new one
   in from the opposite side. Applied to the stage (the flip's perspective
   parent), never to #fc-card itself, so this never fights the flip's rotateY. */
.fc-card-stage.fc-stage-out {
  transition: transform 0.28s cubic-bezier(0.4, 0, 1, 1), opacity 0.24s ease;
  transform: translateX(-36px) rotate(-6deg);
  opacity: 0;
}

.fc-card-stage.fc-stage-in {
  transition: none;
  transform: translateX(36px) rotate(6deg);
  opacity: 0;
}

.fc-save-toggle {
  position: absolute;
  top: 24px;
  right: 14px;
  z-index: 5;
  background: var(--panel);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.fc-card {
  position: relative;
  min-height: 260px;
  border-radius: var(--radius);
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
}

.fc-card.is-flipped {
  transform: rotateY(180deg);
}

.fc-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 52px 24px 28px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.fc-card-back {
  transform: rotateY(180deg);
}

/* backface-visibility: hidden (above) is enough to hide the inactive face's
   own text/background on most browsers, but some mobile engines still let an
   absolutely-positioned interactive child (the bookmark button) render
   through as a mirrored "ghost" on the opposite side. Hide it explicitly by
   flip state instead of relying on backface-visibility alone. */
.fc-card:not(.is-flipped) .fc-card-back .fc-save-toggle {
  visibility: hidden;
  pointer-events: none;
}

.fc-card.is-flipped .fc-card-front .fc-save-toggle {
  visibility: hidden;
  pointer-events: none;
}

.fc-card-kind {
  position: absolute;
  top: 24px;
  left: 24px;
}

.fc-card-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  max-width: 60ch;
  max-height: 100%;
  overflow-y: auto;
}

.fc-card-back .fc-card-text {
  font-size: 0.98rem;
  font-weight: 400;
  color: var(--ink-soft);
}

.fc-card-back .fc-card-text strong { color: var(--ink); }

.fc-answer-note {
  margin-top: 16px;
}

.fc-front-list {
  margin-top: 10px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.fc-front-list-item {
  font-size: 0.94rem;
  font-weight: 500;
  color: var(--ink-soft);
}

.fc-front-list-num {
  font-weight: 700;
  color: var(--ink-soft);
  margin-right: 4px;
}

.fc-options {
  margin-top: 14px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.fc-option {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
}

.fc-option-letter {
  font-weight: 800;
  color: var(--accent);
  margin-right: 4px;
}

#fc-reference {
  margin-top: 20px;
}

.fc-reference-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
  margin-bottom: 8px;
}

.fc-flip-hint {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.76rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.fc-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.fc-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.fc-btn-wrong {
  background: var(--danger-soft);
  color: var(--danger);
}
.fc-btn-wrong:hover { filter: brightness(0.96); }

.fc-btn-right {
  background: var(--success-soft);
  color: var(--success);
}
.fc-btn-right:hover { filter: brightness(0.96); }

.fc-exit-btn {
  display: block;
  margin: 0 auto;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
}
.fc-exit-btn:hover { color: var(--ink); }

.fc-complete-message {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  padding: 30px 16px 20px;
}

.fc-complete-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* My Cards tab */
.fc-add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.fc-add-back {
  resize: vertical;
  font-family: inherit;
}

.fc-add-form .fc-primary-btn {
  align-self: flex-start;
}

.fc-custom-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.fc-custom-card-front {
  font-weight: 700;
  font-size: 0.98rem;
  margin-bottom: 6px;
}

.fc-custom-card-back {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin-bottom: 10px;
  white-space: pre-line;
}

.fc-saved-answer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.fc-saved-answer .fc-custom-card-back {
  margin-bottom: 0;
}

.fc-custom-card-actions {
  display: flex;
  gap: 8px;
}

.fc-custom-card-actions button {
  background: var(--tag-bg);
  color: var(--tag-ink);
  border: none;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.fc-custom-card-actions button:hover { background: var(--accent-soft); color: var(--accent); }

.fc-custom-card-actions .fc-delete-btn:hover { background: var(--danger-soft); color: var(--danger); }

.fc-custom-card-edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fc-saved-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.fc-custom-card-edit-form textarea {
  resize: vertical;
  font-family: inherit;
}

@media (max-width: 480px) {
  .fc-card { min-height: 220px; }
}

/* ---------- Practice Tests ---------- */

.pt-resume-banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.pt-resume-title {
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 4px;
}

.pt-resume-body {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 12px;
}

.pt-resume-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#pt-start-btn {
  margin-left: 16px;
}

#fc-start-btn {
  margin-left: 16px;
  margin-top: 16px;
}

/* The title/tabs inside the header already carry their own 16px inset
   (.page-title padding-left, .tabs margin-left), so the header itself can't
   just get margin-left too -- that would double-indent them. Instead, swap
   its full-width border-bottom for a pseudo-element inset to match. */
#fc-page-header,
#sg-page-header,
#pt-page-header {
  position: relative;
  border-bottom: none;
}
#fc-page-header::after,
#sg-page-header::after,
#pt-page-header::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 0;
  bottom: 0;
  border-top: 1px solid var(--line);
}

/* The footer has no pre-indented children, so shifting the whole box works
   for both its divider and its text in one move. */
#fc-page-footer,
#sg-page-footer,
#pt-page-footer {
  margin-left: 16px;
}

/* Test screen */

.pt-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.pt-timer {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.pt-timer.is-overtime { color: var(--danger); }

.pt-qcounter {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.pt-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.pt-grid-btn {
  width: 34px;
  height: 34px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
  cursor: pointer;
  position: relative;
}

.pt-grid-btn:hover { background: var(--tag-bg); }

.pt-grid-btn.is-answered {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-soft);
}

.pt-grid-btn.is-current {
  border-color: var(--accent);
  border-width: 2px;
}

.pt-grid-btn.is-flagged::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--danger);
}

.pt-question-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.pt-question-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.pt-stem {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
}

.pt-choices {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pt-choice {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

.pt-choice:hover { background: var(--tag-bg); }

.pt-choice.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.pt-choice-letter {
  font-weight: 800;
  margin-right: 4px;
}

.pt-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* Time's up modal */

.pt-modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 41, 59, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60; /* above .back-to-top (z-index 50) so an open modal always covers it */
}

.pt-modal-box {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  max-width: 360px;
  text-align: center;
}

.pt-modal-box h3 { margin: 0 0 10px; }
.pt-modal-box p { margin: 0 0 18px; color: var(--ink-soft); font-size: 0.9rem; }

.pt-modal-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Results screen */

.pt-score-banner {
  text-align: center;
  border-radius: var(--radius);
  padding: 28px 16px;
  margin-bottom: 8px;
  background: var(--tag-bg);
}

.pt-score-banner.is-pass { background: var(--success-soft); }
.pt-score-banner.is-fail { background: var(--danger-soft); }

.pt-score-pct {
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--ink);
}

.pt-score-verdict {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.pt-score-banner.is-pass .pt-score-verdict { color: var(--success); }
.pt-score-banner.is-fail .pt-score-verdict { color: var(--danger); }

.pt-score-meta {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 24px;
}

.pt-breakdown {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.pt-breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 16px;
}

.pt-breakdown-label {
  width: 150px;
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
}

.pt-breakdown-bar {
  flex: 1;
  height: 8px;
  background: var(--tag-bg);
  border-radius: 999px;
  overflow: hidden;
}

.pt-breakdown-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.pt-breakdown-pct {
  width: 90px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.pt-results-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  margin-bottom: 24px;
}

.pt-result-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.pt-result-row.is-correct { border-left-color: var(--success); }
.pt-result-row.is-incorrect { border-left-color: var(--danger); }

.pt-result-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.pt-result-num {
  font-weight: 800;
  color: var(--ink-soft);
}

.pt-result-icon {
  margin-left: auto;
  font-weight: 800;
}

.pt-result-row.is-correct .pt-result-icon { color: var(--success); }
.pt-result-row.is-incorrect .pt-result-icon { color: var(--danger); }

.pt-result-stem {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
  text-align: left;
  margin-bottom: 12px;
}

.pt-result-answers {
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pt-your-answer { color: var(--ink-soft); }
.pt-your-answer.is-wrong { color: var(--danger); font-weight: 600; }
.pt-correct-answer { color: var(--success); font-weight: 600; }

.pt-result-row .fc-reference-label { margin-top: 16px; }

/* ---------- Feedback link + modal (shared across all pages) ---------- */

.fb-footer-link {
  background: none;
  border: none;
  padding: 0;
  margin-top: 6px;
  display: inline-block;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}

.fb-footer-link:hover { text-decoration: none; }

.fb-modal-box {
  max-width: 420px;
  text-align: left;
}

.fb-modal-box h3 { margin: 0 0 8px; text-align: center; }
.fb-modal-box p { text-align: center; }

.fb-textarea {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--panel);
  margin-bottom: 12px;
  box-sizing: border-box;
}

.fb-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.fb-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.fb-status {
  min-height: 1.2em;
  margin: 0 0 10px;
  font-size: 0.85rem;
  text-align: center;
}

.fb-status.is-error { color: var(--danger); }
.fb-status.is-success { color: var(--success); }
