:root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface: #ffffff;
  --text: #191919;
  --text-2: #666666;
  --line: rgba(11, 11, 11, 0.12);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --blue: #257de0;
  --blue-strong: #1b64be;
  --blue-wash: rgba(37, 125, 224, 0.1);
  --plan: #c2c2c2;
  --good: #0aac23;
  --warning: #fbb315;
  --serious: #f18a59;
  --critical: #dc3c3d;
  --fig: #191919;
  --fig-far: #a9a9a9;
  --prop: #b9b2a6;
  --water: rgba(37, 125, 224, 0.12);
  --on-blue: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --text: #efefef;
    --text-2: #9c9c9c;
    --line: rgba(255, 255, 255, 0.13);
    --grid: #303030;
    --axis: #474747;
    --blue: #338ced;
    --blue-strong: #6aabf1;
    --blue-wash: rgba(51, 140, 237, 0.16);
    --plan: #555555;
    --fig: #efefef;
    --fig-far: #6c6c6c;
    --prop: #6e675c;
    --water: rgba(51, 140, 237, 0.2);
    --on-blue: #0b0b0b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0b0b;
  --surface: #191919;
  --text: #efefef;
  --text-2: #9c9c9c;
  --line: rgba(255, 255, 255, 0.13);
  --grid: #303030;
  --axis: #474747;
  --blue: #338ced;
  --blue-strong: #6aabf1;
  --blue-wash: rgba(51, 140, 237, 0.16);
  --plan: #555555;
  --fig: #efefef;
  --fig-far: #6c6c6c;
  --prop: #6e675c;
  --water: rgba(51, 140, 237, 0.2);
  --on-blue: #0b0b0b;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.35; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
a { color: var(--blue-strong); }
h1 { font-size: 22px; margin: 4px 0 12px; line-height: 1.3; }
h2 { font-size: 19px; margin: 2px 0 8px; line-height: 1.35; }
h3 { font-size: 15px; margin: 16px 0 6px; }
.card > h3:first-child { margin-top: 0; }
p { margin: 6px 0; }
ul, ol { margin: 6px 0; padding-left: 20px; }
li { margin: 3px 0; }
.muted { color: var(--text-2); font-size: 13px; }
small { color: var(--text-2); font-size: 12px; }
.center { text-align: center; }
.eyebrow { color: var(--text-2); font-size: 12px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  max-width: 560px; margin: 0 auto; padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--page);
}
.brand { font-weight: 700; }
.sync { margin-left: auto; margin-right: 4px; border: 0; background: none; padding: 4px 6px; font-size: 12px; color: var(--text-2); }
.sync:disabled { opacity: 1; }
.sync[data-state="error"] { color: var(--text); text-decoration: underline; }
.no-plan .top .icon-btn, .no-plan #nav, .in-onboarding #nav, .in-onboarding .top .icon-btn { display: none; }
main { max-width: 560px; margin: 0 auto; padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); }

#nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#nav button {
  flex: 1; max-width: 112px; border: 0; background: none; padding: 8px 0 7px;
  display: flex; flex-direction: column; align-items: center; font-size: 12px; color: var(--text-2);
}
#nav button span { font-size: 18px; line-height: 1.2; }
#nav button.on { color: var(--blue-strong); font-weight: 700; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; margin: 0 0 12px;
}
.alert { border-left: 4px solid var(--blue); }
.alert.good { border-left-color: var(--good); }
.alert.warning { border-left-color: var(--warning); }
.alert.critical { border-left-color: var(--critical); }
.note { background: var(--blue-wash); border-radius: 10px; padding: 9px 12px; font-size: 13px; white-space: pre-wrap; }

.btn {
  display: inline-block; text-align: center; text-decoration: none;
  background: var(--blue-strong); color: var(--on-blue); border: 1px solid var(--blue-strong);
  border-radius: 10px; padding: 11px 18px; font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--text); border-color: var(--critical); }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.wide { display: block; width: 100%; margin: 10px 0; }
