/* ───────────────────────────────────────────
   소설역(小說驛) — 일상에서 소설 세계로 환승하는 정거장
   먹빛 어둠 + 촛불 호박색 + 한지 종이색
   ─────────────────────────────────────────── */

:root {
  --bg: #0e1116;
  --bg-2: #141923;
  --raised: #1a2029;
  --line: #29313e;
  --paper: #ece4d4;
  --paper-dim: #b3aa96;
  --faint: #756e5d;
  --amber: #e8a948;
  --amber-soft: #f3c578;
  --amber-dim: rgba(232, 169, 72, 0.16);
  --stamp: #c0504a;
  --serif: "Gowun Batang", "Nanum Myeongjo", serif;
  --sans: "Gowun Dodum", "Malgun Gothic", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 보기(외형) 설정 — 본문(.page)·미리보기가 소비하고, 읽기 모드에선 #player-screen 배경·
     상단 바·#p-counter(쪽번호)까지 소비해 화면 전체가 책 한 장이 된다(사용자 결정).
     기본값 = 현재 디자인 그대로. app.js(applyAppearance)가 사용자 설정으로 덮어쓴다.
     책장·dock·시트 패널·듣기 모드는 미소비 → 다크 유지. */
  --reader-font: var(--serif);
  --reader-size: 18.5px;
  --reader-bg: linear-gradient(165deg, rgba(236, 228, 212, .055), rgba(236, 228, 212, .02));
  --reader-fg: var(--paper);
  --reader-fg-dim: var(--paper-dim);
  --reader-hl: var(--amber-dim);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--paper);
  background:
    radial-gradient(120% 50% at 50% -8%, #1d2535 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 46%);
  background-attachment: fixed;
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior-y: contain; /* 읽기 모드 스와이프 중 당겨서-새로고침 오발동 방지 */
}

/* 한지 결 — 미세한 노이즈 */
.noise {
  position: fixed; inset: 0; z-index: 40;
  pointer-events: none; opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

button { font-family: inherit; color: inherit; cursor: pointer; }

.ghost-btn {
  position: relative; /* .alert 배지 점의 기준 */
  background: none; border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px;
  font-size: 13px; color: var(--paper-dim);
  transition: color .2s, border-color .2s, background .2s;
}
/* 사용량 경고 배지 — 설정 시트를 열 때까지 점 표시 */
.ghost-btn.alert::after {
  content: ""; position: absolute; top: 2px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--stamp);
  box-shadow: 0 0 5px rgba(192, 80, 74, .8);
}
.ghost-btn:active { color: var(--amber); border-color: var(--amber); background: var(--amber-dim); }
.ghost-btn.on { color: var(--amber); border-color: var(--amber); }

.danger-btn {
  background: var(--stamp); border: none; border-radius: 999px;
  padding: 10px 22px; font-size: 14px; color: #fff;
}

/* ───────── 책장 화면 ───────── */

#shelf-screen {
  max-width: 560px; margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 18px calc(48px + var(--safe-bottom));
}

.shelf-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}

.brand { display: flex; align-items: center; gap: 12px; }

