:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #5b6676;
  --line: #d9dee6;
  --brand: #1f3a5f;
  --accent: #e4572e;
  --ok: #2a9d8f;
  --day: #e9a23b;
  --night: #3d5a98;
  --warn-bg: #fff4e5;
  --warn-line: #f0b45a;
}
body.night {
  --bg: #0b0d10;
  --card: #14171c;
  --ink: #c9b8a8;
  --muted: #8a7f74;
  --line: #2a2f36;
  --brand: #5a3a2a;
  --accent: #b5462a;
  --ok: #3c7a70;
  --day: #8a6a30;
  --night: #4a5f8a;
  --warn-bg: #1d1712;
  --warn-line: #5a4325;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}
a { color: var(--brand); }
body.night a { color: #c08a5a; }
.app { max-width: 760px; margin: 0 auto; padding: 0 14px 40px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 0 6px; }
.top h1 { font-size: 1.15rem; margin: 0; }

button {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; padding: 10px 14px; min-height: 44px;
}
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { color: #b3261e; border-color: #e3b4b0; }
body.night button.danger { color: #c46a5a; border-color: #4a2c26; }
body.night button { color: #e6d6c6; }

.tool, .log, .guide { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 10px 0 14px; }

.start {
  display: block; width: 100%; font-size: 1.6rem; font-weight: 700; padding: 22px 10px; min-height: 84px;
  border-radius: 16px; background: var(--accent); border-color: var(--accent); letter-spacing: 0.05em;
}
.start.on { background: var(--ink); border-color: var(--ink); color: var(--card); }
.hint { text-align: center; color: var(--muted); margin: 8px 0 4px; font-size: 0.92rem; }

.meter { margin-top: 8px; }
.big { text-align: center; font-size: 4rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.bar { position: relative; height: 14px; background: var(--line); border-radius: 7px; overflow: hidden; margin: 8px 0; }
.fill { height: 100%; width: 0; background: var(--ok); transition: width 0.1s linear; }
.fill.over { background: var(--accent); }
.th { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); left: 50%; }
#live, #timeline { width: 100%; height: auto; display: block; background: var(--bg); border-radius: 8px; }
.row { display: flex; justify-content: space-between; }
.small { font-size: 0.85rem; color: var(--muted); }

.settings { margin-top: 14px; display: grid; gap: 10px; }
.settings label { display: grid; gap: 2px; font-weight: 600; }
.settings input[type=range] { width: 100%; height: 32px; accent-color: var(--accent); }
.settings p { margin: 0; }

.note { background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; }
.install { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: 0.92rem; }

.log h2 { margin: 0 0 8px; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.count { background: var(--bg); border-radius: 99px; padding: 0 10px; font-size: 0.9rem; }
.legend { margin: 6px 0 10px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin: 0 3px 0 6px; }
.dot.day { background: var(--day); } .dot.night { background: var(--night); }
.range { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.range label { display: grid; font-size: 0.85rem; color: var(--muted); }
.range input { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tablewrap { overflow-x: auto; margin-top: 12px; max-height: 360px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.events th, .events td { border-bottom: 1px solid var(--line); padding: 6px 6px; text-align: right; font-size: 0.9rem; white-space: nowrap; }
.events th:nth-child(2), .events td:nth-child(2), .events th:nth-child(7), .events td:nth-child(7) { text-align: center; }
.events thead th { position: sticky; top: 0; background: var(--card); }
.empty { text-align: center !important; color: var(--muted); padding: 18px !important; }
.privacy { margin-bottom: 0; }

/* 광고 자리: 비어 있으면 보이지 않음 */
.ad-slot { margin: 14px 0; }
.ad-slot:empty { display: none; }

.guide h2 { font-size: 1.08rem; margin: 18px 0 6px; }
.guide h2:first-child { margin-top: 0; }
.guide ol, .guide ul { padding-left: 20px; }
.guide li { margin: 4px 0; }
.std { margin: 8px 0; }
.std caption { text-align: left; font-weight: 600; padding-bottom: 4px; }
.std th, .std td { border: 1px solid var(--line); padding: 6px; text-align: center; font-size: 0.9rem; }
.std td:nth-child(n+2) { font-weight: 700; }
details { border-top: 1px solid var(--line); padding: 8px 0; }
summary { cursor: pointer; font-weight: 600; }
.foot { text-align: center; }

@media (min-width: 640px) {
  .actions { grid-template-columns: repeat(4, auto); justify-content: start; }
  .top h1 { font-size: 1.35rem; }
}

/* ===== 기록표 미리보기 ===== */
.report-overlay { position: fixed; inset: 0; background: #3a3f47; overflow: auto; z-index: 10; padding: 12px; }
.report-bar { position: sticky; top: 0; display: flex; gap: 8px; justify-content: center; padding-bottom: 10px; z-index: 2; }
.report-bar .ghost { background: #fff; color: #1b2430; }
.sheet {
  background: #fff; color: #111; width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto;
  padding: 14mm 14mm; font-size: 10.5pt; line-height: 1.45; position: relative;
}
.sheet h1 { font-size: 17pt; text-align: center; margin: 0 0 4mm; }
.sheet h2 { font-size: 11.5pt; margin: 5mm 0 2mm; border-left: 4px solid #1f3a5f; padding-left: 6px; }
.sheet table { width: 100%; border-collapse: collapse; }
.sheet th, .sheet td { border: 1px solid #888; padding: 3px 5px; text-align: center; font-size: 9.5pt; }
.sheet th { background: #eef1f5; }
.sheet .meta th { width: 24%; text-align: left; }
.sheet .meta td { text-align: left; }
.sheet .chartimg { width: 100%; border: 1px solid #ccc; display: block; }
.sheet .disclaimer { border: 1.5px solid #c0392b; padding: 3mm; margin-top: 5mm; font-size: 9.5pt; }
.sheet .sign { margin-top: 6mm; display: grid; grid-template-columns: 1fr 1fr; gap: 4mm 10mm; font-size: 10pt; }
.sheet .sign div { border-bottom: 1px solid #333; padding-bottom: 1mm; }
.sheet .memo { height: 22mm; border: 1px solid #888; }
.sheet .src { font-size: 8.5pt; color: #444; }
.sheet .sample-stamp {
  position: absolute; top: 10mm; right: 12mm; border: 2px solid #c0392b; color: #c0392b; font-weight: 800;
  padding: 1mm 4mm; transform: rotate(6deg); font-size: 12pt;
}
.sheet tr { break-inside: avoid; }
@media screen and (max-width: 600px) {
  .sheet { padding: 16px 10px; font-size: 9pt; min-height: 0; }
  .sheet h1 { font-size: 14pt; }
  .sheet th, .sheet td { font-size: 8pt; padding: 2px 3px; }
  .sheet .sample-stamp { position: static; display: block; width: max-content; margin: 0 auto 6px; transform: none; font-size: 10pt; }
}
.sheet thead { display: table-header-group; }

@media print {
  @page { size: A4; margin: 12mm 13mm; }
  body { background: #fff !important; }
  .app, .report-bar { display: none !important; }
  .report-overlay { position: static; background: none; padding: 0; overflow: visible; display: block !important; }
  .sheet { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
  .sheet .sample-stamp { top: 0; right: 0; }
  .sheet th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
