/* ==========================================================================
   Draw Steel Japanese Viewer — "Parchment & Steel" (Light) / "Slate & Brass" (Dark)
   Calm, low-glare reading tones with subtle fantasy editorial accents.
   ========================================================================== */

:root {
  --font-serif: "Shippori Mincho", "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", Georgia, serif;
  --font-sans: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  /* Layout metrics */
  --header-h: 56px;
  --sidebar-w: 276px;
  --right-w: 236px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* Light Theme — Warm Parchment & Iron Ink (not harsh pure white) */
[data-theme="light"] {
  --bg-page: #f1ece1;
  --bg-surface: #faf6ed;
  --bg-subtle: #e9e2d2;
  --bg-elevated: #fcf9f2;
  --bg-en: #f2ede2;
  --bg-hover: rgba(124, 53, 38, 0.08);
  --bg-active: rgba(124, 53, 38, 0.14);

  --text-main: #2b2520;
  --text-muted: #655b50;
  --text-faint: #8c8173;
  --text-en: #3a352f;

  --border: #d7cdba;
  --border-strong: #bfb29b;
  --accent: #7f3425;        /* Wax crimson */
  --accent-soft: rgba(127, 52, 37, 0.11);
  --link: #295374;          /* Tempered steel blue */
  --link-hover: #1b3b54;
  --gold: #9a7436;
  --gold-soft: rgba(154, 116, 54, 0.14);
  --warn-bg: #f6e7dc;
  --warn-border: #b35a38;
  --mark-bg: #f2d58a;
  --mark-text: #2b2520;

  /* Notation token tints */
  --sym-char-bg: rgba(127, 52, 37, 0.10);
  --sym-char-fg: #7a2d1e;
  --sym-kw-bg: rgba(41, 83, 116, 0.10);
  --sym-kw-fg: #244a68;
  --sym-skill-bg: rgba(56, 102, 65, 0.11);
  --sym-skill-fg: #2f5a38;
  --sym-ref-fg: #6b4322;

  --shadow-sm: 0 1px 3px rgba(43, 37, 32, 0.07);
  --shadow-md: 0 6px 20px rgba(43, 37, 32, 0.12);
}

/* Dark Theme — Soft Slate & Antique Brass (not harsh pure black) */
[data-theme="dark"] {
  --bg-page: #181a1f;
  --bg-surface: #20232a;
  --bg-subtle: #272b34;
  --bg-elevated: #2b303a;
  --bg-en: #1c1f26;
  --bg-hover: rgba(203, 161, 93, 0.10);
  --bg-active: rgba(203, 161, 93, 0.17);

  --text-main: #e2dcd0;
  --text-muted: #a69e90;
  --text-faint: #7b756a;
  --text-en: #cfc8ba;

  --border: #353a46;
  --border-strong: #4a5162;
  --accent: #d08266;        /* Muted ember copper */
  --accent-soft: rgba(208, 130, 102, 0.15);
  --link: #7fb2db;
  --link-hover: #a5ccf0;
  --gold: #cba15d;
  --gold-soft: rgba(203, 161, 93, 0.15);
  --warn-bg: #2f2321;
  --warn-border: #c56a4b;
  --mark-bg: #6b5320;
  --mark-text: #f7eed6;

  --sym-char-bg: rgba(208, 130, 102, 0.16);
  --sym-char-fg: #e59e85;
  --sym-kw-bg: rgba(127, 178, 219, 0.14);
  --sym-kw-fg: #9cc6e8;
  --sym-skill-bg: rgba(130, 184, 140, 0.14);
  --sym-skill-fg: #9bd0a4;
  --sym-ref-fg: #d9b678;

  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
}

/* Base Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

button, input, select {
  font: inherit;
  color: inherit;
}

mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 2px;
  padding: 0 2px;
}

/* ==========================================================================
   App Shell & Header
   ========================================================================== */

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

.app-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--text-main);
  text-decoration: none !important;
  white-space: nowrap;
}
.brand__emblem {
  color: var(--gold);
  font-size: 1.15rem;
}
.brand__title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.12rem;
  letter-spacing: 0.04em;
}
.brand__sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-search {
  flex: 1 1 360px;
  max-width: 520px;
  position: relative;
  display: flex;
  align-items: center;
}
.header-search__icon {
  position: absolute;
  left: 11px;
  color: var(--text-faint);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
}
.theme-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.header-search input {
  width: 100%;
  padding: 6px 34px 6px 32px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-page);
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
}
.header-search input:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--bg-elevated);
}
.header-search__kbd {
  position: absolute;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-faint);
  background: var(--bg-surface);
  pointer-events: none;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.segmented {
  display: inline-flex;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}