/* 낙관(落款) 도장 */
.stamp {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  background: linear-gradient(150deg, #d05c52, var(--stamp));
  color: #f6ede0; font-family: var(--serif); font-weight: 700; font-size: 22px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(246, 237, 224, .55), inset 0 0 0 4px var(--stamp),
              0 4px 14px rgba(192, 80, 74, .25);
  transform: rotate(-3deg);
}

.brand-text h1 {
  margin: 0; font-family: var(--serif); font-weight: 700;
  font-size: 24px; letter-spacing: 6px; line-height: 1.1;
}
.brand-text p {
  margin: 2px 0 0; font-size: 11px; letter-spacing: 3px; color: var(--faint);
}

.shelf-hint {
  margin: 18px 2px 26px; font-size: 13px; color: var(--faint);
  border-left: 2px solid var(--amber); padding-left: 10px;
}

/* 책장: 줄(선반) 단위 */
.shelf-row {
  display: flex; gap: 13px; align-items: flex-end;
  padding: 0 6px 0;
  position: relative;
  margin-bottom: 34px;
}
.shelf-row::after {
  /* 나무 선반 */
  content: ""; position: absolute; left: -8px; right: -8px; bottom: -12px;
  height: 12px; border-radius: 2px;
  background: linear-gradient(180deg, #33291c 0%, #1f1812 55%, #120e0a 100%);
  box-shadow: 0 10px 18px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(236, 228, 212, .07);
}

/* 책등 */
.spine {
  position: relative;
  width: 74px; height: var(--h, 190px);
  border: none; border-radius: 3px 6px 6px 3px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.38) 0%, rgba(255,255,255,.09) 7%,
      rgba(255,255,255,0) 22%, rgba(0,0,0,.18) 92%, rgba(0,0,0,.42) 100%),
    var(--c, #2e4057);
  box-shadow: 0 7px 14px rgba(0, 0, 0, .45);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0 10px;
  opacity: 0;
  animation: rise .5s cubic-bezier(.2, .7, .3, 1) forwards;
  animation-delay: calc(var(--i, 0) * 60ms);
  transition: transform .18s ease;
  /* 길게 누르기(삭제)의 전제 — 빼면 모바일 길게 누르기가 텍스트 선택/콜아웃에 먹힌다 */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.spine:active { transform: translateY(-6px); }

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.s-title {
  writing-mode: vertical-rl;
  font-family: var(--serif); font-weight: 700;
  font-size: 15px; letter-spacing: 2px;
  line-height: 1.45;
  color: rgba(246, 240, 228, .92);
  max-height: calc(var(--h, 190px) - 64px);
  max-width: 46px; /* 긴 제목은 둘째 세로줄로 — 그보다 길면 뒷부분 생략 */
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .4);
}

/* 진행도: 책등 왼쪽의 호박색 가름끈 */
.s-band {
  position: absolute; left: 7px; bottom: 8px;
  width: 3px; height: calc((var(--h, 190px) - 50px) * var(--p, 0) / 100);
  background: linear-gradient(180deg, var(--amber-soft), var(--amber));
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(232, 169, 72, .5);
}

.s-percent {
  position: absolute; bottom: 9px; right: 8px;
  font-size: 10px; color: rgba(246, 240, 228, .75);
  letter-spacing: .5px;
}

/* 책 추가 슬롯 */
.spine.add {
  background: none;
  border: 1.5px dashed var(--line);
  box-shadow: none;
  color: var(--faint);
  justify-content: center; gap: 10px;
  animation-name: rise;
}
.spine.add .plus { font-size: 26px; line-height: 1; color: var(--amber); }
.spine.add .add-label {
  writing-mode: vertical-rl; letter-spacing: 4px; font-size: 13px;
}
.spine.add:active { border-color: var(--amber); }

.shelf-empty {
  text-align: center; color: var(--faint); font-size: 14px;
  padding: 30px 0 10px; line-height: 2;
}

/* ───────── 플레이어 화면 ───────── */

#player-screen {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 18px calc(14px + var(--safe-bottom));
  background:
    radial-gradient(130% 46% at 50% -6%, #232c3e 0%, transparent 62%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 50%);
  animation: slide-up .32s cubic-bezier(.2, .7, .3, 1);
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 초슬림 한 줄 바 — 본문을 가리지 않게 작고 흐릿한 "투명 아이콘"들 */
.player-head {
  display: flex; align-items: center; gap: 6px;
  min-height: 34px;
  margin-bottom: 4px;
}
.player-head .ghost-btn {
  border-color: transparent;
  padding: 5px 9px; font-size: 13px;
}
.head-actions { display: flex; gap: 8px; }
.player-head .head-actions { gap: 2px; }

.player-body {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}

/* 면주(상단 제목) — 작고 흐릿하게, 길면 말줄임 */
#p-title {
  flex: 1; min-width: 0; margin: 0;
  text-align: center;
  font-family: var(--serif); font-weight: 700; font-size: 13.5px;
  letter-spacing: .5px;
  color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* 쪽번호 풍 진행률 — 본문 아래 중앙 */
#p-counter {
  margin: 8px 0 2px; text-align: center;
  font-size: 11px; color: var(--faint); letter-spacing: 1px;
}

/* 지금 읽는 페이지 — 글꼴·크기·색은 --reader-* 변수(보기 설정)를 따른다 */
.page {
  flex: 1; min-height: 0; overflow-y: auto;
  background: var(--reader-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 20px 26px;
  font-family: var(--reader-font);
  font-size: var(--reader-size); line-height: 2.02; letter-spacing: .2px;
  color: var(--reader-fg);
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  position: relative;
}
/* 문단: 지금 읽는 문단만 호박색 배경으로 밝힌다 (재생 위치 동기화) */
.page p {
  margin: 0 -8px 1.1em;
  padding: 2px 8px;
  border-radius: 8px;
  color: var(--reader-fg-dim);
  transition: background .35s ease, color .35s ease;
}
.page p:last-child { margin-bottom: 0; }
.page p.reading {
  background: var(--reader-hl);
  color: var(--reader-fg);
}

/* ───────── 읽기 모드 ─────────
   #r-view(.page)에 다단(column) 레이아웃으로 글을 흘려 한 컬럼 = 한 화면.
   크기·컬럼 폭은 app.js가 인라인으로 설정하고, transform으로 화면을 넘긴다. */

#r-view {
  display: none;
  overflow: hidden;          /* .page의 overflow-y:auto 대체 — 컬럼이 옆으로 흐른다 */
  touch-action: pan-y;       /* 가로 제스처는 JS가 처리 */
  user-select: none;         /* 길게 눌러 텍스트 선택이 스와이프를 가로채지 않게 */
  -webkit-user-select: none;
}
#player-screen.mode-read #p-text      { display: none; }
#player-screen.mode-read .player-dock { display: none; }
#player-screen.mode-read #r-view      { display: block; }

/* 읽기 모드 = 화면 전체가 책 한 장 — 배경·상단 바·쪽번호까지 --reader-* 를 따른다.
   배경은 기존 다크 그라데이션을 "교체"하지 않고 그 위에 한 겹 얹는다(::before, z -1) —
   기본 프리셋의 --reader-bg는 거의 투명이라 교체하면 뒤의 책장 화면이 비쳐 보인다. */
#player-screen.mode-read::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: var(--reader-bg);
}
#player-screen.mode-read .player-head .ghost-btn,
#player-screen.mode-read #p-title,
#player-screen.mode-read #p-counter { color: var(--reader-fg-dim); }
#player-screen.mode-read #r-view {
  background: none;          /* 화면 배경과 이중 적용 방지 */
  border: none; border-radius: 0;
  padding: 10px 0 6px;       /* 좌우 0 — 화면 padding 18px가 곧 책 여백 */
}

