:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --done: #16a34a;
  --done-bg: #e8f7ee;
  --danger: #dc2626;
  --input: #f1f2f4;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --card: #181b21;
    --text: #eceef2;
    --muted: #8b93a1;
    --line: #2a2e36;
    --accent: #3b82f6;
    --done: #22c55e;
    --done-bg: #12261a;
    --danger: #f87171;
    --input: #22262e;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
#app { max-width: 640px; margin: 0 auto; padding: 0 16px; }

button {
  font: inherit; color: inherit; background: var(--input);
  border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); background: transparent; }
button.link { background: transparent; color: var(--accent); padding: 6px 4px; }
button.big { width: 100%; padding: 16px; font-size: 18px; }
button:disabled { opacity: .5; }

input, select {
  font: inherit; color: inherit; background: var(--input);
  border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

header.top {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 0 10px; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
header.top h1 { font-size: 20px; margin: 0; flex: 1; }
.sync { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync.warn { color: var(--danger); }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin: 10px 0; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
h2 { font-size: 17px; margin: 18px 0 6px; }

.auth { padding-top: 12vh; }
.auth h1 { font-size: 26px; margin-bottom: 18px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

.workout-item { cursor: pointer; }
.workout-item .title { font-weight: 600; }

.ex-card .ex-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ex-card .ex-name { font-weight: 700; flex: 1; cursor: pointer; }
.ex-card .hint { font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.set {
  display: grid; grid-template-columns: 28px 1fr 1fr 48px; gap: 6px; align-items: center;
  padding: 4px 0;
}
.set.one { grid-template-columns: 28px 2fr 48px; }
.set .no { color: var(--muted); text-align: center; font-size: 14px; cursor: pointer; }
.set .no.warm { color: #d97706; font-weight: 700; }
.set input { text-align: center; padding: 10px 4px; }
.unit { position: relative; }
.unit span {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--muted); pointer-events: none;
}
.set .check {
  height: 44px; padding: 0; font-size: 20px; border-radius: 10px;
}
.set.done .check { background: var(--done); color: #fff; }
.set.done input { background: var(--done-bg); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips button { white-space: nowrap; padding: 6px 12px; font-size: 14px; border-radius: 999px; }
.chips button.on { background: var(--accent); color: var(--accent-text); }

.pick-item {
  display: flex; align-items: center; gap: 8px; padding: 12px 4px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.pick-item .bp { font-size: 12px; color: var(--muted); }

.chart { width: 100%; height: auto; display: block; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.chart .dot { fill: var(--accent); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); }

#rest {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
}
#rest-bar { height: 4px; background: var(--accent); border-radius: 2px; transition: width .25s linear; }
#rest .rest-row { display: flex; align-items: center; gap: 8px; max-width: 640px; margin: 8px auto 0; }
#rest-left { flex: 1; text-align: center; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
#rest.over #rest-left { color: var(--done); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(110px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30;
  font-size: 14px; max-width: calc(100% - 32px);
}
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.footer-links { justify-content: center; margin-top: 24px; }
.workout-foot { margin-top: 16px; }

/* 초대 코드 카드 — 코드는 크게, 길게 눌러 선택도 되게 */
.invite { text-align: center; }
.invite .invite-code { font-size: 32px; font-weight: 700; letter-spacing: 3px; margin: 8px 0 12px; user-select: all; -webkit-user-select: all; font-variant-numeric: tabular-nums; }
.invite .row button { padding: 12px; }

.center { text-align: center; }
button.wide { width: 100%; padding: 12px; }
.cal-btn { margin-top: 10px; }

/* 프로그램 색 — 달력 칸 태그·고르기 버튼 공용 */
:root {
  --t0-bg: #fde8e8; --t0-fg: #b42318;
  --t1-bg: #e3edff; --t1-fg: #1d4ed8;
  --t2-bg: #fff1dc; --t2-fg: #b45309;
  --t3-bg: #dcf5e7; --t3-fg: #15803d;
  --tx-bg: #eceef2; --tx-fg: #4b5563;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --t0-bg: #3a1d1d; --t0-fg: #fca5a5;
    --t1-bg: #1c2a47; --t1-fg: #93c5fd;
    --t2-bg: #3a2a14; --t2-fg: #fcd34d;
    --t3-bg: #15301f; --t3-fg: #86efac;
    --tx-bg: #2a2e36; --tx-fg: #cbd5e1;
  }
}
.tone-0 { background: var(--t0-bg); color: var(--t0-fg); }
.tone-1 { background: var(--t1-bg); color: var(--t1-fg); }
.tone-2 { background: var(--t2-bg); color: var(--t2-fg); }
.tone-3 { background: var(--t3-bg); color: var(--t3-fg); }
.tone-x { background: var(--tx-bg); color: var(--tx-fg); }
.tag { font-size: 11px; font-weight: 600; padding: 1px 4px; border-radius: 6px; }

/* 달력 */
.month-nav { margin: 6px 0; }
.month-nav .title { font-weight: 700; font-size: 17px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 10px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.cal .day {
  background: var(--card); border-radius: 10px; min-height: 64px; padding: 4px 2px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.cal .day .dn { font-size: 13px; }
.cal .day .tag { width: 100%; text-align: center; overflow: hidden; word-break: keep-all; line-height: 1.25; font-size: 10px; }
.cal .day .ok { color: var(--done); font-weight: 700; font-size: 13px; line-height: 1; }
.cal .day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal .sun .dn, .cal .dow.sun { color: var(--danger); }
.cal .sat .dn, .cal .dow.sat { color: var(--accent); }

/* 그날 플랜 */
.plan-title { font-weight: 700; font-size: 17px; margin-bottom: 4px; }
.prog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.prog-grid button { padding: 16px 8px; font-weight: 700; }
.pi { padding: 10px 0; border-bottom: 1px solid var(--line); }
.pi-name { font-weight: 600; cursor: pointer; }
.pi-inputs { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.pi-inputs input { text-align: center; padding: 10px 4px; }
label.field { display: flex; align-items: center; gap: 10px; }
label.field > span { min-width: 76px; }
label.field > input, label.field > select { flex: 1; }

/* 종목 순서 ↑↓ */
button.move { padding: 4px 9px; font-size: 15px; background: var(--input); color: var(--muted); border-radius: 8px; }
.ex-card .ex-head button.move + button.move, .pi button.move + button.move { margin-left: -4px; }
