:root {
  --bg: #f5f3ef;
  --panel: #ffffff;
  --border: #ddd6cc;
  --text: #2a241c;
  --text-muted: #6b6255;
  --accent: #8a4b2c;
  --accent-bg: #f1e4d8;
  --recruited: #4f7942;
  --star: #c9891b;
  --flag: #3b6ea5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --panel: #262320;
    --border: #3c3630;
    --text: #ece6dc;
    --text-muted: #a89e8f;
    --accent: #d68a5c;
    --accent-bg: #3a2e24;
    --recruited: #7fb069;
    --star: #e0ac4c;
    --flag: #6fa3d8;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-header h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; }
/* Button back to the CalcCodex landing page (www.calccodex.com); styled like .spoiler-toggle */
.header-title { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
/* Solid accent fill like the active .seg-toggle / .rank-tag-btn; :link/:visited listed so it never turns purple or underlined. */
.site-link, .site-link:link, .site-link:visited {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  flex-shrink: 0;
}
.site-link .nav-icon { width: 1.15rem; height: 1.15rem; }
.site-link:hover, .site-link:focus-visible { filter: brightness(1.12); text-decoration: none; }
.site-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.path-switcher {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.path-switcher select {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.app-body {
  display: flex;
  min-height: calc(100vh - 110px);
}

.sidebar {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 0.5rem;
}

.nav-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.75rem;
  margin-bottom: 2px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.nav-btn:hover { background: var(--accent-bg); }
.nav-btn.active { background: var(--accent); color: #fff; }

.content {
  flex: 1;
  padding: 1.25rem;
  overflow-x: auto;
}

.app-footer {
  padding: 0.5rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  gap: 0.75rem;
}

button {
  font-family: inherit;
  cursor: pointer;
}

#export-btn, .import-label {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.85rem;
}
.import-label:hover, #export-btn:hover { background: var(--accent-bg); }

/* Mobile shell: bottom tab bar + "More" sheet replace the sidebar and footer below 700px. */
.title-short, .tabbar { display: none; }
.nav-icon.icon-more { stroke-width: 3.5; }
.nav-icon {
  width: 1.4rem;
  height: 1.4rem;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tab-btn {
  flex: 1;
  min-width: 0;
  min-height: 3.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  padding: 0.35rem 0 0.3rem;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab-btn.active { color: var(--accent); font-weight: 600; }

.more-sheet {
  margin: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: 85dvh;
  padding: 0;
  border: none;
  border-radius: 14px 14px 0 0;
  background: var(--panel);
  color: var(--text);
}
.more-sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-inner {
  padding: 0.5rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
}
.sheet-inner::before {
  content: '';
  display: block;
  width: 2.5rem;
  height: 4px;
  margin: 0 auto 0.5rem;
  border-radius: 2px;
  background: var(--border);
}
.sheet-nav { display: flex; flex-direction: column; }
.sheet-actions { border-top: 1px solid var(--border); margin-top: 0.4rem; padding-top: 0.4rem; }
.sheet-btn {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  min-height: 3rem;
  padding: 0 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
}
.sheet-btn .nav-icon { color: var(--text-muted); }
.sheet-btn.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.sheet-btn.active .nav-icon { color: var(--accent); }

/* Spoiler gating (spoilers.js): header toggle + redacted placeholders */
.header-controls { display: flex; align-items: center; gap: 0.5rem; }
.spoiler-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.8rem;
}
.spoiler-toggle .nav-icon { width: 1.15rem; height: 1.15rem; }
.spoiler-toggle:hover { background: var(--accent-bg); }
.spoiler-toggle.on { color: var(--accent); border-color: var(--accent); }
.spoiler {
  display: inline-block;
  padding: 0 0.35rem;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-style: italic;
  font-weight: normal;
  cursor: help;
}
.spoiler-where { font-size: 0.85em; }
.char-row.is-hidden { cursor: default; }
.char-row.is-hidden:hover { background: var(--panel); }
.spoiler-note { color: var(--text-muted); font-size: 0.8rem; font-style: italic; }
/* Path Tracker lord cards: Part I and Part II dot rows */
.dot-row { display: flex; align-items: center; gap: 0.4rem; }
.dot-row-label { flex-shrink: 0; width: 3.1rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.dot-row .part2-reset { padding: 0 0.3rem; }

/* Part III calendar (laterParts.js) */
.timeline-list { list-style: none; padding: 0 !important; display: flex; flex-direction: column; gap: 0.25rem; }
.timeline-list li { margin: 0 !important; padding-left: 0.6rem; border-left: 3px solid var(--recruited); }
.timeline-list li.timeline-mission { border-left-color: var(--accent); }
.timeline-list li.timeline-current { font-weight: 600; }

/* Act II/III battles, time windows, and collapsible basics (laterParts.js) */
.battle-card { border-top: 1px solid var(--border); padding: 0.5rem 0; font-size: 0.85rem; display: flex; flex-direction: column; gap: 0.2rem; }
.battle-card:first-of-type { border-top: none; padding-top: 0; }
.battle-card h5 { margin: 0 0 0.15rem; font-size: 0.9rem; }
.battle-card ul { margin: 0.15rem 0 0; padding-left: 1.2rem; }
.battle-label { display: inline-block; min-width: 4.2rem; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.battle-strategy summary { cursor: pointer; color: var(--accent); font-size: 0.8rem; }
.battle-strategy p { margin: 0.25rem 0 0; }
.free-time-banner.mission-banner { background: var(--panel); border: 1px solid var(--accent); }
.later-basics > summary { cursor: pointer; }
.later-basics > summary h4 { display: inline; margin: 0; }
.later-basics h5 { margin: 0.6rem 0 0.25rem; font-size: 0.8rem; }
.later-basics ul { font-size: 0.85rem; }
.quest-requires { font-size: 0.75rem; font-weight: 600; color: var(--star); }

@media (max-width: 700px) {
  body { padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
  .spoiler-toggle-label { display: none; }
  .spoiler-toggle { min-width: 2.6rem; min-height: 2.4rem; justify-content: center; }
  .title-full, .sidebar, .app-footer, .path-switcher-label { display: none; }
  .title-short { display: inline; }
  /* Icon-only CalcCodex button on phones, sized like the spoiler toggle. */
  .site-link-label { display: none; }
  .site-link { min-width: 2.6rem; min-height: 2.4rem; justify-content: center; }
  .header-title { gap: 0.6rem; flex-shrink: 0; }
  /* The title keeps its width; the path dropdown shrinks to fit the rest. */
  .header-controls, .path-switcher { min-width: 0; }
  .path-switcher select { min-width: 0; max-width: 100%; text-overflow: ellipsis; }
  .app-header { padding: 0.6rem 1rem; flex-wrap: nowrap; }
  .path-switcher select { font-size: 1rem; }
  .app-body { display: block; min-height: 0; }
  .content { padding: 1rem 1rem calc(4.5rem + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; }
}

/* Narrowest phones: tighten the header so the path dropdown keeps room for a lord's name. */
@media (max-width: 380px) {
  .app-header { padding: 0.6rem 0.6rem; gap: 0.5rem; }
  .app-header h1 { font-size: 1rem; }
  .header-title { gap: 0.4rem; }
  .header-controls { gap: 0.35rem; }
  .site-link, .spoiler-toggle { min-width: 2.4rem; padding: 0.3rem 0.45rem; }
  .path-switcher select { padding: 0.3rem 0.3rem; }
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
  padding: 2rem;
  text-align: center;
}

/* Character list */
.char-toolbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.char-toolbar input[type="text"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  min-width: 220px;
}
.char-group { margin-bottom: 1.25rem; }
.char-group h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 0.4rem;
}
.char-group .hint { margin: 0 0 0.5rem; }

.char-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.char-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--panel);
}
.char-row:last-child { border-bottom: none; }
.char-row:hover { background: var(--accent-bg); }
.char-star {
  width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}
.char-star.clickable {
  border: none;
  background: none;
  font-size: 1.1rem;
  padding: 0;
  cursor: pointer;
  border-radius: 4px;
}
.char-star.clickable:hover { background: var(--accent-bg); color: var(--star); }
.char-star.flag.clickable:hover { color: var(--flag); }
.char-star.marked { color: var(--star); }
.char-star.flag.marked { color: var(--flag); }
.char-star.large { width: auto; height: auto; font-size: 1.3rem; vertical-align: middle; }
.char-name { flex: 1; font-weight: 500; }

/* Character portraits (hot-linked from game8; initials show until/unless the image loads) */
.portrait {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--accent-bg);
  color: var(--text-muted);
  font-weight: 600;
}
.portrait img { position: absolute; }
.portrait.loaded .portrait-initials { visibility: hidden; }
/* The source art is a 334x270 slanted card with the face upper-middle; the thumb zooms onto it. */
.portrait-thumb { width: 2.25rem; height: 2.25rem; border-radius: 50%; font-size: 0.75rem; }
.portrait-thumb img { width: 165%; max-width: none; left: -24%; top: 0; }
.portrait-large { width: 10rem; aspect-ratio: 334 / 270; border-radius: 8px; font-size: 2rem; }
.portrait-large.loaded { background: transparent; }
.portrait-large img { inset: 0; width: 100%; height: 100%; object-fit: contain; }
.char-header { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 0.5rem; }
.char-header-text { flex: 1; min-width: 12rem; }
.char-header h2 { margin-top: 0.25rem; }
.char-aptitudes { font-size: 0.85rem; color: var(--text-muted); }
.char-aptitudes .aptitude-boon { color: var(--star); }
@media (max-width: 700px) {
  .portrait-large { width: 8rem; }
}
.char-badges { display: flex; gap: 3px; }
.path-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--text-muted);
}
.path-badge.recruited {
  background: var(--recruited);
  border-color: var(--recruited);
  color: #fff;
}

/* Character detail */
.back-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.9rem;
  padding: 0;
  margin-bottom: 0.75rem;
}
.tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--star);
  color: #fff;
  vertical-align: middle;
  margin-left: 0.5rem;
}
.tag-standard { background: var(--text-muted); }
.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 60ch;
}
.note { font-size: 0.85rem; margin-bottom: 0.75rem; }