#r-flow {
  position: relative;        /* 문단 offsetLeft의 기준점 */
  column-fill: auto;         /* 필수 — 기본 balance면 마지막 화면들이 반쯤 빈다 */
  will-change: transform;
}
#r-flow.anim { transition: transform .26s cubic-bezier(.2, .7, .3, 1); }
/* #r-measure = 전역 화면 번호 측정용 오프스크린 박스(app.js). 같은 문단 규칙을 입어야
   측정이 본 렌더와 일치한다 — 규칙을 바꾸면 양쪽이 함께 적용된다. */
#r-flow p, #r-measure p {
  margin: 0 0 1.1em; padding: 0; border-radius: 0;
  color: var(--reader-fg);   /* 읽기 모드엔 하이라이트가 없으니 전부 본문색 */
  orphans: 1; widows: 1;     /* 기본값 2면 컬럼 바닥의 외톨이 줄을 통째로 넘겨 화면 아래가 2줄+ 빈다 */
}
/* 강제 컬럼 분리는 폐기 — 페이지는 책처럼 이어 붙는다(빈 꼬리 화면 불만, 2026-06-13 사용자
   결정). 재중심 픽셀 안정성은 app.js rebuildReadWindow의 스페이서 정렬이 담당한다. */

/* ── 책장 넘김(잎) — 종이 한 장이 책등(왼쪽 모서리)을 축으로 들려 넘어간다 ──
   .r-leaf 구조는 app.js(leafBegin)가 플립마다 만들어 #player-screen에 얹고 끝나면 지운다.
   #r-view 안이 아니라 화면 직계 자식 — 원근으로 부풀어도 본문 상자에 잘리지 않고,
   들리는 종이가 상단 바·쪽번호 위를 스치는 게 실제 책처럼 자연스럽다. */
.r-leaf {
  position: absolute;
  transform-origin: left center;     /* 책등 = 왼쪽 모서리 */
  will-change: transform;
  pointer-events: none;
  backface-visibility: hidden;       /* 90°를 넘긴 잎(다 넘어간 종이)은 화면 밖 — 그리지 않는다 */
  -webkit-backface-visibility: hidden;
}
.r-leaf .leaf-paper,
.r-leaf .leaf-tint,
.r-leaf .leaf-shade { position: absolute; inset: 0; }
/* 종이 바탕 — 화면 배경(어두운 그라데이션)을 잎 위치만큼 잘라 복제(app.js가 size/position 지정).
   잎이 0°일 때 뒤 화면과 픽셀이 일치해야 플립 시작이 번쩍이지 않는다. */
