:root {
  --bg: #f4f6f9; --card: #fff; --text: #1a2130; --muted: #5d687c; --line: #dfe3ea; --soft: #f7f8fb;
  --accent: #2453c9; --accent-h: #1c44a8; --accent-soft: #edf2ff;
  --ok: #10703a; --ok-bg: #e3f4ea; --warn: #8f5100; --warn-bg: #fff1db;
  --bad: #b42318; --bad-bg: #fdecea; --pend: #4f3fb5; --pend-bg: #ece9fb;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; word-break: keep-all; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid #7aa2ff; outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; padding: 8px 12px; border-radius: 6px; z-index: 10; }
.skip:focus { left: 8px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 20px;
  background: #151b28; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; text-decoration: none; margin-right: auto; }
.brand small { display: block; font-size: 12px; font-weight: 500; opacity: .7; line-height: 1.2; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; background: var(--accent); font-size: 13px; }
.who { font-size: 14px; opacity: .85; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 1120px; margin: 0 auto; padding: 20px; outline: none; }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }

/* cards & headings */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 16px; }
.narrow { max-width: 420px; margin: 48px auto; }
h1 { font-size: 22px; line-height: 1.3; margin: 0 0 4px; } h2 { font-size: 18px; margin: 0 0 8px; }
.page-head, .card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.page-head { margin-bottom: 16px; }
.card-head { margin-bottom: 12px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.layout > .card { margin: 0; }
#new-book { position: sticky; top: 72px; scroll-margin-top: 72px; }
.crumb { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.crumb a { text-decoration: none; } .crumb a:hover { text-decoration: underline; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; color: #3a4456; margin-bottom: 12px; }
.hint { font-weight: 400; color: var(--muted); }
.req { font-style: normal; font-size: 12px; color: var(--bad); font-weight: 600; }
input, select { font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid #c9cfda; border-radius: 8px; color: var(--text);
  background: #fff; min-width: 0; min-height: 44px; }
input:focus, select:focus { border-color: var(--accent); outline: 3px solid #c8d7ff; outline-offset: 0; }
input[aria-invalid="true"] { border-color: var(--bad); }
button, .btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 9px 18px; border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .btn:hover { background: var(--accent-h); }
button.block { width: 100%; }
button.ghost { background: transparent; border: 1px solid #ffffff55; min-height: 36px; padding: 6px 12px; }
button.ghost:hover { background: #ffffff1a; }
button.small { min-height: 34px; padding: 4px 12px; font-size: 14px; }
button.secondary { background: #fff; color: var(--text); border: 1px solid #c9cfda; }
button.secondary:hover { background: var(--soft); }
button:disabled { opacity: .55; cursor: default; }
button[aria-busy="true"]::before { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.grid .span { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-top: 12px; }
.inline label { margin: 0; flex: 1 1 160px; }
.error { color: var(--bad); font-size: 14px; margin: 4px 0 0; }
.error:empty { display: none; }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
.notice { background: var(--warn-bg); color: #5c3a00; border-radius: 8px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; }
.filter { margin: 0; flex: 1 1 220px; max-width: 320px; }

/* book list */
.books { list-style: none; padding: 0; margin: 0; }
.books li + li { border-top: 1px solid var(--line); }
.books a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 14px 8px; color: inherit;
  text-decoration: none; border-radius: 8px; }
.books a:hover { background: var(--accent-soft); }
.books .t { font-weight: 700; overflow-wrap: anywhere; }
.books .sub { grid-column: 1; color: var(--muted); font-size: 14px; }
.books .badge { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* book detail */
.pipeline { list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 0; margin: 4px 0 16px; }
.step { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; background: var(--soft); }
.step b { display: block; }
.step span { color: var(--muted); }
.step.done { border-color: #a8dcbc; background: var(--ok-bg); } .step.done span { color: var(--ok); }
.step.todo { border-style: dashed; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 0 0 12px; }
.stats div { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stats dt { font-size: 13px; color: var(--muted); } .stats dd { margin: 0; font-weight: 700; font-size: 17px; }
.stats .na dd { font-weight: 500; font-size: 14px; color: var(--muted); }
.editions summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.edition-list { padding-left: 20px; margin: 6px 0; font-size: 14px; }
.edition-list code { color: var(--muted); font-size: 12px; }

/* upload */
.edition-pick { flex-direction: row; align-items: center; gap: 10px; }
.edition-pick select { flex: 0 1 260px; }
.drop { border: 2px dashed #a3aec4; border-radius: var(--radius); padding: 28px 16px; text-align: center; cursor: pointer;
  background: var(--soft); transition: background .15s, border-color .15s; }
.drop:hover, .drop:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.drop.over { border-color: var(--accent); border-style: solid; background: var(--accent-soft); }
.drop p { margin: 4px 0; }
.drop-ico { width: 34px; height: 34px; color: var(--accent); }
.warn-line { margin-top: 10px; color: var(--warn); }
.queue { list-style: none; padding: 0; margin: 12px 0 0; }
.queue li { border: 1px solid var(--line); border-left: 4px solid var(--pend); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.queue li.is-ok { border-left-color: var(--ok); } .queue li.is-bad { border-left-color: var(--bad); }
.queue .row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.queue .name { font-weight: 600; overflow-wrap: anywhere; flex: 1 1 220px; }
.queue .size { color: var(--muted); font-weight: 400; font-size: 14px; }
.queue .st { font-size: 14px; color: var(--pend); }
.queue li.is-ok .st { color: var(--ok); font-weight: 600; } .queue li.is-bad .st { color: var(--bad); font-weight: 600; }
progress { appearance: none; width: 100%; height: 8px; margin-top: 8px; border: 0; border-radius: 99px; background: #e6e9f0; overflow: hidden; }
progress::-webkit-progress-bar { background: #e6e9f0; border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; transition: width .2s; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
li.is-ok progress::-webkit-progress-value { background: var(--ok); } li.is-ok progress::-moz-progress-bar { background: var(--ok); }
li.is-bad progress::-webkit-progress-value { background: var(--bad); } li.is-bad progress::-moz-progress-bar { background: var(--bad); }

/* table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--soft); }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num { white-space: nowrap; }
td.hash { font-family: Consolas, "D2Coding", monospace; font-size: 12px; color: var(--muted); max-width: 200px; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge:empty { display: none; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-bad { background: var(--bad-bg); color: var(--bad); }
.b-pend { background: var(--pend-bg); color: var(--pend); } .b-warn { background: var(--warn-bg); color: var(--warn); }
.reason { display: block; color: var(--bad); font-size: 13px; margin-top: 4px; }
.reason.info { color: var(--muted); }

/* responsive */
/* ---------- login: 2-step (TOTP) ---------- */
.login h1 { font-size: 22px; }
.login > .muted { margin-bottom: 14px; }
.stepper { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.stepper b { color: var(--accent); }
.enroll-box { margin: 0 0 12px; }
.enroll-box summary, #secret-box summary { cursor: pointer; font-size: 14px; color: var(--accent); padding: 6px 0; }
.enroll-box label { margin-top: 8px; }
input.otp { font-size: 24px; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.mono, .secret, .rc-list code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-top: 12px; }
button.linklike { min-height: 44px; padding: 8px 0; background: none; border: 0; color: var(--accent); font-weight: 500; text-decoration: underline; }
button.linklike:hover { background: none; color: var(--accent-h); }
.enroll-steps { padding-left: 20px; margin: 12px 0; font-size: 14px; }
.enroll-steps > li { margin-bottom: 14px; }
.qr { width: 100%; max-width: 232px; margin: 10px auto; }
.qr svg { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; }
.secret { display: block; padding: 10px 12px; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; font-size: 15px; word-break: break-all; user-select: all; margin: 6px 0; }
.rc-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 12px; padding-left: 28px; margin: 12px 0; }
.rc-list code { font-size: 15px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; margin: 12px 0; }
label.check input { width: 20px; height: 20px; }
button.block + button.block, .block + .muted { margin-top: 8px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  #new-book { position: static; }
}
@media (max-width: 720px) {
  main { padding: 12px; }
  .top { padding: 8px 12px; }
  .brand small, .who { display: none; }
  .card { padding: 16px; }
  h1 { font-size: 20px; }
  .grid { grid-template-columns: 1fr; }
  .filter { max-width: none; }
  .pipeline { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .edition-pick { flex-direction: column; align-items: stretch; }
  .edition-pick select { flex: none; }
  .actions button, .inline button { width: 100%; }
  /* parts table → stacked cards */
  table.parts thead { display: none; }
  table.parts, table.parts tbody, table.parts tr, table.parts td { display: block; width: 100%; }
  table.parts tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
  table.parts td { border: 0; padding: 4px 0; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 4px 12px; }
  table.parts td .reason { flex-basis: 100%; padding-left: 76px; margin: 0; }
  table.parts td[data-label]::before { content: attr(data-label); flex: 0 0 64px; color: var(--muted); font-size: 13px; }
  table.parts td.hash { max-width: none; }
  table.parts td.empty-row { display: block; text-align: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
