:root{
  --paper:#f4efe6;
  --paper-strong:#fff9ed;
  --vellum:#e7dcc9;
  --ink:#2b241d;
  --muted:#6d6258;
  --line:#c8b89f;
  --brown:#5f3328;
  --brown-soft:#8a5a3e;
  --green:#4f6447;
  --blue:#315268;
  --red:#803b34;
  --gold:#b48a3c;
  --shadow:0 12px 28px rgba(37,28,18,.13);
}

*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{
  margin:0;
  color:var(--ink);
  background:
    linear-gradient(90deg, rgba(49,82,104,.06) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(95,51,40,.05) 0 1px, transparent 1px 100%),
    var(--paper);
  background-size:32px 32px, 32px 32px, auto;
  font-family:Georgia, "Times New Roman", serif;
  min-height:100vh;
}

button,input,select{font:inherit}
button{cursor:pointer}
button:focus-visible,input:focus-visible,select:focus-visible,[tabindex]:focus-visible{
  outline:3px solid rgba(49,82,104,.35);
  outline-offset:2px;
}

.app-header{
  position:sticky;
  top:0;
  z-index:30;
  border-bottom:1px solid rgba(95,51,40,.24);
  background:rgba(244,239,230,.95);
  backdrop-filter:blur(10px);
}

.topbar{
  max-width:1360px;
  margin:0 auto;
  padding:12px 22px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
  min-width:260px;
}

.monogram{
  width:46px;
  height:46px;
  border:2px solid var(--brown);
  display:grid;
  place-items:center;
  color:var(--brown);
  background:var(--paper-strong);
  font-weight:700;
}

.brand h1{
  margin:0;
  font-size:1.22rem;
  line-height:1;
  text-transform:uppercase;
  letter-spacing:.08em;
}

.brand p{
  margin:4px 0 0;
  color:var(--muted);
  font-size:.88rem;
  font-style:italic;
}

.nav-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.pill{
  border:1px solid var(--line);
  border-radius:999px;
  background:var(--paper-strong);
  color:var(--ink);
  padding:8px 13px;
  box-shadow:0 1px 0 rgba(37,28,18,.08);
}

.pill:hover,.pill.active{
  background:var(--brown);
  border-color:var(--brown);
  color:#fffaf0;
}

.pill.ghost{
  background:transparent;
}

.text-button{
  border:0;
  padding:0;
  background:transparent;
  color:var(--brown);
  font-weight:700;
  text-align:left;
  text-decoration:underline;
  text-decoration-thickness:1px;
  text-underline-offset:3px;
}

main{
  max-width:1360px;
  margin:0 auto;
  padding:0 22px 56px;
}

.hero{
  display:grid;
  grid-template-columns:minmax(0,1fr) 280px;
  gap:28px;
  align-items:end;
  padding:34px 0 26px;
  border-bottom:3px double var(--line);
}

.hero-copy h2{
  margin:6px 0 14px;
  font-size:4.4rem;
  line-height:.98;
  text-transform:uppercase;
  letter-spacing:.04em;
  color:#241d18;
}

.kicker{
  margin:0 0 6px;
  color:var(--brown);
  font-size:.78rem;
  font-weight:700;
  letter-spacing:.14em;
  text-transform:uppercase;
}

.subtitle{
  max-width:780px;
  margin:0;
  color:#43382f;
  font-size:1.18rem;
  line-height:1.48;
}

.cover{
  margin:0;
  border:1px solid var(--line);
  border-radius:8px;
  background:var(--paper-strong);
  padding:10px;
  box-shadow:var(--shadow);
}

.cover img{
  display:block;
  width:100%;
  aspect-ratio:3/4;
  object-fit:cover;
  border:1px solid rgba(43,36,29,.18);
}

.cover figcaption{
  margin:10px 0 0;
  color:var(--muted);
  font-size:.88rem;
  line-height:1.35;
}

.stats{
  display:grid;
  grid-template-columns:repeat(4,minmax(120px,1fr));
  gap:10px;
  max-width:760px;
  margin-top:24px;
}

