/* 용도별 QR 페이지 공용 뼈대. 색·글꼴·질감은 페이지 style.css의 토큰으로만 바꾼다.
   토큰: --ink(도크 바탕) --paper(도크 글자) --accent --on-accent --dim --line --bg-in --bg-out --on-bg
         --f-ui --f-display --r(모서리) --studio-bg */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
body {
  min-height: 100%; height: auto; overflow-x: hidden; overflow-y: visible; overscroll-behavior: none;
  background: radial-gradient(120% 90% at 50% 38%, var(--bg-in), var(--bg-out)) fixed var(--bg-out); color: var(--paper);
  font: 400 15px/1.5 var(--f-ui); -webkit-text-size-adjust: 100%; word-break: keep-all; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.veil { position: fixed; inset: 0; background: var(--bg-out); pointer-events: none; animation: veil .35s ease-out forwards; }
@keyframes veil { to { opacity: 0; } }

.top { position: fixed; z-index: 5; top: calc(env(safe-area-inset-top) + 12px); left: 16px; right: 16px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.logo { pointer-events: auto; text-decoration: none; color: var(--on-accent); background: var(--accent); font: 400 17px/1 'Black Han Sans', var(--f-ui); padding: 6px 8px 5px; border-radius: var(--r); }
.chip { pointer-events: auto; cursor: pointer; height: 40px; padding: 0 12px; border-radius: var(--r); background: var(--ink); color: var(--paper); border: 0; font-size: 12.5px; font-weight: 600; }
.chip[aria-pressed="false"] { color: var(--dim); }

/* 드론이 QR을 잡아내는 괄호 */
.lock { position: fixed; left: var(--lx, 0); top: var(--ly, 0); width: var(--lw, 0); height: var(--lh, 0); opacity: var(--lo, 0); pointer-events: none; }
.lock i { position: absolute; width: 22px; height: 22px; border: 0 solid var(--accent); }
.lock i:nth-child(1) { left: 0; top: 0; border-width: 2px 0 0 2px; }
.lock i:nth-child(2) { right: 0; top: 0; border-width: 2px 2px 0 0; }
.lock i:nth-child(3) { right: 0; bottom: 0; border-width: 0 2px 2px 0; }
.lock i:nth-child(4) { left: 0; bottom: 0; border-width: 0 0 2px 2px; }
.lock-note {
  position: fixed; z-index: 6; left: 50%; top: calc(env(safe-area-inset-top) + 13px); transform: translateX(-50%); margin: 0; white-space: nowrap;
  font-size: 13px; padding: 4px 9px; background: var(--ink); color: var(--paper); border-radius: var(--r); opacity: 0; transition: opacity .4s; pointer-events: none;
}
body[data-view="top"] .lock-note { opacity: 1; }
@media (min-width: 900px) { .lock-note { left: var(--qr-cx, 50%); top: 22px; } }
.hint { position: fixed; left: var(--free-cx, 50%); bottom: var(--hint-bottom, 200px); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); margin: 0; text-align: center; font-size: 13px; color: var(--on-bg); opacity: 0; transition: opacity .4s; pointer-events: none; }
body[data-state="done"][data-view="iso"] .hint { opacity: .9; }

/* 하단 도크 */
.dock { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; padding: 16px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--paper); display: grid; gap: 12px; }
.dock h1 { margin: 0; font: var(--h1-font); letter-spacing: -.01em; }
.lede { margin: 2px 0 0; font-size: 14px; color: var(--dim); }
.form { display: grid; gap: 10px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fld { display: grid; gap: 3px; min-width: 0; }
.fld > span { font-size: 12.5px; color: var(--dim); }
.fld input, .fld select {
  width: 100%; min-width: 0; height: 44px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--field-bg, rgba(255,255,255,.06)); outline: none; font-size: 16px;
}
.fld select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%); background-position: calc(100% - 17px) 19px, calc(100% - 12px) 19px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.fld select option { color: #111; }
.fld input:focus, .fld select:focus { border-color: var(--accent); }
.fld input::placeholder { color: var(--dim); opacity: .8; }
.pw { position: relative; }
.pw input { padding-right: 56px; }
.pw button { position: absolute; right: 4px; bottom: 4px; height: 36px; padding: 0 10px; border: 0; background: none; color: var(--dim); cursor: pointer; font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--dim); cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.err-line { min-height: 0; margin: 0; font-size: 13px; color: var(--warn, #ffb4a2); }
.err-line:empty { display: none; }

.btn { height: 44px; padding: 0 14px; border-radius: var(--r); cursor: pointer; background: transparent; border: 1px solid var(--line); color: var(--paper); font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { border-color: transparent; color: var(--dim); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.icon { padding: 0; width: 44px; display: grid; place-items: center; }
.btn.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.playing { display: none; align-items: center; justify-content: space-between; gap: 12px; }
#status { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 14px; }
.result { display: none; gap: 10px; }
.result-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13.5px; color: var(--dim); }
.result-meta b { color: var(--paper); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.result-meta .link { flex: none; }
.actions { display: grid; grid-template-columns: 1fr 44px 44px; gap: 8px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--dim); cursor: pointer; font-size: 13.5px; text-decoration: underline; text-underline-offset: 3px; }

body[data-state="play"] .compose, body[data-state="done"] .compose { display: none; }
body[data-state="play"] .playing { display: flex; }
body[data-state="done"] .result { display: grid; }

.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(var(--dockH, 200px) + 14px); transform: translate(-50%, 8px); max-width: calc(100% - 32px); width: max-content; padding: 10px 14px; border-radius: var(--r); background: var(--paper); color: var(--ink); font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
body.studio-open .toast { bottom: calc(env(safe-area-inset-bottom) + 92px); }

.fallback, .err { position: fixed; inset: auto 16px 45% 16px; text-align: center; font-size: 15px; color: var(--on-bg); }

/* ---------------------------------------------------------------- 인쇄물 작업대 */
.studio { position: fixed; z-index: 50; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; background: var(--studio-bg); color: var(--paper); }
.studio[hidden] { display: none; }
body.studio-open { overflow: hidden; }
body.studio-open .guide, body.studio-open .dock, body.studio-open .top { visibility: hidden; }
.studio-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(env(safe-area-inset-top) + 10px) 16px 8px; background: var(--ink); }
.studio-top h2 { margin: 0; font: var(--h2-font); }
.studio-main { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); overflow: hidden; }
.paper-wrap { min-height: 0; min-width: 0; height: 100%; display: grid; place-items: center; align-content: center; gap: 6px; padding: 12px; }
.studio[data-round="1"] #proof { border-radius: 50%; }
#proof { display: block; box-shadow: 0 1px 1px rgba(0,0,0,.18), 0 12px 28px -8px rgba(0,0,0,.45); background: #fff; }
.proof-size { margin: 0; font-size: 12.5px; color: var(--on-studio, var(--dim)); font-variant-numeric: tabular-nums; }
.studio-ctl { background: var(--ink); padding: 12px 16px 10px; display: grid; gap: 10px; grid-auto-rows: max-content; align-content: start; max-height: 46vh; overflow-y: auto; }
.formats, .qrstyle { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0; padding: 0; border: 0; }
.formats::-webkit-scrollbar { display: none; }
.formats button, .qrstyle button {
  flex: none; display: grid; gap: 1px; text-align: left; min-height: 44px; padding: 6px 10px; border-radius: var(--r); cursor: pointer;
  background: transparent; border: 1px solid var(--line); color: var(--dim); font-size: 13.5px; line-height: 1.25;
}
.formats button small { font-size: 11.5px; opacity: .85; font-variant-numeric: tabular-nums; }
.formats button[aria-checked="true"], .qrstyle button[aria-checked="true"] { border-color: var(--accent); color: var(--paper); box-shadow: inset 0 0 0 1px var(--accent); }
.qrstyle { align-items: center; }
.qrstyle > span { font-size: 12.5px; color: var(--dim); margin-right: 4px; flex: none; }
.qrstyle button { min-height: 36px; padding: 4px 10px; }
.studio-fields { display: grid; gap: 8px; padding-top: 8px; }
.opts > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; min-height: 36px; font-size: 14px; font-weight: 700; color: var(--paper); }
.opts > summary::-webkit-details-marker { display: none; }
.opts > summary::after { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--dim); border-bottom: 2px solid var(--dim); transform: rotate(45deg) translate(-2px, -2px); transition: transform .2s; }
.opts[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.studio-fields .fld input { height: 40px; font-size: 15px; }
.studio-actions { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--ink); border-top: 1px solid var(--line); }
#printArea { display: none; }