.segmented__btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.segmented__btn:hover {
  color: var(--text-main);
}
.segmented__btn.is-active {
  background: var(--bg-elevated);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-page);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.mobile-only { display: none; }

/* ==========================================================================
   3-Pane Layout
   ========================================================================== */

.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* Left Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.book-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 8px 6px;
  border-bottom: 1px solid var(--border);
}
.book-tab {
  flex: 1 1 auto;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 6px 5px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: all 0.15s;
}
.book-tab:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}
.book-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--border-strong);
}

.sidebar-quick {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-quick__btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: var(--text-main);
  text-decoration: none !important;
  transition: background 0.12s;
}
.sidebar-quick__btn:hover,
.sidebar-quick__btn.is-active {
  background: var(--bg-active);
  color: var(--accent);
}

.sidebar-filter {
  padding: 8px 10px 4px;
}
.sidebar-filter input {
  width: 100%;
  padding: 5px 10px;
  font-size: 0.84rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-page);
}
.sidebar-filter input:focus {
  outline: none;
  border-color: var(--gold);
}

.nav-tree {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 16px;
}
.nav-node__row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius-sm);
}
.nav-node__toggle {
  width: 20px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.7rem;
  padding: 0;
}
.nav-node__toggle:hover { color: var(--text-main); }
.nav-node__spacer { width: 14px; flex-shrink: 0; }
.nav-node__link, .nav-node__label {
  flex: 1;
  display: block;
  padding: 4px 8px 4px 4px;
  font-size: 0.86rem;
  line-height: 1.45;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  text-decoration: none !important;
}
.nav-node__label {
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
}
.nav-node__link:hover {
  background: var(--bg-hover);
}
.nav-node__link.is-active {
  background: var(--bg-active);
  color: var(--accent);
  font-weight: 600;
}
.nav-node__children {
  margin-left: 14px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}
.nav-node.is-collapsed > .nav-node__children {
  display: none;
}

.sidebar-meta {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.74rem;
  color: var(--text-faint);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

/* Main Content Area */
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 32px 64px;
  scroll-behavior: smooth;
}
.main-content:focus { outline: none; }

/* Right ToC Panel */
.right-panel {
  width: var(--right-w);
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 12px;
  overflow-y: auto;
}
.right-panel.is-empty {
  display: none;
}
.right-panel__header {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.page-toc {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.page-toc__link {
  display: block;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  text-decoration: none !important;
}
.page-toc__link:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}
.page-toc__link.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
.page-toc__link--l2 { padding-left: 14px; }
.page-toc__link--l3 { padding-left: 24px; font-size: 0.77rem; }
.page-toc__link--l4 { padding-left: 34px; font-size: 0.75rem; }

/* ==========================================================================
   Document Reader Typography & Bilingual Layout
   ========================================================================== */

.doc-container {
  max-width: 820px;
  margin: 0 auto;
}
.doc-container.is-split {
  max-width: 1320px;
}

.doc-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
  color: var(--text-muted);
}
.doc-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.doc-breadcrumb__sep { color: var(--text-faint); }
.doc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Section blocks */
.doc-section {
  margin-bottom: 24px;
  scroll-margin-top: 18px;
  border-radius: var(--radius-md);
  transition: background 0.4s;
}
.doc-section.is-flash {
  background: var(--gold-soft);
  padding: 8px 12px;
  margin-left: -12px;
  margin-right: -12px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-heading {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--text-main);
  margin: 0 0 12px;
  line-height: 1.35;
  flex: 1;
}
h1.section-heading {
  font-size: 1.75rem;
  padding-bottom: 10px;
  margin-top: 6px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--gold);
  position: relative;
}
h1.section-heading::after {
  content: "◆";
  position: absolute;
  right: 0;
  bottom: -10px;
  font-size: 0.7rem;
  color: var(--gold);
  background: var(--bg-page);
  padding-left: 6px;
}
h2.section-heading {
  font-size: 1.35rem;
  margin-top: 26px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  color: var(--accent);
}
h3.section-heading {
  font-size: 1.12rem;
  margin-top: 20px;
}
h4.section-heading {
  font-size: 1rem;
  margin-top: 16px;
  color: var(--text-muted);
}

