:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --bg-elev: #151515;
  --text: #f2f0e9;
  --muted: #b7b2a7;
  --accent: #dbb36b;
  --border: #2b2b2b;
  --reader-content-width: 760px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1e1a14, #090909 42%) no-repeat;
  background-size: 100% 100%;
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  line-height: 1.7;
}

.site-header {
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1rem;
  position: sticky;
  top: 0;
  backdrop-filter: blur(6px);
  background: rgba(10, 10, 10, 0.78);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  min-height: 2rem;
}

.site-header-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 56vw;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  pointer-events: none;
}

.brand {
  color: var(--accent);
  text-decoration: none;
  font-size: 1.2rem;
  letter-spacing: 0.03em;
}

.site-header-auth {
  justify-self: end;
}

.site-header-auth form {
  margin: 0;
}

main {
  padding: 1rem;
}

.library-wrap,
.toc-wrap,
.reader-wrap {
  max-width: 860px;
  margin: 0 auto;
}

.library-wrap,
.reader-wrap {
  padding-bottom: clamp(11rem, 55vh, 26rem);
}

.library-list,
.toc-list {
  list-style: none;
  padding: 0;
}

.library-list li,
.toc-list li {
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0;
}

a {
  color: #f4d59f;
}

a:hover {
  color: #ffe6bc;
}

.reader-content {
  max-width: var(--reader-content-width);
  margin: 1.2rem auto;
  background: rgba(18, 18, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.2rem;
}

.reader-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.85rem auto;
}

.reader-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.tnote-ref {
  position: relative;
  display: inline-block;
  font-size: 0.72em;
  line-height: 1;
  vertical-align: super;
  color: var(--accent);
  cursor: help;
  margin-left: 0.06em;
}

.tnote-ref:focus-visible {
  outline: 1px solid #e9c482;
  outline-offset: 2px;
  border-radius: 4px;
}

.tnote-ref:hover::after,
.tnote-ref:focus-visible::after {
  content: attr(data-note-text);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.55rem);
  transform: translateX(-50%);
  z-index: 30;
  width: max-content;
  max-width: min(34rem, calc(100vw - 2rem));
  background: #13100a;
  border: 1px solid #8a6a37;
  color: #f9f3e6;
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  font-size: 0.92rem;
  line-height: 1.4;
  white-space: normal;
}

.tnote-ref:hover::before,
.tnote-ref:focus-visible::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 0.2rem);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #8a6a37;
  transform: translateX(-50%);
  z-index: 31;
}

.prose h1,
.prose h2,
.prose h3 {
  scroll-margin-top: 5rem;
}

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

.reader-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.6rem;
  align-items: center;
}

.nav-left {
  justify-self: start;
}

.nav-center {
  justify-self: center;
}

.nav-right {
  justify-self: end;
}

.btn {
  display: inline-block;
  border: 1px solid #7d6337;
  color: #f8dbab;
  background: #1b150f;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
}

.btn-sm {
  font-size: 0.78rem;
  padding: 0.24rem 0.58rem;
}

.owner-auth-btn {
  letter-spacing: 0.02em;
}

.btn:hover {
  background: #2a2118;
}

.reader-controls {
  max-width: var(--reader-content-width);
  margin: 0.8rem auto 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(18, 18, 18, 0.72);
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.reader-controls input[type="range"] {
  flex: 1;
}

.reader-width-value {
  color: var(--muted);
  min-width: 4.5rem;
  text-align: right;
}

.library-groups {
  display: grid;
  gap: 1.2rem;
}

.notice-panel {
  border: 1px solid #5b4a2b;
  border-radius: 12px;
  background: rgba(33, 27, 20, 0.78);
  padding: 0.9rem 1rem;
  margin: 0.9rem 0 1rem;
}

.notice-panel h2 {
  margin: 0 0 0.45rem;
  font-size: 1.05rem;
  color: #f0d5a4;
}

.notice-panel p {
  margin: 0.35rem 0;
}

.arc-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(18, 18, 18, 0.72);
  padding: 1rem;
}

.arc-title {
  margin: 0;
  font-size: 1.45rem;
}

.phase-title {
  margin: 0.9rem 0 0.25rem;
  font-size: 1.1rem;
  color: #edd4a7;
}

.progress-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(18, 18, 18, 0.72);
  padding: 0.8rem 1rem;
  margin: 0.8rem 0;
}

.progress-panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.progress-panel p {
  margin: 0.2rem 0;
}

.toc-list .h2 {
  padding-left: 1rem;
}

.toc-list .h3 {
  padding-left: 2rem;
}

@media (max-width: 720px) {
  .site-header {
    padding: 0.72rem 0.8rem;
  }

  .site-header-title {
    max-width: 50vw;
    font-size: 0.84rem;
  }

  .reader-content {
    padding: 1rem 0.9rem;
  }

  .reader-controls {
    padding: 0.65rem 0.75rem;
    gap: 0.6rem;
  }

  .reader-nav {
    grid-template-columns: 1fr;
  }

  .nav-left,
  .nav-center,
  .nav-right {
    justify-self: stretch;
  }

  .btn {
    display: block;
    text-align: center;
  }
}