.instance-columns {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  margin: 1rem 0;
}
.instance-column {
  min-width: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.instance-column h4 { margin: 0 0 0.25rem; font-size: 0.9rem; }
.instance-column label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.8rem; }
.instance-column select, .instance-column textarea, .instance-column input[type="text"] {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}
.instance-column textarea { min-height: 3.5rem; resize: vertical; }
.instance-column label.inline-field { flex-direction: row; align-items: center; justify-content: space-between; }
.own-mount { font-size: 0.8rem; }
.instance-column label.check-field { flex-direction: row; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.instance-column input[type="number"] {
  font-family: inherit;
  font-size: 0.8rem;
  width: 3.8rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}
.base-stats-details .hint { margin: 0 0 0.3rem; max-width: none; }
.base-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem 0.6rem; }
.instance-column .base-stats-grid label { flex-direction: row; align-items: center; justify-content: space-between; gap: 0.3rem; }
.req-text { color: var(--text-muted); font-size: 0.75rem; }

.growth-details { font-size: 0.78rem; }
.growth-details summary { cursor: pointer; font-weight: 500; margin-bottom: 0.3rem; }
.growth-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.3rem;
}
.growth-table th, .growth-table td {
  text-align: right;
  padding: 0.15rem 0.35rem;
  border-bottom: 1px solid var(--border);
}
.growth-table th:first-child, .growth-table td:first-child { text-align: left; }
.growth-details .hint { margin: 0 0 0.2rem; max-width: none; }
.not-documented {
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 3px;
  padding: 0 0.3rem;
  cursor: help;
}
.planned-list { list-style: none; padding: 0; margin: 0.25rem 0; display: flex; flex-direction: column; gap: 0.2rem; }
.planned-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--accent-bg);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
.remove-planned {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
}

