:root {
  --bg: #F8FBFF;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #FFFFFF;
  --tint: #EEF5FA;
  --sky: #DCEEFF;
  --line: #E7EBEF;
  --ink: #111318;
  --muted: #6D7480;
  --accent: #2F5D8A;
  --ok: #2E7D5B;
  --warn: #B7791F;
  --bad: #C2412D;
  --shadow: 0 1px 2px rgba(17, 19, 24, 0.04), 0 8px 30px rgba(47, 93, 138, 0.06);
  --radius: 18px;
  --serif: "Instrument Serif", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1014;
    --surface: rgba(24, 27, 33, 0.78);
    --surface-solid: #181B21;
    --tint: #1C2129;
    --sky: #1E3045;
    --line: #262B33;
    --ink: #EEF2F6;
    --muted: #949BA7;
    --accent: #8BB8E8;
    --ok: #5DBB8F;
    --warn: #E0A84C;
    --bad: #EF7A66;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 30px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--sky), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--tint), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-weight: 400; margin: 0; }
.serif { font-family: var(--serif); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack > * + * { margin-top: 10px; }
.hide { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; padding: 28px 18px;
  display: flex; flex-direction: column; gap: 4px;
  border-right: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-size: 28px; padding: 0 10px 22px; letter-spacing: -0.01em; }
.brand span { color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 12px;
  color: var(--muted); font-weight: 500; text-decoration: none;
}
.nav a:hover { background: var(--tint); color: var(--ink); }
.nav a.on { background: var(--surface-solid); color: var(--ink); box-shadow: var(--shadow); }
.nav svg { width: 18px; height: 18px; flex: none; }
.rail .kbd-hint { margin-top: auto; padding: 10px 12px; }
main { padding: 36px 44px 120px; max-width: 1280px; width: 100%; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
    background: var(--surface); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  }
  .brand, .rail .kbd-hint { display: none; }
  .nav { display: flex; gap: 0; width: 100%; justify-content: space-between; }
  .nav a { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; padding: 6px 1px; font-size: 9.5px; text-align: center; }
  .nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav a.on { box-shadow: none; background: var(--tint); }
  main { padding: calc(20px + env(safe-area-inset-top)) 16px 110px; }
}

/* ---------- headers ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 26px; flex-wrap: wrap; }
.page-head h1 { font-family: var(--serif); font-size: 46px; line-height: 1; letter-spacing: -0.015em; }
.page-head h1 em { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 11px; color: var(--muted); font-weight: 600; }

/* ---------- cards and grid ---------- */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; align-items: start; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  min-width: 0;
}
.card h2 { font-family: var(--serif); font-size: 24px; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card h2 a, .card h2 .muted { font-family: var(--sans); font-size: 12.5px; font-weight: 500; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
@media (max-width: 1100px) { .span-3 { grid-column: span 6; } .span-4, .span-5 { grid-column: span 6; } .span-7, .span-8 { grid-column: span 12; } }
@media (max-width: 720px) { .grid > * { grid-column: span 12 !important; } .page-head h1 { font-size: 36px; } }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface-solid); padding: 8px 14px; border-radius: 999px;
  cursor: pointer; font-weight: 500; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=month], input[type=time], input[type=url], select, textarea {
  background: var(--surface-solid); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
label.field { display: block; }
label.field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background 0.2s; cursor: pointer; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface-solid); transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(16px); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; gap: 12px; align-items: flex-start; }
.list li:first-child { border-top: 0; padding-top: 2px; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; overflow-wrap: anywhere; }
.check { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--muted); background: transparent; cursor: pointer; flex: none; margin-top: 2px; padding: 0; }
.check:hover { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--tint); color: var(--muted); font-weight: 500; white-space: nowrap; }
.chip.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.chip.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

