/* Colors follow the Telegram theme; fallbacks are for a plain browser. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #16181d);
  --muted: var(--tg-theme-hint-color, #8a8f98);
  --accent: var(--tg-theme-button-color, #2f80ed);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --line: color-mix(in srgb, var(--muted) 25%, transparent);
  --ok: #2fa84f;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #0f1115;
    --card: #1b1e24;
    --text: #eef0f3;
    --muted: #8b919c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

h1 { font-size: 22px; margin: 4px 0 4px; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.lead { margin: 0 0 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.ritual-head { display: flex; gap: 12px; align-items: center; }
.ritual-emoji { font-size: 30px; line-height: 1; }
.ritual-head > div { flex: 1; min-width: 0; }
.ritual-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row > * { flex: 1; }

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-weight: 600;
}
button.primary { background: var(--accent); color: var(--accent-text); }
button.danger { background: transparent; color: var(--danger); }
button.ghost { background: transparent; padding: 6px 8px; }
button.back { margin: -6px 0 6px -8px; font-size: 16px; }
button:disabled { opacity: .5; }
button.wide { width: 100%; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.segmented { display: flex; gap: 6px; background: var(--card); padding: 6px; border-radius: var(--radius); margin-bottom: 12px; }
.segmented button { flex: 1; background: transparent; color: var(--muted); }
.segmented button.on { background: var(--accent); color: var(--accent-text); }
.item-row > span { flex: 0 0 auto; }

.feedback-link { margin-top: 18px; font-weight: 600; }
.feedback-banner { display: flex; gap: 12px; align-items: center;
  background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.feedback-banner > div { flex: 1; }
.feedback-banner .small { margin-top: 4px; color: var(--muted); }
.feedback-banner button { flex: 0 0 auto; padding: 10px 12px; font-size: 14px; }

.prio { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.prio-1 { background: #fff3c4; color: #8a6400; }
.prio-2 { background: #ffe0df; color: #b42318; }
.prio-card-1 { box-shadow: inset 4px 0 0 #f5c542; }
.prio-card-2 { box-shadow: inset 4px 0 0 #e5484d; }
.day-title { font-size: 15px; color: var(--muted); margin: 18px 4px 8px; text-transform: none; }
.intro { margin: 0 0 18px; padding: 14px; border-radius: var(--radius); background: var(--card); line-height: 1.45; }
button.add-time { flex: 0 0 auto; padding: 7px 10px; font-size: 13px; }
.small-btn { font-size: 13px; padding: 6px 0 0; margin-top: 6px; }
.confirm { margin-top: 10px; padding: 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--danger) 10%, transparent); }
.confirm > span { display: block; font-weight: 600; margin-bottom: 8px; }
.confirm .row { margin-top: 0; }
button.danger-solid { background: var(--danger); color: #fff; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 26px; }
.stat span { font-size: 12px; color: var(--muted); }
.promo-row { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-top: 1px solid var(--line); }
.promo-row span:last-child { margin-left: auto; }
.section-title { margin: 18px 4px 8px; }
.done-card { opacity: .55; }

.week-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.week-tabs button { padding: 8px 12px; font-size: 14px; background: var(--bg); color: var(--muted); }
.week-tabs button.on { background: var(--accent); color: var(--accent-text); }
.week-tabs button.add-week { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.current-week { margin-bottom: 8px; }

.week-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.week-row:first-child { border-top: 0; }
.week-row > b { flex: 0 0 30px; }
.week-times { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.week-time { display: flex; align-items: center; }
.week-time input { width: 104px; padding: 8px; }
.week-time button { padding: 4px 6px; }

.thought-text { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; }
.thought audio { width: 100%; margin-top: 8px; }
.tabs button { padding: 11px 4px; font-size: 13px; white-space: nowrap; }

input[type=text], input[type=time], input[type=date], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.emojis, .days { display: flex; flex-wrap: wrap; gap: 6px; }
.days { flex-wrap: nowrap; gap: 4px; }
.emojis button { font-size: 22px; padding: 6px 8px; background: var(--bg); }
.emojis button.on { outline: 2px solid var(--accent); }
.days button { flex: 1; min-width: 0; padding: 9px 0; background: var(--bg); color: var(--muted); }
.days button.on { background: var(--accent); color: var(--accent-text); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.switch input { width: 44px; height: 24px; accent-color: var(--accent); }

.item-row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.item-row input { flex: 1; }

.log-items { list-style: none; padding: 0; margin: 10px 0 0; }
.log-items li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-top: 1px solid var(--line); }
.log-items time { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.access { margin: -8px 0 16px; color: var(--ok); font-weight: 600; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.item-photos { margin: 0 0 8px 28px; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--bg); }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.open { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 6px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabs button { flex: 1; background: transparent; color: var(--muted); }
.tabs button.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.tabs[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%; bottom: 84px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--card);
  padding: 10px 16px;
  border-radius: 10px;
  max-width: calc(100% - 32px);
  font-size: 14px;
}
