:root {
  --bg: #0e0f12;
  --band: #1b1d22;
  --line: #22242a;
  --line2: #2a2c31;
  --field: #17191d;
  --fieldline: #4a4e57;
  --fg: #f3f3f3;
  --mute: #a3a9b3;
  --accent: #c8ff2e;
  --on-accent: #0e0f12;
  --warn: #ff7a59;
  --cmp: #7aa2ff;
  --r: 4px;
  --tabh: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: 'Pretendard Variable', Pretendard, system-ui, sans-serif;
  font-size: 15px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--tabh) + var(--safe-b) + 24px);
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mute { color: var(--mute); }
.small { font-size: 13px; }
.up { color: var(--accent); }
.down { color: var(--warn); }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 머리 */
.hd { display: flex; justify-content: space-between; align-items: center; min-height: 52px;
  padding: 6px 8px 6px 16px; border-bottom: 2px solid var(--accent); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.hd h1, .hd h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: .4px; }
.hd .sub { font-size: 13px; color: var(--mute); }
.iconbtn { min-width: 44px; min-height: 44px; border: 0; background: none; border-radius: var(--r); font-size: 15px; color: var(--fg); padding: 0 10px; }
.back { font-weight: 800; font-size: 17px; text-align: left; padding-left: 4px; }

/* 크게 보이는 기록 */
.hero { padding: 14px 16px 16px; border-bottom: 1px solid var(--line2); }
.hero .k { font-size: 13px; color: var(--mute); }
.hero .v { font-size: 42px; font-weight: 800; color: var(--accent); line-height: 1.08; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.hero .v .u { font-size: 17px; }
.hero .v .lb { font-size: 17px; color: var(--mute); font-weight: 600; }
.hero .d { font-size: 14px; color: var(--mute); margin-top: 4px; }

/* 칸 */
.sec h3 { margin: 0; padding: 8px 16px; font-size: 13px; font-weight: 700; letter-spacing: .6px;
  background: var(--band); color: #d3d6dc; border-top: 1px solid var(--line2); border-bottom: 1px solid var(--line2);
  display: flex; justify-content: space-between; gap: 8px; }
.sec h3 .r { font-weight: 500; color: var(--mute); letter-spacing: 0; }
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center;
  min-height: 48px; padding: 6px 16px; border-bottom: 1px solid var(--line); width: 100%; text-align: left;
  background: none; border-left: 0; border-right: 0; border-top: 0; color: var(--fg); }
button.row:active { background: var(--field); }
.row .n { min-width: 0; overflow-wrap: anywhere; }
.row .n small { color: var(--mute); font-size: 13px; margin-left: 4px; }
.row .v { text-align: right; white-space: nowrap; }
.row .x { text-align: right; white-space: nowrap; color: var(--mute); font-size: 14px; min-width: 3.2em; }
.row.dim .n { color: var(--mute); }
.lb { color: var(--mute); font-size: 13px; margin-left: 3px; }
.note { padding: 8px 16px 10px; font-size: 13px; color: var(--mute); }

/* 도장 */
.stamp { display: inline-block; border: 1.5px solid var(--accent); color: var(--accent); font-size: 12px; font-weight: 800;
  line-height: 1.1; padding: 1px 4px; margin-left: 6px; transform: rotate(-6deg); letter-spacing: .5px; vertical-align: 2px; border-radius: 2px; }
.stamp.big { font-size: 14px; padding: 2px 6px; align-self: center; }
.stamp.pop { animation: pop .4s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { from { transform: rotate(-30deg) scale(2.2); opacity: 0; } to { transform: rotate(-6deg) scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .stamp.pop { animation: none; } }

/* 막대 */
.bar { position: relative; height: 8px; background: var(--line); width: 100%; min-width: 80px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--fg); }
.bar s { position: absolute; top: 0; bottom: 0; background: rgba(200, 255, 46, .28); text-decoration: none; }
.bar i { z-index: 1; }
.bar b { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--accent); }
.row.body { grid-template-columns: 5.2em minmax(60px, 1fr) auto; }

/* 그래프 */
.chart { display: block; width: 100%; height: auto; background: #121317; }
.chart text { fill: var(--mute); font-size: 12px; font-family: inherit; }
.legend { padding: 6px 16px 10px; font-size: 13px; color: var(--mute); display: flex; gap: 14px; flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--accent); vertical-align: middle; margin-right: 5px; }
.legend .sw.cmp { border-top: 2px dashed var(--cmp); }

