:root {
  --bg: #f6f4ee; --fg: #1d2421; --muted: #5d6762; --card: #ffffff; --line: #d8d4c8;
  --accent: #17717f; --accent-fg: #ffffff; --warn: #fff1c9; --warn-fg: #6b4a00;
  --danger: #b3261e; --ok: #1b6b3a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a; --fg: #eef1ef; --muted: #a2adaa; --card: #1f2528; --line: #36403f;
    --accent: #5cc4cf; --accent-fg: #06262b; --warn: #4a3b0d; --warn-fg: #ffe9a8;
    --danger: #ff8a80; --ok: #7fd39b;
  }
}
* { box-sizing: border-box; }
html { font-size: 19px; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif; line-height: 1.5; }
#app { max-width: 720px; margin: 0 auto; padding: 8px 16px 48px; }
a { color: var(--accent); }
h1 { font-size: 1.2rem; margin: 0; text-align: center; flex: 1; }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.empty { text-align: center; padding: 24px 0; }

#status { position: sticky; top: 0; z-index: 40; padding: 10px 16px 12px; text-align: center; background: var(--accent); color: var(--accent-fg); font-weight: 600; }
#status[data-kind=waiting], #status[data-kind=offline], #status[data-kind=needs-link] { background: var(--warn); color: var(--warn-fg); }
#status[data-kind=idle-done] { background: var(--card); color: var(--ok); border-bottom: 2px solid var(--line); }
.s-text { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 12px; }
.s-detail { font-weight: 500; opacity: 0.9; }
.s-track { position: relative; height: 8px; margin-top: 8px; overflow: hidden; border-radius: 999px; background: color-mix(in srgb, currentColor 25%, transparent); }
.s-track i { display: block; height: 100%; border-radius: 999px; background: currentColor; transition: width 0.4s linear; }
.s-track.moving::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(115deg, transparent 0 14px, rgb(255 255 255 / 0.35) 14px 28px); background-size: 40px 100%; animation: stripe 0.9s linear infinite; }
@keyframes stripe { to { background-position: 40px 0; } }
.spin { display: inline-block; width: 0.8em; height: 0.8em; margin-right: 6px; vertical-align: -0.1em; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .s-track.moving::after, .spin { animation: none; }
  .s-track i { transition: none; }
}

