:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --sidebar: #efede7;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #dedbd3;
  --accent: #2f8f57;
  --accent-text: #ffffff;
  --accent-soft: #dcefe3;
  --selected: #e4e1d8;
  --pin: #e8820c;
  --star: #e0a100;
  --danger: #c4372f;
  --late: #c4372f;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 8px 24px rgb(0 0 0 / 8%);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #18191b;
    --panel: #1f2022;
    --sidebar: #232427;
    --text: #ececee;
    --muted: #9c9ca3;
    --line: #34353a;
    --accent: #3fae6c;
    --accent-text: #08130c;
    --accent-soft: #1f3a2a;
    --selected: #34363b;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spacer { flex: 1; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- buttons and fields ---------- */

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); font-weight: 500;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.primary:hover { filter: brightness(1.06); }
.button.danger { color: var(--danger); }
.button.wide { width: 100%; min-height: 44px; }
.button.icon-only { width: 40px; padding: 0; flex: none; }
.button:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font-weight: 500; }

.tool {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; min-width: 36px; padding: 0 8px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
}
.tool:hover { background: var(--selected); color: var(--text); }
.tool.on { color: var(--pin); }
.tool.danger:hover { color: var(--danger); }
.tool.talk { background: var(--accent); color: var(--accent-text); padding: 0 14px; border-radius: 18px; font-weight: 600; }
.tool.talk.on { background: var(--danger); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .75; } }

input[type=email], input[type=password], input[type=search], input:not([type]), input[type=date], select {
  min-height: 40px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--selected); gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 5px 14px; border-radius: 7px; font-weight: 500; color: var(--muted); }
.segmented button[aria-selected=true], .segmented button[aria-checked=true] { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 12%); }
.segmented.small button { padding: 3px 10px; font-size: 13px; }

.star-picker { display: inline-flex; }
.star-picker button { border: 0; background: none; padding: 4px 2px; font-size: 18px; line-height: 1; color: var(--line); }
.star-picker button.on { color: var(--star); }
.star-picker button:hover { color: var(--star); }

/* ---------- sign in ---------- */

.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 14px; }
.auth-card h1 { font-size: 22px; margin: 4px 0 0; }
.auth-card p { margin: 0; }
.auth-card .segmented { width: 100%; }
.auth-card .segmented button { flex: 1; white-space: nowrap; padding: 5px 8px; }
.auth-form, .stack { display: grid; gap: 12px; }
.auth-form label, .stack label { display: grid; gap: 4px; font-size: 14px; font-weight: 500; }
.form-error { color: var(--danger); margin: 0; min-height: 0; font-size: 14px; }
.form-error:empty { display: none; }
.auth-card.center { text-align: center; justify-items: center; }
.pin-input { width: 190px; font-size: 34px; letter-spacing: .55em; text-indent: .55em; text-align: center; padding: 10px 0;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.pin-input:disabled { opacity: .5; }
.code-input { width: 230px; font-size: 30px; letter-spacing: .35em; text-indent: .35em; text-align: center; padding: 10px 0;
  border-radius: 12px; border: 1px solid var(--line); background: var(--bg); font-variant-numeric: tabular-nums; }
.code-input:disabled { opacity: .5; }
.pin-small { max-width: 120px; letter-spacing: .3em; }
.sheet-actions.tight { margin-top: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand img { border-radius: 9px; }
.brand.small { font-size: 16px; gap: 8px; }
.brand.small img { border-radius: 6px; }

/* ---------- workspace ---------- */

.workspace { height: 100%; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status[data-status=offline] { color: var(--pin); }

.workspace[data-view=notes] .todo-view, .workspace[data-view=todos] .notes-view { display: none; }

.notes-view { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); min-height: 0; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; gap: 8px; padding: 12px 12px 8px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 12px 8px; }
.filters select { min-height: 34px; padding: 4px 8px; font-size: 14px; }
.sidebar > .segmented { margin: 0 12px 8px; align-self: flex-start; }
.note-list { overflow-y: auto; padding: 0 8px max(16px, env(safe-area-inset-bottom)); flex: 1; -webkit-overflow-scrolling: touch; }
.list-heading { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 8px 4px; font-weight: 600; }
.list-empty { color: var(--muted); padding: 24px 12px; text-align: center; }

.note-card {
  display: grid; gap: 2px; width: 100%; text-align: left; padding: 10px 12px; margin: 2px 0;
  border: 0; border-radius: var(--radius); background: transparent;
}
.note-card:hover { background: var(--selected); }
.note-card[aria-current=true] { background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / 8%); }
.card-top { display: flex; align-items: center; gap: 6px; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.card-pin { color: var(--pin); display: inline-flex; }
.card-pin .icon { width: 16px; height: 16px; }
.card-preview { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.card-stars { color: var(--star); }
.card-tag { color: var(--accent); }

.editor { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--panel); }
.editor-bar { display: flex; align-items: center; gap: 4px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.editor-bar .back { display: none; color: var(--accent); }
.editor-text {
  flex: 1; width: 100%; border: 0; resize: none; outline: none; background: transparent;
  padding: 20px max(24px, env(safe-area-inset-right)) 20px max(24px, env(safe-area-inset-left));
  font-size: 17px; line-height: 1.6; max-width: 820px; margin: 0 auto;
}
.editor-text:focus-visible { outline: none; }
.editor-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 6px 16px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); min-height: 40px; }
.editor-tags { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 2px 10px; font-size: 13px; font-weight: 500; }
.counts { font-size: 12px; color: var(--muted); white-space: nowrap; margin-left: auto; }
.empty { display: none; flex: 1; place-content: center; text-align: center; color: var(--muted); gap: 12px; }
.no-note .empty { display: grid; }
.no-note .editor-text, .no-note .editor-foot, .no-note .editor-bar > :not(.back) { display: none; }

/* ---------- to-dos ---------- */

.todo-view { overflow-y: auto; }
.todo-page { max-width: 760px; margin: 0 auto; padding: 24px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); }
.todo-page h1 { font-size: 28px; margin: 0 0 16px; }
.todo-add { display: grid; grid-template-columns: 1fr auto 150px auto; gap: 8px; align-items: center; margin-bottom: 16px; }
.todo-list { list-style: none; padding: 0; margin: 0 0 12px; background: var(--panel); border-radius: var(--radius); box-shadow: 0 1px 2px rgb(0 0 0 / 6%); }
.todo { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.todo:last-child { border-bottom: 0; }
.todo .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); background: none; padding: 0; }
.todo .check:hover { border-color: var(--accent); background: var(--accent-soft); }
.todo-text, input.todo-text { border: 0; background: transparent; padding: 6px 0; min-height: 0; width: 100%; border-radius: 0; }
input.todo-text:focus-visible { outline: none; border-bottom: 1px solid var(--accent); border-radius: 0; }
.todo-day { position: relative; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.todo-day input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; padding: 0; }
.todo-day.today { color: var(--accent); font-weight: 600; }
.todo-day.late { color: var(--late); font-weight: 600; }
.todo.done { grid-template-columns: 1fr auto auto auto; }
.todo.done .todo-text { text-decoration: line-through; color: var(--muted); }