.r-leaf .leaf-paper { background-color: var(--bg); }
.r-leaf .leaf-tint  { background: var(--reader-bg); } /* 보기 설정 색 — 색이든 그라데이션이든 */
.r-leaf .leaf-shade {                /* 책등 쪽 굴곡 음영 — 들릴수록 진해진다(JS가 opacity) */
  opacity: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, .32), rgba(0, 0, 0, 0) 32%);
}
/* 잎의 글 — .page를 그대로 입어 글꼴·행간이 본문과 동일(컬럼 분리도 동일하게 떨어진다),
   상자 속성만 무력화한다. 잎 자체가 이미 본문 콘텐츠 상자 위치에 놓여 있다. */
.r-leaf .leaf-clip.page {
  position: absolute; inset: 0; overflow: hidden;
  padding: 0; background: none; border: none; border-radius: 0;
  will-change: clip-path;            /* 넘김마다 글자가 우측→좌측 깎임(JS가 clipPath) */
}
.leaf-flow { column-fill: auto; }    /* #r-flow 복제본 — 동일한 다단 규칙 */
.leaf-flow p { margin: 0 0 1.1em; padding: 0; color: var(--reader-fg); orphans: 1; widows: 1; }
/* 넘어가는 잎이 아래 페이지에 드리우는 그림자 — 중간쯤에서 가장 짙다(JS가 opacity) */
.r-undershade {
  position: absolute; opacity: 0; pointer-events: none;
  background: linear-gradient(to right, rgba(0, 0, 0, .42), rgba(0, 0, 0, 0) 36%);
}

/* ───────── 하단 조작부 ───────── */

.player-dock { padding-top: 14px; }

.progress-row { padding: 2px 4px 10px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--amber) var(--fill, 0%), var(--line) var(--fill, 0%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--amber-soft);
  border: 3px solid #3a2f17;
  margin-top: -6.5px;
  box-shadow: 0 0 8px rgba(232, 169, 72, .55);
}

.controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 6px;
}

.ctl {
  width: 50px; height: 50px; border: none; border-radius: 50%;
  background: none; color: var(--paper-dim);
  display: grid; place-items: center;
  transition: color .15s, background .15s;
}
.ctl:active { color: var(--amber); background: var(--amber-dim); }
.ctl svg { width: 26px; height: 26px; }

.play-btn {
  width: 72px; height: 72px; border: none; border-radius: 50%;
  background: radial-gradient(120% 120% at 30% 25%, var(--amber-soft), var(--amber) 58%, #c9882e);
  color: #241a07;
  display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(232, 169, 72, .3);
  transition: transform .12s ease;
}
.play-btn:active { transform: scale(.94); }
.play-btn svg { width: 34px; height: 34px; }
.play-btn.playing { animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 8px 20px rgba(232, 169, 72, .26); }
  50% { box-shadow: 0 8px 34px rgba(232, 169, 72, .5); }
}

.opts {
  display: flex; gap: 10px; justify-content: center;
  padding: 12px 0 2px;
}

.chip {
  appearance: none; -webkit-appearance: none;
  background: var(--raised); color: var(--paper-dim);
  border: 1px solid var(--line); border-radius: 999px;
  font-family: inherit; font-size: 13px;
  padding: 8px 16px;
  text-align: center;
}
.chip:focus { outline: none; border-color: var(--amber); color: var(--paper); }

/* ───────── 시트 (탐색 / 확인) ───────── */

.sheet {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(8, 10, 14, .62);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-panel {
  width: 100%; max-width: 560px; margin: 0 auto;
  max-height: 76dvh;
  background: linear-gradient(180deg, var(--raised), var(--bg-2));
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column;
  animation: sheet-up .26s cubic-bezier(.2, .7, .3, 1);
}
@keyframes sheet-up {
  from { transform: translateY(40px); opacity: .4; }
  to   { transform: translateY(0); opacity: 1; }
}

/* 탐색 시트는 높이를 고정한다 — 미리보기 글 길이에 따라 패널이 늘었다 줄었다 하면
   페이지를 바꿀 때마다 ‹ ›·슬라이더가 위아래로 출렁이기 때문 */
#toc-sheet .sheet-panel { height: 76dvh; }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 2px 4px 12px;
  border-bottom: 1px solid var(--line);
}
/* 안내문이 길어도 닫기 버튼이 짓눌려 줄바꿈되지 않게 — 문구는 줄바꿈, 버튼은 고정 폭 */
.sheet-head p { margin: 0; font-size: 13px; color: var(--amber); flex: 1; min-width: 0; }
.sheet-head .ghost-btn { flex: 0 0 auto; white-space: nowrap; }

