:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --text: #2b2a27;
  --muted: #7b776d;
  --line: #e6e1d6;
  --primary: #4a7c59;
  --primary-ink: #ffffff;
  --husband: #4f8fe8;
  --wife: #f47aa6;
  --both: #e2a62b;
  --hidden: #e9ecef;
  --danger: #c4483e;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181a;
    --surface: #222427;
    --text: #ecebe7;
    --muted: #9c9a93;
    --line: #34373b;
    --primary: #6aa77b;
    --hidden: #2c3035;
  }
}
:root[data-theme="dark"] {
  --bg: #17181a; --surface: #222427; --text: #ecebe7; --muted: #9c9a93;
  --line: #34373b; --primary: #6aa77b; --hidden: #2c3035;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1, h2 { margin: 0; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; margin: 2px 0 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--bg);
}
.sync-badge {
  font-size: 12px; padding: 3px 9px; border-radius: 99px;
  background: var(--line); color: var(--muted);
}
.sync-badge.ok { background: #d8eedf; color: #2f6b41; }
.sync-badge.err { background: #f6dcd9; color: var(--danger); }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; border: 1px solid var(--line);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.lamb-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
.lamb-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; }
.streak { font-size: 12px; color: var(--muted); }
canvas.lamb { width: 100%; display: block; border-radius: 8px; image-rendering: pixelated; }
.bar { height: 6px; background: var(--line); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent, var(--primary)); border-radius: 99px; transition: width .4s; }
.stat { font-size: 12px; color: var(--muted); margin-top: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 99px; padding: 8px 14px; font-size: 14px; font-family: inherit; cursor: pointer;
}
.chip.mine { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .sp { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--spouse-accent); border: 2px solid var(--surface); }
.pace { font-size: 13px; color: var(--muted); margin: 12px 0; }

.together { display: flex; justify-content: space-between; align-items: center; }
.big { font-size: 28px; font-weight: 700; color: var(--both); }
.big small { font-size: 13px; color: var(--muted); font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* 읽기표 */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { border: 0; background: transparent; padding: 9px; border-radius: 10px; font: inherit; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; }
.version-note { margin: 0 4px 8px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 0 4px 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.dot.mine { background: var(--accent); }
.dot.spouse { background: var(--spouse-accent); }
.dot.both { background: var(--both); }

.book { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; overflow: hidden; }
.book-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 13px 14px; border: 0; background: none; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.book-row .name { flex: 1; font-weight: 600; font-size: 15px; }
.book-row .cnt { font-size: 12px; color: var(--muted); min-width: 52px; text-align: right; }
.book-row .mini { width: 56px; height: 5px; background: var(--line); border-radius: 99px; overflow: hidden; }
.book-row .mini i { display: block; height: 100%; background: var(--accent); }
.book.done .name::after { content: " ✓"; color: var(--primary); }
.book-body { display: none; padding: 0 12px 12px; }
.book.open .book-body { display: block; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.ch {
  position: relative; height: 40px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-size: 14px; cursor: pointer;
}
.ch.mine { background: var(--accent); border-color: var(--accent); color: #fff; }
.ch.both { background: var(--both); border-color: var(--both); color: #fff; }
.ch.spouse::after, .ch.both::after {
  content: ""; position: absolute; right: 3px; top: 3px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--spouse-accent); border: 1px solid #fff;
}
.ch.both::after { content: "♥"; background: none; border: 0; color: #fff; font-size: 9px; width: auto; height: auto; top: 1px; right: 3px; }
.book-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.book-actions .btn { min-height: 36px; font-size: 13px; }

/* 폼 */
.form h2 { margin-bottom: 4px; }
.form label.field { display: block; margin-top: 14px; font-size: 13px; color: var(--muted); }
.form input[type=text], .form input[type=date], .form select {
  display: block; width: 100%; margin-top: 6px; min-height: 44px; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
}
.radios { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.radios label { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); font-size: 15px; cursor: pointer; }
.radios input { display: none; }
.radios label:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); font-weight: 600; }
.chars { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.char-opt { border: 2px solid var(--line); border-radius: 12px; padding: 8px; cursor: pointer; color: var(--text); text-align: center; }
.char-opt input { display: none; }
.char-opt canvas { width: 100%; display: block; border-radius: 6px; image-rendering: pixelated; }
.char-opt b { display: block; font-size: 14px; margin-top: 6px; }
.char-opt small { display: block; font-size: 11px; color: var(--muted); line-height: 1.35; }
.char-opt:has(input:checked) { border-color: var(--primary); }
.code-row { display: flex; gap: 8px; margin-top: 6px; }
.code-row input { margin-top: 0 !important; text-transform: uppercase; letter-spacing: 2px; }
.code-row .btn { flex-shrink: 0; }

dialog { border: 0; border-radius: 20px; padding: 20px; width: min(92vw, 480px); background: var(--surface); color: var(--text); max-height: 90vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.celebrate { text-align: center; }
.celebrate canvas { width: 70%; margin: 0 auto 12px; display: block; border-radius: 8px; image-rendering: pixelated; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { border: 0; background: none; font: inherit; font-size: 12px; color: var(--muted); padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .6; }
.tabbar button.on { color: var(--text); font-weight: 600; }
.tabbar button.on span { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #2b2a27; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
