:root {
  color-scheme: dark;
  font-family: "Manrope", system-ui, sans-serif;
  --bg: #0a0b0e;
  --surface: #12151c;
  --surface-2: #0f1218;
  --ink: #f2efe7;
  --muted: #a2a9b5;
  --accent: #d2a14a;
  --accent-strong: #f0c66d;
  --stroke: #2a2f3b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 520px at 10% -10%, rgba(210, 161, 74, 0.16), transparent 60%),
    radial-gradient(700px 420px at 90% 0%, rgba(91, 185, 179, 0.12), transparent 55%),
    linear-gradient(180deg, #090a0d 0%, #0b0d13 60%, #090a0d 100%);
  color: var(--ink);
}

.home main {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.home .search {
  margin: 0;
  width: min(640px, 90vw);
}

.home .search label {
  display: none;
}

.home .reader {
  display: none;
}

.home .back-to-top {
  display: none;
}

.site-header {
  padding: 2.8rem 8vw 1rem;
  text-align: center;
}

.site-title {
  margin: 0;
  font-family: "Cinzel", "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: 0.35em;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  color: var(--ink);
  text-decoration: none;
  display: inline-block;
}

main {
  padding: 0 8vw 4rem;
}

.search {
  max-width: 980px;
  margin: 0 auto 2rem;
  position: relative;
}

.search label {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.search input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  color: var(--ink);
  font-size: 1rem;
}

.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(210, 161, 74, 0.2);
}

.search-results {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  overflow: hidden;
  position: absolute;
  width: 100%;
  z-index: 10;
}

.search-results.show {
  display: grid;
}

.search-results li {
  border-bottom: 1px solid rgba(42, 47, 59, 0.7);
}

.search-results li:last-child {
  border-bottom: none;
}

.search-results button {
  width: 100%;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.search-results button:hover {
  background: rgba(210, 161, 74, 0.12);
}

.recent {
  display: none;
  margin-top: 1.6rem;
  background: rgba(13, 16, 22, 0.92);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 1.2rem 1.4rem 1rem;
}

.home .recent {
  display: block;
}

.recent-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.recent h2 {
  margin: 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
}

.recent-subtitle {
  color: var(--muted);
  font-size: 0.85rem;
}

.recent-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.recent-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(10, 12, 18, 0.7);
  border: 1px solid rgba(42, 47, 59, 0.7);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
}

.recent-list button {
  background: transparent;
  border: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  text-align: left;
  padding: 0;
}

.recent-list button:hover {
  color: var(--accent-strong);
}

.recent-date {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

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

.reader {
  max-width: 980px;
  margin: 0 auto;
  background: rgba(13, 16, 22, 0.92);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 2rem 2.4rem 2.6rem;
  box-shadow: 0 10px 40px rgba(8, 10, 14, 0.55);
}

.audio-player {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 1rem;
  background: rgba(10, 12, 18, 0.8);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  margin-bottom: 1.5rem;
}

.audio-player.hidden {
  display: none;
}

.audio-player.no-audio .audio-progress,
.audio-player.no-audio .audio-time,
.audio-player.no-audio .audio-btn {
  opacity: 0.3;
  pointer-events: none;
}

.audio-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.audio-btn:hover {
  background: var(--accent-strong);
  transform: scale(1.05);
}

.audio-btn:active {
  transform: scale(0.95);
}

.audio-icon {
  width: 18px;
  height: 18px;
  display: none;
}

.audio-btn .play { display: block; }
.audio-btn.playing .play { display: none; }
.audio-btn.playing .pause { display: block; }
.audio-btn.loading .play,
.audio-btn.loading .pause { display: none; }
.audio-btn.loading .loading { display: block; animation: spin 1s linear infinite; }

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.audio-progress {
  flex: 1;
  height: 6px;
  background: var(--stroke);
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}

.audio-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  border-radius: 3px;
  transition: width 0.1s linear;
}

.audio-time {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 40px;
  text-align: center;
}

.audio-status {
  font-size: 0.75rem;
  color: var(--muted);
  font-style: italic;
}

.reader-top {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  gap: 2rem;
}

.toc {
  background: rgba(10, 12, 18, 0.6);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  height: fit-content;
}

.toc h2 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.4rem;
  font-size: 0.95rem;
}

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

.toc li.empty {
  color: var(--muted);
  font-style: italic;
}

.toc button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--ink);
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.toc button:hover {
  color: var(--accent-strong);
}

.toc .level-3 {
  padding-left: 0.8rem;
  font-size: 0.9rem;
}

.page h2 {
  margin-top: 0;
  font-family: "Cinzel", "Times New Roman", serif;
  font-size: 1.9rem;
}

.content h1,
.content h2,
.content h3 {
  font-family: "Cinzel", "Times New Roman", serif;
  color: #ffffff;
}

.content p {
  color: #cfd4de;
  line-height: 1.75;
}

.content ul {
  margin: 0.8rem 0 1.2rem;
  padding-left: 1.1rem;
  color: #cfd4de;
}

.content li {
  margin-bottom: 0.35rem;
}

.content a {
  color: var(--accent-strong);
  text-decoration: none;
  border-bottom: 1px solid rgba(210, 161, 74, 0.3);
}

.back-to-top {
  position: fixed;
  right: 2.5rem;
  bottom: 2.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--stroke);
  background: rgba(15, 18, 26, 0.9);
  color: var(--ink);
  font-size: 1.3rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.back-to-top.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@media (max-width: 900px) {
  .site-header {
    padding: 2.4rem 7vw 0.8rem;
  }

  .reader {
    padding: 1.6rem;
  }

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

  .toc {
    order: -1;
  }

  .back-to-top {
    right: 1.5rem;
    bottom: 1.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .back-to-top {
    transition: none;
  }
}
