/* Mentalka — минимализм в духе iOS. Тема ставится в html[data-theme]. */
:root {
  --bg: #f2f2f7;
  --cell: #ffffff;
  --text: #000000;
  --text2: rgba(60, 60, 67, .6);
  --text3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .18);
  --fill: rgba(118, 118, 128, .12);
  --press: rgba(0, 0, 0, .05);
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --h0: #e5e5ea; --h1: #c4ecce; --h2: #86dc9e; --h3: #34c759; --h4: #248a3d; --hbad: #ff8a80;
  --bar: rgba(249, 249, 249, .94);
  --seg-on: #ffffff;
  --shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04);
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #000000;
  --cell: #1c1c1e;
  --text: #ffffff;
  --text2: rgba(235, 235, 245, .6);
  --text3: rgba(235, 235, 245, .3);
  --sep: rgba(84, 84, 88, .6);
  --fill: rgba(118, 118, 128, .24);
  --press: rgba(255, 255, 255, .06);
  --blue: #0a84ff;
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
  --h0: #2c2c2e; --h1: #1d4a2a; --h2: #237a3d; --h3: #30b350; --h4: #4ee07a; --hbad: #b3362f;
  --bar: rgba(22, 22, 22, .94);
  --seg-on: #636366;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); }
body {
  color: var(--text);
  font-family: -apple-system, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  font-size: 17px; line-height: 1.3; letter-spacing: -.2px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
/* до первой синхронизации с облаком ввод не принимаем */
body.syncing #view { pointer-events: none; opacity: .6; transition: opacity .15s; }

#view {
  max-width: 560px; margin: 0 auto;
  padding: 12px 16px calc(96px + var(--safe-bottom, 0px));
}
.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* заголовки */
.eyebrow { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .2px; }
.large { font-size: 34px; font-weight: 700; letter-spacing: -.8px; line-height: 1.15; }
.back { color: var(--blue); display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-left: -4px; }
.back svg { width: 11px; height: 19px; stroke: currentColor; stroke-width: 2.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* секции и списки */
.sec-title { font-size: 13px; color: var(--text2); text-transform: uppercase; letter-spacing: .2px; margin: 26px 16px 7px; }
button.sec-title { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0; margin-bottom: 3px; }
button.sec-title svg { width: 10px; height: 10px; stroke: currentColor; stroke-width: 2.5; fill: none; }
.sec-foot { font-size: 13px; color: var(--text2); margin: 7px 16px 0; }
.group { background: var(--cell); border-radius: 12px; overflow: hidden; }
.cell {
  display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 11px 16px;
  position: relative; width: 100%; text-align: left;
}
.cell + .cell::before { content: ''; position: absolute; top: 0; left: 16px; right: 0; height: .5px; background: var(--sep); }
button.cell:active { background: var(--press); }
.cell .lbl { flex: 1; min-width: 0; }
.cell .val { color: var(--text2); }
.cell.center { justify-content: center; color: var(--red); text-align: center; }
.cell .sub { display: block; color: var(--text2); font-size: 13px; margin-top: 1px; }
.chev { width: 8px; height: 13px; stroke: var(--text3); stroke-width: 2.2; fill: none; }

/* серия */
.hero { background: var(--cell); border-radius: 16px; padding: 20px 18px; margin-top: 18px; display: flex; align-items: flex-end; justify-content: space-between; }
.hero .big { font-size: 64px; font-weight: 600; letter-spacing: -2.5px; line-height: .95; }
.hero .cap { color: var(--text2); font-size: 15px; margin-top: 6px; }
.hero .side { text-align: right; font-size: 15px; color: var(--text2); }
.hero .side b { display: block; color: var(--text); font-size: 20px; font-weight: 600; }

/* сегменты */
.segc { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: 9px; padding: 2px; }
.segc button { font-size: 13px; font-weight: 500; min-height: 32px; border-radius: 7px; transition: background .2s; }
.segc button.on { background: var(--seg-on); box-shadow: var(--shadow); font-weight: 600; }

/* квадратики */
.heat-wrap { background: var(--cell); border-radius: 16px; padding: 14px 14px 12px; }
.heat-grid { display: grid; grid-template-columns: 16px 1fr; gap: 6px; margin-top: 14px; }
.days { display: grid; grid-template-rows: repeat(7, 1fr); gap: 4px; font-size: 9.5px; color: var(--text3); }
.days span { display: flex; align-items: center; }
.heat { display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; gap: 4px; }
.heat i { aspect-ratio: 1; border-radius: 4px; background: var(--h0); display: block; }
.heat i.l1 { background: var(--h1); } .heat i.l2 { background: var(--h2); }
.heat i.l3 { background: var(--h3); } .heat i.l4 { background: var(--h4); }
.heat i.bad { background: var(--hbad); }
.heat i.out { background: transparent; }
.heat i.today { box-shadow: 0 0 0 1.5px var(--cell), 0 0 0 3px var(--text); }
.heat-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; font-size: 12px; color: var(--text2); }
.legend { display: flex; gap: 3px; align-items: center; white-space: nowrap; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* прогресс-бары целей */
.goal { flex: 1; }
.goal .r { display: flex; justify-content: space-between; gap: 8px; }
.goal .r span:last-child { color: var(--text2); }
.thin { height: 4px; background: var(--fill); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.thin b { display: block; height: 100%; border-radius: 99px; background: var(--blue); transition: width .4s ease-out; }
.thin.g b { background: var(--green); }

/* сегодня */
.pill { position: relative; background: var(--fill); padding: 6px 11px; border-radius: 8px; min-width: 70px; text-align: center; }
.pill.empty { color: var(--text3); }
.pill.now { color: var(--blue); font-weight: 500; }
/* стереть время: маленький серый кружок с крестиком, зона нажатия 44px */
.clear { width: 44px; height: 44px; margin: -10px -12px -10px -6px; display: grid; place-items: center; flex: none; }
.clear svg { width: 20px; height: 20px; padding: 5px; border-radius: 50%; background: var(--fill); stroke: var(--text2); stroke-width: 1.6; fill: none; stroke-linecap: round; }
.heat i[data-act] { cursor: pointer; }
.pill input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 16px; cursor: pointer; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--text3); flex: none;
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.check svg { width: 14px; height: 14px; stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.on > .check { background: var(--blue); border-color: var(--blue); }
.on > .check svg { opacity: 1; }
.done-text { color: var(--text2); text-decoration: line-through; text-decoration-color: var(--text3); }
.stepper { display: flex; background: var(--fill); border-radius: 9px; overflow: hidden; }
.stepper button { width: 46px; height: 34px; display: grid; place-items: center; font-size: 20px; }
.stepper button + button { border-left: .5px solid var(--sep); }
.stepper button:active { background: var(--press); }
.count { font-weight: 600; min-width: 22px; text-align: right; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--fill); border-radius: 9px; padding: 2px; width: 190px; flex: none; }
.scale button { font-size: 14px; min-height: 30px; border-radius: 7px; font-weight: 500; }
.scale button.on { background: var(--seg-on); box-shadow: var(--shadow); font-weight: 600; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 50px; border-radius: 14px; font-size: 17px; font-weight: 600; transition: transform .1s, opacity .1s;
}
.btn:active { transform: scale(.98); opacity: .85; }
.btn.tint { background: color-mix(in srgb, var(--orange) 15%, transparent); color: var(--orange); }
.btn.fill { background: var(--blue); color: #fff; }
.btn.plain { color: var(--red); font-weight: 400; }
.btn.gray { background: var(--fill); }

/* таб-бар */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bar); border-top: .5px solid var(--sep);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  padding: 6px 0 calc(8px + var(--safe-bottom, 0px));
}
.tabs button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 500; color: #8e8e93; min-height: 48px; justify-content: center; }
.tabs button.on { color: var(--blue); }
.tabs button.sos.on { color: var(--orange); }
.tabs .ico { width: 26px; height: 26px; }