/* 빈 화면 */
.empty { padding: 40px 20px; text-align: center; }
.empty p { color: var(--mute); margin: 0 0 16px; }

/* 단추 */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px;
  border-radius: var(--r); border: 1px solid var(--fieldline); background: var(--field); font-weight: 700; color: var(--fg); }
.btn.main { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.danger { color: var(--warn); border-color: var(--warn); background: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.wide { width: 100%; }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 8px 8px 16px;
  background: #2a2410; color: #ffe9a8; font-size: 14px; border-bottom: 1px solid #4d4218; }
.banner .btn { min-height: 44px; padding: 0 12px; }

/* 밑줄 탭(크로스핏 안) */
.subtabs { display: flex; border-bottom: 1px solid var(--line2); }
.subtabs button { flex: 1; min-height: 48px; background: none; border: 0; color: var(--mute); font-weight: 600; }
.subtabs button[aria-selected=true] { color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 800; }

/* 아래 탭 */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: #0b0c0e;
  border-top: 1px solid var(--line2); padding-bottom: var(--safe-b); }
nav.tabs button { flex: 1; min-height: var(--tabh); background: none; border: 0; color: var(--mute); font-size: 14px; font-weight: 600; }
nav.tabs button[aria-current=page] { color: var(--accent); font-weight: 800; box-shadow: inset 0 2px 0 var(--accent); }
#add { position: fixed; right: 14px; bottom: calc(var(--tabh) + var(--safe-b) + 14px); z-index: 11; min-height: 52px; padding: 0 18px;
  border-radius: var(--r); border: 0; background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 16px;
  box-shadow: 0 0 0 3px var(--bg); }
body.sheet-open #add, body.sheet-open nav.tabs { display: none; }

/* 올라오는 창 / 상세 */
#layer:empty { display: none; }
.layer { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: calc(var(--safe-b) + 24px); }
.sheet { animation: up .22s cubic-bezier(.2, .8, .2, 1); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

/* 입력 */
.kinds { display: flex; border-bottom: 1px solid var(--line2); overflow-x: auto; scrollbar-width: none; }
.kinds button { flex: 1 0 auto; min-height: 48px; padding: 0 10px; background: none; border: 0; color: var(--mute); font-weight: 600; font-size: 14px; }
.kinds button[aria-selected=true] { color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent); font-weight: 800; }
.f { padding: 10px 16px 0; }
.f > label, .f > .lab { display: block; font-size: 13px; color: var(--mute); margin-bottom: 6px; }
.in { width: 100%; min-height: 48px; border: 1px solid var(--fieldline); border-radius: var(--r); background: var(--field);
  padding: 0 12px; font-size: 16px; }
select.in { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
textarea.in { padding: 10px 12px; min-height: 64px; resize: vertical; }
.in.big { font-size: 20px; font-weight: 700; }
.line { display: flex; gap: 8px; align-items: stretch; }
.line > * { flex: 1; min-width: 0; }
.seg { display: flex; border: 1px solid var(--fieldline); border-radius: var(--r); overflow: hidden; }
.seg button { flex: 1; min-height: 46px; background: none; border: 0; color: var(--mute); font-weight: 600; padding: 0 6px; }
.seg button + button { border-left: 1px solid var(--fieldline); }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--on-accent); font-weight: 800; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.hint { font-size: 13px; color: var(--mute); margin-top: 6px; }
.err { font-size: 14px; color: var(--warn); margin-top: 6px; }
.preview { margin: 14px 16px 0; padding: 10px 12px; border: 1px dashed var(--fieldline); border-radius: var(--r); font-size: 14px; }
.actions { display: flex; gap: 8px; padding: 16px; }
.actions .btn { flex: 1; }
.file { position: relative; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* 표(퍼센트) */
.pct .row { grid-template-columns: 3.6em minmax(0, 1fr); }
.more { width: 100%; min-height: 48px; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--mute); }

/* 설정 */
.set .row { grid-template-columns: minmax(0, 1fr) auto; }
.dialog { margin: 16px; padding: 14px; border: 1px solid var(--fieldline); border-radius: var(--r); background: var(--field); }
.dialog p { margin: 0 0 12px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabh) + var(--safe-b) + 80px); z-index: 30; padding: 12px 14px;
  background: var(--fg); color: var(--bg); border-radius: var(--r); font-weight: 700; text-align: center; }
