/* Seanchas — a warm, dark reading room.
   Brand notes: premium and modern, story/archive feeling, restrained Celtic
   influence (thin gold hairlines and one interlace mark, no parchment or
   pseudo-medieval ornament). Book covers are the loudest thing on every screen. */

:root {
  --ink:        #0a0d0c;
  --ink-2:      #101614;
  --panel:      #151d1a;
  --panel-2:    #1c2622;
  --line:       #26332e;
  --line-soft:  #1e2925;
  --text:       #f2efe6;
  --text-dim:   #a3afa6;
  --text-faint: #6d7a72;
  --gold:       #c9a765;
  --gold-bright:#e0c288;
  --green:      #4c8168;
  --green-dim:  #2f4f42;
  --danger:     #cf7a72;
  --good:       #7fbc95;
  --warn:       #d8b45f;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, .8);
  --nav-h: 62px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1100px 620px at 82% -12%, #1d3a2f 0%, transparent 62%),
    radial-gradient(760px 460px at 6% 4%, #1a2b30 0%, transparent 58%),
    var(--ink);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.55 var(--sans);
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); text-decoration: none; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- shell */

.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  padding: 26px 16px 18px;
  border-right: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #0d1211f2, #0a0d0cf2);
  backdrop-filter: blur(14px);
  display: flex; flex-direction: column; gap: 6px;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px 4px; }
.brand-name { font-family: var(--serif); font-size: 22px; letter-spacing: .13em; }
.brand-tag {
  font-size: 9.5px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--text-faint); margin-top: 2px;
}

/* The one Celtic element: a simple interlace mark. */
.knot { width: 30px; height: 30px; flex: 0 0 30px; }
.knot path { stroke: var(--gold); stroke-width: 1.4; fill: none; }

nav { margin-top: 20px; display: grid; gap: 2px; }
nav button {
  display: flex; align-items: center; gap: 11px;
  border: 0; background: transparent; color: var(--text-dim);
  text-align: left; padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; width: 100%; position: relative;
}
.sidebar nav button:hover { background: #ffffff08; color: var(--text); }
.sidebar nav button.active { background: var(--panel-2); color: var(--text); }
.sidebar nav button.active::before {
  content: ""; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 2px; background: var(--gold); border-radius: 2px;
}
nav .icon { width: 17px; text-align: center; opacity: .85; }
nav .count {
  margin-left: auto; font-size: 11px; color: var(--ink);
  background: var(--gold); border-radius: 999px; padding: 1px 7px; font-weight: 700;
}
.nav-section {
  font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--text-faint); padding: 16px 12px 5px;
}

.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.whoami { font-size: 12px; color: var(--text-dim); padding: 0 6px 8px; }
.whoami b { display: block; color: var(--text); font-size: 13px; }

.main { padding: 30px 34px 60px; max-width: 1620px; min-width: 0; }

/* ---------------------------------------------------------------- header */

