/* base.css — 바탕, 틀(상단 바·본문·탭 바), 공용 부품.
   색은 var(--*)만 쓴다. 색 리터럴과 !important는 쓰지 않는다. */

*,
*::before,
*::after { box-sizing: border-box; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html.is-locked { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-16);
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4, p, ol, ul, dl, dd, figure, blockquote { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { padding: 0; border: 0; background: none; cursor: pointer; }
a { color: inherit; }
img, svg { display: block; max-width: 100%; }
p { text-wrap: pretty; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tnum { font-variant-numeric: tabular-nums; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ── 틀 ─────────────────────────────────────────────── */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  height: calc(var(--top-h) + var(--safe-t));
  /* 넓은 화면에서는 안쪽 내용을 본문 단(--page-max)의 양 끝에 맞춘다 */
  padding: var(--safe-t) max(var(--gutter), var(--safe-r), calc((100% - var(--page-max)) / 2 + var(--gutter))) 0 max(var(--gutter), var(--safe-l), calc((100% - var(--page-max)) / 2 + var(--gutter)));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--s-2); min-width: 0; font-size: var(--fs-16); font-weight: 750; letter-spacing: -0.02em; text-decoration: none; }
.brand-mark { flex: none; width: 1.5rem; height: 1.5rem; border-radius: 6px; }
.topbar-actions { display: flex; align-items: center; gap: var(--s-1); }

.main {
  flex: 1; width: 100%; max-width: var(--page-max); margin-inline: auto;
  padding: var(--s-6) max(var(--gutter), var(--safe-r)) calc(var(--bar-h) + var(--safe-b) + var(--s-10)) max(var(--gutter), var(--safe-l));
}
.main:focus { outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  height: calc(var(--bar-h) + var(--safe-b));
  padding: 0 max(var(--safe-r), calc((100% - var(--page-max)) / 2)) var(--safe-b) max(var(--safe-l), calc((100% - var(--page-max)) / 2));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--ink-faint); font-size: var(--fs-12); font-weight: 600; text-decoration: none;
  transition: color var(--t-1) var(--ease);
}
.tab::before {
  content: ""; position: absolute; top: -1px; left: 50%; width: 2.5rem; height: 2px;
  background: var(--accent); transform: translateX(-50%) scaleX(0);
  transition: transform var(--t-2) var(--ease);
}
.tab.is-active { color: var(--ink); }
.tab.is-active::before { transform: translateX(-50%) scaleX(1); }
.tab:focus-visible { outline-offset: -4px; }

/* ── 버튼 ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 2.75rem; padding: 0 var(--s-4);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-15); font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
  transition: transform var(--t-1) var(--ease), background-color var(--t-1) var(--ease), border-color var(--t-1) var(--ease);
}
.btn:active { transform: scale(0.96); }
.btn--primary { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.btn--quiet { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--sm { min-height: 2.5rem; padding: 0 var(--s-3); font-size: var(--fs-13); }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 2.5rem; height: 2.5rem; border-radius: var(--r-sm); color: var(--ink-soft);
  transition: transform var(--t-1) var(--ease), background-color var(--t-1) var(--ease);
}
.icon-btn:active { transform: scale(0.96); }

@media (hover: hover) {
  .btn:hover { border-color: var(--ink-faint); }
  .btn--primary:hover { border-color: var(--accent); }
  .btn--quiet:hover { background: var(--surface-sunk); border-color: transparent; }
  .icon-btn:hover { background: var(--surface-sunk); }
  .tab:hover { color: var(--ink); }
}

/* ── 상태 칩·표지 ───────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 0.375rem; flex: none;
  min-height: 1.5rem; padding: 0 0.5rem; border-radius: var(--r-pill);
  background: var(--surface-sunk); color: var(--ink-soft);
  font-size: var(--fs-12); font-weight: 600; line-height: 1; white-space: nowrap;
}
.chip::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.chip--ok { background: var(--accent-soft); color: var(--accent); }
.chip--wait { background: var(--lack-soft); color: var(--lack); }
.chip--bad { background: var(--danger-soft); color: var(--danger); }
/* 누를 수 있는 칩: 보이는 크기는 그대로 두고, 누르는 자리만 40px로 넓힌다 */
button.chip { position: relative; cursor: pointer; }
button.chip::after { content: ""; position: absolute; inset: -0.5rem -0.25rem; }

.tag {
  display: inline-flex; align-items: center; flex: none;
  min-height: 1.375rem; padding: 0 0.4375rem;
  border: 1px solid var(--line); border-radius: var(--r-xs);
  color: var(--ink-soft); font-size: var(--fs-12); line-height: 1; white-space: nowrap;
}

/* 도감 번호 */
.no {
  display: inline-flex; align-items: center; flex: none;
  min-height: 1.375rem; padding: 0 0.375rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-xs);
  color: var(--ink-soft); font-size: var(--fs-12); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.no--none { border-style: dashed; color: var(--ink-faint); font-weight: 600; }

/* ── 입력 ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 0.375rem; min-width: 0; }
.field-label { font-size: var(--fs-13); font-weight: 600; color: var(--ink-soft); }
.field-help { font-size: var(--fs-12); line-height: 1.5; color: var(--ink-faint); }
.field-error { font-size: var(--fs-12); line-height: 1.5; color: var(--danger); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s-3); }

.input,
.textarea {
  width: 100%; min-height: 2.75rem; padding: 0.625rem 0.75rem;
  border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font-size: var(--fs-16); line-height: 1.5;
}
.textarea { min-height: 5.5rem; resize: vertical; }
.input::placeholder,
.textarea::placeholder { color: var(--ink-faint); opacity: 1; }
.input:focus-visible,
.textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.input--num { font-variant-numeric: tabular-nums; }

/* ── 구역 머리 ──────────────────────────────────────── */
.sec { min-width: 0; display: flex; flex-direction: column; gap: var(--s-4); scroll-margin-top: calc(var(--top-h) + var(--safe-t) + var(--s-4)); }
.sec-head { display: flex; flex-direction: column; gap: var(--s-1); padding-top: 0.875rem; border-top: 2px solid var(--ink); }
.sec-head--have { border-top-color: var(--accent); }
.sec-head--lack { border-top-color: var(--lack); }
.sec-title { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-20); font-weight: 750; line-height: 1.35; letter-spacing: -0.02em; }
.sec-title .count { font-size: var(--fs-14); font-weight: 600; color: var(--ink-faint); font-variant-numeric: tabular-nums; letter-spacing: 0; }
.sec-cap { font-size: var(--fs-13); line-height: 1.55; color: var(--ink-faint); }
.sec-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }

.note { font-size: var(--fs-13); line-height: 1.6; color: var(--ink-faint); }
.empty {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-5) var(--s-4); border: 1px dashed var(--line-strong); border-radius: var(--r-md);
  color: var(--ink-soft); font-size: var(--fs-14); line-height: 1.6;
}
.empty-title { font-size: var(--fs-15); font-weight: 700; color: var(--ink); }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-3);
  padding: var(--s-3) var(--s-4); border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); font-size: var(--fs-14); line-height: 1.55; color: var(--ink-soft);
}
.banner b { color: var(--ink); font-weight: 700; }

/* ── 겹침 창(모달)·시트 ─────────────────────────────── */
.layer {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: end center;
  background: var(--scrim);
}
.dialog {
  width: 100%; max-width: 34rem; max-height: calc(100dvh - var(--safe-t) - var(--s-4));
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--surface);
}
.dialog:focus { outline: none; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-3) var(--s-2) var(--s-5); }
.dialog-title { font-size: var(--fs-18); font-weight: 750; line-height: 1.35; letter-spacing: -0.02em; }
.dialog-body { display: flex; flex-direction: column; gap: var(--s-4); padding: var(--s-2) var(--s-5) var(--s-5); overflow-y: auto; overscroll-behavior: contain; }
.dialog-body > p { font-size: var(--fs-15); line-height: 1.6; color: var(--ink-soft); }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  padding: var(--s-3) var(--s-5) calc(var(--s-4) + var(--safe-b));
  border-top: 1px solid var(--line);
}
.dialog--page {
  max-width: none; width: 100%; height: 100dvh; max-height: none;
  border: 0; border-radius: 0; background: var(--bg);
}
.dialog--page > .dialog-head { padding-top: calc(var(--s-3) + var(--safe-t)); border-bottom: 1px solid var(--line); }

@media (min-width: 37.5rem) {
  .layer { place-items: center; padding: var(--s-6); }
  .dialog { border-bottom: 1px solid var(--line); border-radius: var(--r-lg); max-height: calc(100dvh - var(--s-12)); }
  .dialog--page { border-radius: 0; max-height: none; }
  .layer--page { padding: 0; }
}

.menu { display: flex; flex-direction: column; }
.menu-item {
  display: flex; align-items: center; gap: var(--s-3);
  min-height: 3rem; padding: 0 var(--s-2); border-radius: var(--r-sm);
  font-size: var(--fs-16); font-weight: 500; text-align: left;
  transition: background-color var(--t-1) var(--ease);
}
.menu-item:active { background: var(--surface-sunk); }
.menu-item--danger { color: var(--danger); }
.menu-item small { margin-left: auto; font-size: var(--fs-12); color: var(--ink-faint); }
@media (hover: hover) { .menu-item:hover { background: var(--surface-sunk); } }

/* 알림은 위쪽에 뜬다. 아래쪽은 시트와 주요 단추의 자리라, 가리면 다음 동작을 막는다. */
.toasts {
  position: fixed; left: 0; right: 0; top: calc(var(--top-h) + var(--safe-t) + var(--s-2)); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  padding-inline: var(--gutter); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s-3); max-width: 30rem;
  padding: 0.625rem 0.875rem; border-radius: var(--r-md);
  background: var(--ink); color: var(--bg);
  font-size: var(--fs-14); font-weight: 500; line-height: 1.5;
}
.toast button { flex: none; font-weight: 700; text-decoration: underline; text-underline-offset: 0.2em; pointer-events: auto; }

@media (prefers-reduced-motion: no-preference) {
  .layer { animation: fade var(--t-2) var(--ease); }
  .dialog { animation: rise var(--t-3) var(--ease); }
  .toast { animation: drop var(--t-2) var(--ease); }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── 설정 ───────────────────────────────────────────── */
.set-group { display: flex; flex-direction: column; gap: var(--s-3); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.set-group:first-child { padding-top: 0; border-top: 0; }
.set-title { font-size: var(--fs-15); font-weight: 700; }
.set-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); }
.steps { display: flex; flex-direction: column; gap: var(--s-1); padding-left: 1.25rem; list-style: decimal; font-size: var(--fs-13); line-height: 1.6; color: var(--ink-soft); }
.steps li::marker { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--surface-sunk); }
.seg button { min-height: 2.5rem; padding: 0 var(--s-3); border-radius: 6px; font-size: var(--fs-13); font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); }

/* ── 숨김: 맨 끝에 둔다 ─────────────────────────────── */
[hidden] { display: none; }
