/* Дневник здоровья. Только светлая тема и системный шрифт. */

:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --card: #ffffff;
  --hero: #232a4d;
  --hero-soft: #2e3763;
  --accent: #4a5691;
  --accent-soft: rgba(74, 86, 145, 0.11);
  --sand: #f2d9a6;
  --sand-ink: #3a2f16;
  --text: #1a1a1f;
  --muted: #5c5e6d;
  --danger: #b23b45;
  --separator: rgba(35, 42, 77, 0.14);
  --card-radius: 20px;
  --control-radius: 14px;
  --tap: 44px;
  --gap: 16px;
  --pad: 18px;
  --tabbar-height: 66px;
}

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

html {
  font: 100%/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font-family: inherit; }
button { touch-action: manipulation; }

.screen {
  display: none;
  width: 100%;
  max-width: 34rem;
  min-height: 100dvh;
  margin: 0 auto;
  padding: var(--pad) var(--pad) calc(98px + env(safe-area-inset-bottom));
}
.screen.active { display: block; }
#screen-day { padding-bottom: calc(172px + env(safe-area-inset-bottom)); }
#screen-pin { padding-top: 2rem; }

h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  line-height: 1.08;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
h2 { margin: 0 0 0.75rem; font-size: 1.125rem; line-height: 1.2; letter-spacing: -0.01em; }
.sub { margin: 0 0 1.5rem; color: var(--muted); font-size: 1rem; }
.hint { color: var(--muted); font-size: 0.9375rem; line-height: 1.45; }

.bar { display: flex; align-items: center; gap: 8px; min-height: var(--tap); margin: 2px 0 20px; }
.bar h1 { flex: 1; margin: 0; font-size: 1.75rem; }
.back {
  appearance: none;
  min-height: var(--tap);
  padding: 8px 8px 8px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
}

.card {
  margin-bottom: var(--gap);
  padding: 20px;
  border-radius: var(--card-radius);
  background: var(--card);
  box-shadow: 0 8px 28px rgba(35, 42, 77, 0.045);
}

.big {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 60px;
  margin-bottom: 12px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--control-radius);
  background: var(--card);
  color: var(--text);
  font-size: 1.0625rem;
  text-align: left;
  cursor: pointer;
}
.big.primary { background: var(--accent); color: #fff; font-weight: 650; }
.big .chev { color: var(--muted); font-size: 1.25rem; }
.big.primary .chev { color: rgba(255, 255, 255, 0.72); }

.big, .chip, .circle, .step, .save, .add, .time-chip, .usual, .night, .nav, .day-nothing, .tab {
  transition: transform 100ms ease-out, background-color 140ms ease-out, color 140ms ease-out, border-color 140ms ease-out;
}
.big:active, .chip:active, .circle:active, .step:active, .save:active, .add:active,
.time-chip:active, .usual:active, .night:active, .nav:active, .day-nothing:active, .tab:active {
  transform: scale(0.97);
}
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(74, 86, 145, 0.32);
  outline-offset: 2px;
}