/* ---------- account sheet and toasts ---------- */

.sheet { border: 0; border-radius: 16px; padding: 20px 24px 24px; width: min(480px, calc(100% - 32px)); background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgb(0 0 0 / 35%); }
.sheet h2 { margin: 0; font-size: 20px; }
.sheet h3 { margin: 18px 0 4px; font-size: 15px; }
.sheet p { margin: 4px 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }
.danger-zone { margin-top: 20px; }
.danger-zone summary { color: var(--danger); cursor: pointer; font-weight: 500; }

#toasts { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 10; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; transition: opacity .3s, transform .3s; }
.toast.leaving { opacity: 0; transform: translateY(6px); }

/* ---------- phones: one pane at a time ---------- */

@media (max-width: 759px) {
  .topbar { gap: 8px; }
  .brand.small span { display: none; }
  .notes-view { grid-template-columns: minmax(0, 1fr); }
  .editor-bar { padding: 4px 6px; gap: 0; }
  .editor-bar .tool { min-width: 34px; padding: 0 6px; }
  .editor-bar .tool.talk { padding: 0 12px; margin: 0 4px; }
  .editor-bar .tool.talk span { display: none; }
  .star-picker button { padding: 4px 1px; }
  .topbar .segmented button { padding: 5px 10px; }
  .workspace[data-pane=list] .editor, .workspace[data-pane=editor] .sidebar { display: none; }
  .editor-bar .back { display: inline-flex; }
  .no-note .empty { display: grid; }
  .editor-text { padding: 16px; font-size: 17px; }
  .todo-add { grid-template-columns: 1fr auto; }
  .todo-add .todo-date { grid-column: 1; }
  .todo { grid-template-columns: auto 1fr auto; }
  .todo .todo-day { grid-column: 2 / 4; justify-self: start; margin-top: -6px; }
  .todo.done { grid-template-columns: 1fr auto auto; }
  .todo.done .muted { grid-column: 1; }
}

/* ---------- sign-in: Rick's standard look (dark, green glow, dots) ---------- */