/* ---------- today ---------- */
.hero { margin-bottom: 26px; }
.hero h1 { font-family: var(--serif); font-size: 58px; line-height: 0.95; letter-spacing: -0.02em; }
.hero h1 em { color: var(--muted); }
.hero .clock { color: var(--muted); margin-top: 10px; }
.askbar {
  margin: 22px 0 6px; display: flex; gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 6px 6px 20px; box-shadow: var(--shadow);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); max-width: 720px;
}
.askbar input { border: 0; background: transparent; padding: 8px 0; flex: 1; }
.askbar input:focus { border: 0; }
.answer { max-width: 720px; margin: 10px 0 0 6px; white-space: pre-wrap; }
.event { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); }
.event:first-child { border-top: 0; }
.event .when { width: 78px; flex: none; color: var(--muted); font-size: 13px; padding-top: 1px; }
.event .dots { display: flex; gap: 3px; margin-top: 7px; }
.daylabel { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 14px 0 2px; font-weight: 600; }
.big-num { font-family: var(--serif); font-size: 44px; line-height: 1; }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar i.over { background: var(--bad); } .bar i.risk { background: var(--warn); }
.weather-now { display: flex; align-items: baseline; gap: 10px; }
.weather-now .big-num { font-size: 52px; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric { background: var(--tint); border-radius: 14px; padding: 10px 12px; }
.metric b { display: block; font-family: var(--serif); font-size: 26px; font-weight: 400; line-height: 1.1; }
.metric span { font-size: 12px; color: var(--muted); }
.playlists { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.playlist { display: block; color: inherit; text-decoration: none; }
.playlist:hover { text-decoration: none; }
.playlist img, .playlist .ph { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: 12px; background: var(--tint); display: block; }
.playlist div { font-size: 13px; font-weight: 500; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.device { text-align: left; border: 1px solid var(--line); background: var(--surface-solid); border-radius: 14px; padding: 12px 14px; cursor: pointer; }
.device.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.device b { display: block; font-weight: 500; font-size: 14px; }
.device span { font-size: 12px; opacity: 0.7; }
.sparks { display: flex; align-items: flex-end; gap: 4px; height: 56px; }
.sparks i { flex: 1; max-width: 34px; background: var(--sky); border-radius: 4px 4px 2px 2px; min-height: 3px; }
.sparks i.today { background: var(--accent); }
table.plain { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.plain th, table.plain td { text-align: left; padding: 7px 8px; border-top: 1px solid var(--line); vertical-align: top; }
table.plain th { color: var(--muted); font-weight: 500; border-top: 0; }
.scroll-x { overflow-x: auto; }

/* ---------- calendar ---------- */
.cal-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 18px; }
@media (max-width: 1000px) { .cal-wrap { grid-template-columns: 1fr; } }
.timeline { position: relative; display: grid; grid-template-columns: 54px 1fr; height: 1050px; padding-top: 10px; overflow: hidden; }
.timeline .hours { position: relative; }
.timeline .hours div { position: absolute; left: 0; right: 6px; font-size: 11px; color: var(--muted); text-align: right; transform: translateY(-7px); line-height: 1.15; }
.timeline .hours div small { display: block; opacity: 0.7; font-size: 10px; }
.timeline .lane { position: relative; border-left: 1px solid var(--line); }
.timeline .lane .hr { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.timeline .ev {
  position: absolute; border-radius: 10px; padding: 5px 8px; font-size: 12.5px; overflow: hidden;
  background: color-mix(in srgb, var(--c) 18%, var(--surface-solid)); border-left: 3px solid var(--c); color: var(--ink);
  cursor: pointer; line-height: 1.25; text-decoration: none;
}
.timeline .ev:hover { text-decoration: none; filter: brightness(0.97); }
.timeline .ev b { font-weight: 600; display: block; }
.timeline .ev.conflict { box-shadow: inset 0 0 0 1.5px var(--bad); }
.timeline .now { position: absolute; left: 0; right: 0; border-top: 2px solid var(--bad); z-index: 3; }
.timeline .now::before { content: ""; position: absolute; left: -5px; top: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.allday { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.legend label { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 13.5px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.legend label .grow { flex: 1 1 150px; min-width: 0; }
.legend label:first-of-type { border-top: 0; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 12px; max-height: 60vh; overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--ink); color: var(--bg); border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--tint); border-bottom-left-radius: 6px; }
.msg .meta { display: block; font-size: 11px; opacity: 0.6; margin-top: 4px; }
.composer { display: flex; gap: 8px; margin-top: 14px; }
.mic.live { background: var(--bad); color: #fff; border-color: var(--bad); }

/* ---------- palette ---------- */
.overlay { position: fixed; inset: 0; background: rgba(14, 16, 20, 0.35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.palette { width: 100%; max-width: 640px; background: var(--surface-solid); border-radius: 22px; box-shadow: 0 30px 80px rgba(0,0,0,0.25); border: 1px solid var(--line); overflow: hidden; }
.palette input { border: 0; border-radius: 0; padding: 20px 22px; font-size: 18px; border-bottom: 1px solid var(--line); }
.palette .out { padding: 16px 22px 20px; min-height: 60px; white-space: pre-wrap; }
.palette .hints { padding: 0 22px 18px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 34px 30px; }
.login h1 { font-family: var(--serif); font-size: 44px; margin-bottom: 4px; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px; opacity: 0; transition: all 0.25s; z-index: 60; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 860px) { #toast { bottom: 96px; } }

.fade-in { animation: fade 0.35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
code.token { display: block; padding: 10px 12px; background: var(--tint); border-radius: 10px; word-break: break-all; font-size: 13px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
hr.soft { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- plan: checklist, study, routine ---------- */
.checklist li { align-items: center; padding: 8px 0; }
.checklist li.now { background: color-mix(in srgb, var(--ok) 8%, transparent); margin: 0 -10px; padding-left: 10px; padding-right: 10px; border-radius: 10px; }
.checklist li.done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }
.tick { width: 22px; height: 22px; border-radius: 7px; border: 1.5px solid var(--muted); background: transparent; cursor: pointer; flex: none; padding: 0; position: relative; }
.tick:hover { border-color: var(--ok); }
.tick.on { background: var(--ok); border-color: var(--ok); }
.tick.on::after { content: ""; position: absolute; left: 7px; top: 3px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.concept { font-family: var(--serif); font-size: 28px; line-height: 1.12; letter-spacing: -0.01em; }
.weekgrid { display: grid; grid-template-columns: 72px 1fr auto 70px; gap: 6px 12px; align-items: center; font-size: 13.5px; }
.weekgrid .today { font-weight: 600; }
.weekgrid .wk-concept { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.weekgrid select, .weekgrid input { padding: 5px 8px; font-size: 13px; border-radius: 9px; }
.heat { display: grid; grid-template-columns: 90px repeat(28, 1fr); gap: 3px; align-items: center; font-size: 12px; }
.heat i { display: block; aspect-ratio: 1; border-radius: 4px; background: var(--line); }
.heat i.s-done { background: var(--ok); } .heat i.s-prog { background: var(--warn); } .heat i.s-skip { background: color-mix(in srgb, var(--muted) 45%, transparent); }
.heat i.s-miss { background: color-mix(in srgb, var(--bad) 35%, transparent); }
.milestone { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); align-items: baseline; }
.milestone:first-child { border-top: 0; }
.milestone .days { font-family: var(--serif); font-size: 24px; width: 70px; flex: none; text-align: right; line-height: 1; }
.milestone.past .days, .milestone.done .title { color: var(--muted); }
.editor { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.editor th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 6px; font-size: 12px; }
.editor td { padding: 3px 4px; vertical-align: middle; }
.editor input[type=text], .editor input[type=number], .editor input[type=month], .editor input[type=time] { padding: 6px 8px; border-radius: 9px; font-size: 13.5px; }
.editor .x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; padding: 0 6px; }
.editor .x:hover { color: var(--bad); }
.timeline .rt { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--muted) 7%, transparent) 0 6px, transparent 6px 12px); border-top: 1px dashed color-mix(in srgb, var(--muted) 35%, transparent); z-index: 0; }
.timeline .rt span { position: absolute; right: 8px; top: 3px; font-size: 11px; color: var(--muted); }
.timeline .ev { z-index: 1; }
.mobile-only { display: none; }
@media (max-width: 860px) {
  .nav a[data-k="settings"] { display: none; }
  .mobile-only { display: inline-flex; }
  .weekgrid { grid-template-columns: 46px 1fr auto 52px; gap: 6px 8px; font-size: 12.5px; }
  .weekgrid select { max-width: 104px; }
  .heat { grid-template-columns: 64px repeat(28, 1fr); gap: 2px; }
}
.mobile-only svg { width: 18px; height: 18px; }
