/* ── tokens ──────────────────────────────────────────────── */
:root{
  --bg:#f6f4ef; --surface:#fffdf9; --surface-2:#efece4; --line:#ded9cd;
  --text:#23211d; --muted:#6f6a60; --accent:#3f7d47; --accent-soft:#e3efe0;
  --star:#c8931f; --yt:#ff0000; --yt-hi:#cc0000;
  --shadow:0 1px 2px rgba(35,33,29,.07), 0 6px 18px rgba(35,33,29,.06);
  --radius:12px; --bar:rgba(255,253,249,.86);
  --safe-t:env(safe-area-inset-top,0px); --safe-b:env(safe-area-inset-bottom,0px);
  --safe-l:env(safe-area-inset-left,0px); --safe-r:env(safe-area-inset-right,0px);
  color-scheme:light;
}
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    --bg:#101216; --surface:#181b21; --surface-2:#20242c; --line:#2c313a;
    --text:#e7e5e0; --muted:#9b978f; --accent:#8fbf7a; --accent-soft:#1f2a20;
    --star:#e0b34a; --yt:#ff2626; --yt-hi:#ff0000;
    --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.32);
    --bar:rgba(24,27,33,.86);
    color-scheme:dark;
  }
}
:root[data-theme="dark"]{
  --bg:#101216; --surface:#181b21; --surface-2:#20242c; --line:#2c313a;
  --text:#e7e5e0; --muted:#9b978f; --accent:#8fbf7a; --accent-soft:#1f2a20;
  --star:#e0b34a; --yt:#ff2626; --yt-hi:#ff0000;
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.32);
  --bar:rgba(24,27,33,.86);
  color-scheme:dark;
}

*,*::before,*::after{box-sizing:border-box}
[hidden]{display:none!important}
html,body{height:100%}
body{
  margin:0; background:var(--bg); color:var(--text);
  font:15px/1.5 ui-sans-serif,-apple-system,"Pretendard","Apple SD Gothic Neo","Segoe UI",Roboto,sans-serif;
  -webkit-text-size-adjust:100%; -webkit-tap-highlight-color:transparent;
  overscroll-behavior-y:none;
}
button{font:inherit;color:inherit;background:none;border:0;cursor:pointer}
a{color:inherit;text-decoration:none}
svg{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px;border-radius:6px}

.icon-btn{
  display:grid;place-items:center;width:38px;height:38px;border-radius:10px;
  color:var(--muted);transition:background .15s,color .15s;flex:none;
}
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
.icon-btn[aria-pressed="true"]{color:var(--accent);background:var(--accent-soft)}

/* ── library ─────────────────────────────────────────────── */
.topbar{
  position:sticky;top:0;z-index:20;display:flex;gap:10px;align-items:center;
  padding:calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l));
  background:var(--bar);backdrop-filter:saturate(1.6) blur(14px);border-bottom:1px solid var(--line);
}
.brand{display:flex;align-items:center;gap:8px;font-weight:650;letter-spacing:-.01em;flex:none}
.brand span{font-size:16px}
.brand i{color:var(--accent);font-style:normal}
.brand .leaf{width:22px;height:22px;color:var(--accent);fill:currentColor;stroke:none}
.brand .leaf .stem{fill:none;stroke:currentColor;stroke-width:1.8}

.search{position:relative;flex:1;min-width:0;max-width:460px;margin-inline:auto}
.search svg{position:absolute;left:11px;top:50%;translate:0 -50%;color:var(--muted);width:17px;height:17px}
.search input{
  width:100%;height:38px;padding:0 34px 0 34px;border-radius:10px;
  background:var(--surface-2);border:1px solid transparent;color:var(--text);font:inherit;
}
.search input:focus{border-color:var(--line);background:var(--surface);outline:none}
.search input::-webkit-search-cancel-button{display:none}
.qclear{position:absolute;right:6px;top:50%;translate:0 -50%;width:26px;height:26px;border-radius:8px;color:var(--muted);font-size:19px;line-height:1}

.toolbar{display:flex;gap:2px;flex:none}
.ico-moon{display:none}
:root[data-theme="dark"] .ico-sun{display:none}
:root[data-theme="dark"] .ico-moon{display:block}
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]) .ico-sun{display:none}
  :root:not([data-theme="light"]) .ico-moon{display:block}
}

