:root {
  --bg: #0c0a09;
  --surface: #15110e;
  --surface-2: #1e1915;
  --line: #2e2620;
  --text: #ece5d8;
  --muted: #a79a88;
  --gold: #caa866;
  --gold-dim: #8a7042;
  --angel: #a9cdea;
  --demon: #e2584b;
  --human: #e8a15a;
  --nav-h: 52px;
  --serif: "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + 12px);
}

html:has(dialog[open]) { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.8 var(--sans);
  word-break: keep-all;
  overflow-wrap: anywhere;
}

img { display: block; max-width: 100%; height: auto; }
a { color: var(--gold); }
[hidden] { display: none !important; }

.angel { --faction: var(--angel); }
.demon { --faction: var(--demon); }
.human { --faction: var(--human); }

h2, h3, h4 { font-family: var(--serif); font-weight: 800; line-height: 1.35; }

/* ── 로고 ─────────────────────────────── */

.hero {
  padding: calc(env(safe-area-inset-top, 0px) + 36px) 16px 28px;
  text-align: center;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, rgba(150, 28, 28, 0.3), transparent 70%),
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(202, 168, 102, 0.12), transparent 70%);
}

.hero h1 { width: 76%; max-width: 460px; margin: 0 auto; }
.hero h1 img { width: 100%; }

.logline {
  margin: 14px 0 0;
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(15px, 4.2vw, 20px);
  color: var(--gold);
}

/* ── 메뉴 ─────────────────────────────── */

.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px), calc((100% - 960px) / 2)) 0 max(8px, env(safe-area-inset-left, 0px), calc((100% - 960px) / 2));
  background: rgba(12, 10, 9, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.tabs a {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--nav-h);
  color: var(--muted);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 16px;
  border-bottom: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
}

.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--gold); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) 56px max(16px, env(safe-area-inset-left, 0px));
}

.lead {
  margin: 22px 0 6px;
  color: var(--muted);
  font-size: 14.5px;
}

.quote {
  margin: 16px 0;
  padding: 10px 14px;
  background: var(--surface-2);
  border-left: 3px solid var(--faction, var(--gold));
  border-radius: 0 8px 8px 0;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.65;
}

/* ── 세계관: 접히는 장 ───────────────── */

.codex { max-width: 680px; margin: 0 auto; }

.chapter {
  margin: 10px 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.chapter[open] { border-color: var(--gold-dim); }

.chapter summary {
  position: relative;
  display: grid;
  gap: 1px;
  padding: 13px 46px 14px 16px;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.chapter summary::-webkit-details-marker { display: none; }

.chapter summary::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 20px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 0.2s;
}

.chapter[open] summary::after { transform: translateY(-25%) rotate(-135deg); }

.chapter .no {
  color: var(--gold-dim);
  font-family: var(--serif);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.18em;
}

.chapter .ttl { font-family: var(--serif); font-weight: 800; font-size: 21px; line-height: 1.35; }
.chapter .teaser { color: var(--muted); font-size: 14px; line-height: 1.5; }

.chapter-body {
  padding: 2px 18px 22px;
  border-top: 1px solid var(--line);
}

.chapter-body > p { margin: 14px 0 0; }

.creeds { display: grid; gap: 10px; margin: 16px 0 4px; }

@media (min-width: 560px) {
  .creeds { grid-template-columns: 1fr 1fr; }
}

.creed {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--faction);
  border-radius: 10px;
}

.creed cite {
  display: block;
  margin-bottom: 2px;
  color: var(--faction);
  font-style: normal;
  font-weight: 700;
  font-size: 13px;
}

.creed p { margin: 0; font-family: var(--serif); font-weight: 800; line-height: 1.65; }

/* 연대기 · 법칙 (제9·10장) */

.chapter-body h4 {
  margin: 24px 0 8px;
  color: var(--gold);
  font-size: 17px;
}

.timeline {
  margin: 14px 0 0;
  padding: 0 0 0 16px;
  list-style: none;
  border-left: 2px solid var(--gold-dim);
}

.timeline li { position: relative; padding: 0 0 16px 12px; }

.timeline li::before {
  content: "";
  position: absolute;
  top: 9px;
  left: -22px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
}

.timeline b { display: block; color: var(--gold); font-family: var(--serif); font-size: 15px; }
.timeline p { margin: 2px 0 0; font-size: 15px; }

.laws { margin: 10px 0 0; padding-left: 18px; }
.laws li { margin: 6px 0; }

.rules {
  width: 100%;
  margin: 10px 0 0;
  border-collapse: collapse;
  font-size: 14px;
}

.rules th, .rules td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.rules th { color: var(--muted); font-weight: 700; font-size: 12.5px; }
.rules td:last-child { white-space: nowrap; }
.rules tr > td:first-child + td:last-child { text-align: right; font-weight: 700; color: var(--gold); }
.chapter-body .note { margin-top: 8px; color: var(--muted); font-size: 13.5px; }

.closing {
  margin-top: 22px !important;
  color: var(--gold);
  font-family: var(--serif);
  font-weight: 800;
  font-size: 19px;
  line-height: 1.7;
}

/* ── 타일(인물 얼굴 · 장소) ───────────── */

/* 줄에 남는 타일(5 = 3+2)은 가운데로 모은다 */
.tiles {
  --cols: 3;
  --gap: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.tiles li { width: calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols)); }