.stat{
  border-left:4px solid var(--brown);
  background:rgba(255,249,237,.68);
  padding:10px 12px;
}

.stat:nth-child(2){border-color:var(--blue)}
.stat:nth-child(3){border-color:var(--green)}
.stat:nth-child(4){border-color:var(--red)}
.stat strong{display:block;font-size:1.55rem}
.stat span{
  color:var(--muted);
  font-size:.78rem;
  text-transform:uppercase;
  letter-spacing:.08em;
}

.panel,.reader,.result-card,.atlas-card{
  border:1px solid var(--line);
  border-radius:8px;
  background:rgba(255,249,237,.82);
  box-shadow:var(--shadow);
}

.search-panel{
  margin:24px 0 20px;
  padding:20px;
}

.panel-title,.detail-head,.section-heading,.reader-header,.results-head{
  display:flex;
  justify-content:space-between;
  gap:18px;
  align-items:flex-start;
}

.panel-title h2,.section-heading h2,.results-head h2,.detail-head h2,.reader-header h2{
  margin:0;
  font-size:1.85rem;
  line-height:1.1;
}

.toolbar{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

.toolbar.compact{
  justify-content:flex-end;
}

.search-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:12px;
  margin-top:16px;
}

.field.wide{grid-column:span 2}
.field label{
  display:block;
  margin:0 0 6px;
  color:var(--brown);
  font-size:.76rem;
  font-weight:700;
  letter-spacing:.1em;
  text-transform:uppercase;
}

.field input,.field select{
  width:100%;
  min-height:46px;
  border:1px solid var(--line);
  border-radius:6px;
  background:#fffdf7;
  color:var(--ink);
  padding:10px 11px;
}

.badges,.chip-list,.card-actions{
  display:flex;
  gap:7px;
  flex-wrap:wrap;
  align-items:center;
}

.active-filters{
  margin-top:14px;
}

.badge,.chip{
  display:inline-flex;
  align-items:center;
  min-height:28px;
  border:1px solid var(--line);
  border-radius:999px;
  background:rgba(255,255,255,.48);
  color:#40362d;
  padding:4px 9px;
  font-size:.82rem;
  line-height:1.2;
}

.chip{
  min-height:32px;
  text-align:left;
}

