:root {
  color-scheme: light;
  --ink: #1e1c18;
  --muted: #6d675f;
  --paper: #faf7ef;
  --paper-strong: #fffdf7;
  --line: #ddd3c1;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --seal: #a33d2d;
  --shadow: 0 18px 50px rgba(63, 50, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.08), transparent 32%),
    linear-gradient(180deg, #f3ecdf 0%, #fffaf1 100%);
  font-family: "Songti SC", "Noto Serif CJK SC", "STSong", serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 calc(48px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--seal);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 4.4rem);
  font-weight: 700;
  line-height: 1;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.7rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

.stats,
.tabs,
.draw-actions,
.part-title,
.dialog-head {
  display: flex;
  align-items: center;
}

.stats {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
}

.stats span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 253, 247, 0.72);
}

.tabs {
  gap: 8px;
  margin-bottom: 18px;
  padding: 6px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.8);
}

.tab {
  min-width: 96px;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  color: var(--muted);
  background: transparent;
}

.tab.active {
  color: white;
  background: var(--accent);
}

.panel {
  display: none;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.88);
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.section-head p,
.draw-meta {
  color: var(--muted);
}

.search-box {
  display: grid;
  gap: 6px;
  min-width: min(300px, 100%);
  color: var(--muted);
  font-size: 0.9rem;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--paper-strong);
}

.part-block + .part-block {
  margin-top: 28px;
}

.part-title {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.part-title span {
  color: var(--muted);
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.chapter-card {
  display: grid;
  gap: 8px;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  color: var(--ink);
  background: #fffaf2;
}

.chapter-card:hover,
.chapter-card:focus-visible {
  border-color: rgba(15, 118, 110, 0.55);
  outline: none;
  box-shadow: 0 8px 24px rgba(15, 118, 110, 0.12);
}

.chapter-card strong {
  color: var(--accent-dark);
  font-size: 1.15rem;
}

.chapter-card span {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.chapter-card[hidden] {
  display: none;
}

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

.draw-stage {
  min-height: 480px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 30%, rgba(163, 61, 45, 0.1), transparent 34%),
    linear-gradient(180deg, #fffaf2, #f3eadb);
}

.draw-stage h2 {
  margin-bottom: 18px;
}

.draw-number {
  width: min(300px, 68vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 50%;
  color: var(--accent-dark);
  background: rgba(255, 253, 247, 0.9);
  font-family: ui-serif, Georgia, serif;
  font-size: clamp(5rem, 22vw, 9rem);
  font-weight: 800;
  line-height: 1;
  box-shadow: inset 0 0 0 12px rgba(15, 118, 110, 0.08);
}

.draw-number.rolling {
  color: var(--seal);
}

.draw-meta {
  min-height: 24px;
  margin: 18px 0 20px;
}

.draw-actions {
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.primary-action,
.secondary-action,
.text-action,
.icon-button {
  border-radius: 8px;
}

.primary-action,
.secondary-action {
  min-width: 116px;
  border: 1px solid transparent;
  padding: 12px 18px;
  min-height: 44px;
}

.primary-action {
  color: white;
  background: var(--accent);
}

.primary-action:hover {
  background: var(--accent-dark);
}

.secondary-action {
  color: var(--accent-dark);
  border-color: rgba(15, 118, 110, 0.35);
  background: white;
}

.draw-history {
  border-left: 1px solid var(--line);
  padding-left: 22px;
}

.text-action {
  border: 0;
  color: var(--seal);
  background: transparent;
}

.draw-history ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.draw-history li button {
  border: 0;
  padding: 4px 0;
  color: var(--accent-dark);
  background: transparent;
  text-align: left;
}

.chapter-dialog {
  width: min(760px, calc(100% - 28px));
  max-height: min(84vh, 840px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--paper-strong);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(32, 26, 19, 0.28);
}

.chapter-dialog::backdrop {
  background: rgba(30, 28, 24, 0.38);
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.96);
}

.dialog-head h2 {
  margin: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: white;
  font-size: 1.6rem;
  line-height: 1;
}

.chapter-content {
  padding: 22px;
}

.classic-text,
.translation-text,
.notes-text {
  display: grid;
  gap: 12px;
  line-height: 1.9;
}

.classic-text p,
.translation-text p,
.notes-text p {
  margin: 0;
}

.classic-text {
  font-size: 1.18rem;
}

.content-toggle,
.notes-toggle {
  margin: 22px 0 0;
}

.translation-section,
.notes-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.translation-text,
.notes-text {
  color: #4d463d;
  font-size: 1rem;
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 16px, 1120px);
    padding-top: calc(16px + env(safe-area-inset-top));
  }

  .app-header,
  .section-head,
  .draw-layout {
    display: grid;
  }

  .app-header {
    align-items: start;
    gap: 14px;
    margin-bottom: 14px;
  }

  h1 {
    font-size: 2.35rem;
  }

  h2 {
    font-size: 1.35rem;
  }

  .stats {
    justify-content: flex-start;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
  }

  .panel {
    padding: 14px;
    border-radius: 8px;
  }

  .chapter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .chapter-card {
    min-height: 108px;
    padding: 11px;
  }

  .chapter-card strong {
    font-size: 1rem;
  }

  .chapter-card span {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .draw-layout {
    grid-template-columns: 1fr;
  }

  .draw-stage {
    min-height: min(72vh, 520px);
    padding: 28px 12px;
  }

  .draw-number {
    width: min(260px, 72vw);
    font-size: clamp(4.5rem, 28vw, 7.5rem);
  }

  .draw-actions {
    width: 100%;
  }

  .primary-action,
  .secondary-action {
    flex: 1;
    min-width: 0;
  }

  .draw-history {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 18px 0 0;
  }

  .chapter-dialog {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .dialog-head {
    padding: calc(16px + env(safe-area-inset-top)) 16px 14px;
  }

  .chapter-content {
    padding: 18px 16px calc(32px + env(safe-area-inset-bottom));
  }

  .classic-text {
    font-size: 1.08rem;
  }
}