/* сон */
.stat-big { font-size: 34px; font-weight: 600; letter-spacing: -.8px; margin-top: 18px; }
.stat-big small { font-size: 20px; color: var(--text2); font-weight: 500; letter-spacing: 0; }
.stat-cap { color: var(--text2); font-size: 15px; }
.chart-box { background: var(--cell); border-radius: 16px; padding: 14px 10px 10px 6px; margin-top: 16px; }
.chart-box svg { width: 100%; height: auto; display: block; }
.chart-box .grid { stroke: var(--sep); }
.chart-box .lbl { fill: var(--text2); font-size: 10px; font-family: inherit; }
.chart-box .goal-line { stroke: var(--green); stroke-width: 1.2; stroke-dasharray: 3 3; }
.chart-box .bar { fill: var(--blue); }
.empty-note { color: var(--text2); font-size: 15px; text-align: center; padding: 34px 16px; }

/* SOS */
.sos-head { text-align: center; padding-top: 18px; }
.sos-head .title { font-size: 28px; font-weight: 700; letter-spacing: -.6px; }
.sos-head .sub { color: var(--text2); font-size: 16px; margin-top: 6px; }
.ring { position: relative; width: 236px; height: 236px; margin: 26px auto 10px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--fill); }
.ring .arc { stroke: var(--orange); transition: stroke-dashoffset 1s linear; }
.ring .arc.done { stroke: var(--green); }
.ring .t { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .t b { font-size: 60px; font-weight: 300; letter-spacing: -2px; display: block; line-height: 1; }
.ring .t small { color: var(--text2); font-size: 14px; }

/* шторка */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); animation: fade .2s ease-out; }
.sheet {
  position: fixed; z-index: 21; left: 8px; right: 8px; bottom: calc(8px + var(--safe-bottom, 0px));
  max-width: 544px; margin: 0 auto;
  background: var(--cell); border-radius: 28px; padding: 10px 18px 18px;
  display: flex; flex-direction: column; gap: 16px; animation: up .25s ease-out;
}
.grab { width: 36px; height: 5px; border-radius: 99px; background: var(--text3); margin: 0 auto; }
.sheet h3 { font-size: 22px; font-weight: 700; letter-spacing: -.4px; }
.sheet p { color: var(--text2); font-size: 15px; margin-top: -8px; }
.sheet p.after { margin-top: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tags button { padding: 0 14px; min-height: 40px; border-radius: 99px; background: var(--fill); font-size: 15px; }
.tags button.on { background: var(--text); color: var(--cell); }
.sheet .btn.gray { margin-top: -6px; }

/* тост */
#toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom, 0px)); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: rgba(30, 30, 30, .92); color: #fff; font-size: 15px;
  padding: 10px 16px; border-radius: 14px; max-width: calc(100% - 32px); text-align: center;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.actionable { pointer-events: auto; display: flex; align-items: center; gap: 14px; padding-right: 8px; }
#toast button { color: #64a8ff; font-weight: 600; min-height: 36px; padding: 0 8px; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
