:root {
  color-scheme: dark;
  --page: #10151e;
  --panel: #18212e;
  --ink: #f2efe7;
  --muted: #b2bac5;
  --gold: #d6bd87;
  --line: #414854;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
  background: var(--page);
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; }
button { font: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
button:focus-visible, [role="button"]:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 5px;
}
.novel { width: min(1100px, 100%); margin: 0 auto; padding: 28px 32px 24px; }
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.eyebrow { color: var(--gold); font-size: 11px; letter-spacing: .22em; margin: 0 0 10px; }
h1 { font-size: clamp(20px, 3vw, 30px); font-weight: 500; letter-spacing: .12em; margin: 0; }
.edition { color: var(--muted); font-size: 12px; white-space: nowrap; letter-spacing: .12em; }
.stage.home-art { height: clamp(220px, 32vh, 310px); border-bottom: 1px solid var(--line); }
.home-art .characters { inset-block-start: 48px; }
.episode-intro { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px 24px; margin: 27px 0 18px; }
.episode-intro h2 { color: var(--gold); font-size: 17px; font-weight: 500; letter-spacing: .12em; margin: 0; }
.episode-intro p { color: var(--muted); font-size: 13px; line-height: 1.8; margin: 0; }
.episode-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.episode-card { width: 100%; display: flex; align-items: center; gap: 22px; text-align: left; padding: 20px 24px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); font: inherit; }
button.episode-card { cursor: pointer; }
button.episode-card:hover { border-color: var(--gold); background: #222d3c; }
.episode-number { color: var(--gold); font-size: 24px; letter-spacing: .08em; }
.episode-copy { flex: 1; min-width: 0; }
.episode-title { display: block; font-size: 18px; font-weight: 500; letter-spacing: .06em; overflow-wrap: anywhere; }
.episode-description { display: block; color: var(--muted); font-size: 12px; line-height: 1.7; margin-top: 7px; }
.episode-action { color: var(--gold); font-size: 13px; white-space: nowrap; }
.episode-card.is-unavailable { opacity: .6; }
.save-menu { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.save-menu .primary-button { margin-left: 0; }
#save-status { flex: 1 1 240px; margin: 0; color: var(--muted); font: 12px/1.7 "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif; overflow-wrap: anywhere; }
#save-status.save-warning { color: var(--gold); }
.stage {
  position: relative;
  height: clamp(270px, 43vh, 440px);
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: linear-gradient(130deg, #343b44, #232d3a 50%, #121e2e);
}
.stage[data-background^="castle_corridor"] {
  background: linear-gradient(110deg, #26394b, #27313e 48%, #424148);
}
.background-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -1; }
.scene-heading { position: absolute; top: 22px; left: 28px; z-index: 2; padding: 10px 15px; border-left: 2px solid var(--gold); background: #111b29d9; }
.scene-heading p { margin: 0 0 6px; color: #c5cbd4; font-size: 11px; letter-spacing: .12em; }
.scene-heading h2 { font-size: 16px; font-weight: 500; margin: 0; letter-spacing: .1em; }
.stage-note { position: absolute; bottom: 14px; right: 18px; margin: 0; color: #c6cbd2; font-size: 10px; letter-spacing: .12em; background: #17202ad9; padding: 4px 8px; }
.characters { position: absolute; inset: 96px 8% 0; display: flex; justify-content: center; align-items: end; gap: clamp(22px, 8vw, 100px); }
.character { position: relative; width: min(44%, 320px); height: 100%; max-height: 300px; margin: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.character-placeholder { position: absolute; inset: 15px 0 0; display: flex; align-items: center; justify-content: center; flex-direction: column; border: 1px solid #a8b0bc45; border-bottom: 0; background: linear-gradient(#8f99a615, #101a2c85); }
.character-placeholder::before { content: ""; width: 48px; height: 48px; border: 1px solid #a8b0bc70; border-radius: 50%; margin-bottom: 8px; }
.character-placeholder::after { content: ""; width: 90px; height: 70px; border: 1px solid #a8b0bc70; border-bottom: 0; border-radius: 50px 50px 0 0; }
/* 원본의 위쪽 약 54%만 노출해 모자부터 허리까지 표시한다. */
.character img { position: absolute; top: 0; left: 50%; width: auto; height: 185%; max-width: none; transform: translateX(-50%); }
/* 원래 크기를 유지하고 선배 그림만 30px 위로 이동한다. 이름표와 좌우·하단 잘림은 유지한다. */
.character[data-character="senpai"] { overflow: visible; clip-path: inset(-30px 0 0); }
.character[data-character="senpai"] img { top: -30px; }
/* 젤다는 링크보다 아담하게 보이도록 약 8% 줄이고 살짝 아래에 배치한다. */
.character[data-character^="zelda_"] img { height: 170%; top: 6%; }
.character figcaption { position: absolute; bottom: 25px; z-index: 1; background: #152032ef; color: #cbd1d9; border: 1px solid #5d6876; padding: 7px 20px; white-space: nowrap; font-size: 14px; letter-spacing: .15em; }
.character.is-speaking figcaption { border-color: var(--gold); color: var(--gold); }
.character.is-speaking .character-placeholder { border-color: #d6bd8780; }
.reading-area { background: var(--panel); border: 1px solid var(--line); border-top: 2px solid #9a8662; padding: 27px 34px 20px; }
.dialogue { min-height: 154px; cursor: pointer; }
.dialogue.is-waiting { cursor: default; }
.speaker-line { display: flex; align-items: center; gap: 10px; margin-bottom: 15px; }
.speaker-mark { color: var(--gold); font-size: 8px; }
#speaker { margin: 0; font-size: 15px; color: var(--gold); font-weight: 500; letter-spacing: .13em; }
#text { margin: 0; font-size: 18px; line-height: 1.95; letter-spacing: .035em; white-space: pre-wrap; overflow-wrap: anywhere; line-break: strict; }
.dialogue.is-thought #text { color: #d9e0eb; }
.choices { display: grid; gap: 12px; margin: 20px 0 22px; }
.choices button { border: 1px solid #9a8662; background: #222d3c; color: var(--ink); padding: 15px 20px; text-align: left; font-size: 16px; line-height: 1.6; cursor: pointer; }
.choices button::before { content: "◇"; color: var(--gold); margin-right: 14px; }
.choices button:hover { background: #303d4f; border-color: var(--gold); }
.reading-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); padding-top: 17px; margin-top: 18px; }
.reading-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.review-notice { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 16px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.review-notice p { color: var(--gold); font-size: 13px; margin: 0; }
#controls-help { color: var(--muted); font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif; font-size: 11px; line-height: 1.7; margin: 0; }
.primary-button { flex-shrink: 0; min-height: 44px; min-width: 118px; padding: 10px 20px; border: 1px solid #9a8662; background: transparent; color: var(--gold); cursor: pointer; font-size: 15px; letter-spacing: .1em; }
.primary-button span { margin-left: 16px; }
.primary-button:hover { background: #293444; }
.primary-button:disabled { opacity: .4; cursor: default; }
.primary-button:disabled:hover { background: transparent; }
body.history-open { overflow: hidden; }
.history-dialog { width: min(720px, calc(100% - 32px)); max-height: 85vh; padding: 24px; border: 1px solid var(--gold); background: var(--panel); color: var(--ink); }
.history-dialog[open] { display: flex; flex-direction: column; gap: 16px; }
.history-dialog::backdrop { background: #080d16cf; }
.history-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.history-header h2 { margin: 0; color: var(--gold); font-size: 20px; font-weight: 500; letter-spacing: .1em; }
#history-description { color: var(--muted); font-size: 12px; line-height: 1.8; margin: 0; }
.history-entries { min-height: 0; max-height: 55vh; overflow-y: auto; overscroll-behavior: contain; list-style: none; padding: 0 12px 0 0; margin: 0; }
.history-entries li { padding: 18px 0; border-bottom: 1px solid var(--line); }
.history-entries li:last-child { border-bottom: 0; }
.history-scene { font-size: 14px; font-weight: 500; color: var(--gold); margin: 0 0 20px; }
.history-speaker { color: var(--gold); font-size: 13px; margin: 0 0 8px; }
.history-text { font-size: 16px; line-height: 1.95; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.history-choice { color: var(--gold); font-size: 13px; line-height: 1.8; margin: 12px 0 0; overflow-wrap: anywhere; }
.ending { text-align: center; padding: 8px 0; }
.ending p { color: var(--gold); font-size: 24px; letter-spacing: .4em; margin: 12px 0; }
noscript { display: block; padding: 20px; color: var(--gold); }
.loading-screen { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px; background: var(--page); }
.loading-card { width: min(440px, 100%); padding: 32px; border: 1px solid var(--gold); background: var(--panel); text-align: center; }
.loading-card h2 { margin: 20px 0; color: var(--gold); font-size: 20px; font-weight: 500; line-height: 1.8; }
.loading-card p { font-size: 13px; line-height: 1.8; }
.loading-card progress { display: block; width: 100%; height: 12px; accent-color: var(--gold); }
#loading-count { color: var(--gold); font-variant-numeric: tabular-nums; }
#loading-error, .image-status { color: var(--gold); font: 12px/1.8 sans-serif; }
.image-status { margin: 0 0 14px; }

@media (min-width: 601px) and (max-height: 780px) {
  .novel { padding: 18px 28px; }
  .masthead { margin-bottom: 16px; }
  .stage { height: clamp(180px, 32vh, 270px); }
  .characters { inset-block-start: 85px; }
  .character-placeholder::before { width: 30px; height: 30px; }
  .character-placeholder::after { height: 45px; width: 65px; }
  .character figcaption { bottom: 14px; padding: 5px 15px; }
  .dialogue { min-height: 126px; }
  .reading-area { padding: 20px 28px 16px; }
  .reading-footer { margin-top: 12px; padding-top: 12px; }
}

@media (max-width: 600px) {
  .episode-card { gap: 12px; padding: 17px 14px; flex-wrap: wrap; }
  .episode-number { font-size: 20px; }
  .episode-title { font-size: 15px; }
  .episode-description { font-size: 11px; }
  .episode-action { font-size: 11px; }
  .episode-intro { margin-top: 22px; }
  .novel { padding: 19px 14px; }
  .masthead { align-items: start; gap: 10px; margin-bottom: 18px; }
  h1 { font-size: 19px; line-height: 1.6; letter-spacing: .06em; }
  .eyebrow { font-size: 9px; letter-spacing: .12em; }
  .edition { font-size: 10px; writing-mode: vertical-rl; margin: 0; }
  .stage { height: 260px; }
  .scene-heading { top: 16px; left: 16px; padding: 8px 12px; }
  .scene-heading h2 { font-size: 14px; }
  .characters { inset: 90px 6% 0; gap: 16px; }
  .character { width: calc((100% - 16px) / 2); }
  .character-placeholder::before { width: 34px; height: 34px; }
  .character-placeholder::after { width: 65px; height: 48px; }
  .character figcaption { bottom: 32px; padding: 5px 12px; font-size: 12px; }
  .stage-note { bottom: 7px; right: 9px; font-size: 9px; }
  .reading-area { padding: 22px 20px 16px; }
  .dialogue { min-height: 165px; }
  #text { font-size: 16px; line-height: 1.95; }
  #speaker { font-size: 13px; }
  .reading-footer { flex-wrap: wrap; gap: 12px; }
  .reading-actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading-actions .primary-button { min-width: 0; margin-left: 0; padding-inline: 10px; }
  .history-dialog { padding: 18px; }
  .history-header h2 { font-size: 17px; }
  .history-header .primary-button { margin-left: 0; }
  .history-text { font-size: 15px; }
  #controls-help { flex: 1 1 150px; font-size: 10px; }
  .primary-button { margin-left: auto; min-width: 104px; }
  .choices button { font-size: 14px; padding: 13px 14px; }
}