.link { border: 0; background: none; padding: 0; color: var(--blue-strong); font-size: 12px; text-decoration: underline; }
.icon-btn { border: 0; background: none; font-size: 20px; line-height: 1; padding: 8px 10px; border-radius: 8px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }

input[type=number], input[type=text], input[type=url], select, textarea {
  width: 100%; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px;
  font-size: 16px; /* 16px보다 작으면 아이폰이 입력할 때 화면을 확대한다 */
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { accent-color: var(--blue); }
.input-unit { display: flex; align-items: center; gap: 6px; }
.input-unit span { color: var(--text-2); white-space: nowrap; }
.field { margin: 12px 0; }
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.field > small { display: block; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.chip input { position: absolute; opacity: 0; }
.chip span, .chip-btn {
  display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; background: var(--surface); cursor: pointer;
}
.chip input:checked + span, .chip-btn.on { border-color: var(--blue); background: var(--blue-wash); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 3px; flex: none; }

/* 처음 설정 */
.wizard-head { margin-bottom: 14px; }
.wizard-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; }
.wizard-nav .btn[type=submit] { min-width: 150px; }
.activity { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 8px 0; }
.activity > select { width: calc(100% - 44px); }
.activity .icon-btn { position: absolute; right: 6px; top: 11px; }
.activity-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.activity-row select { width: auto; }
.activity-row input[type=number] { width: 68px; }
.week-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0; }
.week-row .check { align-items: center; }
.week-row .check input { margin: 0; }
.week-row select { width: 150px; }
.jump { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.jump .chip-btn { padding: 5px 10px; font-size: 13px; }
.card > .btn.wide + .muted { margin-top: -4px; }
.form-error { margin-top: 12px; }
.level h2 { font-size: 24px; }
.level-bar { display: flex; gap: 2px; margin: 4px 0 10px; }
.level-bar i { flex: 1; height: 8px; background: var(--blue-wash); }
.level-bar i.on { background: var(--blue); }
.level-bar i:first-child { border-radius: 4px 0 0 4px; }
.level-bar i:last-child { border-radius: 0 4px 4px 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.stat { min-width: 0; }
.stat-label, .stat-sub { color: var(--text-2); font-size: 12px; line-height: 1.4; }
.stat-value { font-size: 18px; font-weight: 600; line-height: 1.35; }
.meter { height: 8px; border-radius: 999px; background: var(--blue-wash); overflow: hidden; margin: 8px 0 4px; }
.meter div { height: 100%; background: var(--blue); border-radius: 999px; }

.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; border-radius: 999px;
  border: 2px solid var(--axis); font-size: 11px; font-weight: 700; vertical-align: -4px;
}
.badge.good { border-color: var(--good); }
.badge.warning { border-color: var(--warning); }
.badge.serious { border-color: var(--serious); }
.badge.critical { border-color: var(--critical); }

ul.plain { list-style: none; padding: 0; }
ul.days li { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding: 7px 0; margin: 0; }
ul.days li:first-child { border-top: 0; }
.day-head { display: flex; justify-content: space-between; gap: 10px; width: 100%; border: 0; background: none; padding: 0; text-align: left; }
.day-head > span:last-child { text-align: right; }

/* 오늘 */
.date-nav { display: flex; align-items: center; justify-content: space-between; text-align: center; margin: 4px 0 10px; }
.date-nav h1, .date-nav h2 { margin: 0; }
.progress-text { font-size: 13px; color: var(--text-2); }
.progress-text b { color: var(--text); font-size: 15px; }
.section-title { color: var(--text-2); font-size: 13px; margin: 14px 2px 6px; }
ul.items { list-style: none; padding: 0; margin: 0 0 8px; }
.item { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; margin: 0 0 8px; }
.item.done { background: var(--blue-wash); border-color: var(--blue); }
.tick { display: flex; padding: 6px 2px; cursor: pointer; }
.tick input { position: absolute; opacity: 0; }
.tick span { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--axis); display: flex; align-items: center; justify-content: center; background: var(--surface); }
.tick input:checked + span { background: var(--blue-strong); border-color: var(--blue-strong); }
.tick input:checked + span::after { content: "✓"; color: var(--on-blue); font-weight: 700; }
.tick input:disabled + span { opacity: 0.35; }
.tick input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.item-body { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; border: 0; background: none; padding: 0; text-align: left; }
.thumb { width: 64px; flex: none; }
.thumb .fig .fx-limb, .thumb .fig .fx-torso, .thumb .fig .fx-far { stroke-width: 8; }
.item-name { display: block; font-weight: 600; line-height: 1.35; }
.item-dose { display: block; font-size: 13px; }
.item-link { display: block; font-size: 12px; color: var(--blue-strong); }
.item-time { flex: none; display: flex; align-items: center; gap: 3px; font-size: 13px; }
.item-time input[type=number] { width: 54px; padding: 6px; text-align: right; }
.extra-form { display: grid; grid-template-columns: 1.3fr 1fr; gap: 8px; margin-top: 8px; }
.rpe { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.rpe button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 0; }
.rpe button.on { background: var(--blue-wash); border-color: var(--blue); font-weight: 700; }