/* Gifts section on the character page (the card itself is .gift-card, shared with the Gifts page) */
.char-gifts { margin-bottom: 0.75rem; }
.char-gifts h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.char-source { font-size: 0.85rem; margin: 0.5rem 0 0; }

/* Merging Causality view (inside character detail) */
#merge-planner h3 { margin: 0; font-size: 1rem; }
#merge-planner h5 { margin: 0.9rem 0 0.35rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
#merge-planner > .hint { max-width: 90ch; }
.merge-target.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.merge-target.active .quest-meta { color: #fff; opacity: 0.85; }
.merge-table-wrap { overflow-x: auto; margin-top: 0.6rem; }
.merge-table { width: auto; min-width: 420px; font-size: 0.82rem; }
.merge-table td, .merge-table th { text-align: center !important; padding: 0.25rem 0.6rem; vertical-align: top; }
.merge-table td:first-child, .merge-table th:first-child { text-align: left !important; }
.merge-table tr.target td:first-child { font-weight: 600; }
.merge-table tr.target { background: var(--accent-bg); }
.merge-table td.up { color: var(--recruited); }
.merge-table td.top { font-weight: 700; box-shadow: inset 0 -2px 0 var(--recruited); }
.merge-table td.merged { border-left: 2px solid var(--border); }
.merge-table td.uncovered strong { color: var(--star); }
.merge-recs { list-style: none; padding: 0; margin: 0 0 0.5rem; display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.84rem; max-width: 900px; }
.merge-rec { border: 1px solid var(--border); border-radius: 6px; padding: 0.4rem 0.6rem; background: var(--bg); display: flex; flex-direction: column; gap: 0.2rem; }
.merge-rec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.merge-rec .dash-link { padding-left: 0.3rem; }
.penalty { color: var(--star); }
.merge-late-toggle { margin-bottom: 0.5rem; }
.merge-recs-details { margin: 0.9rem 0 0.35rem; }
.merge-recs-details > summary { cursor: pointer; }
#merge-planner .merge-recs-details > summary h5 { display: inline; margin: 0; }
.merge-recs-details[open] > summary { margin-bottom: 0.4rem; }
.merge-union { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.84rem; }
.merge-union .gift-tier-label { width: auto; display: block; margin-bottom: 0.15rem; }

/* Combat stat preview (inside character detail; reuses planner layout/inputs) */
#combat-preview h3 { margin: 0; font-size: 1rem; }
#combat-preview h5 { margin: 0.75rem 0 0.35rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
#combat-preview .planner-inputs .rank-input { margin-bottom: 0.25rem; }
.preview-source { margin: 0 0 0.3rem; font-size: 0.82rem; }
#combat-preview .rank-input select { max-width: 11rem; }
.preview-table { width: auto; min-width: 320px; font-size: 0.82rem; }
.preview-table td, .preview-table th { text-align: right !important; padding: 0.2rem 0.6rem; }
.preview-table td:first-child, .preview-table th:first-child, .preview-table td.quest-meta, .preview-table th:last-child { text-align: left !important; }
.preview-table td.delta.up { color: var(--recruited); font-weight: 600; }
.preview-table td.delta.down { color: var(--star); font-weight: 600; }

/* Ability-slot planner (inside character detail) */
#ability-planner h3 { margin: 0; font-size: 1rem; }
#ability-planner h5 { margin: 0.75rem 0 0.35rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
#ability-planner h5:first-child { margin-top: 0; }
.planner-layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 1.25rem; align-items: start; }
.planner-inputs, .planner-output { font-size: 0.85rem; min-width: 0; }
.rank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem 0.75rem; }
.rank-input { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; font-size: 0.8rem; }
.rank-input.preferred span { color: var(--star); font-weight: 600; }
.rank-input.bane span { color: var(--text-muted); }
.rank-input select { min-width: 3.6rem; }
.level-input {
  width: 4.5rem;
  font-family: inherit;
  padding: 0.2rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}