.badge.theme,.chip.theme{border-color:rgba(79,100,71,.5);color:var(--green)}
.badge.place,.chip.place{border-color:rgba(49,82,104,.5);color:var(--blue)}
.badge.character,.chip.character{border-color:rgba(128,59,52,.5);color:var(--red)}
.badge.timeline{border-color:rgba(180,138,60,.55);color:#75581e}
.badge.path{border-color:rgba(95,51,40,.45);color:var(--brown)}

.results-layout{
  display:grid;
  grid-template-columns:minmax(0,1fr) 330px;
  gap:20px;
  align-items:start;
}

.results-head{
  margin:4px 0 12px;
  padding:0 2px;
}

.counter{
  color:var(--muted);
  font-size:.95rem;
  white-space:nowrap;
}

.results-list{
  min-height:160px;
}

.result-card{
  padding:18px;
  margin-bottom:12px;
}

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

.result-text{
  margin:0;
  color:#2d261f;
  font-size:1.05rem;
  line-height:1.65;
}

mark{
  background:#f0d987;
  color:#1f1a14;
  border-radius:3px;
  padding:0 3px;
}

.result-tags{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-top:12px;
}

.card-actions{
  margin-top:14px;
}

.side-panel{
  position:sticky;
  top:88px;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.panel.slim{
  padding:16px;
  box-shadow:none;
}

.panel.slim h3{
  margin:0 0 10px;
  font-size:1.25rem;
}

.quick-list{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height:300px;
  overflow:auto;
  padding-right:2px;
}

.quick-item{
  width:100%;
  border:1px solid var(--line);
  border-radius:6px;
  background:#fffdf7;
  color:var(--ink);
  padding:10px;
  text-align:left;
}

.quick-item:hover{
  border-color:var(--brown-soft);
  background:#fff7e8;
}

.quick-item strong{display:block}
.quick-item small{
  display:block;
  margin-top:4px;
  color:var(--muted);
  line-height:1.35;
}

.relation-list{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.relation-item{
  border-top:1px solid var(--line);
  padding-top:9px;
}

.relation-item:first-child{
  border-top:0;
  padding-top:0;
}

.relation-item div{
  display:flex;
  flex-wrap:wrap;
  gap:5px;
  align-items:baseline;
}

.relation-item p{
  margin:5px 0 0;
  color:var(--muted);
  font-size:.9rem;
  line-height:1.35;
}

.detail-panel,.reader{
  margin-top:24px;
  padding:22px;
}

.detail-head{
  border-bottom:1px solid var(--line);
  padding-bottom:14px;
  margin-bottom:16px;
}

.detail-grid{
  display:grid;
  grid-template-columns:minmax(0,1fr) 360px;
  gap:22px;
}

.detail-description{
  margin:0;
  font-size:1.12rem;
  line-height:1.58;
}

.detail-notes{
  margin-top:14px;
  border-left:4px double var(--brown-soft);
  padding-left:14px;
}

.detail-notes p,.student-task{
  margin:0 0 10px;
  color:#453a31;
  line-height:1.48;
}

.student-task{
  border:1px solid rgba(79,100,71,.35);
  border-left:4px solid var(--green);
  border-radius:6px;
  background:rgba(79,100,71,.07);
  padding:10px 12px;
}

.student-task.large{
  margin-top:16px;
}

.steps-list{
  margin:16px 0 0;
  padding-left:22px;
}

.steps-list li{
  margin:9px 0;
  line-height:1.42;
}

.steps-list span{
  display:block;
  color:var(--muted);
  margin-top:3px;
}

.detail-side{
  display:flex;
  flex-direction:column;
  gap:13px;
}

.detail-block{
  border-top:1px solid var(--line);
  padding-top:12px;
}

.detail-block:first-child{
  border-top:0;
  padding-top:0;
}

.detail-block h3{
  margin:0 0 8px;
  font-size:1.05rem;
  color:var(--brown);
}

.detail-passages{
  list-style:none;
  margin:0;
  padding:0;
  display:flex;
  flex-direction:column;
  gap:8px;
}

.detail-passages li{
  display:grid;
  gap:3px;
}

.detail-passages span{
  color:var(--muted);
  font-size:.86rem;
}

.reader-header{
  border-bottom:1px solid var(--line);
  padding-bottom:14px;
  margin-bottom:16px;
}

.summary{
  margin:8px 0 12px;
  color:#453a31;
  line-height:1.48;
}

.chapter-guide{
  margin:0 0 18px;
  border-left:4px double var(--brown);
  background:rgba(231,220,201,.55);
  padding:14px 16px;
}

.chapter-guide h3{
  margin:0 0 8px;
  color:var(--brown);
  font-size:1.1rem;
}

.chapter-guide p{
  margin:6px 0;
  line-height:1.45;
}

.chapter-guide ul{
  margin:8px 0 0;
  padding-left:22px;
}

.reader-body{
  max-width:920px;
  margin:0 auto;
}

.reader-body p{
  margin:0 0 17px;
  font-size:1.08rem;
  line-height:1.78;
}

.reader-body p:hover{
  background:rgba(255,255,255,.45);
}

.focus-par{
  background:rgba(180,138,60,.18);
  box-shadow:0 0 0 5px rgba(180,138,60,.18);
  border-radius:5px;
}

.section{
  margin-top:38px;
}

.section-heading{
  margin-bottom:14px;
  border-bottom:2px solid rgba(95,51,40,.18);
  padding-bottom:10px;
}

.cards-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(250px,1fr));
  gap:14px;
}

.chapters-grid{
  grid-template-columns:repeat(auto-fit,minmax(230px,1fr));
}

.path-grid,.passages-grid{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:16px;
}

.compact-grid{
  grid-template-columns:repeat(auto-fit,minmax(280px,1fr));
}

.atlas-card{
  padding:16px;
  transition:transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.atlas-card[role="button"]:hover{
  transform:translateY(-2px);
  border-color:var(--brown-soft);
  box-shadow:0 14px 30px rgba(37,28,18,.16);
}

.card-topline{
  color:var(--brown);
  font-size:.76rem;
  font-weight:700;
  letter-spacing:.12em;
  text-transform:uppercase;
}

.atlas-card h3{
  margin:7px 0 8px;
  font-size:1.28rem;
  line-height:1.18;
}

.atlas-card p{
  margin:0 0 12px;
  color:#463b32;
  line-height:1.45;
}

.card-meta{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  margin-top:12px;
  color:var(--muted);
  font-size:.88rem;
}

.linked-rows{
  display:grid;
  gap:9px;
  margin:12px 0;
}

.linked-row{
  display:grid;
  grid-template-columns:96px minmax(0,1fr);
  gap:10px;
  align-items:start;
}

.linked-row strong{
  color:var(--brown);
  font-size:.86rem;
}

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

.passage-card blockquote{
  max-height:210px;
  overflow:auto;
  margin:12px 0;
  border-left:4px solid var(--brown-soft);
  background:rgba(255,255,255,.45);
  padding:10px 13px;
  color:#322920;
  font-size:.98rem;
  line-height:1.58;
}

.focus{
  color:var(--muted);
  font-style:italic;
}

.empty-state{
  border:1px dashed var(--line);
  border-radius:8px;
  background:rgba(255,249,237,.65);
  color:var(--muted);
  padding:18px;
  margin:0;
}

.result-limit{
  margin:14px 0 0;
}

.muted{
  color:var(--muted);
}

.hidden{
  display:none!important;
}

.footer{
  max-width:1360px;
  margin:0 auto;
  padding:22px 22px 48px;
  color:var(--muted);
  font-size:.92rem;
  text-align:center;
}

@media(max-width:1120px){
  .topbar{
    align-items:flex-start;
    flex-direction:column;
  }
  .nav-actions{
    justify-content:flex-start;
  }
  .results-layout,.detail-grid{
    grid-template-columns:1fr;
  }
  .side-panel{
    position:static;
    display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));
  }
}