/* 계획 · 기록 */
.card.day.today { border-color: var(--blue); }
.tag { font-size: 11px; background: var(--blue-wash); border-radius: 999px; padding: 2px 8px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill { border: 1px solid var(--line); background: var(--page); border-radius: 10px; padding: 5px 10px; text-align: left; font-size: 13px; }
.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.tabs button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px; }
.tabs button.on { background: var(--blue-wash); font-weight: 700; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-top: 1px solid var(--line); padding: 7px 4px; text-align: right; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th, td:not(:first-child) { white-space: nowrap; }
th:not(:first-child), td:not(:first-child) { width: 1%; padding-left: 12px; }
th { color: var(--text-2); font-weight: 500; font-size: 12px; border-top: 0; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-top: 8px; }
.cal-head { text-align: center; font-size: 12px; color: var(--text-2); }
.cal-day { display: flex; flex-direction: column; align-items: center; border: 1px solid var(--line); background: none; border-radius: 8px; padding: 3px 0; min-width: 0; line-height: 1.3; }
.cal-day span { font-size: 12px; }
.cal-day b { min-height: 18px; font-size: 13px; }
.cal-day small { font-size: 10px; }
.cal-day.good { border-color: var(--good); }
.cal-day.warning { border-color: var(--warning); }
.cal-day.critical { border-color: var(--critical); }
.cal-day.today { box-shadow: 0 0 0 2px var(--blue); }

/* 전망 */
.verdict { border-width: 2px; }
.verdict.good { border-color: var(--good); }
.verdict.warning { border-color: var(--warning); }
.verdict.serious { border-color: var(--serious); }
.verdict.critical { border-color: var(--critical); }
.verdict h2 { font-size: 22px; }
.verdict-badge { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.inline-form .row .input-unit { flex: 1; }

/* 차트 */
.chart { margin: 8px 0 0; }
.chart svg { width: 100%; display: block; overflow: visible; }
.chart-scroll { overflow-x: auto; overflow-y: hidden; }
.chart-scroll svg { overflow: hidden; }
.chart figcaption { color: var(--text-2); font-size: 11px; text-align: right; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.k-plan { background: var(--plan); }
.k-actual { background: var(--blue); }
.k-forecast { height: 0; width: 16px; border-top: 2px dashed var(--blue); border-radius: 0; }
.k-target { height: 0; width: 16px; border-top: 2px solid var(--text-2); border-radius: 0; }
.ch-grid { stroke: var(--grid); stroke-width: 1; }
.ch-axis { stroke: var(--axis); stroke-width: 1; }
.ch-tick, .ch-label { fill: var(--text-2); font-size: 10px; font-variant-numeric: tabular-nums; }
.ch-current { fill: var(--text); font-weight: 700; }
.ch-plan { fill: var(--plan); }
.ch-actual { fill: var(--blue); }
.ch-line { fill: none; stroke: var(--blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-forecast { fill: none; stroke: var(--blue); stroke-width: 2; stroke-dasharray: 5 4; }
.ch-target { fill: none; stroke: var(--text-2); stroke-width: 1; }
.ch-dot { fill: var(--blue); stroke: var(--surface); stroke-width: 2; }
.ch-ring { fill: var(--surface); stroke: var(--blue); stroke-width: 2; }
.ch-hit { fill: transparent; cursor: pointer; }
#tip { position: fixed; z-index: 30; max-width: 240px; background: var(--text); color: var(--surface); font-size: 12px; border-radius: 8px; padding: 6px 10px; pointer-events: none; }

/* 자세 그림 */
.fig { width: 100%; display: block; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fig .fx-limb { stroke: var(--fig); stroke-width: 6; }
.fig .fx-arm { stroke: var(--blue); }
.fig .fx-far { stroke: var(--fig-far); stroke-width: 6; }
.fig .fx-torso { stroke: var(--fig); stroke-width: 8; }
.fig .fx-girdle { stroke-width: 6; }
.fig .fx-head { fill: var(--fig); }
.fig .fx-ground { stroke: var(--axis); stroke-width: 1.5; }
.fig .fx-prop { stroke: var(--prop); stroke-width: 4; }
.fig .fx-prop-line { stroke: var(--prop); stroke-width: 3; }
.fig .fx-prop-fill, .fig .fx-mat { fill: var(--prop); }
.fig .fx-water { fill: var(--water); }
.fig .fx-wave { stroke: var(--blue); stroke-width: 1.5; }
.fig .fx-db { stroke: var(--serious); stroke-width: 4; }
.fig .fx-dbw { stroke: var(--serious); stroke-width: 5; }
.fig .fx-cable { stroke: var(--prop); stroke-width: 2; }
.fig .fx-bad .fx-limb, .fig .fx-bad .fx-torso, .fig .fx-bad .fx-arm { stroke: var(--critical); }
.fig .fx-bad .fx-head { fill: var(--critical); }

#modal { width: min(560px, 100%); max-width: 100%; max-height: 94dvh; margin: auto auto 0; padding: 0; border: 1px solid var(--line); border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text); }
@media (min-width: 600px) { #modal { margin: auto; border-radius: 18px; } }
#modal::backdrop { background: rgba(0, 0, 0, 0.55); }
.modal-body { padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
.modal-close { float: right; position: sticky; top: 6px; background: var(--surface); border: 1px solid var(--line); z-index: 2; }
.dose { display: inline-block; background: var(--blue-wash); border-radius: 8px; padding: 5px 12px; font-weight: 600; }
.player { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; clear: both; }
.player-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding: 8px 10px; }
#phase { font-weight: 600; font-size: 14px; }
.stills { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.stills figure { margin: 0; border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.stills figure.wrong { border-color: var(--critical); }
.stills figcaption { font-size: 12px; text-align: center; margin-top: 4px; }
ul.mistakes { list-style: "✕  "; }
.video { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 12px; margin-bottom: 8px; }
.video-form { margin-top: 8px; }
.video-form .btn { flex: none; }
.filter { margin-bottom: 12px; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lib-card { display: flex; flex-direction: column; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; }
.lib-card b { font-size: 13px; line-height: 1.35; margin-top: 4px; }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));transform: translateX(-50%); z-index: 20; width: max-content; max-width: calc(100% - 32px); background: var(--text); color: var(--surface); border-radius: 10px; padding: 10px 16px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
#toast.show { opacity: 1; }

@media (max-width: 380px) {
  .grid3 { gap: 6px; }
  .stat-value { font-size: 16px; }
  .thumb { width: 52px; }
}
