:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14171a);
  --hint: var(--tg-theme-hint-color, #6b7580);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f4f7);
  --line: color-mix(in srgb, var(--hint) 28%, transparent);
  --event: #2f7de1;
  --deadline: #e8890c;
  --danger: #d64550;
  --ok: #2e9e5b;
  --radius: 14px;
  --nav-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #7f91a4);
    --link: var(--tg-theme-link-color, #6ab3f3);
    --accent: var(--tg-theme-button-color, #5288c1);
    --card: var(--tg-theme-secondary-bg-color, #232e3c);
    --event: #5aa2f5;
    --deadline: #f0a53c;
    --danger: #ef6b73;
    --ok: #5cc98a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 0 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}

main { max-width: 640px; margin: 0 auto; padding-top: 16px; }

h1 { font-size: 24px; margin: 4px 0 2px; }
h2 { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--hint); margin: 22px 0 8px; }
.sub { color: var(--hint); margin: 0 0 8px; }

.card { background: var(--card); border-radius: var(--radius); padding: 4px 14px; }
.row { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.time { width: 52px; flex: none; font-variant-numeric: tabular-nums; font-weight: 600; }
.time small { display: block; color: var(--hint); font-weight: 400; font-size: 12px; }
.meta { color: var(--hint); font-size: 14px; }
.empty { color: var(--hint); padding: 14px 0; }

.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: color-mix(in srgb, var(--hint) 18%, transparent); color: var(--hint); margin-right: 6px; white-space: nowrap; }
.chip.soon { background: color-mix(in srgb, var(--deadline) 20%, transparent); color: var(--deadline); font-weight: 600; }
.chip.warn { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.chip.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }

.banner { background: color-mix(in srgb, var(--deadline) 16%, var(--bg)); border: 1px solid color-mix(in srgb, var(--deadline) 45%, transparent); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; font-size: 14px; }

a { color: var(--link); }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.btn { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; min-height: 44px; }
.btn.ghost { background: transparent; color: var(--link); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; font-weight: 500; }
.btn[disabled] { opacity: .5; }

input[type="text"], input[type="search"], textarea { width: 100%; background: var(--card); border: 1px solid transparent; border-radius: 12px; padding: 11px 12px; min-height: 44px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); }
textarea { resize: vertical; min-height: 84px; }

.stack { display: grid; gap: 10px; margin: 10px 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* month grid */
.month-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 10px; }
.month-head h1 { font-size: 20px; margin: 0; text-transform: capitalize; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { text-align: center; color: var(--hint); font-size: 12px; padding: 4px 0; }
.day { aspect-ratio: 1; min-height: 44px; border: 0; border-radius: 12px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-variant-numeric: tabular-nums; }
.day.other { color: var(--hint); opacity: .55; }
.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.day.sel { background: var(--accent); color: var(--accent-text); }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--event); }
.dot.d { background: var(--deadline); }
.day.sel .dot { background: var(--accent-text); opacity: .85; }

/* bottom nav */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--bg); border-top: 1px solid var(--line); z-index: 5; }
#tabs button { flex: 1; background: none; border: 0; color: var(--hint); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; min-height: 44px; }
#tabs button span:first-child { font-size: 20px; line-height: 1; }
#tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.skeleton { height: 64px; border-radius: var(--radius); background: var(--card); margin: 10px 0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } #toast { transition: none; } }