/* 페이지 탐색: 슬라이더로 크게 훑고, ‹ › 와 번호 입력으로 미세 조정 */
.toc-nav {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 4px 4px;
  font-size: 13px;
}
.toc-nav input {
  width: 84px; padding: 8px 10px;
  background: var(--raised); color: var(--paper);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px; text-align: center;
}
.toc-nav input:focus { outline: none; border-color: var(--amber); }
.toc-nav input::-webkit-inner-spin-button,
.toc-nav input::-webkit-outer-spin-button { -webkit-appearance: none; }
#toc-total { color: var(--faint); }
.toc-step { padding: 8px 13px; font-size: 16px; line-height: 1; }
#toc-cur { margin-left: auto; white-space: nowrap; }

/* 본문 문자열 검색 — 회차("236화")로 페이지를 찾는다 */
.toc-search {
  display: flex; gap: 8px;
  padding: 8px 4px 0;
}
.toc-search input {
  flex: 1; min-width: 0; padding: 8px 12px;
  background: var(--raised); color: var(--paper);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px;
}
.toc-search input:focus { outline: none; border-color: var(--amber); }
.toc-search .ghost-btn { flex: 0 0 auto; white-space: nowrap; }
.toc-preview mark {
  background: var(--amber); color: #241a07;
  border-radius: 4px; padding: 0 2px;
}

.toc-slider-row { padding: 8px 4px 0; }

.toc-pct {
  margin: 2px 8px 8px; text-align: right;
  font-size: 11.5px; color: var(--faint); letter-spacing: .5px;
}

/* 선택한 페이지의 전문 미리보기 — 패널 고정 높이의 나머지를 전부 차지 */
.toc-preview {
  flex: 1; min-height: 120px;
  overflow-y: auto;
  background: linear-gradient(165deg, rgba(236, 228, 212, .05), rgba(236, 228, 212, .02));
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px;
  font-family: var(--serif); font-size: 15.5px; line-height: 1.9;
  color: var(--paper-dim);
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.toc-preview p { margin: 0 0 1em; }
.toc-preview p:last-child { margin-bottom: 0; }

.toc-go {
  margin-top: 12px; width: 100%;
  border: none; border-radius: 12px;
  padding: 14px; font-size: 15px; font-weight: 700;
  font-family: inherit;
  background: radial-gradient(120% 120% at 30% 25%, var(--amber-soft), var(--amber) 58%, #c9882e);
  color: #241a07;
  box-shadow: 0 6px 18px rgba(232, 169, 72, .25);
  transition: transform .12s ease;
}
.toc-go:active { transform: scale(.98); }

/* 확인 시트는 다른 시트(TTS 설정 등) 위에서도 떠야 한다 — DOM 순서상 앞이라 z로 끌어올림 */
#confirm-sheet { z-index: 35; }
.confirm-panel { gap: 16px; }
.confirm-panel p { margin: 8px 4px 0; font-size: 15px; line-height: 1.7; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ───────── 플레이어 메뉴(☰) — .sheet를 재사용하되 패널만 우측 사이드바 ───────── */

#menu-sheet { align-items: stretch; justify-content: flex-end; }
#menu-sheet .sheet-panel {
  width: min(62vw, 230px);
  max-height: none; margin: 0;
  border: none; border-left: 1px solid var(--line);
  border-radius: 0;
  padding: calc(24px + var(--safe-top)) 12px calc(20px + var(--safe-bottom));
  gap: 4px; justify-content: flex-start;
  animation: menu-in .26s cubic-bezier(.2, .7, .3, 1);
}
@keyframes menu-in {
  from { transform: translateX(48px); opacity: .4; }
  to   { transform: none; opacity: 1; }
}
.menu-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 12px;
  background: none; border: none; border-radius: 12px;
  font-size: 14.5px; color: var(--paper);
  text-align: left;
  position: relative; /* .alert 배지 점의 기준 */
  transition: color .15s, background .15s;
}
.menu-item:active { color: var(--amber); background: var(--amber-dim); }
.menu-ic { flex: 0 0 24px; text-align: center; font-size: 17px; color: var(--amber); }
.menu-item.alert::after {
  content: ""; position: absolute; top: 10px; right: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--stamp);
  box-shadow: 0 0 5px rgba(192, 80, 74, .8);
}

