/* 평생뷰어 — 화면 */
:root {
  --bg: #e9ecf1;          /* 작업대(쪽 뒤 배경) */
  --panel: #ffffff;       /* 머리·도구막대 */
  --ink: #1b1f27;
  --ink-2: #4b5260;
  --ink-3: #7a8190;
  --line: #d5d9e1;
  --accent: #1f4e79;      /* 평생요금제닷컴 계열 짙은 파랑 */
  --accent-ink: #ffffff;
  --page-shadow: 0 1px 2px rgba(20, 30, 50, .18), 0 6px 18px rgba(20, 30, 50, .10);
  --warn-bg: #fff6d9; --warn-ink: #6b4e00;
  --err-bg: #fde8e8; --err-ink: #8a1c1c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181e; --panel: #1f232b; --ink: #e8eaef; --ink-2: #b7bcc8; --ink-3: #8a90a0; --line: #2f3542;
    --accent: #6ea8dc; --accent-ink: #0d1a26;
    --page-shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.35);
    --warn-bg: #3a3010; --warn-ink: #f3dd8a; --err-bg: #3d1a1a; --err-ink: #ffb4b4;
  }
}
:root[data-theme="dark"] {
  --bg: #15181e; --panel: #1f232b; --ink: #e8eaef; --ink-2: #b7bcc8; --ink-3: #8a90a0; --line: #2f3542;
  --accent: #6ea8dc; --accent-ink: #0d1a26;
  --page-shadow: 0 1px 2px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.35);
  --warn-bg: #3a3010; --warn-ink: #f3dd8a; --err-bg: #3d1a1a; --err-ink: #ffb4b4;
}

/* 한글 문서가 요구하는 글꼴 이름 — 기기에 없을 때만 내려받는다 (rhwp 가 SVG 에 쓰는 대체 사슬 이름 그대로) */
@font-face { font-family: 'Nanum Myeongjo'; font-weight: 400; font-display: swap; src: url(fonts/NanumMyeongjo-Regular.woff2) format('woff2'); }
@font-face { font-family: 'Nanum Myeongjo'; font-weight: 700; font-display: swap; src: url(fonts/NanumMyeongjo-Bold.woff2) format('woff2'); }
@font-face { font-family: 'NanumGothic'; font-weight: 400; font-display: swap; src: url(fonts/NanumGothic-Regular.woff2) format('woff2'); }
@font-face { font-family: 'NanumGothic'; font-weight: 700; font-display: swap; src: url(fonts/NanumGothic-Bold.woff2) format('woff2'); }
@font-face { font-family: 'Noto Sans KR'; font-weight: 400; font-display: swap; src: url(fonts/NotoSansKR-Regular.woff2) format('woff2'); }
@font-face { font-family: 'Noto Sans KR'; font-weight: 700; font-display: swap; src: url(fonts/NotoSansKR-Bold.woff2) format('woff2'); }
@font-face { font-family: 'Noto Serif KR'; font-weight: 400; font-display: swap; src: url(fonts/NotoSerifKR-Regular.woff2) format('woff2'); }
@font-face { font-family: 'Noto Serif KR'; font-weight: 700; font-display: swap; src: url(fonts/NotoSerifKR-Bold.woff2) format('woff2'); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", "NanumGothic", system-ui, sans-serif;
  display: flex; flex-direction: column; height: 100%; overflow: hidden; /* 쪽 작업대(.stage)만 스크롤한다 */
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
body.plain { height: auto; overflow: auto; }
a { color: var(--accent); }
button { font: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: #fff; object-fit: cover; flex: none; display: block; }
.name { font-weight: 800; font-size: 18px; letter-spacing: -.01em; line-height: 1.2; }
.tag { font-size: 12px; color: var(--ink-3); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; line-height: 1.2; min-height: 36px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; white-space: nowrap; }
.btn.icon { width: 36px; padding: 0; font-size: 20px; }
.link { color: var(--accent); text-decoration: underline; cursor: pointer; }

.toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.toolbar[hidden] { display: none; }
.fname { flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--ink-2); }
.group { display: inline-flex; align-items: center; gap: 4px; }
.pageinfo { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; font-size: 14px; }

#main { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

.drop { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.drop[hidden] { display: none; }
.drop-inner {
  max-width: 560px; width: 100%; text-align: center; padding: 36px 20px;
  border: 2px dashed var(--line); border-radius: 16px; background: var(--panel);
}
.drop.over .drop-inner { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--panel)); }
.drop-title { font-size: 17px; font-weight: 700; text-wrap: balance; }
.formats { list-style: none; padding: 0; margin: 18px 0 8px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 14px; color: var(--ink-2); font-size: 14px; }
.formats b { color: var(--ink); margin-right: 4px; }
.note { margin: 8px 0 0; color: var(--ink-2); font-size: 14px; }
.note.small { font-size: 12px; color: var(--ink-3); }