.top { display: flex; align-items: center; gap: 8px; min-height: 56px; }
.top > * { min-width: 72px; }
.top h1 { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.row > * { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > * { flex: 1 1 auto; }
.row.between { justify-content: space-between; }
.row.between > * { flex: 0 0 auto; }

input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; min-height: 52px; padding: 10px 12px; font: inherit; color: var(--fg); background: var(--card); border: 2px solid var(--line); border-radius: 10px;
}
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .cell:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
textarea { min-height: 45vh; line-height: 1.7; resize: vertical; }
label { display: block; font-weight: 600; }
label > input[type=text], label > input[type=number] { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 12px; min-height: 52px; font-weight: 500; }
input[type=checkbox] { width: 28px; height: 28px; flex: none; accent-color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; min-width: 52px; padding: 8px 16px; font: inherit; font-weight: 600; text-align: center; text-decoration: none; color: var(--fg); background: var(--card); border: 2px solid var(--line); border-radius: 12px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.big { min-height: 60px; font-size: 1.05rem; }
.btn.small { min-width: 64px; }
.btn:disabled { opacity: 0.4; cursor: default; }
[hidden] { display: none !important; }

.card { background: var(--card); border: 2px solid var(--line); border-radius: 14px; }
.book { display: flex; align-items: center; padding: 4px 8px 4px 0; }
.book-link { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; min-height: 64px; color: inherit; text-decoration: none; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.grid .empty { grid-column: 1 / -1; }
.cell { display: block; color: inherit; text-decoration: none; background: var(--card); border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.thumb { position: relative; }
.cell img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--line); }
.cap-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; min-height: 48px; }
.num { font-weight: 700; }

.photo { display: block; width: 100%; padding: 0; border: 2px solid var(--line); border-radius: 12px; background: var(--card); overflow: hidden; cursor: zoom-in; }
.photo img { display: block; width: 100%; max-height: 38vh; object-fit: contain; }
.zoom { position: fixed; inset: 0; z-index: 30; background: #000; }
.zoom-scroll { position: absolute; inset: 0; overflow: auto; touch-action: pan-x pan-y pinch-zoom; }
.zoom-scroll img { display: block; width: 250vw; max-width: none; }
.zoom-close { position: fixed; top: calc(var(--status-h, 0px) + 12px); right: 12px; z-index: 31; }

.cap { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; display: flex; flex-direction: column; }
.cap-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.cap-top { position: relative; display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: linear-gradient(#000a, transparent); }
.cap-done { min-height: 52px; min-width: 72px; padding: 0 20px; font: inherit; font-weight: 700; color: #fff; background: #0008; border: 2px solid #fff6; border-radius: 12px; }
.cap-count { font-weight: 700; padding: 6px 14px; background: #0008; border-radius: 999px; }
.cap-notice { position: relative; margin: 16px; padding: 14px; background: #000c; border-radius: 12px; }
.cap-pick { position: relative; align-self: center; min-height: 64px; padding: 0 28px; font: inherit; font-size: 1.1rem; font-weight: 700; color: var(--accent-fg); background: var(--accent); border: 0; border-radius: 14px; }
.cap-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px 20px calc(24px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, #000a); }
.cap-side { flex: 1; display: flex; }
.cap-side:last-child { justify-content: flex-end; }
.cap-thumb { width: 56px; height: 72px; object-fit: cover; border: 2px solid #fff; border-radius: 8px; }
.cap-shutter { width: 88px; height: 88px; border-radius: 50%; border: 6px solid #fff; background: #ffffffcc; cursor: pointer; }
.cap-shutter:active { transform: scale(0.94); background: #fff; }
.cap-split { min-height: 52px; max-width: 110px; padding: 6px 10px; font: inherit; font-size: 0.8rem; font-weight: 700; color: #fff; background: #0008; border: 2px solid #fff6; border-radius: 12px; }
.cap-split[aria-pressed=true] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.cap-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cap-flash.go { animation: flash 0.25s ease-out; }
@keyframes flash { from { opacity: 0.8; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cap-flash.go { animation: none; } }

.import-note { margin: 4px 0; }
.cap-top .import-note { position: relative; }

.cap, .zoom { top: var(--status-h, 0px); }

.mark { display: inline-flex; align-items: center; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.mark.recognizing { color: var(--accent); }
.mark.done { color: var(--ok); font-size: 1.25rem; font-weight: 800; }
.mark.failed { color: var(--danger); }

.veil { display: none; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(105deg, color-mix(in srgb, var(--card) 62%, transparent) 30%, color-mix(in srgb, var(--card) 92%, transparent) 50%, color-mix(in srgb, var(--card) 62%, transparent) 70%); background-size: 250% 100%; animation: shimmer 1.6s ease-in-out infinite; }
.cell[data-status=pending] .veil { display: block; }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }

.work-card { display: flex; align-items: center; gap: 16px; margin: 8px 0 12px; padding: 16px; background: var(--card); border: 2px solid var(--line); border-radius: 16px; transition: opacity 0.3s; }
.work-card[data-kind=waiting], .work-card[data-kind=offline] { background: var(--warn); color: var(--warn-fg); border-color: transparent; }
.work-card[data-kind=done] { color: var(--ok); }
.work-card.leaving { opacity: 0; }
.card-title { margin: 0; font-size: 1.2rem; font-weight: 800; }
.card-count { margin: 2px 0 0; font-size: 1.05rem; font-weight: 600; }
.card-count:empty, .card-wait:empty { display: none; }
.card-wait { margin: 2px 0 0; font-weight: 600; }
.card-note { margin: 6px 0 0; font-size: 0.9rem; opacity: 0.85; }
.work-card.compact { padding: 8px 12px; gap: 10px; }
.work-card.compact .card-title { font-size: 1rem; }
.work-card.compact .card-count { margin: 0; font-size: 0.95rem; }
.work-card.compact .card-note { display: none; }
.work-card.compact .ring-wrap { width: 40px; height: 40px; }
.ring-wrap { position: relative; flex: none; width: 72px; height: 72px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 7; stroke-linecap: round; }
.ring-track { stroke: color-mix(in srgb, currentColor 18%, transparent); }
.ring-arc { stroke: var(--accent); transition: stroke-dasharray 0.6s ease; }
.work-card[data-kind=done] .ring-arc { stroke: var(--ok); }
.ring-sweep { display: none; stroke: var(--accent); opacity: 0.55; transform-origin: 32px 32px; animation: spin 1.1s linear infinite; }
.work-card[data-kind=recognizing] .ring-sweep { display: block; }
.ring-check { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 800; color: var(--ok); }
.work-card[data-kind=done] .ring-check { display: flex; }
.work-card.compact .ring-check { font-size: 1.1rem; }

.home { display: flex; flex-direction: column; align-items: center; gap: 20px; padding-top: 8px; }
.home-icon { border-radius: 22px; }
.home-title { flex: none; font-size: 1.8rem; }
.tile { align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: 6px; min-height: 150px; padding: 24px; text-align: center; text-decoration: none; color: var(--accent-fg); background: var(--accent); border-radius: 22px; }
.tile strong { font-size: 1.7rem; }
.tile span { font-size: 1.05rem; opacity: 0.92; }
.tile:focus-visible { outline: 3px solid var(--fg); outline-offset: 3px; }

.howto { margin: 12px 0; padding-left: 1.4rem; }
.howto li { margin: 10px 0; }
.howto strong { display: block; }

.doc { min-height: 45vh; padding: 12px 14px; color: var(--fg); background: var(--card); border: 2px solid var(--line); border-radius: 10px; line-height: 1.8; overflow-wrap: anywhere; }
.doc:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.doc > :first-child { margin-top: 0; }
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6 { margin: 1em 0 0.4em; line-height: 1.4; }
.doc h1 { font-size: 1.35rem; }
.doc h2 { font-size: 1.2rem; }
.doc h3, .doc h4, .doc h5, .doc h6 { font-size: 1.08rem; }
.doc p { margin: 0.5em 0; }
.doc ul { margin: 0.5em 0; padding-left: 1.3rem; }
.doc li[data-level="1"] { margin-left: 1.4rem; }
.doc li[data-level="2"] { margin-left: 2.8rem; }
.doc li[data-level="3"] { margin-left: 4.2rem; }
.doc blockquote { margin: 0.7em 0; padding: 4px 14px; background: color-mix(in srgb, var(--accent) 10%, var(--card)); border-left: 5px solid var(--accent); border-radius: 8px; }
.doc blockquote p { margin: 0.3em 0; }
.doc table { width: 100%; margin: 0.7em 0; border-collapse: collapse; table-layout: fixed; }
.doc th, .doc td { height: 2.8em; padding: 6px 8px; vertical-align: top; text-align: left; border: 1.5px solid var(--muted); overflow-wrap: anywhere; }
.doc th { font-weight: 700; background: color-mix(in srgb, var(--accent) 14%, var(--card)); }

.page-note { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 140px; padding: 16px; text-align: center; border: 2px dashed var(--line); border-radius: 12px; }
.page-note p { margin: 0; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .veil, .ring-sweep { animation: none; }
  .ring-arc { transition: none; }
  .work-card { transition: none; }
}

.fb-open { position: absolute; top: calc(var(--status-h, 0px) + 8px); left: 12px; z-index: 50; min-height: 52px; padding: 0 18px; font: inherit; font-weight: 700; color: var(--fg); background: var(--card); border: 2px solid var(--accent); border-radius: 999px; box-shadow: 0 2px 8px #0004; cursor: pointer; }
body:not([data-screen=capture]) #app { padding-top: 68px; }
body.zoomed .fb-open { display: none; }
body[data-screen=capture] .fb-open { position: fixed; top: auto; bottom: calc(148px + env(safe-area-inset-bottom)); }
.fb-sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.fb-backdrop { position: absolute; inset: 0; background: #0007; }
.fb-panel { position: relative; width: 100%; max-width: 720px; margin: 0 auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); background: var(--bg); border-radius: 20px 20px 0 0; max-height: 90vh; overflow: auto; }
.fb-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fb-head h2 { margin: 0; font-size: 1.2rem; }
.fb-text { width: 100%; margin-top: 12px; padding: 12px; font: inherit; font-size: 1.1rem; color: var(--fg); background: var(--card); border: 2px solid var(--line); border-radius: 12px; resize: vertical; }
.fb-hint { min-height: 1.5em; margin: 6px 0 0; color: var(--danger); font-weight: 600; }
.fb-send { min-height: 64px; font-size: 1.15rem; }
.fb-toast { position: fixed; left: 16px; right: 16px; top: calc(var(--status-h, 0px) + 16px); z-index: 70; max-width: 420px; margin: 0 auto; padding: 14px 18px; text-align: center; font-weight: 700; color: var(--accent-fg); background: var(--accent); border-radius: 14px; box-shadow: 0 4px 16px #0005; }
