:root {
  color-scheme: light;
  --ink: #121a22;
  --teal: #17877b;
  --teal-dark: #0f766e;
  --teal-light: #52cfc0;
  --mint: #cde9e5;
  --bg: #f2f6f5;
  --muted: #4c5a66;
  --line: #dde7e5;
  --danger: #b3261e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

/* Пока открыто окно, страница под ним не прокручивается. */
html:has(dialog[open]) { overflow: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.5 Manrope, system-ui, sans-serif;
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
button, a { touch-action: manipulation; }
button:disabled { cursor: default; opacity: .4; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
svg {
  flex: none; width: 24px; height: 24px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
img { display: block; object-fit: cover; }

/* Шапка и страница */

header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  max-width: 720px; margin: 0 auto;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}
header strong { font-size: 20px; font-weight: 800; letter-spacing: 3px; line-height: 44px; }
header .title {
  flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: 18px; letter-spacing: 0;
}
header small { color: var(--muted); }
.logo { width: 28px; height: 28px; stroke-width: 5; }

main {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 720px; margin: 0 auto;
  padding: 4px 16px calc(104px + env(safe-area-inset-bottom));
}
main.sub { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
main.auth {
  justify-content: center; max-width: 420px; min-height: 100vh; min-height: 100dvh;
  padding-top: calc(32px + env(safe-area-inset-top)); padding-bottom: 32px;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.brand strong { font-size: 24px; font-weight: 800; letter-spacing: 4px; }
.auth h1 { text-align: center; }
hr { border: 0; border-top: 1px solid var(--line); }

/* Текст */

h1, h4 { font-family: Oswald, Impact, sans-serif; font-weight: 700; line-height: 1.2; }
h1 { font-size: clamp(36px, 12vw, 48px); }
h1 span { color: var(--teal); }
h2 { padding-top: 8px; font-size: 16px; font-weight: 800; text-align: center; }
h3 { font-size: 14px; font-weight: 800; text-transform: uppercase; }
h3::after { content: ""; display: block; width: 36px; height: 3px; margin-top: 8px; background: var(--teal); }
h4 { font-size: 26px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.accent { color: var(--teal-dark); font-weight: 700; }
.error { color: var(--danger); text-align: center; }
.error:empty { display: none; }
.pre { display: block; white-space: pre-line; }
.big { display: block; font-size: 17px; font-weight: 800; }
.number { font-size: 28px; font-weight: 800; }
.grow { flex: 1; min-width: 0; }
.grow > small { display: block; color: var(--muted); font-size: 13px; }

/* Главный экран */

.hero { display: flex; align-items: center; gap: 12px; }
.hero > div { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; min-width: 0; }
.hero img { width: 132px; height: 240px; border-radius: 80px 80px 20px 20px; background: var(--mint); }
.streak { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 16px; background: #fff; }
.streak svg { width: 22px; height: 22px; color: var(--teal-dark); }

.ring { position: relative; width: 132px; height: 132px; margin: 8px auto; }
.ring svg { width: 100%; height: 100%; stroke-width: 11; }
.ring circle { stroke: var(--line); }
.ring .arc { stroke: var(--teal); }
.ring div { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring b { font-size: 29px; font-weight: 800; line-height: 1.2; }
.ring span { font-size: 12px; color: var(--muted); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.path { display: flex; flex-direction: column; padding-bottom: 14px; overflow: hidden; border-radius: 24px; background: #fff; }
.path img { width: 100%; height: 110px; margin-bottom: 12px; background: var(--mint); }
.path b, .path small { padding: 0 14px; }
.path b { font-size: 17px; font-weight: 800; }
.path small { color: var(--muted); font-size: 13px; }

/* Карточки и строки */

.card { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 24px; background: #fff; }
.card.list { gap: 2px; padding: 8px; }
.card.mint { background: var(--mint); }
.card.dark { padding: 20px; background: var(--ink); color: #fff; }
.dark p, .dark small, .dark span { color: #c3ccd5; }
.dark > .btn { align-self: flex-start; }
.dark.center > .btn { align-self: stretch; }

.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 8px 12px; border-radius: 16px; text-align: left; }
a.row:active, button.row:active { background: var(--bg); }
.row > span { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.row small { color: var(--muted); font-size: 13px; }
.row small.accent { color: var(--teal-dark); }
.row > .end { flex: none; margin-left: auto; font-weight: 700; }
.row > svg:last-child { color: var(--muted); }
.mark { flex: none; width: 22px; height: 22px; border: 2px solid var(--teal); border-radius: 50%; }
.mark.done { background: var(--teal) radial-gradient(circle, #fff 0 3px, transparent 4px); }

.line { display: flex; align-items: center; gap: 12px; }
.line.top { align-items: flex-start; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: center; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stats.one { grid-template-columns: 1fr; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 28px; font-weight: 800; }
.stats span { font-size: 13px; }

.bar { flex: none; height: 10px; overflow: hidden; border-radius: 5px; background: var(--line); }
.bar i { display: block; height: 100%; background: var(--teal); }
.dark .bar { background: #2c3a46; }
.dark .bar i { background: var(--teal-light); }

.book { display: flex; flex-direction: column; gap: 2px; }
.book small { color: var(--muted); }

details.card { display: block; }
summary { min-height: 32px; font-weight: 800; cursor: pointer; }
details p { padding-top: 8px; }

/* Кнопки */

.btn {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 8px 20px; border: 2px solid transparent; border-radius: 24px;
  background: var(--teal-dark); color: #fff; font-weight: 700; text-align: center;
}
.btn:active { filter: brightness(.92); }
.btn svg { width: 20px; height: 20px; }
.btn.outline { border-color: var(--teal-dark); background: transparent; color: var(--teal-dark); }
.btn.soft { background: var(--mint); color: var(--ink); }
.btn.text { background: transparent; color: var(--teal-dark); }
.btn.danger { background: var(--danger); }
.btn.danger-text { background: transparent; color: var(--danger); }
.btn.grow { flex: 1; }

.round { flex: none; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; }
.round:active { background: var(--mint); }
.round.outline { border: 2px solid var(--teal-dark); color: var(--teal-dark); }
.round.filled { background: var(--teal-dark); color: #fff; }
.round.done, .round.missed { border: 2px solid var(--line); color: var(--muted); }
.round.done.on { border-color: var(--teal-dark); background: var(--teal-dark); color: #fff; }
.round.missed.on { border-color: var(--danger); background: var(--danger); color: #fff; }

.box { flex: none; display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 2px solid var(--teal); border-radius: 12px; }
.box.on { background: var(--teal); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 16px; border-radius: 20px; background: var(--mint); font-weight: 700; }
.chips .btn { flex: 1 0 auto; min-width: 56px; padding: 8px 12px; white-space: nowrap; }

.segmented { display: flex; overflow: hidden; border: 1px solid var(--teal-dark); border-radius: 24px; background: #fff; }
.segmented button { flex: 1; min-height: 44px; padding: 4px 8px; font-weight: 700; }
.segmented button + button { border-left: 1px solid var(--teal-dark); }
.segmented .on { background: var(--mint); }

.switcher { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: center; }

.week, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week button { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60px; border: 2px solid transparent; border-radius: 16px; background: #fff; }
.week small { font-size: 12px; }
.week .some { background: var(--mint); }
.week .full { background: var(--teal-dark); color: #fff; }
.week .selected { border-color: var(--ink); }
.days button { min-height: 44px; border-radius: 14px; background: #fff; font-weight: 700; }
.days .on { background: var(--ink); color: #fff; }

/* Формы; шрифт полей не меньше 16px, иначе iPhone увеличивает страницу */

form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid #b9c9c6; border-radius: 14px; background: #fff;
  color: var(--ink); font-size: 16px; font-weight: 500;
}
textarea { min-height: 112px; resize: vertical; }
input[type="date"] { display: block; -webkit-appearance: none; appearance: none; text-align: left; }
fieldset { display: flex; flex-direction: column; gap: 6px; border: 0; }
legend { padding-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 700; }
.radios { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.radios label, label.check {
  flex-direction: row; align-items: center; gap: 12px; min-height: 48px; padding: 0 14px;
  border-radius: 14px; background: #fff; color: var(--ink); font-size: 15px;
}
.radios input, .check input { flex: none; width: 22px; height: 22px; min-height: 0; padding: 0; accent-color: var(--teal-dark); }

/* Окна */

dialog {
  width: min(480px, calc(100% - 24px));
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px - env(safe-area-inset-top));
  margin: calc(12px + env(safe-area-inset-top)) auto auto;
  padding: 20px 16px; overflow-y: auto; overscroll-behavior: contain;
  border: 0; border-radius: 24px; background: #fff; color: var(--ink);
}
dialog::backdrop { background: rgb(18 26 34 / .55); }
dialog h2 { padding: 0; font-size: 20px; text-align: left; }
dialog small { color: var(--muted); font-size: 13px; }
dialog label.check { background: var(--bg); }

/* Нижние вкладки и сообщения */

nav {
  position: fixed; right: 0; bottom: 0; left: 0; z-index: 3;
  display: flex; justify-content: center; background: #fff;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}
nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 144px; min-height: 52px; font-size: 12px; }
nav svg { width: 56px; height: 32px; padding: 4px 16px; border-radius: 16px; }
nav .on { font-weight: 800; }
nav .on svg { background: var(--mint); }

#toast {
  position: fixed; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); left: 16px; z-index: 4;
  max-width: 480px; margin: 0 auto; padding: 14px 16px; border-radius: 14px;
  background: var(--ink); color: #fff; text-align: center;
  opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .2s, visibility .2s;
}
#toast.visible { opacity: 1; visibility: visible; }