.field { padding: 18px 0; border-bottom: 1px solid var(--separator); }
.field:first-child { padding-top: 0; }
.field:last-child { padding-bottom: 0; border-bottom: 0; }
.field > label, .field-title { display: block; margin-bottom: 12px; font-size: 1.0625rem; font-weight: 600; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  appearance: none;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--separator);
  border-radius: var(--control-radius);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.chip[aria-pressed='true'] { border-color: var(--accent); background: var(--accent); color: #fff; }
.chip.ghost[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.circle {
  appearance: none;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0;
  aspect-ratio: 1;
  border: 1px solid var(--separator);
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 1.0625rem;
  cursor: pointer;
}
.circle[aria-pressed='true'] { border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 650; }

.stepper { display: flex; align-items: center; gap: 12px; }
.step {
  appearance: none;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--separator);
  border-radius: 50%;
  background: var(--card);
  color: var(--accent);
  font-size: 1.375rem;
  line-height: 1;
  cursor: pointer;
}
.stepper output { min-width: 4.5rem; font-size: 1.0625rem; text-align: center; font-variant-numeric: tabular-nums; }

input[type='time'], input[type='text'], input[type='number'], input[type='date'], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1px solid var(--separator);
  border-radius: var(--control-radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
textarea { min-height: 96px; resize: vertical; }
input[type='time'] { width: auto; min-width: 7rem; }

.event { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.event .remove {
  appearance: none;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  background: none;
  color: var(--danger);
  font-size: 1.25rem;
  cursor: pointer;
}
.night, .time-chip, .usual, .add {
  appearance: none;
  min-height: var(--tap);
  padding: 0 13px;
  border-radius: var(--control-radius);
  font-size: 0.9375rem;
  cursor: pointer;
}
.night, .time-chip {
  border: 1px solid var(--separator);
  background: var(--card);
  color: var(--muted);
  white-space: nowrap;
}
.night[data-offset='1'], .time-chip[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.time-chip { color: var(--text); font-size: 1rem; }
.time-chip.own { color: var(--accent); }
.usual { border: 1px dashed var(--accent); background: none; color: var(--accent); }
.add { border: 1px dashed var(--separator); background: none; color: var(--accent); font-size: 1rem; }
.times { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

/* Герой дня */
.day-hero {
  position: relative;
  overflow: hidden;
  margin-bottom: 18px;
  padding: 20px;
  border-radius: var(--card-radius);
  background: var(--hero);
  color: #fff;
  box-shadow: 0 18px 38px rgba(35, 42, 77, 0.18);
}
.day-hero::after {
  content: '';
  position: absolute;
  top: -76px;
  right: -66px;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.035);
  pointer-events: none;
}
.daybar { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: start; }
.daybar-title { min-width: 0; }
.daybar h1 { margin: 4px 0 0; color: #fff; font-size: 2rem; line-height: 1.05; letter-spacing: -0.035em; }
.daybar-note { margin: 0; color: rgba(255, 255, 255, 0.62); font-size: 0.875rem; line-height: 1.3; }
.day-progress { display: flex; min-width: 78px; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.day-progress strong { color: var(--sand); font-size: 1.75rem; line-height: 1; letter-spacing: -0.035em; }
.day-progress span { margin-top: 4px; color: rgba(255, 255, 255, 0.58); font-size: 0.75rem; }
.left-to-fill { position: relative; z-index: 1; margin: 20px 0 16px; color: rgba(255, 255, 255, 0.65); font-size: 0.9375rem; }
.left-to-fill:empty { min-height: 1.4em; }
.day-nothing {
  position: relative;
  z-index: 1;
  appearance: none;
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--control-radius);
  background: var(--sand);
  color: var(--sand-ink);
  font-size: 0.9875rem;
  font-weight: 650;
  cursor: pointer;
}
.day-nothing[aria-pressed='true'] { box-shadow: inset 0 0 0 2px rgba(58, 47, 22, 0.22); }
.day-switcher { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }
.day-switcher span { color: rgba(255, 255, 255, 0.46); font-size: 0.8125rem; }
.nav {
  appearance: none;
  display: grid;
  width: var(--tap);
  height: var(--tap);
  place-items: center;
  padding: 0 0 3px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  background: var(--hero-soft);
  color: #fff;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}
.nav[disabled] { opacity: 0.3; cursor: default; }

/* Кнопка сохранения стоит над панелью вкладок. Своего размытия у неё НЕТ:
   два полупрозрачных слоя друг на друге съедают читаемость и заметно тормозят
   отрисовку. Размывает только панель вкладок, а это - плотная подложка над ней. */
.savebar {
  position: fixed;
  z-index: 20;
  right: env(safe-area-inset-right);
  bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  left: env(safe-area-inset-left);
  padding: 10px var(--pad);
  border-top: 1px solid var(--separator);
  background: var(--bg);
}
.savebar .inner { max-width: 34rem; margin: 0 auto; }
.save {
  appearance: none;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: var(--control-radius);
  background: var(--hero);
  color: #fff;
  font-size: 1.0625rem;
  font-weight: 650;
  cursor: pointer;
}

/* Нижняя панель вкладок */
.tabbar {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  min-height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  padding: 4px max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--separator);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(22px) saturate(165%);
  -webkit-backdrop-filter: blur(22px) saturate(165%);
}
.tabbar[hidden] { display: none; }
.tabbar-inner { display: grid; max-width: 34rem; height: 62px; margin: 0 auto; grid-template-columns: repeat(4, 1fr); }
.tab {
  appearance: none;
  display: flex;
  min-width: var(--tap);
  min-height: var(--tap);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  padding: 3px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.6875rem;
  cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab:last-child circle { fill: currentColor; stroke: none; }
.tab.active { color: var(--accent); font-weight: 600; }

/* Календарь */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head button {
  appearance: none;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
}
.weekdays, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.weekdays div { padding-bottom: 8px; color: var(--muted); font-size: 0.8125rem; text-align: center; }
.day {
  appearance: none;
  position: relative;
  min-height: 44px;
  padding: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.day[disabled] { color: var(--separator); cursor: default; }
.day.today { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.day.filled::after {
  content: '';
  position: absolute;
  bottom: 5px;
  left: 50%;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateX(-50%);
}

/* Статистика */
.stats-section { margin-bottom: 24px; }
.stats-section > h2 { margin: 0 2px 12px; font-size: 1.1875rem; }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat {
  display: flex;
  min-width: 0;
  min-height: 138px;
  padding: 16px;
  flex-direction: column;
  border-radius: var(--card-radius);
  background: var(--card);
  box-shadow: 0 8px 26px rgba(35, 42, 77, 0.04);
}
.stat-label { color: var(--muted); font-size: 0.8125rem; line-height: 1.3; }
.stat .val {
  margin: 10px 0 8px;
  color: var(--hero);
  font-size: 1.5rem;
  font-weight: 750;
  line-height: 1.05;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}
.stat-note { margin-top: auto; color: var(--muted); font-size: 0.75rem; line-height: 1.35; }
.stats-note { margin: -6px 2px 22px; }

.pill {
  display: inline-block;
  padding: 7px 12px;
  border-radius: var(--control-radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.875rem;
}
.pill.warn { background: rgba(178, 59, 69, 0.1); color: var(--danger); }

/* Пин-код */
.pin { display: flex; justify-content: center; gap: 12px; margin: 2rem 0 1rem; }
.pin i { display: block; width: 14px; height: 14px; border: 1.5px solid var(--muted); border-radius: 50%; }
.pin i.on { border-color: var(--accent); background: var(--accent); }
.keys { display: grid; max-width: 16rem; margin: 0 auto; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.keys button {
  appearance: none;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0;
  aspect-ratio: 1;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
}
.keys button.blank { background: none; }
.error { min-height: 1.5rem; margin: 0.5rem 0; color: var(--danger); text-align: center; }

.toast {
  /* Поднято над кнопкой сохранения: сообщение о незаполненных полях
     закрывало ровно ту кнопку, на которую человек только что нажал. */
  position: fixed;
  z-index: 40;
  bottom: calc(var(--tabbar-height) + 76px + env(safe-area-inset-bottom));
  left: 50%;
  max-width: calc(100vw - 36px);
  padding: 12px 20px;
  border-radius: var(--control-radius);
  background: rgba(35, 42, 77, 0.94);
  color: #fff;
  font-size: 1rem;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 180ms ease-out;
}
.toast.show { opacity: 1; }

@media (max-width: 350px) {
  :root { --pad: 14px; }
  .day-hero { padding: 18px; }
  .daybar h1 { font-size: 1.75rem; }
  .stat { min-height: 128px; padding: 14px; }
  .stat .val { font-size: 1.3rem; }
}

/* Уважаем системные настройки: движение, прозрачность, контраст */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition-duration: 1ms !important; }
  .big:active, .chip:active, .circle:active, .step:active, .save:active, .add:active,
  .time-chip:active, .usual:active, .night:active, .nav:active, .day-nothing:active, .tab:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .tabbar { background: var(--card); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --separator: rgba(35, 42, 77, 0.48); --muted: #555765; }
  .daybar-note, .left-to-fill, .day-progress span, .day-switcher span { color: rgba(255, 255, 255, 0.82); }
}

/* Карточка последней записи - настоящая кнопка: её можно поймать с клавиатуры
   и она правильно читается голосовым доступом. */
.card-button {
  display: block;
  width: 100%;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

/* Пояснение под счётчиком порций: что такое одна порция и сколько вышло спирта */
.hint-note { display: block; margin-top: 2px; font-size: 0.8125rem; color: var(--muted); }

/* Одна тренировка: вид, своё название, минуты и время */
.activity-row { padding: 12px 0; border-bottom: 1px dashed var(--separator); }
.activity-row:last-child { border-bottom: 0; }