.mastered-actions { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.4rem; align-items: flex-start; }
.ability-slot { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.4rem 0; border-top: 1px solid var(--border); }
.ability-slot:first-of-type { border-top: none; }
.slot-num {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
}
.slot-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.slot-select { width: 100%; max-width: 420px; }
.planner-output { max-width: 760px; }
.slot-effect { font-size: 0.82rem; }
.ability-slot.stale .slot-num { background: var(--star); color: #fff; }
.slot-warning { color: var(--star); font-size: 0.78rem; }
.ability-list { list-style: none; padding: 0; margin: 0.3rem 0; display: flex; flex-direction: column; gap: 0.4rem; }
.ability-list li { font-size: 0.82rem; }
.arts-section { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 0.6rem; font-size: 0.85rem; }
.arts-section > summary { font-size: 0.9rem; }
.arts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.6rem; margin-top: 0.4rem; }
.arts-card { border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.6rem; display: flex; flex-direction: column; gap: 0.35rem; background: var(--bg); }
.arts-card-head { display: flex; justify-content: space-between; gap: 0.5rem; }
.arts-next { display: flex; flex-direction: column; gap: 0.2rem; }
.gift-chip.tier-art { border-color: var(--accent); }
.gift-chip.tier-spell { border-color: var(--flag); }
.gift-chip.locked { opacity: 0.6; border-style: dashed; }
.arts-extras { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.25rem; }
.arts-extras .gift-tier-label, .arts-next .gift-tier-label { width: auto; }
.arts-learned { margin: 0; }
.arts-learned li { border-left: 3px solid var(--accent); padding-left: 0.45rem; }
@media (max-width: 800px) {
  .planner-layout { grid-template-columns: 1fr; }
}