@media (min-width: 900px) {
  .top { left: 24px; right: 24px; top: 20px; }
  .dock { left: 24px; right: auto; bottom: 24px; width: 440px; padding: 20px; border-radius: var(--r-dock, var(--r)); }
  .toast { left: 244px; bottom: calc(var(--dockH, 200px) + 40px); }
  .studio { grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: auto minmax(0, 1fr) auto; }
  .studio-top { grid-column: 1 / -1; padding: 16px 24px; }
  .studio-main { grid-column: 1; grid-row: 2 / 4; }
  .paper-wrap { padding: 32px; }
  .studio-ctl { grid-column: 2; grid-row: 2; max-height: none; padding: 20px 24px; align-content: start; border-left: 1px solid var(--line); }
  .studio-actions { grid-column: 2; grid-row: 3; border-left: 1px solid var(--line); padding: 14px 24px 20px; }
  .formats { flex-wrap: wrap; }
  body.studio-open .toast { left: 50%; bottom: 40px; }
}
@media (prefers-reduced-motion: reduce) { .veil { animation-duration: .01s; } }

/* ---------------------------------------------------------------- 설명서 (첫 화면 아래) */
.guide {
  position: relative; z-index: 30; margin-top: 100vh; margin-top: 100svh;
  background: var(--ink); color: var(--paper); border-top: 1px solid var(--line);
  font: 400 15.5px/1.75 var(--f-ui); content-visibility: auto; contain-intrinsic-size: auto 2000px;
}
.guide-in { max-width: 1040px; margin: 0 auto; padding: 44px 16px calc(56px + env(safe-area-inset-bottom)); }
.guide h2 { margin: 0; font: var(--h2-font); font-size: 26px; line-height: 1.25; }
.guide h3 { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--accent); }
.guide p { max-width: 38em; }
.guide-lede { margin: 12px 0 0; color: var(--dim); }
.guide section, .guide-more { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); }
.guide-steps ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; counter-reset: s; }
.guide-steps li { counter-increment: s; position: relative; padding-left: 40px; color: var(--dim); }
.guide-steps li::before { content: counter(s); position: absolute; left: 0; top: 2px; width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid var(--accent); border-radius: var(--r); color: var(--accent); font-weight: 700; }
.guide b { display: block; color: var(--paper); font-weight: 700; }
.guide dl { margin: 0; display: grid; gap: 22px; }
.guide dt { font-weight: 700; }
.guide dd { margin: 4px 0 0; color: var(--dim); max-width: 38em; }
.guide table { width: 100%; max-width: 40em; border-collapse: collapse; font-size: 14.5px; color: var(--dim); }
.guide th, .guide td { text-align: left; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.guide th { color: var(--paper); font-weight: 700; }
.guide code { font-size: .92em; padding: 1px 5px; border-radius: 3px; background: var(--line); color: var(--paper); word-break: break-all; }
.guide ul.plain { margin: 0; padding-left: 1.2em; color: var(--dim); }
.guide-more ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.guide-more a { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); color: var(--dim); text-decoration: none; }
.guide-more a:hover, .guide-more a:focus-visible { border-color: var(--accent); }
@media (min-width: 900px) {
  .guide-in { padding: 64px 24px 72px; }
  .guide h2 { font-size: 32px; }
  .guide-steps ol { grid-template-columns: repeat(3, 1fr); gap: 28px; }
  .guide dl { grid-template-columns: 1fr 1fr; gap: 26px 48px; }
  .guide-more ul { grid-template-columns: 1fr 1fr; gap: 12px; }
}

/* ---------------------------------------------------------------- 인쇄: A4 한 장 이미지만 */
@media print {
  html, body { background: #fff !important; height: auto; overflow: visible; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea img { display: block; width: 210mm; height: 297mm; }
  #printArea img.landscape { width: 297mm; height: 210mm; }
}
