/* ===== 색상 (밝은 화면 / 어두운 화면) ===== */
:root {
  --bg: #F6F5F1;
  --surface: #FFFFFF;
  --ink: #1D2321;
  --muted: #5E6763;
  --line: #E3E1DA;
  --line2: #D6D3CA;
  --soft: #F1F0EB;
  --done-bg: #ECEAE3;
  --dash: #9AA09C;
  --connector: #C9CCC8;
  --accent: #0B7A61;
  --accent-soft: #E3EDE9;
  --on-accent: #FFFFFF;
  --hint-bg: #EAF1EE;
  --hint-ink: #0B4A3B;
  --warn-bg: #FDF0EF;
  --warn-line: #F2CFCB;
  --warn-ink: #8A2A22;
  --btn-bg: #1D2321;
  --btn-fg: #FFFFFF;
  --on-cat: #FFFFFF;
  --plus: #2F6FD6;
  --minus: #D9822B;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.18);

  --rest: #4F6BD8;  --rest-tint: #E8EDFB;  --rest-dark: #2F4CB3;
  --work: #B85C14;  --work-tint: #F7EBDD;  --work-dark: #8A4510;
  --prod: #0B7A61;  --prod-tint: #E2F1EB;  --prod-dark: #0B5E4B;
  --etc: #7A5FB0;   --etc-tint: #EFEAF8;   --etc-dark: #5A4290;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131615;
    --surface: #1C201F;
    --ink: #ECEEED;
    --muted: #A3ABA7;
    --line: #2C3230;
    --line2: #3A403E;
    --soft: #252A28;
    --done-bg: #252A28;
    --dash: #6E7672;
    --connector: #48504D;
    --accent: #3DBB98;
    --accent-soft: #1E3A33;
    --on-accent: #0E1513;
    --hint-bg: #17302A;
    --hint-ink: #A7DCCB;
    --warn-bg: #3A1F1C;
    --warn-line: #5C2E29;
    --warn-ink: #F2B8B0;
    --btn-bg: #ECEEED;
    --btn-fg: #131615;
    --on-cat: #0E1513;
    --plus: #6E9CF0;
    --minus: #E8A25A;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);

    --rest: #8BA0F2;  --rest-tint: #1E2742;  --rest-dark: #B9C6FA;
    --work: #E59A5A;  --work-tint: #3A2818;  --work-dark: #F4C9A2;
    --prod: #4CC7A3;  --prod-tint: #173A30;  --prod-dark: #A2E5D0;
    --etc: #B39BE6;   --etc-tint: #2C2442;   --etc-dark: #D6C9F5;

    color-scheme: dark;
  }
}

/* 활동 영역별 색 (data-cat 속성으로 지정) */
[data-cat="rest"] { --c: var(--rest); --t: var(--rest-tint); --d: var(--rest-dark); }
[data-cat="work"] { --c: var(--work); --t: var(--work-tint); --d: var(--work-dark); }
[data-cat="prod"] { --c: var(--prod); --t: var(--prod-tint); --d: var(--prod-dark); }
[data-cat="etc"]  { --c: var(--etc);  --t: var(--etc-tint);  --d: var(--etc-dark); }

/* ===== 기본 ===== */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

#app {
  position: relative;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
main { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.screen { padding: 12px 20px 28px; display: flex; flex-direction: column; gap: 14px; }
.screen.fill { min-height: 100%; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== 상단 레벨 바 ===== */
.hud { flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 20px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.hud-lv { font-size: 14px; font-weight: 800; color: var(--accent); }
.bar { flex: 1; height: 8px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width 0.4s; }
.hud-xp { font-size: 12px; color: var(--muted); }

/* ===== 버튼 ===== */
.btn { width: 100%; min-height: 56px; border: 0; border-radius: 16px; background: var(--btn-bg); color: var(--btn-fg); font-size: 17px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn.big { min-height: 62px; border-radius: 18px; font-size: 19px; font-weight: 800; }
.btn.accent { background: var(--accent); color: var(--on-accent); font-weight: 800; }
.btn-ghost { width: 100%; min-height: 50px; border: 1px solid var(--line2); border-radius: 16px; background: var(--surface); font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-text { min-height: 44px; border: 0; background: none; color: var(--muted); font-size: 14px; }
.btn-small { min-height: 40px; padding: 0 12px; border: 1px solid var(--line2); border-radius: 10px; background: var(--surface); font-size: 13px; }
.btn-danger { color: var(--warn-ink); border-color: var(--warn-line); }
.icon-btn { flex: none; width: 44px; height: 44px; border: 0; background: none; display: flex; align-items: center; justify-content: center; }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== 공통 조각 ===== */
.backrow { display: flex; align-items: center; gap: 4px; margin-left: -10px; }
.crumb { font-size: 13px; color: var(--muted); line-height: 1.4; }
.hint { display: flex; gap: 10px; align-items: flex-start; background: var(--hint-bg); color: var(--hint-ink); border-radius: 14px; padding: 12px 14px; font-size: 14px; line-height: 1.55; }
.hint svg { flex: none; margin-top: 1px; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 14px; padding: 10px 14px; font-size: 13px; line-height: 1.5; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.panel-title { font-size: 15px; font-weight: 700; }
.tag { font-size: 12px; color: var(--muted); background: var(--soft); border-radius: 6px; padding: 2px 8px; }
.tag.ok { color: var(--hint-ink); background: var(--hint-bg); }
.tag.cat { color: var(--on-cat); background: var(--c); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

/* ===== 홈 ===== */
.home { min-height: 100%; padding: 32px 24px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.home h1 { font-size: 34px; font-weight: 800; text-align: center; }
.home p { text-align: center; font-size: 15px; color: var(--muted); line-height: 1.6; margin-bottom: 18px; }
.active-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 16px; border: 1.5px solid var(--c); background: var(--t); color: var(--d); margin-bottom: 8px; text-align: left; width: 100%; }
.active-card b { display: block; font-size: 15px; }
.active-card span { font-size: 13px; }
.active-card .time { margin-left: auto; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ===== 에너지 체크 ===== */
.grid6 { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.grid5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.numbtn { min-height: 48px; border: 1px solid var(--line2); border-radius: 12px; background: var(--surface); font-size: 17px; font-weight: 700; }
.numbtn[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-fg); border-color: var(--btn-bg); }
.scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* ===== 가지 선택 카드 ===== */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { display: flex; align-items: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.card-main { flex: 1; min-width: 0; min-height: 72px; border: 0; background: none; text-align: left; padding: 14px 6px 14px 16px; display: flex; align-items: center; gap: 12px; }
.card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.card-label { font-size: 17px; font-weight: 700; line-height: 1.35; }
.card-pass { flex: none; width: 52px; border: 0; border-left: 1px solid var(--soft); background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.dice { width: 100%; min-height: 52px; border: 1px dashed var(--dash); border-radius: 16px; background: var(--surface); font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* ===== 구체화 ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; }
.input { min-height: 48px; border: 1px solid var(--line2); border-radius: 12px; padding: 0 14px; font-size: 16px; background: var(--surface); width: 100%; }
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.chips2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.chip { min-height: 46px; border: 1px solid var(--line2); border-radius: 12px; background: var(--surface); font-size: 15px; font-weight: 700; }
.chip.wide { font-size: 14px; }
.custom { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line2); border-radius: 12px; background: var(--surface); padding: 0 12px; min-height: 46px; }
.custom input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 16px; text-align: right; outline: none; }
.custom span { font-size: 13px; color: var(--muted); }
.sentence { background: var(--btn-bg); color: var(--btn-fg); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.sentence b { font-size: 18px; line-height: 1.5; }
.sentence span { font-size: 12px; opacity: 0.75; }
.title { font-size: 24px; font-weight: 800; line-height: 1.35; }

/* ===== 타이머 ===== */
.timer { min-height: 100%; padding: 28px 20px 24px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.timer-head { text-align: center; display: flex; flex-direction: column; gap: 4px; }
.timer-head b { font-size: 20px; line-height: 1.4; }
.ring { position: relative; width: 260px; height: 260px; }
.ring svg { display: block; }
.ring-track { stroke: var(--soft); }
.ring-bar { stroke: var(--c); transition: stroke-dashoffset 0.25s linear; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.ring-time { font-size: 50px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.laps { display: flex; gap: 5px; min-height: 8px; }
.laps i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.done-banner { width: 100%; text-align: center; background: var(--hint-bg); color: var(--hint-ink); border-radius: 16px; padding: 14px; font-size: 16px; font-weight: 700; }
.timer-btns { width: 100%; display: flex; gap: 8px; }
.timer-btns .btn-ghost, .timer-btns .btn { min-height: 54px; flex: 1; }
.timer-btns .plus5 { flex: none; width: 84px; }
.timer-foot { width: 100%; margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--line2); display: flex; flex-direction: column; }

/* ===== 완료 ===== */
.complete-head { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 20px 0 4px; }
.check-circle { width: 64px; height: 64px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; }
.complete-head h2 { font-size: 26px; font-weight: 800; }
.row { display: flex; justify-content: space-between; align-items: center; font-size: 15px; gap: 12px; }
.row b { font-weight: 800; }
.row .gain { color: var(--accent); }
.mins-edit { display: flex; align-items: center; gap: 6px; }
.mins-edit input { width: 64px; min-height: 40px; border: 1px solid var(--line2); border-radius: 10px; background: var(--surface); text-align: right; padding: 0 8px; font-size: 16px; }

/* ===== 전체 지도 ===== */
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; background: var(--done-bg); border-radius: 12px; padding: 4px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 4px; }
.legend i { width: 14px; height: 10px; border-radius: 3px; border: 1.5px solid var(--accent); background: var(--surface); }
.legend i.l-hidden { border-style: dashed; border-color: var(--dash); }
.legend i.l-done { border-color: var(--line2); background: var(--done-bg); }
.legend .badge { position: static; }
.map-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.map-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

.node { position: relative; border: 1.5px solid var(--c); background: var(--surface); color: var(--ink); border-radius: 9px; font-size: 12px; line-height: 1.25; padding: 3px 5px; min-height: 34px; word-break: keep-all; overflow-wrap: anywhere; }
.node.is-branch { background: var(--t); color: var(--d); font-weight: 700; }
.node.is-top { background: var(--c); color: var(--on-cat); font-weight: 800; min-height: 40px; border-radius: 10px; font-size: 13px; }
.node.st-done { background: var(--done-bg); color: var(--muted); border-color: var(--line2); font-weight: 400; }
.node.st-hidden { background: var(--surface); color: var(--muted); border-style: dashed; border-color: var(--dash); text-decoration: line-through; font-weight: 400; }
.node.st-off { background: var(--soft); color: var(--muted); border-color: var(--line2); }
.node-root { flex: none; display: flex; align-items: center; justify-content: center; text-align: center; border-radius: 10px; background: var(--btn-bg); color: var(--btn-fg); font-weight: 800; }
.badge { position: absolute; top: -7px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--btn-bg); color: var(--btn-fg); font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* 옆으로 펼치기 */
.tside-scroll { overflow-x: auto; padding: 12px 6px; }
.tside { display: flex; align-items: center; width: max-content; }
.tside .node-root { width: 50px; min-height: 44px; font-size: 12px; padding: 4px; line-height: 1.2; }
.tside .node.is-top { width: 64px; }
.tside .node { width: 78px; min-height: 34px; }
.tside-children { display: flex; flex-direction: column; }
.tside-item { position: relative; display: flex; align-items: center; padding: 3px 0 3px 10px; }
.tside-item.lv1 { padding: 8px 0 8px 10px; }
.tside-item::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--connector); }
.tside-item:first-child::before { top: 50%; }
.tside-item:last-child::before { bottom: 50%; }
.tside-item:only-child::before { display: none; }
.tside-item::after { content: ''; position: absolute; left: 0; top: calc(50% - 1px); width: 10px; height: 2px; background: var(--connector); }
.stub { flex: none; width: 8px; height: 2px; background: var(--connector); }

/* 위에서 아래로 */
.tdown { padding: 16px 8px 18px; }
.tdown-root { display: flex; justify-content: center; }
.tdown-root .node-root { min-width: 120px; min-height: 40px; padding: 0 16px; font-size: 15px; }
.tdown-conn { position: relative; height: 24px; }
.tdown-conn::before { content: ''; position: absolute; left: calc(50% - 1px); top: 0; width: 2px; height: 12px; background: var(--connector); }
.tdown-conn::after { content: ''; position: absolute; top: 12px; height: 2px; background: var(--connector); left: var(--l, 16%); right: var(--l, 16%); }
.tdown-cols { display: grid; gap: 6px; align-items: start; }
.tdown-col { display: flex; flex-direction: column; min-width: 0; }
.tdown-col::before { content: ''; align-self: center; width: 2px; height: 12px; margin-top: -12px; background: var(--connector); }
.tdown-col > .node { width: 100%; }
.tdown-list { margin-left: 8px; }
.tdown-list .tdown-list { margin-left: 6px; }
.tdown-item { position: relative; padding: 6px 0 0 12px; }
.tdown-item::before { content: ''; position: absolute; left: 0; top: 0; height: 100%; width: 2px; background: var(--connector); }
.tdown-item:last-child::before { height: 25px; }
.tdown-item::after { content: ''; position: absolute; left: 0; top: 24px; width: 12px; height: 2px; background: var(--connector); }
.tdown-item > .node { width: 100%; min-height: 36px; }

/* ===== 아래에서 올라오는 창 ===== */
.sheet-wrap { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; border: 0; padding: 0; background: rgba(10, 14, 13, 0.45); }
.sheet { position: relative; background: var(--surface); border-radius: 22px 22px 0 0; padding: 12px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.sheet-grip { align-self: center; width: 40px; height: 4px; border-radius: 2px; background: var(--line2); }
.sheet-title { font-size: 20px; font-weight: 800; line-height: 1.35; }

/* ===== 통계 ===== */
.radar { position: relative; width: 260px; height: 250px; align-self: center; }
.radar-grid { fill: none; stroke: var(--line); }
.radar-shape { fill: var(--accent); fill-opacity: 0.18; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.radar-label { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.radar-label b { font-size: 13px; }
.radar-label span { font-size: 11px; color: var(--muted); }
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; background: var(--soft); }
.stack i { display: block; background: var(--c); }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.legend-row .sq { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.legend-row .grow { flex: 1; }
.legend-row .pct { width: 40px; text-align: right; font-weight: 700; }
.hbar { height: 6px; border-radius: 3px; background: var(--soft); }
.hbar i { display: block; height: 100%; border-radius: 3px; background: var(--c); }
.diverge { display: grid; grid-template-columns: 80px minmax(0, 1fr) 40px; align-items: center; gap: 8px; min-height: 22px; font-size: 13px; }
.diverge .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.diverge .track { position: relative; height: 12px; }
.diverge .track::before { content: ''; position: absolute; left: 50%; top: -4px; bottom: -4px; width: 1px; background: var(--line2); }
.diverge .track i { position: absolute; top: 0; height: 100%; border-radius: 3px; }
.diverge .val { text-align: right; font-weight: 700; }

/* ===== 설정 ===== */
.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--soft); }
.switch-row:last-child { border-bottom: 0; }
.switch-text { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.switch-text b { font-size: 15px; }
.switch-text span { font-size: 12px; color: var(--muted); line-height: 1.4; }
.switch { flex: none; position: relative; width: 50px; height: 30px; border: 0; border-radius: 15px; background: var(--dash); padding: 0; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #FFFFFF; transition: left 0.2s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { left: 23px; }
.edit-list { padding: 6px 0; }
.edit-row { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 8px 0 16px; }
.edit-row .name { flex: 1; min-width: 0; font-size: 14px; }
.edit-row .name.branch { font-weight: 700; }
.edit-panel { margin: 4px 12px 12px; background: var(--bg); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.edit-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.edit-panel .input, .edit-panel select { min-height: 44px; border: 1px solid var(--line2); border-radius: 10px; padding: 0 10px; font-size: 15px; background: var(--surface); color: var(--ink); }
.edit-btns { display: flex; gap: 8px; }
.edit-btns button { flex: 1; min-height: 44px; }

/* ===== 하단 메뉴 ===== */
nav.tabs { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); }
nav.tabs button { min-height: 52px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); }
nav.tabs button span { font-size: 11px; font-weight: 500; }
nav.tabs button[aria-current="page"] { color: var(--accent); }
nav.tabs button[aria-current="page"] span { font-weight: 700; }

/* ===== 알림 메시지 ===== */
#toast { position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 20px); width: min(440px, calc(100% - 40px)); background: var(--btn-bg); color: var(--btn-fg); border-radius: 14px; padding: 12px 16px; font-size: 14px; text-align: center; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
