:root {
  --ink: #21302c;
  --muted: #67736f;
  --paper: #f7f7f2;
  --card: #fffef9;
  --line: #d9ded8;
  --green: #236b52;
  --green-dark: #174c3a;
  --green-soft: #dcebe4;
  --gold: #b98533;
  --reason: #d87852;
  --breakdown: #c49a45;
  --solution: #559982;
  --task: #246b54;
  --shadow: 0 12px 32px rgba(39, 57, 50, .09);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(184, 133, 51, .09), transparent 30rem),
    linear-gradient(180deg, #fafaf6 0%, #f2f4ef 100%);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", system-ui, sans-serif;
}

button, input, select { font: inherit; }
button { color: inherit; }

.topbar {
  height: 82px;
  padding: 0 clamp(20px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid rgba(35, 107, 82, .12);
  background: rgba(250, 250, 246, .88);
  backdrop-filter: blur(12px);
}

.brand, .top-actions, .goal-input-row, .examples, .legend, .node-topline, .node-actions, .dialog-head, .dialog-actions { display: flex; align-items: center; }
.brand { gap: 12px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: white; background: var(--green); font-family: Georgia, serif; font-size: 22px; }
.brand h1 { margin: 1px 0 0; font-size: 17px; letter-spacing: .06em; }
.eyebrow { margin: 0; color: var(--muted); font: 700 10px/1.2 system-ui, sans-serif; letter-spacing: .18em; }
.eyebrow.accent { color: var(--gold); }
.version { margin-left: 4px; padding: 5px 9px; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 700; }
.top-actions { gap: 10px; }
.save-status { color: var(--muted); font-size: 12px; }

.button { border: 0; border-radius: 10px; padding: 11px 16px; cursor: pointer; font-weight: 700; transition: transform .15s, background .15s; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--green); box-shadow: 0 8px 18px rgba(35, 107, 82, .2); }
.button.primary:hover { background: var(--green-dark); }
.button.ghost { border: 1px solid var(--line); background: rgba(255,255,255,.65); }
.button.danger { color: #9c4b3f; }

main { min-height: calc(100vh - 82px); }
.start-screen { width: min(1080px, calc(100% - 40px)); min-height: calc(100vh - 82px); margin: 0 auto; display: grid; grid-template-columns: .9fr 1.1fr; align-items: center; gap: clamp(40px, 8vw, 120px); }
.start-copy h2 { margin: 14px 0 20px; font: 500 clamp(34px, 4.5vw, 62px)/1.35 Georgia, "Yu Mincho", serif; letter-spacing: .02em; }
.start-copy > p:last-child { max-width: 32em; color: var(--muted); line-height: 1.9; }
.goal-form { padding: clamp(24px, 4vw, 44px); border: 1px solid rgba(35,107,82,.13); border-radius: 22px; background: rgba(255,254,249,.86); box-shadow: var(--shadow); }
.goal-form > label, .dialog label { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 700; }
.goal-input-row { align-items: stretch; gap: 10px; }
.goal-input-row input, .dialog input, .dialog select { width: 100%; min-height: 50px; padding: 0 15px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; outline: none; }
.goal-input-row input:focus, .dialog input:focus, .dialog select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(35,107,82,.11); }
.goal-input-row .button { white-space: nowrap; }
.examples { flex-wrap: wrap; gap: 8px; margin-top: 16px; color: var(--muted); font-size: 11px; }
.examples button { padding: 5px 8px; border: 0; border-radius: 6px; background: #eef1ec; cursor: pointer; font-size: 11px; }

.workspace { padding: 34px clamp(18px, 4vw, 64px) 46px; }
.workspace-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.workspace-head h2 { margin: 7px 0 0; font: 500 clamp(24px, 3vw, 38px)/1.3 Georgia, "Yu Mincho", serif; }
.legend { flex-wrap: wrap; justify-content: flex-end; gap: 12px; color: var(--muted); font-size: 11px; }
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: currentColor; }
.dot.goal { color: var(--green); } .dot.reason { color: var(--reason); } .dot.breakdown { color: var(--breakdown); } .dot.solution { color: var(--solution); } .dot.task { color: var(--task); }
.progress-wrap { margin-top: 24px; }
.progress-wrap::before { content: ""; display: block; height: 3px; border-radius: 3px; background: #e1e5df; }
.progress-bar { height: 3px; max-width: 100%; margin-top: -3px; border-radius: 3px; background: linear-gradient(90deg, var(--gold), var(--green)); transition: width .35s; }
.progress-wrap p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.progress-stats { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.progress-stat { padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.62); font-size: 10px; font-weight: 700; }
.progress-stat.warn { border-color: rgba(216,120,82,.35); color: #a65338; background: #fff5f0; }
.progress-stat.good { border-color: rgba(35,107,82,.25); color: var(--green); background: #eef7f2; }

.map-scroll { min-height: 440px; margin: 22px calc(clamp(18px, 4vw, 64px) * -1) 0; padding: 10px clamp(18px, 4vw, 64px) 28px; overflow-x: auto; }
.map { position: relative; width: max-content; min-width: 100%; }
.columns { position: relative; z-index: 2; display: flex; align-items: flex-start; gap: 68px; }
.column { width: 250px; flex: 0 0 250px; }
.column-title { min-height: 28px; margin: 0 0 13px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.column-nodes { display: flex; flex-direction: column; gap: 14px; }
.connections { position: absolute; z-index: 1; inset: 0; overflow: visible; pointer-events: none; }
.connections path { fill: none; stroke: #cbd2cc; stroke-width: 1.5; }

.node-card { position: relative; min-height: 136px; padding: 17px; border: 1px solid #dce1dc; border-top: 3px solid var(--node-color, var(--green)); border-radius: 12px; background: var(--card); box-shadow: 0 5px 16px rgba(38,55,49,.055); }
.node-card.is-task { background: #f1f8f4; }
.node-card.is-editing { box-shadow: 0 0 0 3px rgba(35,107,82,.1), var(--shadow); }
.node-topline { justify-content: space-between; gap: 10px; }
.node-type { color: var(--node-color); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.node-menu { border: 0; color: #9aa39f; background: transparent; cursor: pointer; }
.node-text { min-height: 42px; margin: 13px 0 15px; font-size: 15px; font-weight: 700; line-height: 1.65; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 5px; margin: -6px 0 12px; }
.task-meta:empty { display: none; }
.task-meta span { padding: 4px 7px; border-radius: 5px; color: var(--green-dark); background: var(--green-soft); font-size: 10px; }
.branch-status { margin: -6px 0 11px; }
.branch-status:empty { display: none; }
.branch-status span { display: inline-flex; align-items: center; gap: 5px; padding: 5px 7px; border-radius: 6px; color: #a65338; background: #fff0ea; font-size: 10px; font-weight: 800; }
.branch-status span.complete { color: var(--green); background: var(--green-soft); }
.node-actions { flex-wrap: wrap; gap: 6px; }
.node-actions button { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: white; cursor: pointer; font-size: 10px; font-weight: 700; }
.node-actions .add-button { border-color: transparent; color: white; background: var(--node-color); }
.node-actions .ai-button { border-color: rgba(87,77,142,.22); color: #554b8f; background: #f2effd; }
.node-actions .ai-button[disabled] { cursor: wait; opacity: .62; }
.node-editor { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.node-editor textarea { width: 100%; min-height: 70px; resize: vertical; padding: 9px; border: 1px solid var(--line); border-radius: 8px; }
.editor-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 7px; }
.node-editor button { padding: 6px 9px; border: 0; border-radius: 6px; cursor: pointer; font-size: 10px; font-weight: 700; }
.node-editor .save-child { color: white; background: var(--green); }
.ai-suggestions { margin-top: 12px; padding: 12px; border: 1px solid #ded8f2; border-radius: 9px; background: #faf8ff; }
.ai-suggestions[hidden] { display: none; }
.ai-suggestions-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; color: #554b8f; font-size: 10px; font-weight: 800; }
.ai-suggestions-head button { border: 0; background: transparent; cursor: pointer; }
.ai-suggestion { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 9px 0; border-top: 1px solid #ebe7f6; }
.ai-suggestion p { margin: 0; font-size: 12px; line-height: 1.55; }
.ai-suggestion button { flex: 0 0 auto; padding: 6px 8px; border: 0; border-radius: 6px; color: #fff; background: #675aa2; cursor: pointer; font-size: 10px; font-weight: 800; }
.ai-error { margin: 0; color: #a65338; font-size: 11px; line-height: 1.6; }

.coach { max-width: 840px; margin: 8px auto 0; padding: 17px 20px; display: flex; gap: 14px; border: 1px solid rgba(185,133,51,.22); border-radius: 12px; background: #fffbef; }
.coach-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--gold); font-family: Georgia, serif; font-weight: 700; }
.coach-label { margin: 0 0 3px; color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.coach p:last-child { margin: 0; font-size: 13px; line-height: 1.7; }

.dialog { width: min(540px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 24px 80px rgba(20,40,32,.25); }
.dialog::backdrop { background: rgba(25,39,34,.42); backdrop-filter: blur(3px); }
.dialog form { padding: 28px; }
.dialog-head { justify-content: space-between; gap: 20px; }
.dialog h2 { margin: 5px 0 0; font: 500 25px/1.35 Georgia, "Yu Mincho", serif; }
.dialog-intro { margin: 14px 0 22px; color: var(--muted); font-size: 13px; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eef1ec; cursor: pointer; font-size: 20px; }
.dialog input, .dialog select { margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dialog-actions { justify-content: flex-end; gap: 8px; margin-top: 8px; }
.goal-summary { margin: 18px 0 8px; padding: 12px 14px; border-left: 3px solid var(--green); color: var(--ink); background: #f1f6f3; font-size: 14px; font-weight: 700; line-height: 1.6; }
.optional { margin-left: 5px; color: var(--muted); font-size: 10px; font-weight: 500; }
.date-nudge { margin: -9px 0 20px; color: var(--gold); font-size: 11px; }

@media (max-width: 780px) {
  body { background: linear-gradient(180deg, #fafaf6 0%, #f4f5f1 100%); }
  .topbar { height: auto; min-height: 74px; padding: 14px 18px; }
  .topbar { position: sticky; z-index: 20; top: 0; }
  .brand { gap: 9px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand h1 { font-size: 14px; }
  .save-status, .version, #export-button { display: none; }
  .top-actions { margin-left: auto; }
  #reset-button { min-height: 42px; padding: 8px 11px; font-size: 11px; }
  .start-screen { min-height: calc(100vh - 74px); grid-template-columns: 1fr; align-content: center; gap: 34px; padding: 42px 0; }
  .start-copy h2 { font-size: 36px; }
  .start-copy br { display: none; }
  .start-copy > p:last-child { margin-bottom: 0; font-size: 14px; }
  .goal-form { padding: 22px 18px; border-radius: 16px; }
  .goal-input-row { flex-direction: column; }
  .goal-input-row input { min-height: 54px; font-size: 16px; }
  .goal-input-row .button { min-height: 50px; }
  .examples { align-items: flex-start; flex-direction: column; }
  .examples button { min-height: 34px; text-align: left; }
  .workspace { padding: 24px 16px 112px; }
  .workspace-head { align-items: flex-start; flex-direction: column; }
  .workspace-head h2 { font-size: 28px; }
  .legend { justify-content: flex-start; }
  .progress-wrap { position: sticky; z-index: 12; top: 74px; margin: 18px -16px 0; padding: 12px 16px 10px; background: rgba(250,250,246,.94); backdrop-filter: blur(8px); }
  .map-scroll { min-height: 0; margin: 14px 0 0; padding: 0; overflow: visible; }
  .map { width: 100%; min-width: 0; }
  .columns { width: 100%; flex-direction: column; gap: 10px; }
  .column { position: relative; width: 100%; flex: none; padding-bottom: 22px; }
  .column:not(:last-child)::after { content: "↓"; position: absolute; bottom: 0; left: 50%; color: #aeb8b2; font-size: 16px; transform: translateX(-50%); }
  .column-title { min-height: 0; margin: 0 0 8px; padding-left: 3px; font-size: 10px; }
  .column-nodes { gap: 10px; }
  .connections { display: none; }
  .node-card { min-height: 0; padding: 15px; border-radius: 11px; }
  .node-text { min-height: 0; margin: 10px 0 13px; font-size: 15px; }
  .node-actions button { min-height: 40px; padding: 9px 12px; font-size: 11px; }
  .node-editor textarea { min-height: 86px; font-size: 16px; }
  .node-editor button { min-height: 40px; padding: 8px 12px; font-size: 11px; }
  .coach { position: sticky; z-index: 10; bottom: 10px; margin-top: 18px; padding: 13px 14px; box-shadow: 0 8px 28px rgba(38,55,49,.12); }
  .coach p:last-child { font-size: 12px; }
  .dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .dialog form { max-height: 88vh; padding: 24px 18px calc(22px + env(safe-area-inset-bottom)); overflow-y: auto; }
  .dialog input, .dialog select { min-height: 52px; font-size: 16px; }
  .dialog-actions { position: sticky; bottom: 0; padding-top: 10px; background: white; }
  .dialog-actions .button { min-height: 46px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 390px) {
  .brand .eyebrow { display: none; }
  .start-copy h2 { font-size: 31px; }
  .workspace-head h2 { font-size: 25px; }
  .legend { gap: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