.tiles a {
  display: block;
  height: 100%;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.tiles a:active { border-color: var(--gold-dim); }
.tiles img { width: 100%; object-fit: cover; }

.tiles b {
  display: block;
  padding: 7px 10px 0;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.3;
}

.tiles span {
  display: block;
  padding: 1px 10px 9px;
  color: var(--faction, var(--muted));
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
}

.faces a { border-top: 2px solid var(--faction); }
.faces img { aspect-ratio: 4 / 5; }

@media (min-width: 640px) {
  .faces { --cols: 5; }
}

.places { --cols: 2; }
.places img { aspect-ratio: 16 / 9; }

@media (min-width: 760px) {
  .places { --cols: 3; }
}

/* ── 등장인물 ─────────────────────────── */

.faction { margin: 26px 0 0; }

.banner {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.banner img { width: 100%; height: 124px; object-fit: cover; object-position: 50% 35%; }

@media (min-width: 640px) {
  .banner img { height: 180px; }
}

.banner div {
  position: absolute;
  inset: auto 0 0 0;
  padding: 30px 14px 10px;
  background: linear-gradient(transparent, rgba(8, 6, 5, 0.94));
}

.banner h2 { margin: 0; color: var(--faction); font-size: 26px; }
.banner p { margin: 0; font-size: 13px; line-height: 1.5; }

/* ── 지역 ─────────────────────────────── */

.map {
  position: relative;
  margin-top: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.map img { width: 100%; }

.pin {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  padding: 4px 7px;
  background: rgba(10, 8, 7, 0.78);
  border: 1px solid var(--faction, var(--gold));
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
}

@media (min-width: 640px) {
  .pin { padding: 6px 11px; font-size: 14px; }
}

.map-more { margin: 8px 0 0; font-size: 13.5px; text-align: right; }

.group { margin: 26px 0 0; font-size: 22px; }
.group-note { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; }

/* ── 창(인물·장소 상세) ───────────────── */

.sheet {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 0;
  color: var(--text);
}

.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: rgba(0, 0, 0, 0.75); }

@media (min-width: 760px) {
  .sheet {
    width: min(720px, calc(100% - 48px));
    height: auto;
    max-height: calc(100dvh - 64px);
    margin: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
  }
}

.sheet-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: calc(env(safe-area-inset-top, 0px) + 4px) 6px 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.sheet-title {
  flex: 1;
  padding-left: 6px;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 17px;
}

.sheet-bar button {
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* 닫기는 왼쪽, 엄지가 바로 찾게 크게 */
.sheet-bar .sheet-close {
  width: 52px;
  height: 52px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  font-size: 26px;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.detail > img { width: 100%; }
.detail-body { padding: 16px 18px 30px; }

.epithet {
  margin: 0;
  color: var(--faction, var(--gold));
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.detail h3 { margin: 2px 0 0; font-size: 30px; }
.detail h3 small { margin-left: 6px; color: var(--muted); font-family: var(--sans); font-weight: 400; font-size: 14px; }
.detail .power { margin: 0; color: var(--muted); font-size: 14px; }
.detail-body > p { margin: 12px 0 0; }

.pair {
  margin-top: 18px !important;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.pair a { margin-left: 4px; font-weight: 700; text-decoration: none; }

/* 인물 시트 — 사실 칸 · 말투 견본 · 관계 */

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 14px;
  margin: 18px 0 0;
  font-size: 14.5px;
  line-height: 1.7;
}

.facts dt { color: var(--muted); font-weight: 700; font-size: 13px; padding-top: 2px; }
.facts dd { margin: 0; }

.voice { margin: 0 0 8px !important; color: var(--muted); font-size: 14px; }

.lines { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }

.lines li {
  padding: 9px 12px;
  background: var(--surface-2);
  border-left: 3px solid var(--faction, var(--gold));
  border-radius: 0 8px 8px 0;
  font-family: var(--serif);
  font-weight: 800;
  font-size: 15.5px;
  line-height: 1.6;
}

.lines span { display: block; margin-bottom: 2px; color: var(--muted); font-family: var(--sans); font-weight: 700; font-size: 12px; }

.ties { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 14.5px; line-height: 1.7; }
.ties b { color: var(--faction, var(--gold)); }

.detail h4 {
  margin: 22px 0 10px;
  color: var(--muted);
  font-family: var(--sans);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.mobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mobs li {
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mobs img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.mobs div { padding: 8px 10px 12px; font-size: 13.5px; line-height: 1.6; }
.mobs b { display: block; font-size: 15px; }

.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border: 1px solid var(--demon);
  border-radius: 4px;
  color: var(--demon);
  font-style: normal;
  font-size: 11px;
  vertical-align: 2px;
}

.side {
  margin: 14px 0 8px !important;
  color: var(--faction);
  font-weight: 700;
  font-size: 14px;
}

.relic {
  margin-top: 22px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(202, 168, 102, 0.1), transparent);
  border: 1px solid var(--gold-dim);
  border-radius: 10px;
}

.relic-tag { margin: 0; color: var(--gold); font-weight: 700; font-size: 13px; letter-spacing: 0.08em; }
.relic h4 { margin: 2px 0 8px; color: var(--text); font-family: var(--serif); font-weight: 800; font-size: 20px; letter-spacing: 0; }
.relic p { margin: 0 0 6px; }
.relic .use { color: var(--muted); font-size: 14px; }

/* 인물 창의 스틸컷 갤러리 + 확대 보기 */

.stills ul {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 560px) {
  .stills ul { grid-template-columns: repeat(4, 1fr); }
}

.stills button {
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stills img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.stills span { display: block; padding: 3px 7px 5px; font-size: 12px; line-height: 1.4; }

.zoom {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 12px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: rgba(0, 0, 0, 0.94);
}

.zoom img { max-width: 100%; max-height: calc(100% - 48px); width: auto; height: auto; border-radius: 8px; }
.zoom-cap { margin: 0; color: var(--text); font-size: 14px; }

footer {
  padding: 28px 16px calc(env(safe-area-inset-bottom, 0px) + 28px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
