:root {
  --bg: #f4f4f8;
  --surface: #fff;
  --ink: #1c1d2b;
  --ink-2: #4b4d62;
  --ink-3: #6b6d82;
  --line: #dfe0ea;
  --field: #b9bbcc;
  --main: #3b3f7a;
  --main-2: #5458a3;
  --main-soft: #e8e9f6;
  --amber: #8a5300;
  --amber-soft: #fbeed6;
  --red: #a82a22;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  word-break: keep-all; overflow-wrap: anywhere;
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; text-decoration: none; }
small { color: var(--ink-3); font-size: 13px; }
:focus-visible { outline: 3px solid var(--main-2); outline-offset: 2px; }

/* 상단 */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--main); color: #fff;
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.top nav { display: flex; gap: 2px; }
.top nav a { padding: 8px 10px; border-radius: 8px; font-size: 15px; opacity: .85; white-space: nowrap; }
.top nav a.on { background: rgba(255, 255, 255, .18); opacity: 1; font-weight: 600; }
@media (max-width: 400px) { .top { padding-left: 12px; padding-right: 8px; } .brand { font-size: 15px; } .top nav a { padding: 8px 7px; font-size: 14px; } }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
main.center { min-height: 80dvh; display: grid; place-items: center; }

/* 공통 요소 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 46px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--main); border-color: var(--main); color: #fff; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.small { min-height: 38px; padding: 4px 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.link { border: 0; background: none; color: var(--main); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px 4px; text-align: left; }
.x { min-height: 36px; min-width: 36px; border: 0; background: none; color: var(--ink-3); font-size: 16px; cursor: pointer; }
.hint { font-size: 14px; color: var(--ink-2); }
.empty { padding: 20px 8px; text-align: center; color: var(--ink-3); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.actions .btn { flex: 1 1 auto; }

input, select, textarea {
  width: 100%; min-height: 46px; padding: 9px 12px;
  border: 1px solid var(--field); border-radius: 10px; background: #fff; color: var(--ink);
  font: inherit; font-size: 16px;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; margin: 0; accent-color: var(--main); }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sec-head h2 { font-size: 17px; }
.sub { display: flex; flex-direction: column; gap: 8px; padding: 10px; background: var(--bg); border-radius: 10px; }
.sub-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.warn-card { background: var(--amber-soft); border-color: #eed8ad; color: var(--amber); }
.warn-card ul { margin: 6px 0 0; padding-left: 18px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
details.more summary { font-size: 14px; color: var(--ink-2); cursor: pointer; padding: 2px 0; }
details.more[open] summary { margin-bottom: 10px; }

/* 목록 */
.rows { background: var(--surface); }
.row {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 12px 0;
  border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-main small { display: block; }
.row-main .note { color: var(--ink-2); }
.tag { flex: none; min-width: 48px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 8px; border-radius: 999px; text-align: center; font-size: 13px; font-weight: 600; background: var(--main-soft); color: var(--main); }
.tag.plain { background: var(--bg); color: var(--ink-3); }
.filters { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 4px; }
.filters select { width: auto; max-width: 140px; }
.due-card { border: 2px solid #e2b04a; background: #fffaf0; }
.account { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--ink-3); }

/* 결정 화면 */
.page-head { display: flex; flex-direction: column; gap: 8px; }
.page-head h2 { font-size: 20px; }
.back-link { align-self: flex-start; padding-left: 0; }
.head-links { display: flex; gap: 12px; flex-wrap: wrap; }
.step { display: flex; flex-direction: column; gap: 10px; }
.step.done { background: #fafafd; }
.step.now { border: 2px solid var(--main-2); }
.step-q { font-size: 17px; font-weight: 700; display: flex; gap: 8px; align-items: flex-start; }
.step-no { flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; margin-top: 1px; border-radius: 50%; background: var(--main); color: #fff; font-size: 14px; }
.step.done .step-no { background: var(--ink-3); }
.picked { font-weight: 700; color: var(--main); font-size: 16px; }
.why { font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.why b { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; background: var(--main-soft); color: var(--main); font-size: 12px; }
.step .link { align-self: flex-start; padding-left: 0; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; flex-direction: column; gap: 2px; width: 100%; min-height: 54px; padding: 12px 14px;
  border: 1px solid var(--field); border-radius: 12px; background: var(--surface); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.choice strong { font-size: 16px; }
.choice small { color: var(--ink-2); line-height: 1.5; }
.choice:hover, .choice:focus-visible { border-color: var(--main-2); background: var(--main-soft); }
.step.result { border: 2px solid var(--main); }
.result-label { font-size: 13px; font-weight: 700; color: var(--main); }
.result-text { font-size: 18px; font-weight: 700; line-height: 1.5; }
.path-title { font-size: 14px; color: var(--ink-2); font-weight: 600; margin-top: 4px; }
.opts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.opts li { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 10px; border: 1px dashed var(--line); color: var(--ink-3); }
.opts li small { color: var(--ink-3); }
.opts li.on { border: 2px solid var(--main-2); background: var(--surface); color: var(--ink); font-weight: 700; }
.opts li.on small { color: var(--ink-2); font-weight: 400; }

/* 결정 나무 그림 (들여쓰기 목록) */
ul.dt, ul.dt ul { list-style: none; margin: 0; padding: 0; }
ul.dt ul { margin-left: 10px; padding-left: 12px; border-left: 2px solid var(--line); }
ul.dt li { margin: 6px 0; }
ul.dt small { display: block; color: var(--ink-3); font-size: 12px; line-height: 1.5; }
.dt-node { font-weight: 700; }
.dt-r > .dt-node { color: var(--main); }
.dt-label { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 14px; }
.dt-missing { color: var(--amber); font-size: 13px; }
ul.dt li.dt-opt.on > .dt-label { background: var(--main); border-color: var(--main); color: #fff; font-weight: 700; }
ul.dt li.dt-opt.on > ul { border-left-color: var(--main-2); }
ul.dt li.dt-r.on > .dt-node { background: var(--main-soft); padding: 2px 6px; border-radius: 6px; }

/* 나무 고치기 · 바로 적기 */
.dt-edit { display: flex; flex-direction: column; gap: 10px; }
.dt-edit .sec-head { margin-bottom: 0; }
.dt-edit-r { border-left: 4px solid var(--main-2); }
.free-opts { display: flex; flex-direction: column; gap: 8px; }
.free-opt { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 6px; align-items: start; }
.free-pick { display: grid; place-items: center; height: 46px; cursor: pointer; }
.free-opt input[type="radio"] { width: 22px; height: 22px; min-height: 0; margin: 0; padding: 0; border: 0; accent-color: var(--main); }
.free-fields { display: flex; flex-direction: column; gap: 4px; }
.free-fields input:last-child { font-size: 14px; min-height: 40px; }
.free-opt + .free-opt { padding-top: 8px; border-top: 1px solid var(--line); }

/* 로그인 · 알림 */
.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login h1 { font-size: 22px; color: var(--main); }
dialog#sheet { width: min(560px, 100% - 24px); max-height: 90dvh; padding: 0; border: 0; border-radius: 16px; }
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 100;
  max-width: 480px; margin: 0 auto; padding: 12px 14px; border-radius: 10px;
  background: var(--ink); color: #fff; font-size: 14px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }
.free-card .btn { margin-top: 10px; }