.section-heading__sub {
  display: block;
  font-family: var(--font-serif);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-faint);
  margin-top: 2px;
}

.btn-en-toggle {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-en-toggle:hover,
.btn-en-toggle.is-open {
  border-color: var(--gold);
  color: var(--accent);
  background: var(--gold-soft);
}

/* Inline EN drawer (in JA mode) */
.en-drawer {
  margin: 10px 0 18px;
  padding: 14px 18px;
  background: var(--bg-en);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-md);
  color: var(--text-en);
  font-size: 0.93rem;
}
.en-drawer__label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
}

/* Split (Parallel) Mode: Section-by-section aligned 2-column grid */
.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.split-pane {
  min-width: 0;
}
.split-pane--en {
  background: var(--bg-en);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  color: var(--text-en);
  font-size: 0.93rem;
}

/* Prose elements */
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 14px; padding-left: 1.5em; }
.prose li { margin-bottom: 4px; }
.prose strong { font-weight: 700; }
.prose blockquote {
  margin: 12px 0;
  padding: 8px 16px;
  border-left: 3px solid var(--gold);
  background: var(--bg-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-subtle);
  padding: 1px 5px;
  border-radius: 3px;
}
.prose pre {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  overflow-x: auto;
}
.prose pre code { background: none; padding: 0; }
.ds-hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* Tables */
.ds-table-wrap {
  overflow-x: auto;
  margin: 14px 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}
.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.ds-table th {
  background: var(--bg-subtle);
  font-weight: 700;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.ds-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ds-table tbody tr:last-child td { border-bottom: none; }
.ds-table tbody tr:nth-child(even) { background: rgba(128, 118, 102, 0.04); }

/* Directives (:::sidebar, :::epigraph, :::content-warning, :::figure, :::table, :::display) */
.ds-directive {
  margin: 16px 0 18px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}
.ds-directive__title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--accent);
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}
.ds-directive__body > :last-child { margin-bottom: 0; }
.ds-directive--sidebar {
  border-left: 4px solid var(--gold);
  background: var(--bg-elevated);
}
.ds-directive--epigraph {
  background: transparent;
  border: none;
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  border-radius: 0;
  box-shadow: none;
  padding: 14px 20px;
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--text-muted);
}
.ds-directive__speaker {
  text-align: right;
  font-style: normal;
  font-size: 0.86rem;
  color: var(--gold);
  margin-top: 6px;
}
.ds-directive--content-warning {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  border-left: 4px solid var(--warn-border);
}
.ds-directive--figure {
  border: 1px dashed var(--border-strong);
  background: var(--bg-subtle);
}
.ds-directive--table {
  padding: 12px 14px;
}
.ds-directive--table .ds-table-wrap { margin: 8px 0 0; }
.ds-directive__source {
  font-size: 0.76rem;
  color: var(--text-faint);
  text-align: right;
  margin-top: 6px;
}
.ds-directive--display {
  text-align: center;
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Draw Steel Notation Tokens */
.ds-sym {
  border-radius: 3px;
  padding: 0 1px;
}
.ds-sym--char {
  background: var(--sym-char-bg);
  color: var(--sym-char-fg);
  font-weight: 600;
}
.ds-sym--kw {
  background: var(--sym-kw-bg);
  color: var(--sym-kw-fg);
  font-size: 0.94em;
}
.ds-sym--skill {
  background: var(--sym-skill-bg);
  color: var(--sym-skill-fg);
}
.ds-sym--ref {
  color: var(--sym-ref-fg);
  font-weight: 500;
}

/* Footnotes */
.ds-fn-ref a { font-size: 0.78em; color: var(--gold); }
.ds-footnotes {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
  color: var(--text-muted);
  list-style: none;
  padding-left: 0;
}
.ds-footnotes li { margin-bottom: 6px; }
.ds-fn-num { font-weight: 700; color: var(--gold); margin-right: 4px; }

/* Glossary Section */
.glossary-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 16px;
}
.glossary-toolbar input {
  flex: 1;
  max-width: 380px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  font-size: 0.9rem;
}
.glossary-toolbar__count {
  font-size: 0.82rem;
  color: var(--text-faint);
}
.glossary-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: 24px;
  border-radius: var(--radius-sm);
}
.glossary-row:hover { background: var(--bg-hover); }
.glossary-row.is-flash { background: var(--gold-soft); }
.glossary-row__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.glossary-row__ja { flex: 1; }
.glossary-row__ja p, .glossary-row__en p { margin: 0; }
.glossary-row__en {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-en);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-en);
}

