:root {
  --ink: #080b0b;
  --surface: rgba(15, 18, 18, 0.88);
  --paper: #e9e0d0;
  --muted: #aaa79f;
  --line: rgba(233, 224, 208, 0.19);
  --cinnabar: #bd3229;
  --cinnabar-bright: #e54b3f;
  --jade: #9cb7a8;
  font-family: "Manrope", system-ui, sans-serif;
  color: var(--paper);
  background: var(--ink);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 72% 8%, rgba(218, 214, 196, .11) 0 7%, transparent 17%),
    linear-gradient(155deg, transparent 0 47%, rgba(143, 38, 32, .1) 48%, transparent 56%),
    linear-gradient(180deg, #0c1112 0%, #070909 66%, #0d1010 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .23;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.78' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 620px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.screen { display: none; min-height: calc(100dvh - 48px); }
.screen.is-active { display: flex; animation: screen-in .5s cubic-bezier(.2,.8,.2,1) both; }

.start-screen, .result-screen { flex-direction: column; justify-content: center; align-items: flex-start; }
.start-screen { justify-content: flex-start; padding-top: clamp(22px, 5vh, 48px); }
.start-screen::after {
  content: "山";
  position: fixed;
  right: -20px;
  bottom: -90px;
  z-index: -1;
  color: rgba(233, 224, 208, .025);
  font: 700 340px/1 "PT Serif", serif;
}
.cover-backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(180deg, rgba(6, 10, 12, .52) 0%, rgba(6, 9, 10, .92) 62%, #080b0b 100%),
    url("assets/demonology-cover.jpg") center top / cover no-repeat;
  opacity: .64;
}

.seal {
  display: grid;
  width: 62px;
  height: 72px;
  place-items: center;
  margin-bottom: 28px;
  border: 2px solid var(--cinnabar);
  color: var(--cinnabar-bright);
  font: 700 31px/1 "PT Serif", serif;
  box-shadow: inset 0 0 0 4px var(--ink), inset 0 0 0 5px rgba(189, 50, 41, .55), 0 0 35px rgba(189, 50, 41, .12);
  transform: rotate(-2deg);
  animation: seal-pulse 3s ease-in-out infinite;
}

.overline { margin: 0 0 13px; color: var(--cinnabar-bright); font-size: 12px; font-weight: 700; letter-spacing: .17em; text-transform: uppercase; }
h1, h2 { font-family: "PT Serif", Georgia, serif; }
h1 { margin: 0; max-width: 540px; font-size: clamp(43px, 12vw, 69px); line-height: .98; letter-spacing: -.035em; }
.book-visual {
  position: relative;
  width: min(62vw, 255px);
  aspect-ratio: 819 / 1054;
  margin: 28px auto 22px;
  border: 1px solid rgba(233, 224, 208, .3);
  border-radius: 3px 9px 9px 3px;
  background: #151819;
  box-shadow: -10px 13px 0 #080909, -12px 15px 0 rgba(229, 75, 63, .35), 0 28px 60px rgba(0,0,0,.5);
  transform: perspective(900px) rotateY(-5deg) rotateX(1deg);
  overflow: hidden;
}
.book-visual::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 5%; background: linear-gradient(90deg, rgba(0,0,0,.7), rgba(255,255,255,.08), transparent); }
.book-visual img { display: block; width: 100%; height: 100%; object-fit: cover; }
.source-copy { max-width: 520px; margin: 0 0 24px; color: #cbc5ba; font: 400 14px/1.55 "PT Serif", serif; }
.source-copy strong, .source-copy span { display: block; }
.source-copy strong { margin-top: 3px; color: var(--paper); }
.source-copy span { margin-top: 12px; color: var(--muted); font-family: "Manrope", system-ui, sans-serif; font-size: 12px; }
.source-copy a { color: inherit; text-decoration-color: rgba(229, 75, 63, .7); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.source-copy a:focus-visible { outline: 2px solid var(--cinnabar-bright); outline-offset: 3px; border-radius: 2px; }
.fine-print { align-self: center; margin: 16px 12px 0; color: #8a8b85; font-size: 11px; line-height: 1.5; text-align: center; }
.mode-list { display: grid; width: 100%; gap: 10px; }
.mode-button {
  display: flex;
  width: 100%;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--paper);
  background: rgba(13, 17, 17, .74);
  text-align: left;
  cursor: pointer;
  transition: transform .2s ease, border-color .2s ease, background .2s ease;
}
.mode-button strong, .mode-button small { display: block; }
.mode-button strong { font: 700 17px/1.3 "PT Serif", serif; }
.mode-button small { margin-top: 5px; color: var(--muted); font-size: 11px; }
.mode-button > span:last-child { color: var(--cinnabar-bright); font-size: 22px; }
.mode-button:active { transform: scale(.985); }
.mode-button-exam { border-color: rgba(229, 75, 63, .62); background: linear-gradient(115deg, rgba(104,24,20,.58), rgba(32,20,19,.72)); }

button { font: inherit; }
.primary-button {
  display: flex;
  width: 100%;
  min-height: 62px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 22px;
  border: 1px solid #ec4a3e;
  border-radius: 4px;
  color: #fff1e6;
  background: linear-gradient(115deg, #8f1d18, #bd3329 62%, #751713);
  box-shadow: 0 12px 32px rgba(116, 20, 16, .25), inset 0 1px rgba(255,255,255,.12);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s ease, filter .2s ease, opacity .2s ease;
}
.primary-button:active { transform: scale(.985); filter: brightness(1.12); }
.primary-button:disabled { cursor: default; opacity: .35; filter: grayscale(.5); }

.quiz-screen { flex-direction: column; }
.quiz-header { display: grid; grid-template-columns: 44px 1fr 84px; align-items: center; min-height: 44px; }
.icon-button { width: 40px; height: 40px; border: 0; color: var(--muted); background: transparent; font-size: 29px; cursor: pointer; }
.progress-copy { font-family: "PT Serif", serif; text-align: center; letter-spacing: .08em; }
.score-live { color: var(--muted); font-size: 11px; text-align: right; }
.progress-track { height: 2px; margin-top: 10px; overflow: hidden; background: var(--line); }
.progress-bar { width: 0; height: 100%; background: var(--cinnabar-bright); box-shadow: 0 0 12px var(--cinnabar); transition: width .45s ease; }
.question-stage { flex: 1; padding: clamp(29px, 7vh, 60px) 0 25px; }
.question-stage.leaving { animation: question-out .2s ease both; }
.question-stage.entering { animation: question-in .38s ease both; }
.question-stage h2 { margin: 0 0 28px; font-size: clamp(24px, 6.4vw, 34px); line-height: 1.28; letter-spacing: -.017em; }
.answers { display: grid; gap: 10px; }
.answer {
  display: grid;
  grid-template-columns: 42px 1fr;
  min-height: 64px;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--paper);
  background: rgba(12, 15, 15, .66);
  text-align: left;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.answer:active { transform: scale(.99); }
.answer-letter { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid rgba(233,224,208,.32); border-radius: 50%; font-family: "PT Serif", serif; }
.answer-text { font-size: 14px; line-height: 1.45; }
.answer.selected { border-color: var(--cinnabar-bright); background: rgba(136, 30, 25, .18); }
.answer.selected .answer-letter { border-color: var(--cinnabar-bright); color: #ff9b8e; box-shadow: 0 0 18px rgba(229,75,63,.16); }
.answer.correct { border-color: var(--jade); background: rgba(79, 117, 96, .17); }
.answer.wrong { border-color: var(--cinnabar-bright); background: rgba(142, 32, 26, .22); }
.answer:disabled { cursor: default; }

.comment-box { display: none; margin-top: 16px; border: 1px solid var(--line); border-radius: 4px; background: rgba(12, 15, 15, .62); }
.comment-box.has-comment { display: block; }
.comment-box summary { display: flex; min-height: 50px; align-items: center; justify-content: space-between; padding: 0 16px; color: var(--muted); font-size: 13px; cursor: pointer; list-style: none; }
.comment-box summary::-webkit-details-marker { display: none; }
.comment-box[open] summary span { transform: rotate(180deg); }
.comment-box p { margin: 0; padding: 0 16px 16px; color: var(--paper); font: 400 14px/1.55 "PT Serif", serif; }
.next-button { flex: none; }

.result-screen { align-items: center; text-align: center; }
.result-seal { margin-inline: auto; }
.result-screen h2 { margin: 0; font-size: clamp(38px, 11vw, 58px); }
.result-score { display: flex; flex-direction: column; margin: 20px 0; }
.result-score strong { color: var(--cinnabar-bright); font: 700 clamp(64px, 19vw, 96px)/1 "PT Serif", serif; }
.result-score span { margin-top: 6px; color: var(--muted); font-size: 13px; }
.result-message { max-width: 510px; min-height: 96px; margin: 2px 0 32px; font: 400 17px/1.6 "PT Serif", serif; }

.mist { position: fixed; z-index: 0; width: 130vw; height: 32vh; border-radius: 50%; background: rgba(164, 178, 169, .045); filter: blur(38px); pointer-events: none; }
.mist-one { top: 16%; left: -60%; animation: drift 18s ease-in-out infinite alternate; }
.mist-two { right: -75%; bottom: 5%; animation: drift 23s ease-in-out infinite alternate-reverse; }

@keyframes screen-in { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }
@keyframes question-in { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes question-out { to { opacity: 0; transform: translateX(-12px); } }
@keyframes seal-pulse { 50% { box-shadow: inset 0 0 0 4px var(--ink), inset 0 0 0 5px rgba(189,50,41,.7), 0 0 38px rgba(189,50,41,.25); } }
@keyframes drift { to { transform: translateX(42vw) scale(1.18); } }

@media (min-width: 700px) {
  .app-shell { padding-inline: 36px; }
  .answer-text { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
