:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ebe6db;
  --ink: #1d1c19;
  --ink-2: #5e5a52;
  --line: #ddd6c8;
  --accent: #0d6b5f;
  --accent-ink: #ffffff;
  --accent-soft: #d6ebe6;
  --warn: #b4410c;
  --warn-soft: #fbe3d4;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(40, 32, 20, .06), 0 4px 14px rgba(40, 32, 20, .05);
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141614;
    --surface: #1c1f1d;
    --surface-2: #262a27;
    --ink: #ecebe5;
    --ink-2: #a3a39b;
    --line: #2f3430;
    --accent: #5cc4b2;
    --accent-ink: #0d1f1b;
    --accent-soft: #1d3833;
    --warn: #f59a5c;
    --warn-soft: #3b2518;
    --danger: #f2766b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.screen {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- boot ---------- */
.boot { display: grid; place-items: center; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { display: grid; place-items: center; padding-inline: 16px; }
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px 22px; box-shadow: var(--shadow);
}
.login-logo { display: block; border-radius: 16px; margin-bottom: 14px; }
.login-card h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.login-card > .muted { margin: 4px 0 22px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input {
  width: 100%; font: inherit; font-size: 17px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 12px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.hint { color: var(--ink-2); font-size: 13px; margin: 14px 0 0; }

.btn-primary, .btn-secondary, .btn-danger {
  width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 600;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-secondary { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: 10px 8px 6px; padding-top: calc(10px + env(safe-area-inset-top));
  margin-top: calc(-1 * env(safe-area-inset-top));
  background: var(--bg);
}
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 50%;
  display: grid; place-items: center;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.date-btn {
  border: 0; background: transparent; border-radius: 12px; padding: 4px 8px;
  display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.date-btn:active { background: var(--surface-2); }
.date-weekday { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.date-main { font-size: 22px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.date-input { position: absolute; left: 50%; top: 56px; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

.subbar {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 16px 10px; min-height: 40px;
}
.subbar #count { margin-right: auto; }
.chip {
  border: 0; border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.chip-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.dot.stale { background: var(--warn); }

.list { flex: 1; padding: 0 16px 32px; touch-action: pan-y; }
.list.loading { opacity: .5; transition: opacity .15s; }

.event {
  display: grid; grid-template-columns: 58px 1fr; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 14px 14px 12px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.event.overdue { border-color: var(--warn); }
.event-time { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 600; padding-top: 1px; }
.event-text { margin: 0; overflow-wrap: anywhere; }
.event-comment { margin: 4px 0 0; font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }
.event-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.empty { text-align: center; padding: 56px 16px; color: var(--ink-2); }
.empty-mark { font-size: 40px; line-height: 1; margin-bottom: 10px; opacity: .5; }
.empty .btn-secondary { width: auto; margin-top: 16px; }

/* ---------- session sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 85dvh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: -6px -10px 6px 0; }
.sheet h2 { margin: 0; font-size: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--ink-2); font-size: 14px; }
.kv dd { margin: 0; text-align: right; font-size: 14px; }
.sheet-actions { display: grid; gap: 10px; margin-top: 18px; }
.log { list-style: none; padding: 12px; margin: 16px 0 0; background: var(--bg); border-radius: 10px; font-size: 12px; color: var(--ink-2); max-height: 160px; overflow: auto; }
.log:empty { display: none; }
.log li + li { margin-top: 2px; }

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

@media (min-width: 640px) {
  .main { max-width: 640px; margin: 0 auto; }
}