/* Prev / Next Footer */
.doc-pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.doc-pager__link {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  max-width: 48%;
  text-decoration: none !important;
  transition: border-color 0.15s, background 0.15s;
}
.doc-pager__link:hover {
  border-color: var(--gold);
  background: var(--bg-elevated);
}
.doc-pager__dir { font-size: 0.75rem; color: var(--text-faint); }
.doc-pager__title { font-family: var(--font-serif); font-weight: 700; color: var(--text-main); }

/* ==========================================================================
   Draw Steel Entity Cards (Ability / Creature / Treasure / Enhancement)
   ========================================================================== */

.ds-card {
  margin: 14px 0 18px;
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.ds-card--creature { border-top-color: var(--accent); }
.ds-card--ability { border-top-color: var(--link); }
.ds-card--treasure { border-top-color: var(--gold); }
.ds-card--enhancement { border-top-color: #4f7a5a; }

.ds-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}
.ds-card__title-wrap {
  min-width: 0;
  flex: 1;
}
.ds-card__title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.06rem;
  color: var(--text-main);
  margin: 0;
}
.ds-card__subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.ds-card__controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.ds-card__lang-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  overflow: hidden;
}
.ds-card__lang-btn {
  border: none;
  background: transparent;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.ds-card__lang-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}
.ds-card__open {
  font-size: 0.78rem;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-muted);
  text-decoration: none !important;
}
.ds-card__open:hover { border-color: var(--gold); color: var(--text-main); }

.ds-card__body {
  padding: 12px 16px 14px;
  font-size: 0.92rem;
}
.ds-card__split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.ds-card__split-col--en {
  padding-left: 14px;
  border-left: 1px solid var(--border);
  color: var(--text-en);
}

.ds-card__flavor {
  font-style: italic;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.ds-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}
.ds-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text-muted);
}
.ds-badge--accent {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.ds-badge--gold {
  background: var(--gold-soft);
  border-color: transparent;
  color: var(--gold);
}

.ds-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px 12px;
  padding: 8px 10px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 0.85rem;
}
.ds-meta-item__k {
  font-size: 0.73rem;
  color: var(--text-faint);
  display: block;
}
.ds-meta-item__v { font-weight: 600; }

/* Creature Stats & Characteristics */
.ds-stat-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}
.ds-stat-box {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 6px;
  text-align: center;
}
.ds-stat-box__label { font-size: 0.71rem; color: var(--text-faint); display: block; }
.ds-stat-box__val { font-weight: 700; font-size: 0.96rem; }

/* Power Roll Tiers */
.ds-tiers {
  margin: 8px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.ds-tiers__head {
  background: var(--bg-subtle);
  padding: 4px 10px;
  font-weight: 700;
  font-size: 0.84rem;
  border-bottom: 1px solid var(--border);
}
.ds-tier-row {
  display: grid;
  grid-template-columns: 62px 1fr;
  border-bottom: 1px solid var(--border);
}
.ds-tier-row:last-child { border-bottom: none; }
.ds-tier-row__roll {
  background: var(--bg-page);
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--accent);
  text-align: center;
  border-right: 1px solid var(--border);
}
.ds-tier-row__text {
  padding: 6px 10px;
}

.ds-subblock {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.ds-subblock__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.ds-subblock__name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.96rem;
}

.ds-malice-box {
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}

.ds-card__refs {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}
.ds-card__refs h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Search & Catalog Views
   ========================================================================== */

.view-header {
  margin-bottom: 18px;
}
.view-header h1 {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  margin: 0 0 8px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.filter-bar input[type="search"] {
  flex: 1 1 240px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
}
.filter-bar select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-page);
}

