:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1c1c1e;
  --muted: #6e6d69;
  --line: #e2e0da;
  --accent: #e5484d;
  --accent-ink: #ffffff;
  --ok: #2f9e66;
  --warn: #c98a00;
  --chip: #ecebe6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111214;
    --surface: #1b1c1f;
    --surface-2: #232428;
    --text: #ececec;
    --muted: #9a9a9f;
    --line: #2c2d31;
    --accent: #ff5f63;
    --chip: #26272b;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111214; --surface: #1b1c1f; --surface-2: #232428; --text: #ececec; --muted: #9a9a9f;
  --line: #2c2d31; --accent: #ff5f63; --chip: #26272b; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 16px; font-weight: 500;
}
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.danger { color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.error { color: var(--accent); font-size: 14px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center;
  background: var(--surface); padding: 28px 22px; border-radius: 20px; box-shadow: var(--shadow);
}
.login-card img { justify-self: center; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 0; color: var(--muted); font-size: 14px; }
.login-card input {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 12px; text-align: center;
}

/* Layout */
main { max-width: 720px; margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(120px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 14px 0 10px; }
.top h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.top-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.month-cost { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; margin-bottom: 10px; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 7px 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border-radius: 10px; padding: 0 12px; color: var(--muted);
}
.search input { flex: 1; border: 0; background: transparent; padding: 10px 0; outline: none; color: var(--text); min-width: 0; }

/* List */
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 10px; }
.day { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin: 14px 2px 2px; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
  display: grid; gap: 6px; cursor: pointer; border: 1px solid transparent; text-align: left; width: 100%;
}
.card:active { transform: scale(.995); }
.card-head { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.card-title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.card-time { color: var(--muted); font-size: 13px; white-space: nowrap; }
.card-sum { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.card-cost { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; opacity: .8; }
.meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { background: var(--chip); border-radius: 999px; padding: 0 9px; font-size: 12px; line-height: 18px; height: 22px; display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.chip.rem { color: var(--ok); }
.chip.busy { color: var(--warn); }
.chip.err { color: var(--accent); }
.spin { display: inline-block; width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); margin-top: 60px; }

/* Dock */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 14px 24px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.dock .round { justify-self: start; }
.mode-btn {
  justify-self: end; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.mode-btn.on { color: var(--accent); border-color: var(--accent); }
.round { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; }
.rec {
  width: 76px; height: 76px; border-radius: 50%; border: 4px solid var(--text); background: transparent;
  display: grid; place-items: center; padding: 0;
}
.rec-dot { width: 58px; height: 58px; border-radius: 50%; background: var(--accent); transition: all .2s; }
.rec.on .rec-dot { width: 30px; height: 30px; border-radius: 8px; }
.rec-time { justify-self: end; color: var(--muted); font-variant-numeric: tabular-nums; visibility: hidden; }

/* Recording overlay */
.overlay { position: fixed; inset: 0; z-index: 4; }
.rec-overlay {
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  display: grid; place-items: center; padding: 16px;
}
.rec-panel { width: 100%; max-width: 420px; display: grid; gap: 20px; justify-items: center; }
#meter { width: 100%; height: 120px; }
.rec-clock { font-size: 48px; font-weight: 300; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rec-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.rec-actions .btn { padding: 14px; font-size: 17px; }

/* Sheets (dialogs) */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(720px, 100vw); max-width: 100vw; max-height: 92dvh;
  margin: auto auto 0; border-radius: 20px 20px 0 0; box-shadow: 0 -8px 40px rgba(0,0,0,.2);
}
@media (min-width: 760px) { dialog.sheet { margin: auto; border-radius: 20px; } }
dialog.sheet::backdrop { background: rgba(0,0,0,.35); }
dialog.sheet > form, .detail-inner { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
dialog h2 { margin: 0; font-size: 20px; }
textarea, .field {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; resize: vertical;
}

/* Detail */
.detail-inner { overflow-y: auto; max-height: 92dvh; }
.d-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.d-close { border: 0; background: var(--surface-2); border-radius: 50%; width: 32px; height: 32px; display: grid; place-items: center; flex: none; }
.d-title { font-size: 22px; font-weight: 700; letter-spacing: -.01em; border: 0; background: transparent; padding: 0; width: 100%; outline: none; }
.d-sum { white-space: pre-line; }
.d-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 0 8px; }
.rems { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.rem { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.rem-title { font-weight: 600; }
.rem-sub { color: var(--muted); font-size: 13px; }
.d-transcript { color: var(--muted); font-size: 15px; white-space: pre-wrap; }
audio { width: 100%; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.small-muted { color: var(--muted); font-size: 12px; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(110px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px);
}

/* Recording overlay extras */
.rec-mode { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.rec-sync { color: var(--muted); font-size: 13px; min-height: 1.2em; text-align: center; }

/* Cards */
.card.digest { border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

/* Answers, write-ups (rendered Markdown) */
.answer { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; }
.md { font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { font-size: 15px; margin: 14px 0 6px; }
.md ul, .md ol { padding-left: 20px; margin: 6px 0; }
.md p { margin: 6px 0; }
.md code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.mindmap { height: 320px; background: var(--surface-2); border-radius: 12px; overflow: hidden; }
.mindmap svg { width: 100%; height: 100%; color: var(--text); }
.mindmap .markmap-foreign { color: var(--text); }

/* Ask */
#ask-view { display: flex; flex-direction: column; min-height: calc(100dvh - 190px); }
#ask-view[hidden] { display: none; }
.chat { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 6px 0 110px; }
.chat-hint { color: var(--muted); font-size: 14px; text-align: center; margin: 30px 10px; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--text); color: var(--bg); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.assistant { align-self: flex-start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.bubble-meta { color: var(--muted); font-size: 11px; margin-top: 4px; }
.ask-form {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; gap: 8px; align-items: flex-end;
  max-width: 720px; margin: 0 auto; padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.ask-form textarea {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--surface); border-radius: 18px;
  padding: 10px 14px; outline: none; max-height: 160px;
}
.ask-form .btn { border-radius: 50%; width: 42px; height: 42px; padding: 0; display: grid; place-items: center; flex: none; }
