@font-face { font-family: Galmuri11; src: url(assets/Galmuri11.woff2) format("woff2"); font-display: swap; }

/* 색 토큰: iOS Theme.swift와 같은 값. 흰 글자를 얹는 채움색과 종이 위 글자는 4.5:1 이상. */
:root {
  --bg: #2f6fc9; --paper: #f6f2e6; --chip: #dce8fa; --edge: #23356b; --shadow: rgba(0, 0, 0, .3);
  --blue: #2b67c4; --bar: #23468f; --spine: #1e4796; --accent: #1f4fa8; --big: #2b67c4;
  --ink: #1c2748; --sub: #4c5878; --dim: #4b5575; --warn: #c62828; --danger: #b3261e; --gold: #ffd54f;
  --n: 3px;                       /* 도트 테두리 두께 = 모서리 깎임 */
  --u: calc(11px / 3);            /* Galmuri11 한 도트. 글자 크기는 --u × n (iOS Font.px(n)과 같다) */
  --col: 100%;
  --st: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
html.night {
  --bg: #0b1230; --paper: #1e2747; --chip: #2b3a66; --edge: #050818;
  --blue: #3466c8; --bar: #172a5c; --spine: #1a3a7c; --accent: #8cb8ff; --big: #8cb8ff;
  --ink: #eef2ff; --sub: #a9b6da; --dim: #3a4468; --warn: #ff8a80;
  color-scheme: dark;
}
@media (min-width: 700px) and (min-height: 600px) { :root { --col: 560px; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: Galmuri11, "Hiragino Sans", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; font-size: calc(var(--u) * 5); line-height: 1.4; color: var(--ink); background: var(--bg); overscroll-behavior: none; touch-action: manipulation; -webkit-text-size-adjust: 100%; }
h1, h2, h3, p { margin: 0; font-weight: 400; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 5px var(--edge); }
[hidden] { display: none !important; }

.t4 { font-size: calc(var(--u) * 4); } .t5 { font-size: calc(var(--u) * 5); } .t6 { font-size: calc(var(--u) * 6); }
.t7 { font-size: calc(var(--u) * 7); } .t9 { font-size: calc(var(--u) * 9); } .t10 { font-size: calc(var(--u) * 10); }
.t12 { font-size: calc(var(--u) * 12); } .t14 { font-size: calc(var(--u) * 14); } .t18 { font-size: calc(var(--u) * 18); }

/* 배경: 후지산 건널목 180×320 도트를 최근접 확대해 아래(눈길)에 맞춘다(app.js가 캔버스에 그린다). 나이트 모드는 남색을 덮는다. */
#bg, #snow { position: fixed; inset: 0; z-index: -2; width: 100%; height: 100%; image-rendering: pixelated; }
html.night body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: rgba(10, 15, 48, .62); }

#app, .sheet { width: min(100%, var(--col)); }
#app { position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; margin: 0 auto; overflow: hidden; padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
body.sheet-open #app { visibility: hidden; }
.home, .study, .chapters { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.scroll { flex: 1; min-height: 0; overflow: auto; }

/* ── 도트 상자: 네 모서리가 한 칸씩 깎인 테두리 + 아래로 깔리는 하드 그림자 ── */
.px::before, .px::after, .btn::after, .clipn {
  clip-path: polygon(var(--n) 0, calc(100% - var(--n)) 0, calc(100% - var(--n)) var(--n), 100% var(--n), 100% calc(100% - var(--n)), calc(100% - var(--n)) calc(100% - var(--n)), calc(100% - var(--n)) 100%, var(--n) 100%, var(--n) calc(100% - var(--n)), 0 calc(100% - var(--n)), 0 var(--n), var(--n) var(--n));
}
.px { --f: var(--paper); display: block; position: relative; isolation: isolate; padding: var(--n); }
.px::before, .px::after { content: ""; position: absolute; inset: 0; z-index: -1; }
.px::before {
  background:
    linear-gradient(var(--f), var(--f)) calc(var(--n) * 2) var(--n) / calc(100% - var(--n) * 4) calc(100% - var(--n) * 2) no-repeat,
    linear-gradient(var(--f), var(--f)) var(--n) calc(var(--n) * 2) / calc(100% - var(--n) * 2) calc(100% - var(--n) * 4) no-repeat,
    var(--edge);
}
.px::after { z-index: -2; transform: translateY(var(--depth, 4px)); background: var(--shadow); }
.px.blue { --f: var(--blue); } .px.dim { --f: var(--dim); } .px.chip { --f: var(--chip); }
.px.gold { --f: var(--gold); } .px.danger { --f: var(--danger); }
.px.sm { --n: 2px; --depth: 0px; }

/* 아래쪽 두께가 있는 버튼. 누르면 두께만큼 내려앉는다. */
.btn { position: relative; display: inline-block; padding-bottom: 4px; color: #fff; }
.btn.wide { display: block; width: 100%; }
.btn::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; bottom: 0; background: var(--edge); }
.btn > .px { --depth: 0px; position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 56px; padding: var(--n) calc(var(--n) + 14px); color: #fff; text-align: center; }
.btn:active > .px { transform: translateY(4px); }
.btn.ic > .px { min-height: 48px; min-width: 56px; padding: var(--n) calc(var(--n) + 10px); }
svg { flex: none; }

/* 화면 제목(장 목록·설정·단어 목록) */
.hdr { display: flex; align-items: center; gap: 8px; padding: calc(var(--st) + 8px) 16px 8px; }
.hdr .ht { --depth: 3px; flex: 0 1 auto; min-width: 0; padding: calc(var(--n) + 8px) calc(var(--n) + 14px); color: var(--ink); }
.hdr .sp, .sp { flex: 1; }
.hdr .btn + .btn { margin-left: 0; }

/* 홈 */
.title { padding: calc(var(--st) + 24px) 16px 0; text-align: center; color: #fff; text-shadow: 0 4px 0 var(--edge); font-size: calc(var(--u) * 10); }
.title a { color: inherit; text-decoration: none; }
.title a:hover { text-decoration: underline; }
.title a:focus-visible { outline: 3px solid currentColor; outline-offset: 4px; }
.pager { display: flex; flex: none; height: 300px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100%; display: flex; justify-content: center; padding: 12px 0; scroll-snap-align: center; }
.cover { display: flex; height: 100%; max-height: 360px; max-width: 80%; aspect-ratio: 78 / 100; align-self: center; color: #fff; }
.row { flex: 1; min-width: 0; display: flex; }
.spine { flex: 0 0 20%; background: var(--spine); }
.line { flex: 0 0 var(--n); background: var(--edge); }
.face { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.cats { position: relative; flex: none; height: 80px; margin: 0 16px 4px; }
.cat { position: absolute; left: 0; bottom: 0; width: 66px; height: 60px; background: url(assets/cat.png) 0 0 / 990px 60px no-repeat; image-rendering: pixelated; will-change: transform; }
.dotsw, .setw { display: flex; justify-content: center; }
.dotsw { margin-top: 8px; }
.setw { margin: 8px 0; }
.dots { --depth: 3px; display: flex; align-items: center; padding: calc(var(--n) + 4px) calc(var(--n) + 8px); }
.dot { width: 24px; height: 24px; display: grid; place-items: center; }
.dot i { display: block; width: 8px; height: 8px; background: var(--sub); opacity: .5; }
.dot.on i { width: 14px; height: 14px; background: var(--blue); opacity: 1; }

/* 장 목록 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; padding: 16px 16px 24px; }
.crow { display: flex; align-items: center; gap: 12px; }
.ccard { flex: 1; min-width: 0; display: flex; min-height: 160px; color: #fff; }
.ccard .spine { flex-basis: 36px; }
.ccard .face { gap: 6px; }
.badge { position: absolute !important; top: 10px; right: 10px; padding: calc(var(--n) + 3px) calc(var(--n) + 8px) !important; color: #000; }
.logb { flex: none; width: 62px; height: 62px; display: grid; place-items: center; color: #fff; }

/* 학습 */
.hbar { display: flex; align-items: center; justify-content: space-between; padding: var(--st) 8px 0; background: var(--blue); color: #fff; }
.hbar .ttl { text-align: center; line-height: 1.3; }
.sbar { position: relative; display: flex; align-items: center; justify-content: center; min-height: 44px; background: var(--bar); color: #fff; border-bottom: 3px solid var(--edge); }
.sbar .ib { position: absolute; right: 8px; top: 0; }
.ib { width: 44px; height: 44px; display: grid; place-items: center; color: inherit; }
.card { flex: 1; min-height: 0; display: flex; margin: 12px 16px 8px; }
.card .in { flex: 1; min-width: 0; overflow: auto; display: flex; flex-direction: column; background: var(--paper); }
.card .c { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 12px 24px; text-align: center; max-width: 100%; }
.big { color: var(--big); overflow-wrap: anywhere; line-height: 1.2; }
.read, .ko { color: var(--ink); }
.sent { color: var(--accent); overflow-wrap: anywhere; }
.hid { visibility: hidden; }
.spk { display: flex; gap: 12px; }
.spk .px { --depth: 3px; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: var(--n) calc(var(--n) + 14px); color: var(--accent); font-size: calc(var(--u) * 4); }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 8px 16px; }
.mark { display: grid; place-items: center; width: 24px; height: 24px; background: #fff; color: #000; --n: 2px; clip-path: polygon(var(--n) 0, calc(100% - var(--n)) 0, calc(100% - var(--n)) var(--n), 100% var(--n), 100% calc(100% - var(--n)), calc(100% - var(--n)) calc(100% - var(--n)), calc(100% - var(--n)) 100%, var(--n) 100%, var(--n) calc(100% - var(--n)), 0 calc(100% - var(--n)), 0 var(--n), var(--n) var(--n)); font-size: calc(var(--u) * 4); }
.q { color: var(--gold); }

/* 안내창 */
.scrim { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 32px; background: rgba(0, 0, 0, .6); }
.pop { width: min(440px, 100%); max-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: calc(var(--n) + 24px); text-align: center; overflow: visible; }
.catpic { flex: none; width: 88px; height: 80px; background: url(assets/cat.png) -792px 0 / 1320px 80px no-repeat; image-rendering: pixelated; }
.pbody { width: 100%; min-height: 0; max-height: 40vh; overflow: auto; }
.pbody .r2 { display: flex; justify-content: space-between; gap: 16px; margin-top: 10px; }
.pbody .r2 span { color: var(--sub); }
.pbody .r2 b { font-weight: 400; }
.pbody p + p, .pbody .note { margin-top: 10px; }
.note { color: var(--accent); font-size: calc(var(--u) * 4); }
.pacts { width: 100%; display: grid; gap: 8px; }

/* 시트(설정·단어 목록) */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; margin: 0 auto; padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.panels { display: grid; gap: 16px; padding: 16px; }
.panel { display: grid; gap: 12px; margin-bottom: 4px; padding: calc(var(--n) + 16px); }
.panel h3 { color: var(--accent); font-size: calc(var(--u) * 4); }
.panel .foot { color: var(--sub); font-size: calc(var(--u) * 4); }
.sw { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; color: var(--ink); }
.sw .lbl { flex: 1; }
.knob { --n: 2px; --depth: 0px; --f: var(--dim); width: 60px; height: 36px; display: flex; align-items: center; padding: calc(var(--n) + 6px) calc(var(--n) + 4px); }
.knob i { display: block; width: 20px; height: 20px; background: #fff; }
.sw[aria-checked="true"] .knob { --f: var(--blue); justify-content: flex-end; }
.wl { background: var(--paper); }
.wrow { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 16px; color: var(--ink); border-bottom: 1px solid rgba(35, 53, 107, .25); }
.wrow .no { flex: 0 0 44px; text-align: right; color: var(--sub); font-size: calc(var(--u) * 4); }
.wrow .w { flex: 1; min-width: 0; }
.wrow .w small { display: block; color: var(--sub); font-size: calc(var(--u) * 4); }
.wrow svg { color: var(--warn); }

@media (max-height: 500px) {
  .title, .cats { display: none; }
  .pager { flex: 1; height: auto; }
  .btns { grid-template-columns: repeat(4, 1fr); }
  .big.t18 { font-size: calc(var(--u) * 12); }
  .big.t12 { font-size: calc(var(--u) * 9); }
}
@media (prefers-reduced-motion: reduce) { .pager { scroll-behavior: auto; } }
