/* 모아모아 툴즈 — 5가지 도구 공통 스타일
   모바일 390×844 첫 화면에서 탭 전환과 첫 입력이 바로 보이도록 위에서부터 촘촘히 쌓습니다. */

:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --mut: #5f6673;
  --line: #e2e5ea;
  --line-strong: #cfd4dc;
  --accent: #2356d8;
  --accent-soft: #eaf0ff;
  --ok: #0b6b34;
  --ok-soft: #e3f5e9;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #8a5300;
  --warn-soft: #fff3dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --card: #161a21;
    --ink: #eceff4;
    --mut: #9fa7b5;
    --line: #262b35;
    --line-strong: #39404d;
    --accent: #6d95ff;
    --accent-soft: #1b2440;
    --ok: #5ed492;
    --ok-soft: #12291d;
    --bad: #ff8b7f;
    --bad-soft: #2c1715;
    --warn: #f0bd63;
    --warn-soft: #2a2113;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", Pretendard,
    "Noto Sans KR", "Noto Sans CJK KR", "Malgun Gothic", "맑은 고딕", "Helvetica Neue",
    Arial, "DejaVu Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); text-underline-offset: 2px; }
strong { font-weight: 700; }
[hidden] { display: none !important; }

.skip {
  position: absolute; left: 8px; top: -60px; z-index: 20;
  background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 8px;
  text-decoration: none;
}
.skip:focus { top: 8px; }

/* ── 헤더 ─────────────────────────────────────────── */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px 8px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.mark {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 9px;
  font-weight: 800; font-size: 18px; letter-spacing: -0.02em;
}
.brand-txt { min-width: 0; }
h1 { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.tag { font-size: 12px; color: var(--mut); }

/* ── 탭 ───────────────────────────────────────────── */
.tabs {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.tab {
  appearance: none; background: none; border: 0;
  padding: 7px 2px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--mut); font: inherit; font-size: 11.5px; font-weight: 600;
  letter-spacing: -0.02em;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  min-height: 52px;
}
.tab .ic { font-size: 17px; line-height: 1.1; }
.tab .tl { white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); background: var(--accent-soft); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

@media (max-width: 380px) {
  .top { padding: 9px 12px 7px; }
  .tag { display: none; }
  h1 { font-size: 16px; }
  #installBtn { font-size: 11.5px; padding: 6px 9px; min-height: 32px; white-space: nowrap; }
  main { padding: 12px 12px 24px; }
  .privacy { padding: 7px 12px; }
  footer { padding: 14px 12px 24px; }
}

/* ── 본문 ─────────────────────────────────────────── */
.privacy {
  margin: 0; padding: 7px 16px;
  font-size: 11.5px; color: var(--mut);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  line-height: 1.45;
}
.privacy strong { color: var(--ink); font-weight: 600; }

main { max-width: 720px; margin: 0 auto; padding: 14px 16px 28px; }

.panel { animation: fade .12s ease-out; }
@keyframes fade { from { opacity: .6; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } }

.phead { margin-bottom: 12px; }
h2 { font-size: 19px; font-weight: 800; letter-spacing: -0.02em; }
.phead p { margin-top: 4px; color: var(--mut); font-size: 13.5px; }

/* ── 폼 요소 ──────────────────────────────────────── */
.field { display: block; margin-bottom: 12px; }
.flabel {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--mut);
  margin-bottom: 5px;
}
.hint { font-size: 12px; color: var(--mut); margin: -4px 0 12px; }

input[type="text"], input[type="url"], input[type="tel"], input[type="email"],
input[type="number"], textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 11px;
  min-height: 42px;
}
textarea { resize: vertical; line-height: 1.55; font-size: 14px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--mut) 50%), linear-gradient(135deg, var(--mut) 50%, transparent 50%); background-position: right 14px top 18px, right 9px top 18px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 26px; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input[readonly], textarea[readonly] { background: var(--bg); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .grid2 { grid-template-columns: 1fr; } }

.check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 4px 0; cursor: pointer;
}
.check.tall { align-self: end; min-height: 42px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 18px; }