.banner { margin: 10px 16px 0; padding: 8px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; }
.banner[hidden] { display: none; }
.msg { margin: 24px auto; max-width: 560px; padding: 14px 16px; border-radius: 10px; background: var(--err-bg); color: var(--err-ink); font-size: 14px; white-space: pre-wrap; }
.msg[hidden] { display: none; }

.sheet-tabs { display: flex; gap: 4px; padding: 8px 12px 0; overflow-x: auto; }
.sheet-tabs[hidden] { display: none; }
.sheet-tabs button { border: 1px solid var(--line); border-bottom: none; background: var(--panel); color: var(--ink-2); padding: 6px 12px; border-radius: 8px 8px 0 0; cursor: pointer; white-space: nowrap; }
.sheet-tabs button[aria-selected="true"] { color: var(--ink); font-weight: 700; border-color: var(--accent); }

/* 쪽 작업대: 쪽들을 세로로 쌓는다 */
.stage { flex: 1; min-height: 0; overflow: auto; padding: 16px 12px 40px; -webkit-overflow-scrolling: touch; }
.drop { overflow: auto; min-height: 0; }
.stage[hidden] { display: none; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.page { position: relative; background: #fff; box-shadow: var(--page-shadow); flex: none; overflow: hidden; }
/* 그림은 쪽 상자 가운데에 두고 --rot 만큼 돌린다 (회전하면 상자의 가로·세로가 바뀜) */
.page > svg, .page > canvas { position: absolute; top: 50%; left: 50%; width: var(--pw, 100%); height: var(--ph, auto); transform: translate(-50%, -50%) rotate(var(--rot, 0deg)); display: block; }
.page .pnum { position: absolute; right: 6px; bottom: 4px; font-size: 11px; color: #999; user-select: none; }
.page.loading::after {
  content: "그리는 중…"; position: absolute; inset: 0; display: grid; place-items: center; color: #9aa; font-size: 13px;
}

/* 워드 (docx-preview 가 만드는 .docx-wrapper) */
.docx-host { display: flex; justify-content: center; }
.docx-host .docx-wrapper { background: transparent !important; padding: 0 !important; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.docx-host .docx-wrapper > section.docx { box-shadow: var(--page-shadow) !important; margin-bottom: 0 !important; }

/* 엑셀 */
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 0 8px 8px 8px; overflow: auto; max-width: 100%; }
.sheet table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.sheet td, .sheet th { border: 1px solid var(--line); padding: 3px 8px; white-space: nowrap; color: var(--ink); }
.sheet tr:first-child td { background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }

.foot {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px;
  padding: 10px 16px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line); background: var(--panel);
}

@media (max-width: 600px) {
  .top { padding: 8px 12px; }
  .tag { display: none; }
  .toolbar { padding: 4px 8px; gap: 4px 6px; flex-wrap: nowrap; overflow-x: auto; }
  .toolbar .btn { padding: 5px 9px; min-height: 32px; }
  .toolbar .btn.icon { width: 32px; }
  .fname { display: none; }
  .stage { padding: 10px 6px 40px; }
  .foot { font-size: 11px; }
}

@media print {
  .top, .toolbar, .foot, .banner, .drop, .sheet-tabs { display: none !important; }
  html, body { background: #fff; height: auto; overflow: visible; }
  #main { display: block; }
  .stage { overflow: visible; padding: 0; }
  .pages { gap: 0; }
  .page { box-shadow: none; width: 100% !important; height: auto !important; overflow: visible; page-break-after: always; break-after: page; }
  .page > svg, .page > canvas { position: static; width: 100%; height: auto; transform: none; }
  .page .pnum { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