/* Calendar */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.cal-header h2 { margin: 0; }
.cal-header select {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  min-width: 260px;
}
.free-time-banner {
  background: var(--accent-bg);
  border-radius: 6px;
  padding: 0.5rem 0.9rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}
.cal-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.75rem;
  background: var(--panel);
}
.cal-section h4 { margin: 0 0 0.4rem; font-size: 0.9rem; }
.cal-section ul { margin: 0; padding-left: 1.2rem; font-size: 0.85rem; }
.cal-section li { margin-bottom: 0.3rem; }
.weekly-actions-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.25rem;
  margin-bottom: 0.6rem;
}
.weekly-action {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}
.reset-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.reset-btn:hover { background: var(--accent-bg); }

/* Path Tracker (quest-list styles are shared with Calendar) */
.path-lanes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
  align-items: start;
}
.path-lane {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.path-lane.status-in-progress { border-color: var(--accent); }
.path-lane.status-cleared { border-color: var(--recruited); }
.path-lane-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.path-lane-head h3 { margin: 0; font-size: 1rem; }
.path-status-select {
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0.2rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}
.path-progress-text { color: var(--text-muted); min-height: 1.2em; }
.chapter-dots { display: flex; gap: 3px; flex-wrap: wrap; }
.chapter-dot {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 0;
}
.chapter-dot:hover { border-color: var(--accent); }
.chapter-dot.done { background: var(--recruited); border-color: var(--recruited); }
.chapter-dot.current { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }
.path-lane-stats { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.8rem; color: var(--text-muted); }
.path-lane-stats strong { color: var(--text); }
.path-quests summary { cursor: pointer; font-weight: 500; }
.path-quests .quest-list { margin-top: 0.4rem; max-height: 22rem; overflow-y: auto; }
.open-calendar-btn { align-self: flex-start; }
.replay-rules summary { cursor: pointer; }
.replay-rules summary h4 { display: inline; margin: 0; }
.replay-rules dl { margin: 0.6rem 0 0.4rem; display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; font-size: 0.85rem; max-width: 900px; }
.replay-rules dt { font-weight: 600; }
.replay-rules dd { margin: 0; }
@media (max-width: 600px) {
  .replay-rules dl { grid-template-columns: 1fr; gap: 0.1rem; }
  .replay-rules dd { margin-bottom: 0.4rem; }
}

.quest-list { list-style: none; padding: 0 !important; margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.quest-list li { margin: 0 !important; }
.quest-chapter {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-top: 0.3rem !important;
}
.quest-item { display: flex; gap: 0.45rem; align-items: flex-start; cursor: pointer; font-size: 0.85rem; }
.quest-item input { margin-top: 0.2rem; flex-shrink: 0; }
.quest-item > span { display: flex; flex-direction: column; gap: 0.1rem; }
.quest-name { font-weight: 500; }
.quest-meta { font-size: 0.75rem; color: var(--text-muted); }
.quest-where { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.1rem; }
.path-badge-inline {
  font-size: 0.7rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.quest-item.done .quest-name { text-decoration: line-through; color: var(--text-muted); }

/* Equipment (cards reuse .gift-card, chips reuse .gift-chip) */
.seg-toggle.small button { padding: 0.2rem 0.55rem; font-size: 0.75rem; }
.equip-card { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.equip-card h4 { margin: 0; flex-wrap: wrap; }
.equip-card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.equip-card-actions { display: flex; align-items: center; gap: 0.4rem; }
.equip-card.status-gathering { border-color: var(--accent); }
.equip-card.status-obtained { opacity: 0.75; }
.trade-list { list-style: none; padding: 0; margin: 0.2rem 0 0; display: flex; flex-direction: column; gap: 0.35rem; }
.trade-list li { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
.trade-trader { min-width: 14rem; font-weight: 500; }
.trade-trader .tag { margin: 0 0.4rem 0 0; }
.mat-chip.rarity-uncommon { border-color: var(--flag); }
.mat-chip.rarity-rare { border-color: var(--star); }
.mat-chip.unknown { border-style: dashed; }
.chest-line { font-size: 0.82rem; }
.farm-spots { font-size: 0.8rem; border-top: 1px dashed var(--border); padding-top: 0.35rem; }
.farm-spots ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.farm-spots li { margin-bottom: 0.15rem; }
.loc-type {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 0.25rem;
}
.mat-locations { display: flex; flex-direction: column; }
@media (max-width: 600px) {
  .trade-trader { min-width: 0; }
}

/* Rankings */
.rank-tag-filter { margin: 0 0 0.75rem; align-items: center; }
.rank-tag-filter .gift-tier-label { width: auto; margin-right: 0.3rem; }
button.rank-tag-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.rank-weights .rank-weight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: 0.3rem 1rem; margin-bottom: 0.4rem; max-width: 760px; }
.rank-table { font-size: 0.82rem; width: auto; }
.rank-table td, .rank-table th { text-align: left !important; }
.rank-table th, .rank-table td { padding: 0.3rem 0.5rem; vertical-align: middle; }
.rank-table th { white-space: nowrap; }
.rank-table th.sortable { cursor: pointer; user-select: none; }
.rank-table th.sortable:hover { color: var(--accent); }
.rank-table th.sorted { color: var(--accent); }
.rank-table .role-col { background: var(--accent-bg); }
.rank-table td.score { text-align: right !important; font-variant-numeric: tabular-nums; }
.rank-table td.score.high { color: var(--recruited); font-weight: 600; }
.rank-table td.score.low { color: var(--star); }
.rank-table td.rank-num { color: var(--text-muted); text-align: right !important; }
.rank-table .rank-name { white-space: nowrap; }
.rank-table .rank-name .dash-link { padding: 0; font-size: 0.85rem; color: var(--text); font-weight: 500; }
.rank-table .rank-name .dash-link:hover { color: var(--accent); }
.rank-table .rank-tags { max-width: 26rem; }
.rank-table .rank-tags .gift-chip { font-size: 0.72rem; padding: 0 0.4rem; margin: 0.05rem 0.1rem; }
.rank-table .path-badge { width: 1.2rem; height: 1.2rem; font-size: 0.65rem; margin-right: 2px; }

/* Dashboard (chips reuse .gift-chip) */
.dash-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0 0 0 0.5rem;
}
.dash-link:hover { text-decoration: underline; }
.dash-row { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.85rem; padding: 0.35rem 0; }
.dash-row + .dash-row { border-top: 1px solid var(--border); }
.dash-row .gift-chips { margin-top: 0.3rem; }
.dash-row .hint { margin: 0; }
.dash-icon { width: 1.4rem; flex-shrink: 0; text-align: center; }
button.gift-chip { font-family: inherit; font-size: inherit; color: var(--text); cursor: pointer; }
button.gift-chip:hover { border-color: var(--accent); background: var(--accent-bg); }
.dash-weekly::before { content: '☐ '; color: var(--text-muted); }
.dash-summary { font-size: 0.85rem; margin: 0.2rem 0 0.5rem; }
.dash-subgroup { font-size: 0.85rem; margin-bottom: 0.6rem; }
.dash-subgroup .gift-chips { margin-top: 0.3rem; }
.dash-path.status-in-progress { border-color: var(--accent); }
.dash-path.status-cleared { border-color: var(--recruited); color: var(--recruited); }

/* Paralogues (cards reuse .gift-card, tables reuse .growth-table) */
.paralogue-card { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.paralogue-card h4 { margin-bottom: 0; }
.paralogue-card.cleared { border-color: var(--recruited); }
.paralogue-card .tag { margin-left: 0; margin-right: 0.35rem; }
.paralogue-table { margin-top: 0.3rem; font-size: 0.8rem; max-width: 760px; }
.paralogue-table th, .paralogue-table td { text-align: left !important; vertical-align: top; }
.paralogue-table tr.unavailable td { color: var(--text-muted); font-style: italic; }
.paralogue-table tr.done td:first-child { color: var(--recruited); font-weight: 600; }
.paralogue-done strong { text-decoration: line-through; color: var(--text-muted); }

/* Gift Reference */
.seg-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.seg-toggle button {
  border: none;
  background: var(--panel);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}
.seg-toggle button + button { border-left: 1px solid var(--border); }
.seg-toggle button:hover { background: var(--accent-bg); }
.seg-toggle button.active { background: var(--accent); color: #fff; }
.gift-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.6rem;
  background: var(--panel);
}
.gift-card h4 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.gift-card .char-star { width: auto; height: auto; }
.gift-card .hint { margin: 0.3rem 0 0; }
.gift-count {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--text-muted);
}
.gift-tier {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}
.gift-tier-label {
  flex-shrink: 0;
  width: 7.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.gift-chips { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.gift-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.gift-chip.tier-loved { border-color: var(--star); }
.gift-chip.hit { background: var(--accent-bg); border-color: var(--accent); }
.gift-card mark { background: var(--star); color: #fff; border-radius: 2px; padding: 0 1px; }
@media (max-width: 600px) {
  .gift-tier { flex-direction: column; gap: 0.15rem; }
  .gift-tier-label { width: auto; }
}

/* ---------------------------------------------------------------------------------------
   Mobile phase 2: touch basics. Applies to touch screens (coarse pointer) at any width.
   --------------------------------------------------------------------------------------- */

/* Tap-to-read bubble for title tooltips (js/touchTips.js). */
.touch-tip {
  position: fixed;
  z-index: 30;
  max-width: min(22rem, calc(100vw - 32px));
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.85rem;
  line-height: 1.35;
  white-space: pre-line;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

@media (pointer: coarse) {
  /* iOS Safari zooms the page when focusing a field with text under 16px. */
  input, select, textarea { font-size: 16px !important; }
  input[type="checkbox"] { width: 1.2rem; height: 1.2rem; }

  /* Bigger tap targets (~40px where the layout allows). */
  .char-star { width: 2.5rem; height: 2.5rem; }
  .char-star.large { width: auto; height: auto; padding: 0.3rem; }
  .remove-planned { min-width: 2rem; min-height: 2rem; padding: 0.3rem 0.5rem; font-size: 0.9rem; }
  .dash-link { padding: 0.45rem 0.5rem; }
  .back-btn { padding: 0.5rem 0; }
  .seg-toggle button, .seg-toggle.small button { padding: 0.5rem 0.8rem; font-size: 0.85rem; }
  button.gift-chip, .merge-target { padding: 0.35rem 0.75rem; }
  .reset-btn { padding: 0.5rem 0.9rem; }
  /* 12 dots must still fit one lane row on a phone, so these grow to 22px rather than 40. */
  .chapter-dots { gap: 4px; }
  .chapter-dot { width: 1.4rem; height: 1.4rem; }
  .weekly-action { min-height: 2rem; }
  .quest-item { padding: 0.2rem 0; }
}

/* ---------------------------------------------------------------------------------------
   Mobile phase 3: layouts for the dense views, below 700px.
   --------------------------------------------------------------------------------------- */

.path-picker, .rank-roles-toggle { display: none; }

@media (max-width: 700px) {
  /* The page itself must not scroll sideways (and position: sticky needs a non-scrolling
     ancestor); wide tables scroll inside their own .merge-table-wrap instead. */
  .content { overflow-x: visible; }

  /* Character page: one sticky Version picker drives the page; columns show one at a time. */
  .path-picker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 -1rem 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .path-picker-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
  .section-path-tabs { display: none; }
  .instance-columns { overflow-x: visible; }
  .instance-columns .instance-column { flex: 1; min-width: 0; }
  .instance-columns .instance-column:not(.is-active) { display: none; }

  /* Wide tables: keep the first column pinned while the rest scrolls. */
  .merge-table-wrap .merge-table, .merge-table-wrap .preview-table { min-width: 0; }
  .merge-table-wrap .growth-table th:first-child,
  .merge-table-wrap .growth-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
  }
  .merge-table tr.target td:first-child { background: var(--accent-bg); }

  /* Rankings: selected role only unless "Show all roles"; # and name stay pinned. */
  .rank-roles-toggle { display: inline-block; margin-bottom: 0.5rem; }
  .rank-table .other-role { display: none; }
  .show-all-roles .rank-table .other-role { display: table-cell; }
  .merge-table-wrap .rank-table th:first-child, .merge-table-wrap .rank-table td:first-child { width: 2.2rem; min-width: 2.2rem; background: var(--bg); }
  .rank-table th:nth-child(2), .rank-table td:nth-child(2) { position: sticky; left: 2.2rem; z-index: 1; background: var(--bg); }

  /* Fixed minimum widths that overflow a phone. */
  .char-toolbar input[type="text"] { min-width: 0; width: 100%; }
  .cal-header select { min-width: 0; max-width: 100%; }
  .trade-trader { min-width: 0; }
}
