:root {
  color-scheme: dark;
  --paper: #101017;
  --paper-soft: #171720;
  --paper-lift: #20202b;
  --ink: #f5efe4;
  --muted: #b6aa99;
  --quiet: #766f66;
  --gold: #d6b77b;
  --gold-deep: #9a7540;
  --sage: #9fb7a5;
  --rose: #c48778;
  --line: rgba(245,239,228,.13);
  --shadow: 0 26px 70px rgba(0,0,0,.34);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100%;
  font-family: "Source Sans 3", ui-sans-serif, sans-serif;
  background:
    radial-gradient(circle at 12% -8%, rgba(214,183,123,.28), transparent 34rem),
    radial-gradient(circle at 90% 18%, rgba(159,183,165,.16), transparent 26rem),
    linear-gradient(180deg, #101017 0%, #13131b 58%, #0d0d12 100%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { width: min(980px, 100%); margin: 0 auto; padding: 18px 16px 108px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 2px 14px; }
h1, h2, h3 { font-family: "Literata", Georgia, serif; margin: 0; text-wrap: pretty; }
h1 { font-size: clamp(2.15rem, 8vw, 4.5rem); line-height: .92; letter-spacing: -.06em; }
h2 { font-size: clamp(1.45rem, 5.6vw, 2.35rem); line-height: 1.02; letter-spacing: -.035em; }
h3 { font-size: 1.18rem; line-height: 1.1; }
p { margin: 0; }
.eyebrow { color: var(--gold); text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 760; }
.hero-card {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(245,239,228,.11), rgba(245,239,228,.035));
  box-shadow: var(--shadow);
}
.hero-card::after { content:""; position:absolute; inset:auto -30px -70px auto; width:190px; height:190px; background: radial-gradient(circle, rgba(214,183,123,.18), transparent 68%); }
.book-mark { border-radius: 18px; background: linear-gradient(145deg, var(--cover, #6d3d43), #171720); box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), 0 18px 35px rgba(0,0,0,.28); min-height: 126px; }
.hero-copy { display: grid; gap: 8px; align-content: start; min-width: 0; }
.hero-copy p { color: var(--muted); line-height: 1.35; }
.pill { width: fit-content; border: 1px solid rgba(214,183,123,.35); color: var(--gold); border-radius: 999px; padding: 4px 10px; font-size: .78rem; font-weight: 700; background: rgba(214,183,123,.08); }
.progress-control { display: grid; gap: 6px; margin-top: 4px; color: var(--muted); }
input[type="range"] { accent-color: var(--gold); min-height: 34px; }
.search-panel { margin: 16px 0; padding: 14px; background: rgba(16,16,23,.72); border: 1px solid var(--line); border-radius: var(--radius-lg); backdrop-filter: blur(18px); }
.search-panel label { display: block; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.search-panel input, .form-grid input, .form-grid textarea, .form-grid select {
  width: 100%; min-height: 48px; border: 1px solid var(--line); border-radius: 16px; background: rgba(245,239,228,.06); color: var(--ink); padding: 12px 14px; outline: none;
}
.form-grid select option { color: #111; }
.search-panel input:focus, .form-grid input:focus, .form-grid textarea:focus, .form-grid select:focus { border-color: rgba(214,183,123,.65); box-shadow: 0 0 0 4px rgba(214,183,123,.11); }
.search-results { display: grid; gap: 8px; margin-top: 10px; }
.search-results:empty { display: none; }
.view { display: none; animation: rise .28s ease both; }
.view.active { display: block; }
@keyframes rise { from { opacity:0; transform: translateY(8px);} to { opacity:1; transform:none; } }
.section-head { display:flex; justify-content:space-between; align-items:end; gap:12px; margin: 18px 2px 12px; }
.section-head p { color: var(--muted); max-width: 38rem; }
.card-grid { display:grid; gap: 12px; grid-template-columns: 1fr; }
.info-card, .character-card, .relation-card, .book-card, .note-card, .search-hit {
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: rgba(245,239,228,.065); padding: 15px; box-shadow: 0 12px 30px rgba(0,0,0,.12);
}
.character-card, .book-card, .search-hit { display: grid; gap: 8px; }
.card-row { display:flex; align-items:center; justify-content:space-between; gap: 12px; }
.aliases, .chip-row { display:flex; flex-wrap:wrap; gap: 6px; }
.chip { border:1px solid var(--line); color: var(--muted); border-radius:999px; padding: 4px 9px; font-size:.78rem; background: rgba(0,0,0,.12); }
.chip.gold { color: var(--gold); border-color: rgba(214,183,123,.35); }
.muted { color: var(--muted); }
.relation-card { display:grid; gap: 10px; }
.relation-line { display:flex; flex-wrap:wrap; gap: 8px; align-items:center; }
.arrow { color: var(--gold); }
.meter { height: 8px; border-radius:999px; background: rgba(245,239,228,.08); overflow:hidden; }
.meter span { display:block; height:100%; width: calc(var(--value) * 20%); background: linear-gradient(90deg, var(--gold-deep), var(--gold)); }
.stat-grid { display:grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { padding: 14px; border-radius: 20px; background: rgba(214,183,123,.08); border:1px solid rgba(214,183,123,.18); }
.stat strong { display:block; font-size:1.55rem; font-family:"Literata", serif; }
.bottom-nav { position: fixed; z-index: 20; left: 50%; transform: translateX(-50%); bottom: max(10px, var(--safe-bottom)); width: min(620px, calc(100% - 20px)); display:grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 7px; border:1px solid var(--line); border-radius: 24px; background: rgba(17,17,24,.88); backdrop-filter: blur(22px); box-shadow: 0 18px 55px rgba(0,0,0,.4); }
.bottom-nav button { min-height: 48px; border:0; border-radius:18px; background: transparent; color: var(--muted); font-weight:760; font-size:.82rem; }
.bottom-nav button.active { background: var(--gold); color: #19140d; }
.fab { position: fixed; z-index: 22; right: 18px; bottom: calc(82px + var(--safe-bottom)); width: 60px; height: 60px; border: 0; border-radius: 22px; background: var(--gold); color: #17120b; font-size: 2rem; box-shadow: 0 18px 42px rgba(0,0,0,.38); }
.ghost-button, .primary-button, .secondary-button, .icon-button { min-height: 44px; border-radius: 15px; border: 1px solid var(--line); color: var(--ink); background: rgba(245,239,228,.07); padding: 10px 14px; font-weight: 760; }
.primary-button { background: var(--gold); color: #17120b; border: 0; width: 100%; }
.icon-button { width:44px; padding:0; font-size:1.4rem; }
.sheet { width: min(720px, 100%); max-width: none; margin: auto auto 0; padding: 0; border:0; background: transparent; color: var(--ink); }
.sheet::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(4px); }
.sheet-card { margin:0; max-height: 88vh; overflow:auto; padding: 10px 16px 22px; border-radius: 30px 30px 0 0; background: #171720; border: 1px solid var(--line); box-shadow: var(--shadow); }
.sheet-handle { width: 56px; height: 5px; border-radius:999px; background: rgba(245,239,228,.22); margin: 2px auto 14px; }
.sheet header { display:flex; align-items:start; justify-content:space-between; gap:16px; margin-bottom: 14px; }
.segmented { display:grid; grid-template-columns: repeat(3, 1fr); gap:6px; background: rgba(0,0,0,.18); padding:5px; border-radius:18px; margin-bottom:14px; }
.segmented button { border:0; border-radius:14px; background: transparent; color: var(--muted); min-height:42px; font-weight:760; }
.segmented button.active { background: rgba(214,183,123,.16); color: var(--gold); }
.form-grid { display:grid; gap: 12px; }
.form-grid label { display:grid; gap: 6px; color: var(--muted); font-weight:700; }
.graph-wrap { border: 1px solid var(--line); border-radius: var(--radius-xl); overflow: hidden; background: radial-gradient(circle at 50% 35%, rgba(214,183,123,.08), rgba(245,239,228,.03)); min-height: 460px; }
.graph-wrap svg { display:block; width:100%; height: 460px; touch-action: none; }
.node { cursor:pointer; }
.node circle { fill: #242431; stroke: var(--gold); stroke-width: 2; filter: drop-shadow(0 10px 18px rgba(0,0,0,.3)); }
.node text { fill: var(--ink); font-weight:760; font-size: 12px; pointer-events:none; }
.edge { stroke: rgba(214,183,123,.36); stroke-width: 2; }
.empty { padding: 28px 18px; text-align:center; color: var(--muted); border:1px dashed var(--line); border-radius: var(--radius-lg); }
.danger { color: var(--rose); }
@media (min-width: 720px) {
  .app-shell { padding-top: 28px; }
  .hero-card { grid-template-columns: 132px 1fr; padding: 24px; }
  .book-mark { min-height: 184px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wide { grid-column: 1 / -1; }
  .fab { right: calc(50% - 470px); }
}
@media (max-width: 390px) {
  .app-shell { padding-inline: 11px; }
  .hero-card { grid-template-columns: 68px 1fr; gap: 11px; padding: 13px; }
  .book-mark { min-height: 106px; }
  .bottom-nav button { font-size:.75rem; }
}