.filters{
  display:flex;gap:7px;overflow-x:auto;scrollbar-width:none;
  padding:12px calc(16px + var(--safe-r)) 4px calc(16px + var(--safe-l));
}
.filters::-webkit-scrollbar{display:none}
.chip{
  flex:none;padding:5px 12px;border-radius:999px;border:1px solid var(--line);
  background:var(--surface);color:var(--muted);font-size:13px;white-space:nowrap;
  transition:background .15s,color .15s,border-color .15s;
}
.chip[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:#fff;font-weight:600}
:root[data-theme="dark"] .chip[aria-pressed="true"]{color:#0f1214}
@media (prefers-color-scheme:dark){:root:not([data-theme="light"]) .chip[aria-pressed="true"]{color:#0f1214}}

.grid{
  display:grid;gap:18px 14px;
  grid-template-columns:repeat(auto-fill,minmax(150px,1fr));
  padding:16px calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l));
}
@media (min-width:700px){.grid{grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:24px 18px;padding-inline:24px}}
@media (min-width:1200px){.grid{grid-template-columns:repeat(auto-fill,minmax(200px,1fr))}}

.card{display:flex;flex-direction:column;gap:9px;text-align:left;width:100%;align-self:start}
.thumb{
  position:relative;border-radius:var(--radius);overflow:hidden;background:var(--surface);
  border:1px solid var(--line);box-shadow:var(--shadow);aspect-ratio:1/1.3;
  transition:transform .18s ease, box-shadow .18s ease;
}
.card:hover .thumb{transform:translateY(-3px);box-shadow:0 4px 10px rgba(0,0,0,.10),0 14px 30px rgba(0,0,0,.12)}
.thumb img{width:100%;height:100%;object-fit:cover;object-position:top center;display:block;background:#fff}
.badge{
  position:absolute;right:7px;bottom:7px;padding:2px 7px;border-radius:7px;font-size:11px;font-weight:600;
  background:rgba(15,17,20,.72);color:#fff;backdrop-filter:blur(6px);letter-spacing:.01em;
}
.star{
  position:absolute;left:5px;top:5px;width:30px;height:30px;display:grid;place-items:center;
  border-radius:9px;color:#fff;background:rgba(15,17,20,.5);backdrop-filter:blur(6px);opacity:0;transition:opacity .15s;
}
.thumb:hover .star,.star[aria-pressed="true"]{opacity:1}
.star[aria-pressed="true"]{color:var(--star)}
.star[aria-pressed="true"] svg{fill:currentColor}
.pill{
  position:absolute;right:6px;top:6px;padding:2px 7px;border-radius:7px;font-size:10.5px;font-weight:600;
  background:rgba(200,147,31,.94);color:#231f16;
}
.progress{position:absolute;left:0;right:0;bottom:0;height:3px;background:rgba(15,17,20,.22)}
.progress i{display:block;height:100%;background:var(--accent)}
.meta{display:flex;flex-direction:column;gap:2px;min-width:0}
.meta b{font-size:13.5px;font-weight:600;line-height:1.35;letter-spacing:-.005em;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.meta small{font-size:12px;color:var(--muted);line-height:1.35;
  display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden}

.empty{text-align:center;color:var(--muted);padding:48px 16px}
.foot{
  display:flex;justify-content:space-between;gap:12px;flex-wrap:wrap;
  padding:16px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  color:var(--muted);font-size:12.5px;border-top:1px solid var(--line);margin-top:16px;
}
.offstat{color:var(--accent)}

/* ── reader ──────────────────────────────────────────────── */
html[data-view="reader"],html[data-view="reader"] body{overflow:hidden;overscroll-behavior:none}
/* iOS 는 position:fixed 를 툴바가 접힌 기준으로 잡아서 실제 보이는 높이보다
   길어진다. app.js 가 visualViewport 값을 --app-* 로 넘겨주면 그걸 쓴다. */
#reader{position:fixed;left:0;top:0;width:100%;height:100%;background:#0c0d10;display:flex;flex-direction:column}
#reader{left:var(--app-x,0px);top:var(--app-y,0px);width:var(--app-w,100%);height:var(--app-h,100dvh)}

/* 악보는 원본 픽셀 크기로 깔고 transform 하나로만 확대·이동한다 */
.stage{flex:1;min-height:0;position:relative;overflow:hidden;touch-action:none}
.pages{position:absolute;left:0;top:0;transform-origin:0 0}
.pages.gesturing{will-change:transform}
.pages img{
  position:absolute;display:block;
  background:#fff;border-radius:3px;box-shadow:0 2px 18px rgba(0,0,0,.5);
}
#reader.pannable .stage{cursor:grab}
#reader.grabbing .stage{cursor:grabbing}

/* 확대 배율 — 누르면 맞춤으로 되돌아간다 */
.zoom-badge{
  position:absolute;z-index:9;left:calc(12px + var(--safe-l));
  bottom:calc(64px + var(--safe-b));
  padding:6px 11px;border-radius:999px;
  font-size:12px;font-variant-numeric:tabular-nums;color:#e7e5e0;
  background:rgba(14,16,20,.82);backdrop-filter:blur(10px);
  border:1px solid rgba(255,255,255,.14);
  transition:bottom .22s ease;
}
#reader.chrome-off .zoom-badge{bottom:calc(12px + var(--safe-b))}

/* 탭 영역 */
.tap{position:absolute;top:0;bottom:0;z-index:5;touch-action:none}
.tap-prev{left:0;width:30%}
.tap-next{right:0;width:30%}
.tap-mid{left:30%;right:30%}
html[data-view="reader"] .tap{cursor:pointer}

/* 상·하단 바 */
.rbar{
  position:absolute;left:0;right:0;z-index:10;display:flex;align-items:center;gap:8px;
  background:rgba(14,16,20,.9);backdrop-filter:blur(14px);color:#e7e5e0;
  transition:opacity .22s ease, transform .22s ease;
}
#reader.chrome-off .rbar{opacity:0;pointer-events:none}
.rbar-top{
  top:0;padding:calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 8px calc(10px + var(--safe-l));
  border-bottom:1px solid rgba(255,255,255,.08);
}
#reader.chrome-off .rbar-top{transform:translateY(-100%)}
.rbar-bottom{
  bottom:0;padding:8px calc(14px + var(--safe-r)) calc(10px + var(--safe-b)) calc(14px + var(--safe-l));
  border-top:1px solid rgba(255,255,255,.08);
}
#reader.chrome-off .rbar-bottom{transform:translateY(100%)}
.rbar .icon-btn{color:#a7a49d}
.rbar .icon-btn:hover{background:rgba(255,255,255,.09);color:#fff}
.rbar .icon-btn[aria-pressed="true"]{color:#8fbf7a;background:rgba(143,191,122,.14)}
#favBtn[aria-pressed="true"]{color:var(--star);background:rgba(224,179,74,.15)}
#listenBtn{color:#ff5a5a}
#listenBtn:hover{color:#fff;background:rgba(255,0,0,.75)}
#favBtn[aria-pressed="true"] svg{fill:currentColor}

.rtitle{flex:1;min-width:0;display:flex;flex-direction:column;line-height:1.3}
.rtitle strong{font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rtitle span{font-size:11.5px;color:#a7a49d;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.rtools{display:flex;gap:2px;flex:none}

.scrub{
  flex:1;min-width:0;height:26px;background:none;appearance:none;cursor:pointer;
}
.scrub::-webkit-slider-runnable-track{height:4px;border-radius:2px;background:rgba(255,255,255,.2)}
.scrub::-webkit-slider-thumb{appearance:none;width:15px;height:15px;border-radius:50%;background:#e7e5e0;margin-top:-5.5px}
.scrub::-moz-range-track{height:4px;border-radius:2px;background:rgba(255,255,255,.2)}
.scrub::-moz-range-thumb{width:15px;height:15px;border:0;border-radius:50%;background:#e7e5e0}
.counter{font-variant-numeric:tabular-nums;font-size:12.5px;color:#a7a49d;flex:none;min-width:64px;text-align:center}

/* ── 미니 플레이어 ────────────────────────────────────────── */
.player{
  position:fixed;z-index:60;overflow:hidden;
  right:calc(14px + var(--safe-r)); bottom:calc(14px + var(--safe-b));
  width:min(340px, calc(100vw - 28px));
  background:#14171c;color:#e7e5e0;border:1px solid rgba(255,255,255,.1);
  border-radius:14px;box-shadow:0 14px 44px rgba(0,0,0,.5);
}
.player-bar{display:flex;align-items:center;gap:4px;padding:7px 6px 7px 12px}
.player-bar strong{flex:1;min-width:0;font-size:12.5px;font-weight:600;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.player-bar .icon-btn{width:30px;height:30px;color:#a7a49d}
.player-bar .icon-btn:hover{background:rgba(255,255,255,.1);color:#fff}
#plCollapse svg{transition:rotate .2s}
.player.collapsed #plCollapse svg{rotate:180deg}
.player-frame{aspect-ratio:16/9;background:#000}
.player-frame iframe{width:100%;height:100%;border:0;display:block}
.player.collapsed .player-frame,.player.collapsed .player-tabs{display:none}
.player-tabs{display:flex;flex-wrap:wrap;gap:5px;padding:8px 10px 10px}
.player-tabs:empty{display:none}
.player-tabs button{
  padding:4px 9px;border-radius:999px;font-size:11.5px;color:#a7a49d;
  border:1px solid rgba(255,255,255,.14);white-space:nowrap;
}
.player-tabs button[aria-pressed="true"]{background:#8fbf7a;border-color:#8fbf7a;color:#0f1214;font-weight:600}
/* 뷰어에서 하단 바와 겹치지 않게 */
html[data-view="reader"] .player{bottom:calc(56px + var(--safe-b))}
@media (max-width:520px){ .player{left:calc(10px + var(--safe-l));right:calc(10px + var(--safe-r));width:auto} }

/* 목록 카드의 재생 버튼 — 항상 보이게 두고 YouTube 빨강으로 표시 */
.play{
  position:absolute;left:7px;bottom:7px;width:32px;height:32px;display:grid;place-items:center;
  border-radius:50%;color:#fff;background:var(--yt);
  box-shadow:0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.22);
  transition:transform .15s ease, background .15s;
}
.play svg{width:16px;height:16px;fill:currentColor;stroke:none;margin-left:1.5px}
.play:hover,.play:focus-visible{background:var(--yt-hi);transform:scale(1.09)}

/* ── toast ───────────────────────────────────────────────── */
.toast{
  position:fixed;z-index:100;left:50%;translate:-50% 0;bottom:calc(24px + var(--safe-b));
  padding:10px 16px;border-radius:11px;background:rgba(20,22,27,.94);color:#f2f0ec;
  font-size:13.5px;box-shadow:0 10px 34px rgba(0,0,0,.4);max-width:min(90vw,420px);text-align:center;
}

/* ── 새 배포 알림 ─────────────────────────────────────────────
   악보를 보는 중에는 끼어들지 않는다. 목록으로 나왔을 때만 뜬다. */
.update-pill{
  position:fixed;z-index:90;left:50%;translate:-50% 0;bottom:calc(24px + var(--safe-b));
  padding:10px 16px;border-radius:999px;background:rgba(20,22,27,.94);color:#f2f0ec;
  font-size:13px;font-weight:600;box-shadow:0 10px 34px rgba(0,0,0,.4);
  border:1px solid rgba(143,191,122,.5);max-width:min(90vw,420px);
}
.update-pill::before{content:'';display:inline-block;width:7px;height:7px;border-radius:50%;
  background:#8fbf7a;margin-right:8px;vertical-align:1px}
.update-pill:disabled{opacity:.65}
html[data-view="reader"] .update-pill{display:none!important}

@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}

/* ── 인쇄 ─────────────────────────────────────────────────────
   화면에서는 완전히 숨기고, 인쇄할 때만 곡의 전체 페이지를 한 장에 한 면씩 깐다.
   악보는 전부 세로(비율 0.685~0.816).

   한 장 높이를 '알아내서' 지정하려 하면 안 된다. vh 는 iOS Safari 가 인쇄 시
   용지가 아니라 화면 뷰포트로 계산하고, mm 절대값은 Safari 가 @page margin 을
   무시하고 자체 여백(약 0.5in)을 쓰는 탓에 넘친다. 둘 다 22장을 44장으로
   만들었다.

   그래서 높이를 아예 지정하지 않고 padding-top 백분율로 만든다. 백분율 패딩은
   '박스 너비' 기준이라, 브라우저가 여백을 얼마로 잡든 인쇄 영역 너비를 따라
   높이가 같이 줄어든다 — 여백을 알 필요가 없어진다.

   129% 는 대칭 여백 M 에서 (용지높이-2M)/(용지너비-2M) 의 하한이다.
     A4     297/210   = 1.414  (M=0 이 최악)
     Letter 279.4/215.9 = 1.294 (M=0 이 최악)
   즉 129% 면 A4·Letter 어느 쪽이든, 여백이 0 이든 20mm 든 박스가 한 장을
   넘지 않는다. Safari 기본 여백(0.5in)에서는 A4 기준 33mm 가 남는다.
   최대 크기보다 약 10% 작게 나오는 대신 용지·여백 추측을 안 한다. */
.print-area{display:none}

@media print{
  @page{size:A4 portrait;margin:5mm}
  html,body{height:auto!important;overflow:visible!important;background:#fff!important}
  html[data-view="reader"],html[data-view="reader"] body{overflow:visible!important}
  body>*{display:none!important}
  .print-area{display:block!important}
  .print-page{
    position:relative;width:100%;height:auto;padding:129% 0 0;margin:0;
    overflow:hidden;break-inside:avoid;break-after:page;page-break-after:always;
  }
  .print-page:last-child{break-after:auto;page-break-after:auto}
  .print-page img{
    position:absolute;top:0;right:0;bottom:0;left:0;margin:auto;
    max-width:100%;max-height:100%;width:auto;height:auto;object-fit:contain;
  }
}
