/* Цвета берутся из темы Telegram (--tg-theme-*), запасные значения — для браузера */
:root {
  --fb-bg: #f2f2f7;
  --fb-card: #ffffff;
  --fb-text: #0b0b0c;
  --fb-hint: #8e8e93;
  --fb-accent: #2481cc;
  --fb-accent-text: #ffffff;
  --fb-destructive: #e5383b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #0e0e10;
    --fb-card: #1c1c1e;
    --fb-text: #f2f2f7;
    --fb-hint: #8e8e93;
    --fb-accent: #5ea9ff;
  }
}
:root {
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --destructive: var(--tg-theme-destructive-text-color, var(--fb-destructive));

  --red: #ef4f5a;
  --yellow: #f2b134;
  --green: #31be78;
  --empty: rgba(127, 127, 127, 0.13);
  --line: rgba(127, 127, 127, 0.2);
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card { background: var(--card); border-radius: var(--radius); padding: 18px 16px; }
.eyebrow { color: var(--hint); font-size: 13px; font-weight: 500; }
.eyebrow::first-letter { text-transform: uppercase; }

/* ---------- Сегодня ---------- */
.today h1 { font-size: 24px; line-height: 1.15; margin: 4px 0 16px; letter-spacing: -0.02em; }
.skeleton { color: var(--hint); }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice {
  --c: var(--hint);
  border: 0;
  border-radius: 16px;
  background: var(--empty);
  padding: 14px 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 14px;
  transition: transform .12s ease, background-color .2s ease, opacity .2s ease, color .2s ease;
}
.choice[data-status="red"] { --c: var(--red); }
.choice[data-status="yellow"] { --c: var(--yellow); }
.choice[data-status="green"] { --c: var(--green); }
.choice:active { transform: scale(.95); }
.choice .orb {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--c);
  box-shadow: 0 8px 18px -8px var(--c);
  display: grid; place-items: center;
  transition: background-color .2s ease;
}
.choice .orb svg { width: 20px; height: 20px; stroke: #fff; stroke-width: 2.2; transition: stroke .2s ease; }
.choice.selected { background: var(--c); color: #fff; }
.choice.selected .orb { background: #fff; box-shadow: none; }
.choice.selected .orb svg { stroke: var(--c); }
.choices.picked .choice:not(.selected) { opacity: .5; }

.note-link {
  margin-top: 12px;
  width: 100%;
  border: 0;
  background: none;
  padding: 4px 0 0;
  text-align: left;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-link.has-note { color: var(--hint); font-weight: 400; }

/* ---------- Статистика ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 18px; padding: 12px 12px 11px; min-width: 0; }
.stat .val { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.stat .val small { font-size: 14px; font-weight: 600; color: var(--hint); margin-left: 2px; }
.stat .lbl { font-size: 12px; color: var(--hint); margin-top: 3px; line-height: 1.2; }
.stat.hot .val { color: var(--green); }

/* ---------- Календарь ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.icon-btn {
  border: 0; background: var(--empty); width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
  transition: opacity .2s ease, transform .12s ease;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { transform: scale(.92); }
.icon-btn:disabled { opacity: .25; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--empty); border-radius: 11px; padding: 3px; margin-bottom: 14px; }
.segmented button { border: 0; background: none; padding: 7px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--hint); transition: background-color .2s ease, color .2s ease; }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }

.view { touch-action: pan-y; }
.view.in-next { animation: in-next .25s ease; }
.view.in-prev { animation: in-prev .25s ease; }
@keyframes in-next { from { opacity: 0; transform: translateX(18px); } }
@keyframes in-prev { from { opacity: 0; transform: translateX(-18px); } }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.weekdays { margin-bottom: 6px; }
.weekdays span { text-align: center; font-size: 11px; font-weight: 600; color: var(--hint); }

.day {
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: var(--empty);
  font-size: 15px;
  font-weight: 600;
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform .12s ease;
}
.day:active { transform: scale(.92); }
.day.blank { visibility: hidden; }
.day.red { background: var(--red); color: #fff; }
.day.yellow { background: var(--yellow); color: #fff; }
.day.green { background: var(--green); color: #fff; }
.day.future { background: none; color: var(--hint); opacity: .45; }
.day.today { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--accent); }
.day .note { position: absolute; bottom: 5px; width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .75; }

.year { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px 12px; }
.mini { border: 0; background: none; padding: 0; text-align: left; }
.mini h3 { margin: 0 0 6px; font-size: 13px; font-weight: 600; }
.mini.current h3 { color: var(--accent); }
.mini.future { opacity: .35; }
.mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mgrid i { aspect-ratio: 1; border-radius: 3px; background: var(--empty); }
.mgrid i.blank { visibility: hidden; }
.mgrid i.red { background: var(--red); }
.mgrid i.yellow { background: var(--yellow); }
.mgrid i.green { background: var(--green); }
.mgrid i.future { background: none; }
.mgrid i.today { box-shadow: 0 0 0 1.5px var(--accent); }

.summary { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.summary .empty { margin: 0; text-align: center; color: var(--hint); font-size: 14px; }
.sum-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; font-size: 13px; color: var(--hint); }
.sum-head b { color: var(--text); font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-right: 5px; }
.bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--empty); }
.bar span { min-width: 4px; transition: flex-grow .3s ease; }
.bar .red { background: var(--red); }
.bar .yellow { background: var(--yellow); }
.bar .green { background: var(--green); }
.legend { display: flex; align-items: center; gap: 12px; margin-top: 10px; font-size: 13px; color: var(--hint); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend b { color: var(--text); font-weight: 600; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend i.red { background: var(--red); }
.legend i.yellow { background: var(--yellow); }
.legend i.green { background: var(--green); }

/* ---------- Нижняя шторка ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4);
  opacity: 0; pointer-events: none; transition: opacity .25s ease;
}
.backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(105%);
  visibility: hidden;
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
}
.sheet.open { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h3 { margin: 2px 0 0; font-size: 20px; letter-spacing: -0.01em; }
.sheet-head h3::first-letter { text-transform: uppercase; }

.field { display: block; margin-top: 14px; }
.field span { display: block; font-size: 13px; color: var(--hint); margin: 0 0 6px 2px; }
.field textarea {
  width: 100%; resize: none; border: 0; border-radius: 14px;
  background: var(--empty); color: var(--text);
  padding: 12px 14px; font: inherit; font-size: 16px; outline: none;
}
.field textarea:focus { box-shadow: 0 0 0 2px var(--accent); }

.primary {
  width: 100%; margin-top: 14px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-text);
  padding: 14px; font-size: 16px; font-weight: 600;
  transition: opacity .2s ease, transform .12s ease;
}
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .4; }
.danger-link { width: 100%; margin-top: 6px; border: 0; background: none; padding: 10px; color: var(--destructive); font-size: 15px; font-weight: 500; }
.danger-link[hidden] { display: none; }

/* ---------- Прочее ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: rgba(30, 30, 32, .92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.fatal { text-align: center; padding: 48px 20px; }
.fatal .big { font-size: 44px; }
.fatal h1 { font-size: 20px; margin: 12px 0 6px; }
.fatal p { color: var(--hint); margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
