:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --primary: #141413;
  --on-primary: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --danger-text: #b42323;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --font: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #252523;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --grid: #2c2c2a;
    --axis: #383835;
    --primary: #f0efec;
    --on-primary: #111110;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-text: #0ca30c;
    --danger-text: #ee7a7a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #252523;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --border: rgba(255, 255, 255, 0.10);
  --grid: #2c2c2a;
  --axis: #383835;
  --primary: #f0efec;
  --on-primary: #111110;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-text: #0ca30c;
  --danger-text: #ee7a7a;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px 120px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

/* 상단 바 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.topbar .inner {
  max-width: 640px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 8px; min-height: 56px;
}
.topbar .title { flex: 1; min-width: 0; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { font-weight: 800; letter-spacing: 0.08em; font-size: 15px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text); font-size: 20px;
  display: inline-grid; place-items: center; cursor: pointer; text-decoration: none; flex: none;
}
.icon-btn:active { background: var(--surface-2); }

/* 카드 */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 24px 2px 10px; }
.section-title h2 { font-size: 16px; }

/* 버튼 */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; font-size: 15px;
  min-height: 46px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.danger { color: var(--danger-text); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; font-size: 14px; padding: 0 12px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }

.fab {
  position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); border-radius: 999px; padding: 0 22px; min-height: 54px;
}

/* 폼 */
.field { display: block; }
.field + .field, .field + .field-row, .field-row + .field, .field-row + .field-row { margin-top: 14px; }
.field > span.label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid transparent; border-radius: 10px;
  padding: 11px 12px; min-height: 46px; outline: none;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--text-2); background: var(--surface); }
.unit { position: relative; }
.unit input { padding-right: 38px; }
.unit::after { content: attr(data-unit); position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: grid; place-items: center; min-height: 40px; border-radius: 8px;
  font-size: 14px; font-weight: 600; color: var(--text-2); cursor: pointer; text-align: center; padding: 0 4px;
}
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--text-2); }

/* 칩 */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.chip b { font-weight: 800; }
.chip.tone-good b { color: var(--good); }
.chip.tone-warning { box-shadow: inset 0 0 0 1px var(--warning); }
.chip.tone-warning b { color: #b07a00; }
.chip.tone-serious { box-shadow: inset 0 0 0 1px var(--serious); }
.chip.tone-serious b { color: var(--serious); }
.chip.tone-critical { box-shadow: inset 0 0 0 1px var(--critical); }
.chip.tone-critical b { color: var(--critical); }
.chip.tone-neutral b { color: var(--muted); }
.chip.ok { color: var(--good-text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* 리스트 */
.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--border); }
.list a.item, .list .item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-decoration: none; color: inherit; min-height: 60px;
}
.list a.item:active { background: var(--surface-2); }
.item .avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); flex: none;
  display: grid; place-items: center; font-weight: 700; color: var(--text-2);
}
.item .meta { flex: 1; min-width: 0; }
.item .name { font-weight: 650; }
.item .chev { color: var(--muted); font-size: 18px; }
.item.inactive { opacity: .5; }

/* 반 카드 */
.class-grid { display: grid; gap: 10px; }
.class-card { display: block; text-decoration: none; color: inherit; }
.class-card:active { transform: scale(.99); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--text-2); border-radius: 99px; }

/* 기록 타일 */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; min-width: 0; }
.tile .k { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); font-weight: 600; }
.tile .k i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tile .v { font-size: 24px; font-weight: 750; margin-top: 4px; letter-spacing: -0.02em; }
.tile .v small { font-size: 13px; font-weight: 600; color: var(--text-2); margin-left: 1px; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
.delta { font-size: 12px; font-weight: 600; color: var(--text-2); display: block; margin-top: 2px; }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--danger-text); }
.delta .muted { font-weight: 400; }

/* 테이블 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 8px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
tbody tr + tr td { border-top: 1px solid var(--border); }
tbody tr.memo td { border-top: 0; padding-top: 0; text-align: left; white-space: normal; color: var(--text-2); font-size: 13px; }
.pr { color: var(--good-text); font-weight: 700; }

/* 차트 */
.chart { position: relative; }
.chart .legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.chart .legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart .legend i { width: 10px; height: 10px; border-radius: 3px; }
.chart-plot { position: relative; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dlabel { fill: var(--text-2); font-size: 11.5px; font-weight: 600; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .empty { color: var(--muted); text-align: center; padding: 32px 0; }
.chart .tooltip {
  position: absolute; top: 0; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .15); padding: 8px 10px; font-size: 12.5px; min-width: 140px;
}
.tip-date { font-weight: 700; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.tip-row i { width: 8px; height: 8px; border-radius: 50%; }
.tip-row b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; scrollbar-width: none; }
.tabs button {
  border: 1px solid var(--border); background: transparent; color: var(--text-2); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 7px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--primary); color: var(--on-primary); border-color: transparent; }

/* 정보 목록 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }
.note { white-space: pre-wrap; font-size: 14px; color: var(--text-2); margin-top: 8px; }

/* 다이얼로그 & 토스트 */
dialog {
  border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .dlg { padding: 20px; }
dialog h2 { margin-bottom: 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--primary); color: var(--on-primary); padding: 11px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; z-index: 100; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.toast.error { background: var(--critical); color: #fff; }

.steps { display: flex; gap: 6px; margin: 4px 0 16px; }
.steps i { flex: 1; height: 4px; border-radius: 99px; background: var(--surface-2); }
.steps i.on { background: var(--primary); }

.choice { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.choice .grow b { display: block; }

.measure-card .name { font-weight: 700; }
.measure-card .field-row { grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.measure-card input { padding: 9px 8px; text-align: center; min-height: 44px; }
.measure-card .lbl { font-size: 11.5px; color: var(--muted); text-align: center; margin-bottom: 4px; }

/* 켜기/끄기 스위치 */
.switch { position: relative; flex: none; width: 50px; height: 30px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--axis); transition: background .15s; }
.switch span::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s;
}
.switch input:checked + span { background: var(--good-text); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--text-2); outline-offset: 2px; }

.center-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.empty-state { text-align: center; color: var(--muted); padding: 32px 16px; }
.spinner { text-align: center; color: var(--muted); padding: 48px 0; }

@media (max-width: 380px) {
  .tile .v { font-size: 20px; }
  .tiles { gap: 6px; }
  .tile { padding: 10px; }
}