.inline { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.inline input { max-width: 130px; }
.unit { font-size: 13px; color: var(--mut); }

.link {
  appearance: none; background: none; border: 0; padding: 0;
  color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

/* ── 버튼 ─────────────────────────────────────────── */
.btn {
  appearance: none; font: inherit; font-size: 14px; font-weight: 700;
  background: var(--accent); color: #fff;
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 11px 16px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: var(--card); color: var(--ink); border-color: var(--line-strong); }
.btn.sm { font-size: 12.5px; padding: 7px 11px; min-height: 34px; font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .btn { color: #0e1014; }
  .btn.ghost { color: var(--ink); }
  .mark { background: var(--accent); color: #0e1014; }
}

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.row .btn { flex: 1 1 auto; }

/* ── 세그먼트(프리셋) ─────────────────────────────── */
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 8px; overflow: hidden;
  margin-bottom: 14px;
}
.seg.wrap { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.seg button {
  appearance: none; border: 0; border-right: 1px solid var(--line);
  background: transparent; color: var(--mut);
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 10px 4px; min-height: 42px; cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 700; }
@media (prefers-color-scheme: dark) { .seg button[aria-pressed="true"] { color: #0e1014; } }
.seg.wrap button:nth-child(2n) { border-right: 0; }
.seg.wrap button:nth-child(-n+2) { border-bottom: 1px solid var(--line); }

/* ── 파일 드롭존 ──────────────────────────────────── */
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-align: center;
  background: var(--card);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 18px 14px;
  margin-bottom: 14px;
  cursor: pointer;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-ic { font-size: 20px; color: var(--accent); line-height: 1.2; }
.drop-t { font-size: 14px; font-weight: 700; }
.drop-s { font-size: 11.5px; color: var(--mut); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 안내·통계 ────────────────────────────────────── */
.empty { font-size: 13px; color: var(--mut); padding: 10px 0; }
.stats {
  font-size: 12.5px; color: var(--ink);
  background: var(--warn-soft); color: var(--warn);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 10px;
}
.more { margin: 4px 0 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.more summary { font-size: 13px; font-weight: 600; color: var(--mut); cursor: pointer; padding: 4px 0; }
.more pre {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px; margin-top: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
  color: var(--mut);
}

/* ── 사진 결과 ────────────────────────────────────── */
.results { display: grid; gap: 12px; }
.res {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px; box-shadow: var(--shadow);
}
.res-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.res-name { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-name small { display: block; font-weight: 500; color: var(--mut); font-size: 11px; }
.x {
  appearance: none; background: none; border: 0; color: var(--mut);
  font-size: 15px; line-height: 1; padding: 6px; cursor: pointer; border-radius: 6px;
}
.x:hover { background: var(--bg); color: var(--ink); }
.cmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cmp figure { margin: 0; }
.cmp img {
  width: 100%; height: 108px; object-fit: contain;
  background: repeating-conic-gradient(var(--bg) 0% 25%, var(--card) 0% 50%) 50% / 16px 16px;
  border: 1px solid var(--line); border-radius: 6px;
}
.cmp figcaption { font-size: 11px; color: var(--mut); margin-top: 4px; text-align: center; }
.cmp figcaption b { display: block; color: var(--ink); font-size: 13px; }
.res-bar {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  font-size: 11.5px; color: var(--mut); margin: 9px 0;
}
.res-bar .pill {
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 1px 8px; font-weight: 600;
}
.res-bar .pill.good { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.res-bar .pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.res .btn { width: 100%; }
.busy { font-size: 12px; color: var(--mut); }

/* ── QR ───────────────────────────────────────────── */
.qr-stage {
  display: flex; align-items: center; justify-content: center;
  min-height: 180px; margin: 4px 0 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px;
}
#qrCanvas { width: min(240px, 62vw); height: auto; image-rendering: pixelated; display: block; }
.qr-stage .empty { text-align: center; margin: 0; }

/* ── 색 대비 ──────────────────────────────────────── */
.colors { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.color-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.color-row .flabel { margin: 0; flex: 0 0 46px; }
.color-row input[type="color"] {
  width: 42px; height: 42px; padding: 0; border: 1px solid var(--line-strong);
  border-radius: 8px; background: none; flex: 0 0 42px; cursor: pointer;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.color-row input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.color-row input[type="text"] { flex: 1 1 auto; min-width: 0; font-family: var(--mono); text-transform: uppercase; }
.colors .swaprow { display: flex; justify-content: flex-end; margin-top: 4px; }
#cErr:empty { display: none; }
#cErr { color: var(--bad); margin: 2px 0 0; }

.ratio {
  display: flex; align-items: baseline; gap: 2px;
  padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 10px;
}
.ratio-n { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.ratio-u { font-size: 15px; font-weight: 700; color: var(--mut); }
.ratio-s { margin-left: auto; font-size: 12.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--bg); color: var(--mut); }
.ratio-s.ok { background: var(--ok-soft); color: var(--ok); }
.ratio-s.bad { background: var(--bad-soft); color: var(--bad); }

.checks { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.checks li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.checks li:last-child { border-bottom: 0; }
.checks em { font-style: normal; color: var(--mut); font-size: 11.5px; margin-left: 3px; font-variant-numeric: tabular-nums; }
.checks b { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--mut); }
.checks b.ok { background: var(--ok-soft); color: var(--ok); }
.checks b.bad { background: var(--bad-soft); color: var(--bad); }

.preview {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  margin-bottom: 12px; background: #fff;
}
.preview p { margin: 0; }
.preview .pv-n { font-size: 16px; }
.preview .pv-l { font-size: 24px; font-weight: 700; margin-top: 6px; letter-spacing: -0.02em; }

.suggest {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; font-size: 13px;
}
.suggest .s-t { font-weight: 700; margin-bottom: 8px; }
.suggest .s-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.suggest .sw { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line-strong); flex: 0 0 26px; }
.suggest code { font-family: var(--mono); font-size: 12.5px; }
.suggest .btn { margin-left: auto; }

/* ── PDF ──────────────────────────────────────────── */
.files { display: grid; gap: 6px; margin-bottom: 10px; }
.file {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-size: 12.5px;
}
.file .fname { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file .fmeta { color: var(--mut); font-size: 11.5px; flex: 0 0 auto; }

.pages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 4px; }
@media (min-width: 520px) { .pages { grid-template-columns: repeat(4, 1fr); } }
.page {
  position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 6px 4px;
}
.page img, .page .ph {
  width: 100%; height: 92px; object-fit: contain; display: block;
  background: var(--bg); border-radius: 4px;
}
.page .ph { display: grid; place-items: center; color: var(--mut); font-size: 11px; }
.page .pno {
  position: absolute; top: 10px; left: 10px;
  background: rgba(22, 24, 29, .82); color: #fff;
  font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.page .pctl { display: flex; justify-content: space-between; gap: 2px; margin-top: 3px; }
.page .pctl button {
  appearance: none; background: none; border: 0; color: var(--mut);
  font-size: 12px; line-height: 1; padding: 6px 1px; min-width: 0; flex: 1 1 0;
  cursor: pointer; border-radius: 5px;
}
.page .pctl button:hover { background: var(--bg); color: var(--ink); }
.page .pctl button.del:hover { color: var(--bad); background: var(--bad-soft); }
.page .rot { position: absolute; top: 10px; right: 10px; font-size: 10.5px; font-weight: 700; color: #fff; background: rgba(35, 86, 216, .9); padding: 1px 5px; border-radius: 4px; }
.pages .empty-item { grid-column: 1 / -1; }
progress { width: 100%; height: 6px; margin-top: 10px; accent-color: var(--accent); }

/* ── 푸터·다이얼로그·토스트 ──────────────────────── */
footer {
  max-width: 720px; margin: 0 auto; padding: 16px 16px 28px;
  border-top: 1px solid var(--line);
  font-size: 12px; color: var(--mut);
}
footer .small { margin-top: 4px; font-size: 11.5px; }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  background: var(--card); color: var(--ink);
  max-width: min(420px, calc(100vw - 32px)); width: 100%;
}
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog h2 { font-size: 16px; margin-bottom: 8px; }
dialog ol, dialog ul { margin: 8px 0 10px; padding-left: 18px; list-style: disc; font-size: 13.5px; }
dialog li { margin: 4px 0; }
dialog .hint { margin: 8px 0 0; }
dialog .row .btn { flex: 0 0 auto; margin-left: auto; }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: #16181d; color: #fff; font-size: 13px; font-weight: 600;
  padding: 10px 16px; border-radius: 999px; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
@media (prefers-color-scheme: dark) { .toast { background: #e9edf5; color: #101318; } }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
