:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --holiday: #dc2626;
  --ok: #059669;
  --c-event: #4f46e5;
  --c-task: #059669;
  --c-birthday: #db2777;
  --c-nameday: #d97706;
  --c-anniversary: #7c3aed;
  --c-reminder: #0284c7;
  --c-other: #64748b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f1a;
    --surface: #141a29;
    --surface-2: #1b2234;
    --text: #e8eaf0;
    --muted: #949bb0;
    --line: #262e44;
    --accent: #818cf8;
    --accent-ink: #0b0f1a;
    --holiday: #f87171;
    --c-event: #818cf8;
    --c-task: #34d399;
    --c-birthday: #f472b6;
    --c-nameday: #fbbf24;
    --c-anniversary: #a78bfa;
    --c-reminder: #38bdf8;
    --c-other: #94a3b8;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }

button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
button.small { padding: 4px 10px; font-size: 13px; }
button:active { transform: translateY(1px); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 11px;
  margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { color: var(--text); font-size: 15px; }

.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.logo {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-size: 18px;
}

/* top bar */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 2px; background: var(--surface-2); border-radius: 11px; padding: 3px; }
.tabs button { border: 0; background: transparent; padding: 6px 11px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
@media (max-width: 420px) { .top .brand { font-size: 0; gap: 0; } .top .brand .logo { font-size: 18px; } }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px 0; }

.banner {
  max-width: 760px; margin: 12px auto 0; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border-radius: var(--radius);
  font-size: 14px;
}
@media (max-width: 788px) { .banner { margin: 12px 14px 0; } }

/* days */
.day { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 8px; margin-bottom: 12px; border: 1px solid var(--line); }
.day.today { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.day.today h3 { color: var(--accent); }
.day.overdue h3 { color: var(--danger); }
.day > header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.day h3 { font-size: 15px; font-weight: 650; }
.day h3::first-letter { text-transform: uppercase; }
.nameday { font-size: 13px; color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.holiday { background: color-mix(in srgb, var(--holiday) 14%, transparent); color: var(--holiday); font-weight: 600; }
.empty { color: var(--muted); font-size: 14px; margin: 8px 0 4px; }

.entries { list-style: none; margin: 6px 0 0; padding: 0; }
.entry {
  display: grid; grid-template-columns: 46px 26px 1fr; align-items: start; gap: 6px;
  padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.entry:first-child { border-top: 0; }
.entry .time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; padding-top: 1px; display: flex; flex-direction: column; }
.entry .time small { color: var(--muted); font-weight: 400; font-size: 12px; }
.entry .ico { font-size: 17px; line-height: 1.2; }
.entry .body { display: flex; flex-direction: column; min-width: 0; border-left: 3px solid var(--c, var(--c-other)); padding-left: 9px; }
.entry .title { font-weight: 550; overflow-wrap: anywhere; }
.entry .meta { font-size: 13px; color: var(--muted); }
.entry .meta.overdue { color: var(--danger); }
.entry.is-done .title { text-decoration: line-through; color: var(--muted); }
.entry input.done { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--c-task); cursor: pointer; }
.t-event { --c: var(--c-event); }
.t-task { --c: var(--c-task); }
.t-birthday { --c: var(--c-birthday); }
.t-nameday { --c: var(--c-nameday); }
.t-anniversary { --c: var(--c-anniversary); }
.t-reminder { --c: var(--c-reminder); }
.t-other { --c: var(--c-other); }

.add-on { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 6px 0; }
.add-on:hover { color: var(--accent); }
.more { display: block; margin: 4px auto 20px; }

/* month */
.month-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.month-head h2 { font-size: 20px; flex: 1; text-align: center; text-transform: capitalize; }
.grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 14px;
}
.wd { text-align: center; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding-bottom: 2px; }
.cell {
  min-height: 78px; padding: 4px; border-radius: 10px; text-align: left;
  display: flex; flex-direction: column; gap: 2px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
}
.cell .num { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cell.other { opacity: .45; }
.cell.we .num { color: var(--muted); }
.cell.hol .num { color: var(--holiday); }
.cell.today .num { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 6px; align-self: flex-start; }
.cell.sel { outline: 2px solid var(--accent); outline-offset: -1px; }
.chip-mini {
  display: block; font-size: 11px; line-height: 1.3; padding: 1px 4px; border-radius: 5px;
  background: color-mix(in srgb, var(--c) 16%, transparent); color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip-mini.is-done { text-decoration: line-through; opacity: .6; }
.chip-more { font-size: 11px; color: var(--muted); }
@media (max-width: 520px) {
  .cell { min-height: 54px; }
  .chip-mini { font-size: 0; height: 6px; padding: 0; background: var(--c); }
}

/* tasks + settings */
.toggle { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.toggle input { width: auto; margin: 0; accent-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h3 { font-size: 16px; margin-bottom: 8px; }
.card p { margin: 6px 0; }
.copy { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.copy code { flex: 1; overflow-wrap: anywhere; font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }
.spacer { flex: 1; }

/* fab */
.fab {
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 20;
  width: 58px; height: 58px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-size: 30px; line-height: 1;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* dialog */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 20px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 12, 20, .45); }
dialog form { padding: 18px; max-height: calc(100dvh - 40px); overflow: auto; }
dialog h2 { font-size: 18px; margin-bottom: 14px; }
details { margin: 4px 0 10px; }
summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-bottom: 8px; }
fieldset.remind { border: 0; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
fieldset.remind legend { font-size: 13px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chip { margin: 0; }
.chip input { display: none; }
.chip span {
  display: inline-block; padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line);
  font-size: 13px; color: var(--text); cursor: pointer; user-select: none;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 99px; font-size: 14px; z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}

/* login + oauth */
.login, body.oauth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
body.oauth { padding-bottom: 20px; }
.oauth-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 22px; box-shadow: var(--shadow);
}
.oauth-card .brand { margin-bottom: 16px; }
.oauth-card h1 { font-size: 20px; margin-bottom: 8px; }
.oauth-card button { width: 100%; margin-top: 8px; padding: 10px; }
.muted { color: var(--muted); font-size: 14px; }