body.gate-page { background: radial-gradient(ellipse at top, #162033 0%, #0d1220 45%, #0a0d18 100%) fixed; color-scheme: dark; }
.gate {
  --g-text: #f8fafc; --g-muted: #94a3b8; --g-card: #0a0e1a; --g-field: #070b14; --g-line: #2a3140;
  --g-green: #76f03b; --g-green-2: #58c84a; --g-ring: #4c9a2a; --g-border: #3f8f2a; --g-red: #f87171;
  min-height: 100%; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color: var(--g-text);
}
.gate-card {
  width: 100%; max-width: 440px; background: var(--g-card); border: 1px solid var(--g-border); border-radius: 24px;
  padding: 36px 32px 32px; text-align: center;
  box-shadow: 0 0 0 1px rgb(118 240 59 / 4%), 0 0 40px rgb(118 240 59 / 10%), 0 24px 60px rgb(0 0 0 / 45%);
}
.gate-logo {
  width: 150px; height: 150px; margin: 0 auto 22px; border-radius: 50%; background: #fff; overflow: hidden;
  border: 4px solid var(--g-ring); box-shadow: 0 0 22px rgb(118 240 59 / 35%);
}
.gate-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gate-title { font-size: 34px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 8px; color: var(--g-text); }
.gate-sub { color: var(--g-muted); font-size: 16px; margin: 0 0 28px; }
.gate-form { display: grid; gap: 14px; text-align: left; }
.gate-label { font-weight: 600; font-size: 15px; margin: 4px 0 -4px; color: var(--g-text); }
.gate-label.center { text-align: center; margin-top: 6px; }
.gate-field {
  display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 14px 0 16px;
  background: var(--g-field); border: 1px solid var(--g-line); border-radius: 12px;
}
.gate-field:focus-within { border-color: var(--g-green); box-shadow: 0 0 0 3px rgb(118 240 59 / 15%); }
.gate-field > .gate-icon { color: var(--g-muted); flex: none; }
.gate-input, .gate input.gate-input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--g-text); font-size: 17px; padding: 0;
  outline: none; min-height: 0; border-radius: 0;
}
.gate-input::placeholder { color: #64748b; }
.gate-mic { border: 0; background: none; color: var(--g-muted); padding: 6px; border-radius: 8px; display: inline-flex; }
.gate-mic:hover, .gate-mic.on { color: var(--g-green); }
.gate-mic.on { animation: pulse 1.2s ease-in-out infinite; }
.gate-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.gate-button {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; min-height: 56px; margin-top: 6px;
  border: 0; border-radius: 12px; font-size: 18px; font-weight: 700; color: #0b0f19; cursor: pointer;
  background: linear-gradient(100deg, var(--g-green) 0%, var(--g-green-2) 100%);
  box-shadow: 0 8px 28px rgb(118 240 59 / 22%);
}
.gate-button:hover { filter: brightness(1.05); }
.gate-button:disabled { opacity: .6; cursor: default; }
.gate-button .gate-icon { width: 22px; height: 22px; stroke-width: 2; flex: none; }
.gate-button span { text-align: center; }

.gate-banner {
  display: flex; gap: 12px; align-items: flex-start; margin: 0; padding: 14px 16px; border-radius: 12px; text-align: left; font-size: 16px;
}
.gate-banner[hidden] { display: none; }
.gate-banner.ok { color: var(--g-green); background: rgb(118 240 59 / 7%); border: 1px solid rgb(118 240 59 / 30%); }
.gate-banner.error { color: var(--g-red); background: rgb(248 113 113 / 8%); border: 1px solid rgb(248 113 113 / 30%); }
.gate-banner .gate-icon { flex: none; margin-top: 1px; }
.gate-sent { color: var(--g-muted); text-align: center; margin: 4px 0 0; font-size: 16px; }
.gate-sent strong { color: var(--g-text); }
.gate-note { color: #64748b; text-align: center; font-size: 13px; margin: 2px 0 0; }

.dots-box {
  position: relative; display: block; height: 100px; border-radius: 14px; background: var(--g-field); cursor: text;
  border: 3px solid var(--g-green); box-shadow: 0 0 22px rgb(118 240 59 / 25%);
}
.dots-box.busy { opacity: .6; }
.dots-real {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; font-size: 16px; color: transparent;
  caret-color: transparent; background: transparent; z-index: 1; min-height: 0;
}
.dots { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 30px; }
.dots-box.n4 .dots { gap: 36px; }
.dot { width: 15px; height: 15px; border-radius: 50%; background: #3f8f2a; display: grid; place-items: center; transition: all .12s; }
.dot.digit { width: auto; height: auto; min-width: 22px; background: none; color: var(--g-text); font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot.lit { background: var(--g-green); box-shadow: 0 0 10px rgb(118 240 59 / 60%); width: 18px; height: 18px; }
.dots-box:focus-within .dot.next { background: var(--g-green); animation: pulse 1.1s ease-in-out infinite; }

.gate-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 6px; flex-wrap: wrap; }
.gate-row.center { justify-content: center; }
.gate-link { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 6px 0; color: var(--g-muted); font-size: 16px; cursor: pointer; }
.gate-link:hover { color: var(--g-text); }
.gate-link.green { color: var(--g-green); }
.gate-link .gate-icon { width: 18px; height: 18px; }

@media (max-width: 480px) {
  .gate-card { padding: 28px 20px 24px; border-radius: 20px; }
  .gate-logo { width: 120px; height: 120px; }
  .gate-title { font-size: 28px; }
  .gate-sub { font-size: 15px; margin-bottom: 22px; }
  .gate-button { font-size: 16px; }
  .dots { gap: 20px; }
  .dots-box.n4 .dots { gap: 28px; }
  .dot.digit { font-size: 30px; }
}