.page-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 20px; margin-bottom: 26px; flex-wrap: wrap;
}
.eyebrow {
  color: var(--gold); font-size: 10.5px; letter-spacing: .2em;
  text-transform: uppercase; margin-bottom: 5px;
}
h1 { font-family: var(--serif); font-weight: 400; font-size: 38px; margin: 0; line-height: 1.1; }
h2 { font-family: var(--serif); font-weight: 400; font-size: 22px; margin: 0; }
.subtle { color: var(--text-dim); }
.tiny { font-size: 12px; }

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

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 9px 15px; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { border-color: #3a4a43; background: #222d28; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border-color: var(--gold); color: #1a1508; font-weight: 650;
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); background: #ffffff08; }
.btn.danger { border-color: #5e3a36; color: var(--danger); background: #1d1413; }
.btn.danger:hover { background: #251817; }
.btn.small { padding: 6px 11px; font-size: 13px; }

/* ---------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  padding: 16px 18px; border: 1px solid var(--line-soft); border-radius: var(--radius);
  background: linear-gradient(160deg, var(--panel), #0e1412);
}
.stat b { display: block; font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.stat span { color: var(--text-dim); font-size: 12px; }

/* ---------------------------------------------------------------- shelves */

.shelf { margin: 34px 0; }
.shelf-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.rail {
  display: grid; grid-auto-flow: column; grid-auto-columns: 158px; gap: 15px;
  align-items: start;
  overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.rail > * { scroll-snap-align: start; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 18px 15px; }

/* ---------------------------------------------------------------- book card */

.book { cursor: pointer; border: 0; background: none; padding: 0; text-align: left; width: 100%; }
.cover-wrap {
  position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
  background: linear-gradient(150deg, var(--green-dim), #141d19);
  box-shadow: var(--shadow); border: 1px solid #ffffff0f;
}
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fallback {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 14px;
  font-family: var(--serif); font-size: 15px; text-align: center; color: #d9c795;
  line-height: 1.25;
}
.book:hover .cover-wrap { border-color: var(--gold); }
.book-title {
  margin-top: 9px; font-size: 13.5px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-sub {
  color: var(--text-dim); font-size: 12px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Rating straight from a shelf, so pruning a grid does not mean opening
   every book. Always visible on touch; on a pointer it fades in on hover. */
.book-slot { display: flex; flex-direction: column; }
.quick-rate { display: flex; gap: 1px; margin-top: 5px; align-items: center; }
.quick-rate .qs {
  background: none; border: 0; padding: 0 1px; cursor: pointer; line-height: 1;
  color: var(--text-faint); font-size: 15px;
}
.quick-rate .qs.on { color: var(--gold); }
.quick-rate .qs:hover { color: var(--gold-bright); }
.quick-rate .qs.alt { margin-left: auto; font-size: 13px; }
.quick-rate .qs.alt.on { color: var(--danger); }
.quick-rate .qs.alt[data-state="favorite"].on { color: var(--good); }
@media (hover: hover) and (pointer: fine) {
  .quick-rate { opacity: 0; transition: opacity .15s; }
  .book-slot:hover .quick-rate,
  .quick-rate:focus-within { opacity: 1; }
}

.badges { position: absolute; top: 7px; left: 7px; display: flex; gap: 4px; flex-wrap: wrap; }
.badge {
  font-size: 10px; padding: 2px 6px; border-radius: 5px; font-weight: 600;
  background: #0a0d0cd9; border: 1px solid #ffffff1f; backdrop-filter: blur(6px);
}
.badge.series-pos { background: #0a0d0cd9; color: var(--gold); }
.corner-note .formats { display: flex; gap: 4px; }
.fmt {
  font-size: 9px; letter-spacing: .06em; font-weight: 700; padding: 1px 5px;
  border-radius: 4px; background: #0a0d0cd9; border: 1px solid var(--green);
  color: var(--good);
}
.corner-note {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 18px 8px 6px;
  background: linear-gradient(transparent, #050706cc 45%, #050706f2);
  font-size: 11px; color: var(--text-dim);
  display: flex; justify-content: space-between; gap: 6px;
}

/* ---------------------------------------------------------------- pills */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; color: var(--text-dim);
}
.pill.owned { border-color: var(--green); color: var(--good); }
.pill.missing { border-color: #4a3f2a; color: var(--text-faint); }
.pill.gold { border-color: var(--gold); color: var(--gold-bright); }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--text-dim);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--gold); border-color: var(--gold); color: #1a1508; font-weight: 600; }

/* ---------------------------------------------------------------- fields */

.field {
  background: #0c1110; border: 1px solid var(--line); color: var(--text);
  padding: 10px 13px; border-radius: var(--radius-sm); width: 100%;
}
.field:focus { outline: none; border-color: var(--gold); }
.field::placeholder { color: var(--text-faint); }
.search-row { display: flex; gap: 9px; align-items: center; }
.search-row .field { max-width: 460px; }

/* ---------------------------------------------------------------- book page */

.book-page { display: grid; grid-template-columns: 288px 1fr; gap: 22px 34px; align-items: start; }
.book-cover-col { grid-column: 1; grid-row: 1; }
.book-info-col { grid-column: 2; grid-row: 1 / span 2; }
.book-admin-col { grid-column: 1; grid-row: 2; display: grid; gap: 8px; }
.book-page .cover-wrap { aspect-ratio: auto; }
.book-page .cover-wrap img { height: auto; }
.book-hero-title { font-family: var(--serif); font-size: 34px; line-height: 1.12; margin: 0 0 6px; }
.book-hero-sub { color: var(--text-dim); font-size: 16px; margin-bottom: 14px; }
.meta-row { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 20px; }
.description { color: #d7d2c4; line-height: 1.65; max-width: 68ch; margin: 18px 0 24px; }
.description.clamped { display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }

.formats { display: grid; gap: 11px; grid-template-columns: repeat(auto-fit, minmax(258px, 1fr)); margin: 22px 0; }
.format {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px;
  background: var(--panel); display: flex; align-items: center; gap: 13px;
}
.format.is-owned { border-color: var(--green-dim); }
.format .glyph { font-size: 21px; font-family: var(--emoji); }
.format .lines { flex: 1; min-width: 0; }
.format .lines b { display: block; font-size: 14px; }
.format .lines span { color: var(--text-dim); font-size: 12px; }

.stars { display: flex; gap: 3px; }
.stars button {
  background: none; border: 0; color: var(--text-faint); font-size: 25px;
  cursor: pointer; padding: 0 2px; line-height: 1;
}
.stars button.on { color: var(--gold); }
.stars button:hover { color: var(--gold-bright); }

/* ---------------------------------------------------------------- doctor */

.issue-list { display: grid; gap: 9px; }
.issue {
  display: flex; align-items: center; gap: 14px; padding: 13px 16px;
  border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel);
  cursor: pointer; text-align: left; width: 100%;
}
.issue:hover { border-color: var(--line); background: var(--panel-2); }
.issue .n { font-family: var(--serif); font-size: 25px; min-width: 56px; }
.issue .sev { width: 3px; align-self: stretch; border-radius: 2px; background: var(--green); }
.issue .sev.high { background: var(--danger); }
.issue .sev.mid { background: var(--warn); }

.proposal {
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  background: var(--panel); margin-bottom: 13px; overflow: hidden;
}
.proposal-head {
  display: flex; align-items: center; gap: 14px; padding: 14px 17px;
  border-bottom: 1px solid var(--line-soft);
}
.proposal-head .grow { flex: 1; min-width: 0; }
.proposal-title { font-weight: 620; }
.conf {
  font-family: var(--serif); font-size: 19px; padding: 3px 11px; border-radius: 8px;
  border: 1px solid var(--line);
}
.conf.extremely_confident { color: var(--good); border-color: var(--green); }
.conf.strong { color: var(--gold-bright); border-color: var(--gold); }
.conf.needs_review { color: var(--warn); border-color: #5d4d24; }
.conf.manual { color: var(--danger); border-color: #5e3a36; }

.proposal-body { padding: 15px 17px; display: grid; gap: 17px; }
.evidence { display: grid; gap: 5px; }
.signal { display: grid; grid-template-columns: 92px 74px 1fr; gap: 10px; font-size: 12.5px; align-items: baseline; }
.signal .name { color: var(--text-dim); }
.signal .verdict { font-weight: 650; }
.verdict.exact, .verdict.strong { color: var(--good); }
.verdict.close { color: var(--warn); }
.verdict.differs { color: var(--danger); }
.signal .detail { color: var(--text-faint); overflow-wrap: anywhere; }

.diff { display: grid; gap: 7px; }
.diff-row { display: grid; grid-template-columns: 118px 1fr 18px 1fr; gap: 10px; font-size: 12.5px; align-items: baseline; }
.diff-row .k { color: var(--text-dim); }
.diff-row .from { color: var(--text-faint); text-decoration: line-through; overflow-wrap: anywhere; }
.diff-row .to { color: var(--good); overflow-wrap: anywhere; }
.diff-row .arrow { color: var(--text-faint); text-align: center; }
.path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; overflow-wrap: anywhere; }

.cover-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 11px; }
.cover-choice { position: relative; cursor: pointer; border: 2px solid transparent; border-radius: 9px; overflow: hidden; padding: 0; background: none; }
.cover-choice.selected { border-color: var(--gold); }
.cover-choice img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.cover-choice .dims { position: absolute; bottom: 0; left: 0; right: 0; background: #050706cc; font-size: 10px; padding: 3px; text-align: center; }

/* ---------------------------------------------------------------- table */

.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 10.5px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-faint); padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.table td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tr:hover td { background: #ffffff05; }

.state { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.state.requested { color: var(--gold); border-color: #5d4d24; }
.state.downloading, .state.searching, .state.processing { color: var(--warn); border-color: #5d4d24; }
.state.available, .state.imported { color: var(--good); border-color: var(--green); }
.state.failed, .state.rejected { color: var(--danger); border-color: #5e3a36; }

/* ---------------------------------------------------------------- misc */

.card { border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--panel); padding: 18px 20px; }
.card + .card { margin-top: 13px; }
.card h2 { margin-bottom: 12px; }
.rows { display: grid; gap: 9px; }
.row { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--text-dim); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 7px; }
.dot.ok { background: var(--good); } .dot.bad { background: var(--danger); } .dot.off { background: var(--text-faint); }

.empty { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty .glyph { font-size: 40px; opacity: .5; display: block; margin-bottom: 12px; }
.empty h2 { margin-bottom: 8px; }

.progress { height: 4px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); transition: width .4s; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 90; max-width: 380px; }
.toast {
  background: #1d2723; border: 1px solid var(--line); border-left: 3px solid var(--gold);
  padding: 11px 15px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  animation: rise .22s ease-out;
}
.toast.bad { border-left-color: var(--danger); }
.toast.good { border-left-color: var(--good); }
@keyframes rise { from { opacity: 0; transform: translateY(9px); } }

.spinner {
  width: 15px; height: 15px; border: 2px solid #ffffff26; border-top-color: var(--gold);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.jobbar {
  display: flex; align-items: center; gap: 11px; padding: 10px 15px; margin-bottom: 18px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.jobbar .grow { flex: 1; }

/* ---------------------------------------------------------------- sign-in */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.signin-box { width: min(410px, 100%); }
.signin-box .knot { width: 44px; height: 44px; margin-bottom: 14px; }
.signin-box h1 { font-size: 40px; letter-spacing: .1em; }
.signin-form { display: grid; gap: 10px; margin-top: 22px; }

/* ---------------------------------------------------------------- mobile */

.mobile-nav { display: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 15px calc(var(--nav-h) + 30px); }
  h1 { font-size: 28px; }
  .page-head { margin-bottom: 18px; align-items: flex-start; }
  .book-page { grid-template-columns: 1fr; gap: 20px; }
  .book-cover-col, .book-info-col, .book-admin-col { grid-column: 1; grid-row: auto; }
  .book-page .cover-wrap { max-width: 220px; }
  .book-hero-title { font-size: 26px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 15px 11px; }
  .rail { grid-auto-columns: 132px; }
  .signal { grid-template-columns: 80px 66px 1fr; }
  .diff-row { grid-template-columns: 1fr; gap: 2px; }
  .diff-row .arrow { display: none; }
  .diff-row .from::after { content: ""; }
  .toast-stack { left: 14px; right: 14px; bottom: calc(var(--nav-h) + 14px); max-width: none; }

  .mobile-nav {
    display: grid; grid-auto-flow: column; position: fixed; inset: auto 0 0 0;
    height: var(--nav-h); background: #0b100ef2; backdrop-filter: blur(16px);
    border-top: 1px solid var(--line-soft); z-index: 80;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mobile-nav button {
    border: 0; background: none; color: var(--text-faint); display: grid;
    place-items: center; gap: 2px; font-size: 10px; cursor: pointer;
  }
  .mobile-nav button .icon { font-size: 18px; }
  .mobile-nav button.active { color: var(--gold); }
  .mobile-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: 0 0 14px; gap: 12px;
  }
}

@media (min-width: 861px) { .mobile-head { display: none; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