/* ───────── 설정 시트 공통 (보기 설정 / TTS 설정) ───────── */

.sheet-body {
  overflow-y: auto; min-height: 0;
  padding: 12px 4px 2px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.set-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.set-row input[type="range"] { flex: 1; min-width: 0; }
.set-label { flex: 0 0 68px; font-size: 13px; color: var(--paper-dim); }
.set-val { flex: 0 0 38px; text-align: right; font-size: 12.5px; color: var(--amber); }
.size-step {
  flex: 0 0 30px; height: 30px;
  border: 1px solid var(--line); border-radius: 8px;
  background: none; color: var(--paper-dim);
  font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.size-step:disabled { opacity: .3; }
.size-step:not(:disabled):active { color: var(--amber); border-color: var(--amber); background: var(--amber-dim); }
.set-foot { display: flex; justify-content: space-between; gap: 10px; padding-top: 14px; }
.fine { margin: 4px 0 0; font-size: 11.5px; line-height: 1.7; color: var(--faint); }
.fine a { color: var(--amber); text-decoration: none; }
.note-list { margin: 8px 0 0; padding-left: 1.1em; }
.note-list li { margin-top: 5px; }

/* 입력 필드 — 탐색 시트 입력과 같은 룩(시트 폼 공용) */
.field {
  flex: 1; min-width: 0;
  padding: 9px 12px;
  background: var(--raised); color: var(--paper);
  border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14px;
}
.field:focus { outline: none; border-color: var(--amber); }
select.field { appearance: auto; -webkit-appearance: auto; }
.field-suffix { flex: 0 0 auto; font-size: 12.5px; color: var(--faint); }

/* 보기 설정: 미리보기 + 색 스와치 */
.look-sample {
  background: var(--reader-bg);
  color: var(--reader-fg-dim);
  font-family: var(--reader-font);
  font-size: min(var(--reader-size), 20px);
  line-height: 1.9; letter-spacing: .2px;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 4px;
}
.look-sample p { margin: 0 0 6px; padding: 2px 8px; border-radius: 8px; }
.look-sample p:last-child { margin-bottom: 0; }
.look-sample p.reading { background: var(--reader-hl); color: var(--reader-fg); }

.swatches { display: flex; gap: 12px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--sw-bg, #171c26); color: var(--sw-fg, #ece4d4);
  font-family: var(--serif); font-size: 14px; line-height: 1;
  display: grid; place-items: center; padding: 0;
  transition: border-color .15s, box-shadow .15s;
}
.swatch.on { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber-dim); }

.color-pick {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--paper-dim);
}
input[type="color"] {
  width: 34px; height: 34px; padding: 0;
  border: 2px solid var(--line); border-radius: 50%;
  background: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }

/* TTS 설정 시트 */
.seg { display: flex; gap: 8px; }
.eye-btn { flex: 0 0 auto; padding: 8px 11px; }
.tts-test { width: 100%; margin: 4px 0 2px; padding: 11px; font-size: 13.5px; }
.usage-title {
  margin: 16px 0 6px; padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px; font-weight: 700; color: var(--amber);
  font-family: inherit;
}
.usage-count { margin: 0 0 8px; font-size: 16px; color: var(--paper); }
.usage-bar {
  height: 6px; border-radius: 3px; overflow: hidden;
  background: var(--line); margin-bottom: 6px;
}
.usage-bar i {
  display: block; height: 100%; width: 0;
  background: var(--amber); border-radius: 3px;
  transition: width .3s ease;
}
.usage-bar.warn i { background: var(--amber-soft); }
.usage-bar.over i { background: var(--stamp); }
.set-foot { align-items: center; }

/* ───────── 토스트 ───────── */

#toast {
  position: fixed; left: 50%; bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%) translateY(16px);
  z-index: 50;
  background: #241f15; color: var(--amber-soft);
  border: 1px solid rgba(232, 169, 72, .4);
  border-radius: 999px;
  padding: 10px 20px; font-size: 13.5px;
  max-width: 86vw;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 480px) {
  .spine { width: 80px; }
}