@media(max-width:900px){
  .hero{
    grid-template-columns:1fr;
    align-items:start;
  }
  .cover{
    display:grid;
    grid-template-columns:120px minmax(0,1fr);
    gap:12px;
    align-items:center;
  }
  .cover img{
    aspect-ratio:1;
  }
  .search-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }
  .path-grid,.passages-grid,.side-panel{
    grid-template-columns:1fr;
  }
}

@media(max-width:680px){
  main,.topbar,.footer{
    padding-left:16px;
    padding-right:16px;
  }
  .brand{
    min-width:0;
  }
  .brand h1{
    font-size:1rem;
  }
  .nav-actions{
    width:100%;
    overflow-x:auto;
    flex-wrap:nowrap;
    padding-bottom:4px;
  }
  .nav-actions .pill{
    white-space:nowrap;
  }
  .hero-copy h2{
    font-size:2.55rem;
  }
  .subtitle{
    font-size:1rem;
  }
  .stats,.search-grid{
    grid-template-columns:1fr;
  }
  .field.wide{
    grid-column:auto;
  }
  .panel-title,.detail-head,.section-heading,.reader-header,.results-head{
    flex-direction:column;
    align-items:stretch;
  }
  .toolbar.compact{
    justify-content:flex-start;
  }
  .cover{
    grid-template-columns:88px minmax(0,1fr);
  }
  .reader-body p,.result-text{
    font-size:1rem;
  }
  .linked-row{
    grid-template-columns:1fr;
    gap:4px;
  }
}

@media print{
  .app-header,.search-panel,.side-panel,.footer,.card-actions,.detail-panel{
    display:none!important;
  }
  body{
    background:#fff;
  }
  main{
    max-width:none;
  }
  .hero{
    display:block;
    border-bottom:1px solid #000;
  }
  .cover{
    display:none;
  }
  .results-layout{
    display:block;
  }
  .result-card,.reader,.atlas-card{
    box-shadow:none;
    break-inside:avoid;
  }
}