.search-status {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.result-item {
  display: block;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  text-decoration: none !important;
  color: var(--text-main);
  transition: border-color 0.15s, background 0.15s;
}
.result-item:hover {
  border-color: var(--gold);
  background: var(--bg-elevated);
}
.result-item__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.result-item__title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--link);
}
.result-item__en {
  font-size: 0.82rem;
  color: var(--text-faint);
}
.result-item__meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.result-item__snippet {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* Catalog Grid */
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.catalog-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  text-decoration: none !important;
  color: var(--text-main);
  transition: border-color 0.15s, transform 0.12s;
}
.catalog-card:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}
.catalog-card__name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 0.98rem;
}
.catalog-card__en {
  font-size: 0.78rem;
  color: var(--text-faint);
}
.catalog-card__meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

/* Home / Welcome Card */
.home-hero {
  padding: 26px 28px;
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  margin-bottom: 22px;
}
.home-hero h1 {
  font-family: var(--font-serif);
  font-size: 1.7rem;
  margin: 0 0 8px;
}
.home-books {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.home-book-card {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  text-decoration: none !important;
  color: var(--text-main);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.home-book-card:hover {
  border-color: var(--gold);
  box-shadow: var(--shadow-md);
}
.home-book-card__title {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent);
}
.home-book-card__en {
  font-size: 0.82rem;
  color: var(--text-faint);
  margin-bottom: 8px;
}

/* Glossary Popover */
.glossary-popover {
  position: fixed;
  z-index: 80;
  max-width: 400px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  line-height: 1.55;
  pointer-events: none;
}
.glossary-popover__head {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.glossary-popover__en {
  font-size: 0.78rem;
  color: var(--text-faint);
  font-family: var(--font-sans);
  font-weight: 400;
  margin-left: 6px;
}
.glossary-popover p { margin: 0; }

.loading-state, .empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* ==========================================================================
   Account Button & Modal (Auth / Entitlements / Invites)
   ========================================================================== */

.header-ext-slot {
  display: inline-flex;
  align-items: center;
}

.login-btn, .user-btn {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.login-btn:hover, .user-btn:hover {
  border-color: var(--gold);
  background: var(--bg-subtle);
}
.user-btn__avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}
.user-btn__initial {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
}
.user-btn__name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 16, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop[hidden] { display: none; }

.modal-dialog {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-top: 3px solid var(--gold);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-family: var(--font-serif);
  font-size: 1.12rem;
  margin: 0;
}
.modal-body {
  padding: 16px 18px 20px;
}
.modal-lead {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 14px;
}
.modal-note, .modal-notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--gold-soft);
  border: 1px solid var(--border-strong);
  font-size: 0.86rem;
  margin-bottom: 12px;
}
.modal-msg {
  font-size: 0.84rem;
  color: var(--accent);
  margin-top: 6px;
}
.modal-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.modal-section h3 {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  margin: 0 0 10px;
  color: var(--accent);
}

.account-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.oauth-btn-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none !important;
  border: 1px solid transparent;
  transition: filter 0.15s;
}
.oauth-btn--discord {
  background: #5865f2;
  color: #ffffff;
}
.oauth-btn--discord:hover {
  filter: brightness(1.08);
  color: #ffffff;
}

.ent-list, .invite-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ent-row, .invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}
.ent-row__en {
  font-size: 0.78rem;
  color: var(--text-faint);
}
.invite-row.is-revoked { opacity: 0.55; }
.invite-code {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
}

.redeem-form, .invite-create-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.redeem-form input, .invite-create-form input, .invite-create-form select {
  flex: 1 1 150px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-page);
  font-size: 0.86rem;
}
.btn-primary {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #faf6ed;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 1180px) {
  .right-panel { display: none; }
}

@media (max-width: 860px) {
  .mobile-only { display: inline-flex; }
  .brand__sub { display: none; }
  .header-search__kbd { display: none; }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 45;
  }

  .main-content {
    padding: 16px 16px 56px;
  }
  .split-grid, .ds-card__split {
    grid-template-columns: 1fr;
  }
  .ds-card__split-col--en {
    padding-left: 0;
    padding-top: 10px;
    border-left: none;
    border-top: 1px dashed var(--border);
  }
  .ds-stat-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
