:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --surface-3: #e7e5df;
  --border: #e2e0d9;
  --text: #1d1c1a;
  --text-2: #55534e;
  --text-3: #7d7a73;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-tint: #e7f0fb;
  --accent-tint-2: #cde2fb;
  --band: rgba(42, 120, 214, 0.22);
  --truth: #1d1c1a;
  --buy-tint: #fdf0d6;
  --buy-ink: #7a4d00;
  --family-tint: #efebfb;
  --crit: #d03b3b;
  --house-tint: #f7efe6;
  --house-ink: #6b4a2b;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.05), 0 4px 16px rgba(20, 20, 15, 0.05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --surface-3: #2e2e2b;
    --border: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #918f86;
    --accent: #3987e5;
    --accent-ink: #9ec5f4;
    --accent-tint: #1a2a3e;
    --accent-tint-2: #1f3b5e;
    --band: rgba(57, 135, 229, 0.32);
    --truth: #f0efec;
    --buy-tint: #3a2d12;
    --buy-ink: #f5c86a;
    --family-tint: #29253b;
    --crit: #e66767;
    --house-tint: #2f261d;
    --house-ink: #e3c29e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #242422;
  --surface-3: #2e2e2b;
  --border: #33332f;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #918f86;
  --accent: #3987e5;
  --accent-ink: #9ec5f4;
  --accent-tint: #1a2a3e;
  --accent-tint-2: #1f3b5e;
  --band: rgba(57, 135, 229, 0.32);
  --truth: #f0efec;
  --buy-tint: #3a2d12;
  --buy-ink: #f5c86a;
  --family-tint: #29253b;
  --crit: #e66767;
  --house-tint: #2f261d;
  --house-ink: #e3c29e;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  word-break: auto-phrase;
  line-break: strict;
}
h1, h2, h3, p { margin: 0; }
p, li { text-wrap: pretty; }
button { font: inherit; color: inherit; }
small { font-size: 12px; }

/* ---------- header */
.site {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  max-width: 1200px; margin: 0 auto;
}
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: 0.02em; }
.logo { font-size: 20px; }
.badge { font-size: 11px; font-weight: 600; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }

/* ---------- buttons */
.primary, .ghost, .seg, .toggle, .chip, .link {
  cursor: pointer; border: 1px solid transparent; border-radius: 10px;
  transition: background-color .15s, border-color .15s, color .15s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.primary { background: var(--accent); color: #fff; padding: 9px 16px; font-weight: 600; }
.primary:hover { background: var(--accent-ink); }
:root:not([data-theme="light"]) .primary:hover { filter: brightness(1.08); }
.primary:active, .ghost:active, .chip:active { transform: translateY(1px); }
.primary.big { width: 100%; padding: 14px 18px; font-size: 17px; border-radius: 12px; }
.ghost { background: var(--surface); border-color: var(--border); padding: 8px 14px; color: var(--text); }
.ghost:hover { background: var(--surface-2); }
.link { background: none; border: 0; padding: 4px 2px; color: var(--text-2); text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
button:disabled { cursor: default; opacity: 0.55; transform: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- setup */
body[data-view="setup"] #app {
  max-width: 1040px; margin: 0 auto; padding: 8px 16px 48px;
  display: grid; grid-template-columns: 1.15fr 0.85fr; grid-template-areas: "hero setup" "how setup"; column-gap: 28px; align-items: start;
}
.hero { grid-area: hero; }
.how { grid-area: how; }
.setup { grid-area: setup; }
.hero { padding: 24px 4px 0; }
.eyebrow { color: var(--accent-ink); font-weight: 700; font-size: 13px; letter-spacing: 0.08em; }
.hero h1 { font-size: clamp(32px, 5vw, 46px); line-height: 1.2; margin: 6px 0 14px; letter-spacing: 0.01em; }
.lead { font-size: 17px; color: var(--text-2); max-width: 34em; }
.steps { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; }
.steps li { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.steps .ic { font-size: 22px; width: 44px; height: 44px; display: grid; place-items: center; background: var(--surface-2); border-radius: 10px; }
.steps b { display: block; font-size: 15px; }
.steps span { color: var(--text-2); font-size: 14px; }
.setup { padding: 22px; margin-top: 24px; position: sticky; top: 16px; }
.setup h2 { font-size: 19px; margin-bottom: 16px; }
.field { margin-bottom: 18px; }
.label { display: block; font-weight: 600; margin-bottom: 8px; }
.segs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.seg { background: var(--surface-2); padding: 10px 0; font-weight: 600; }
.seg[aria-pressed="true"], .toggle[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-ink); }
.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { background: var(--surface-2); padding: 8px 12px; }
.toggle[aria-pressed="true"]::before { content: "✓ "; }
.hint, .fine { color: var(--text-3); font-size: 13px; margin-top: 8px; }
.fine { margin-top: 12px; }

/* ---------- main: status bar */
body[data-view="main"] #app { max-width: 1200px; margin: 0 auto; padding: 0 16px 40px; }
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
  padding: 10px 14px; margin-bottom: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.bar-stats { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px; }
.wk { font-size: 20px; font-weight: 800; }
.stat-k { color: var(--text-3); font-size: 12px; margin-right: 4px; }
.stat-v { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-ctrl { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bar-ctrl .primary small { font-weight: 500; opacity: 0.85; margin-left: 4px; }

.layout { display: grid; grid-template-columns: minmax(360px, 440px) 1fr; gap: 16px; align-items: start; }
.side { display: grid; gap: 16px; }
.side h2 { font-size: 16px; }
.sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }

/* ---------- chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 520px; position: sticky; top: 76px; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.chat-head small { display: block; color: var(--text-3); line-height: 1.3; }
.avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; background: var(--accent); }
.avatar.fam { background: #6250d6; }
.msgs { position: relative; flex: 1; overflow-y: auto; padding: 14px 12px 20px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; background: var(--bg); }
.msg { display: flex; gap: 8px; align-items: flex-start; max-width: 100%; }
.msg.me { justify-content: flex-end; }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 9px 12px; max-width: calc(100% - 40px); min-width: 0; }
.bubble p + p, .bubble p + ul, .bubble ul + p { margin-top: 6px; }
.msg.me .bubble { background: var(--accent-tint); border-color: var(--accent-tint-2); border-radius: 14px 4px 14px 14px; white-space: pre-wrap; }
.msg.fam .bubble { background: var(--family-tint); border-color: transparent; }
.who { font-size: 11px; color: var(--text-3); margin-bottom: 2px; }
.pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.pill { font-size: 13px; background: var(--surface-2); border-radius: 999px; padding: 1px 9px; }
.lines { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 2px; font-size: 14px; }
.sys { align-self: center; text-align: center; font-size: 12.5px; color: var(--text-2); max-width: 92%; }
.sys.divider { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 100%; color: var(--text-3); font-weight: 600; margin: 6px 0 0; }
.sys.divider::before, .sys.divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.sys.ev { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 12px; }
.sys.home { background: var(--house-tint); color: var(--house-ink); border-color: transparent; }
.sys.compact { border-radius: 10px; text-align: left; }
.next-inline { margin-top: 10px; }

/* check-in card */
.checkin { padding: 0; overflow: hidden; width: 100%; }
.ck-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ck-head b { font-size: 15px; }
.ck-state { font-size: 12px; color: var(--text-3); }
.ck-sec { padding: 10px 12px 4px; }
.ck-sec h3 { font-size: 13.5px; font-weight: 700; }
.ck-sec .note { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }
.row { padding: 9px 0; border-top: 1px dashed var(--border); }
.ck-sec h3 + .note + .row, .ck-sec h3 + .row { border-top: 0; }
.row-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.emo { font-size: 17px; line-height: 1; }
.name { font-weight: 700; }
.est { color: var(--text); font-variant-numeric: tabular-nums; }
.est small { color: var(--text-3); margin-left: 2px; }
.est.guess { color: var(--text-2); font-style: normal; }
.buyinfo { font-size: 12.5px; color: var(--buy-ink); background: var(--buy-tint); display: inline-block; border-radius: 6px; padding: 0 7px; margin-top: 4px; }
.peek { display: inline-flex; align-items: baseline; gap: 6px; margin-top: 5px; font-size: 12.5px; color: var(--house-ink); background: var(--house-tint); border-radius: 6px; padding: 1px 8px; }
.peek b { font-size: 13.5px; }
.peek .tag { font-size: 10.5px; opacity: 0.75; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.chip { background: var(--surface); border-color: var(--border); padding: 4px 10px; font-size: 13px; border-radius: 999px; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[data-kind="confirm"][aria-pressed="true"] { background: var(--accent-tint); color: var(--accent-ink); border-color: var(--accent); }
.ck-foot { padding: 10px 12px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border-top: 1px solid var(--border); background: var(--surface-2); }
.ck-foot .primary { flex: 1 1 auto; }
.ck-foot .ghost { font-size: 13px; padding: 7px 10px; }
.checkin.done .chips .chip:not([aria-pressed="true"]) { display: none; }
.checkin.done .ck-foot { display: none; }
.checkin.done .row.cancelled .row-main { text-decoration: line-through; color: var(--text-3); }
.empty { padding: 12px; color: var(--text-2); }

.composer-wrap { border-top: 1px solid var(--border); padding: 10px 12px 12px; background: var(--surface); }
.composer { display: flex; gap: 8px; }
.composer input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.composer input:focus { outline: 2px solid var(--accent); outline-offset: 0; background: var(--surface); }
.send { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 0 16px; font-weight: 600; cursor: pointer; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.examples .k { font-size: 12px; color: var(--text-3); align-self: center; }
.ex { cursor: pointer; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; color: var(--text-2); }
.ex:hover { background: var(--surface-3); }

/* ---------- house panel */
.house { padding: 14px 16px 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px; color: var(--text-2); margin: 6px 0 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg-band { width: 22px; height: 10px; border-radius: 3px; background: var(--band); position: relative; }
.lg-band::after { content: ""; position: absolute; left: 10px; top: -1px; width: 2px; height: 12px; background: var(--accent); border-radius: 1px; }
.lg-truth { width: 10px; height: 10px; transform: rotate(45deg); background: var(--truth); border-radius: 1px; }
.rows { display: grid; }
.hrow { display: grid; grid-template-columns: minmax(118px, 150px) 1fr 52px; grid-template-areas: "name track stat" "name val stat"; column-gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.hrow:first-child { border-top: 0; }
.hname { grid-area: name; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; line-height: 1.3; }
.hname .mini { font-size: 11px; font-weight: 500; color: var(--text-3); }
.track { grid-area: track; position: relative; height: 14px; background: var(--surface-2); border-radius: 4px; }
.band { position: absolute; top: 0; bottom: 0; background: var(--band); border-radius: 4px; transition: left .35s ease, width .35s ease; }
.mu { position: absolute; top: -2px; bottom: -2px; width: 2px; margin-left: -1px; background: var(--accent); border-radius: 1px; transition: left .35s ease; }
.truth { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; transform: rotate(45deg); background: var(--truth); border: 2px solid var(--surface); border-radius: 2px; box-sizing: content-box; transition: left .35s ease; }
.hval { grid-area: val; display: flex; flex-wrap: wrap; gap: 0 10px; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; margin-top: 2px; }
.hval .tv { color: var(--text-2); }
.stat { grid-area: stat; justify-self: end; font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.s-ask { background: var(--accent-tint); color: var(--accent-ink); }
.s-buy { background: var(--buy-tint); color: var(--buy-ink); }

/* ---------- trend chart */
.trend { padding: 14px 16px 12px; }
#chart { position: relative; margin-top: 8px; }
#chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.ax { fill: var(--text-3); font-size: 11px; font-family: var(--font); }
.vl { fill: var(--text-2); font-size: 11px; font-weight: 700; font-family: var(--font); }
.grid { stroke: var(--surface-3); stroke-width: 1; }
.bar-m { fill: var(--accent); }
.hit { fill: transparent; cursor: default; }
.hit:hover + .bar-m, .col:focus-visible .bar-m { filter: brightness(1.12); }
.so { fill: var(--crit); }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -100%); z-index: 2; }
.tip b { display: block; }
details.tbl { margin-top: 6px; font-size: 13px; color: var(--text-2); }
details.tbl summary { cursor: pointer; color: var(--text-3); }
details.tbl table { border-collapse: collapse; margin-top: 6px; font-variant-numeric: tabular-nums; }
details.tbl th, details.tbl td { padding: 2px 10px 2px 0; text-align: right; }
details.tbl th:first-child, details.tbl td:first-child { text-align: left; }

.about { padding: 14px 16px; font-size: 13.5px; color: var(--text-2); }
.about h2 { color: var(--text); margin-bottom: 6px; }
.about ul { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; }

/* ---------- small screens */
@media (max-width: 900px) {
  body[data-view="setup"] #app { grid-template-columns: 1fr; grid-template-areas: "hero" "setup" "how"; }
  .setup { position: static; margin-top: 18px; }
  .steps { margin-top: 20px; }
  .hero { padding-top: 8px; }
  .layout { grid-template-columns: 1fr; }
  .bar { position: static; }
  .chat { position: static; height: 76vh; min-height: 460px; }
}
@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .site { padding: 10px 16px; }
  .bar { padding: 8px 10px; border-radius: 12px; }
  .wk { font-size: 17px; }
  .bar-stats { gap: 2px 12px; }
  .bar-ctrl { width: 100%; flex-wrap: nowrap; gap: 6px; }
  .bar-ctrl .primary { flex: 1; padding: 9px 10px; }
  .bar-ctrl .primary small { display: none; }
  .bar-ctrl .ghost { padding: 8px 9px; font-size: 12.5px; white-space: nowrap; }
  .hrow { grid-template-columns: 104px 1fr 46px; column-gap: 8px; }
  .hname { font-size: 13px; }
  .lead { font-size: 15.5px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
