:root {
  --accent: #1f9d6b;
  --accent-text: #ffffff;
  --miss: color-mix(in srgb, #e5484d 55%, transparent);
}
:root[data-scheme='dark'] { --accent: #34c58a; --accent-text: #08261a; }

body { padding-bottom: 76px; }
.wrap { padding-top: 12px; }

/* --- Шапка --------------------------------------------------------------- */
.top { display: flex; align-items: flex-end; justify-content: space-between; margin: 4px 2px 14px; }
.top h1 { margin: 0; font-size: 26px; }
.top .date { color: var(--hint); font-size: 14px; margin-bottom: 2px; }
:root { --toast-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* --- Лента недели ---------------------------------------------------------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 12px; }
.wday {
  border: 0; background: var(--card); border-radius: 14px; padding: 8px 0 7px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--shadow);
}
.wday .wd { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: .03em; }
.wday .num { font-size: 15px; font-weight: 600; }
.wday.sel { background: var(--accent); color: var(--accent-text); }
.wday.sel .wd { color: inherit; opacity: .8; }
.mini-ring { width: 20px; height: 20px; }
.mini-ring circle { fill: none; stroke-width: 3.2; }
.mini-ring .bg { stroke: var(--line); }
.mini-ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray .3s; }
.wday.sel .mini-ring .bg { stroke: color-mix(in srgb, var(--accent-text) 30%, transparent); }
.wday.sel .mini-ring .fg { stroke: var(--accent-text); }
.mini-dot { width: 20px; height: 20px; display: grid; place-items: center; }
.mini-dot::after { content: ''; width: 4px; height: 4px; border-radius: 50%; background: var(--line); }
.wday.sel .mini-dot::after { background: color-mix(in srgb, var(--accent-text) 50%, transparent); }

/* --- Прогресс -------------------------------------------------------------- */
.progress { display: flex; align-items: center; gap: 16px; }
.ring { width: 76px; height: 76px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; }
.ring circle { fill: none; stroke-width: 8; }
.ring .bg { stroke: var(--accent-soft); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray .35s ease; }
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 17px; }
.progress .big { font-size: 18px; font-weight: 600; }
.progress .note { color: var(--hint); font-size: 14px; margin-top: 2px; }

/* --- Привычки -------------------------------------------------------------- */
.habit {
  display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--radius);
  padding: 12px 12px 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .08s;
}
.habit:active { transform: scale(0.985); }
.habit .ico {
  width: 42px; height: 42px; border-radius: 12px; background: var(--bg2); flex: none;
  display: grid; place-items: center; font-size: 22px;
}
.habit .title { font-weight: 600; overflow-wrap: anywhere; }
.habit .meta { color: var(--hint); font-size: 13px; margin-top: 1px; }
.habit .meta .fire { color: #f08c00; font-weight: 600; }
.habit.done .title { color: var(--hint); text-decoration: line-through; text-decoration-color: var(--line); }
.check {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; background: transparent; transition: background .15s, border-color .15s;
}
.check svg { width: 18px; height: 18px; opacity: 0; transform: scale(.6); transition: opacity .15s, transform .15s; }
.habit.done .check { background: var(--accent); border-color: var(--accent); }
.habit.done .check svg { opacity: 1; transform: scale(1); }
.check svg path { stroke: var(--accent-text); }
.edit-btn {
  border: 0; background: transparent; color: var(--hint); padding: 6px; margin: -6px -2px -6px -6px;
  cursor: pointer; border-radius: 8px; flex: none;
}
.edit-btn svg { width: 18px; height: 18px; display: block; }
.rest { color: var(--hint); font-size: 14px; padding: 4px 4px 12px; }
.add-row { margin-top: 4px; }

/* --- Статистика ------------------------------------------------------------ */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: 14px; padding: 12px 10px; box-shadow: var(--shadow); }
.tile .v { font-size: 22px; font-weight: 700; line-height: 1.1; }
.tile .k { font-size: 12px; color: var(--hint); margin-top: 4px; }
.hcard .head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.hcard .head .e { font-size: 22px; }
.hcard .head .t { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hcard .head .s { font-size: 13px; color: var(--hint); text-align: right; white-space: nowrap; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .wd { font-size: 10px; color: var(--hint); text-align: center; text-transform: uppercase; }
.cal .c {
  aspect-ratio: 1; border-radius: 8px; background: var(--bg2); position: relative;
  display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--hint);
}
.cal .c.done { background: var(--accent); color: var(--accent-text); }
.cal .c.miss { background: transparent; box-shadow: inset 0 0 0 1.5px var(--miss); }
.cal .c.off { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.cal .c.before { opacity: .55; }
.cal .c.future { opacity: .35; }
.cal .c.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.hcard .foot { display: flex; justify-content: space-between; font-size: 13px; color: var(--hint); margin-top: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--hint); margin: 2px 4px 14px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }

/* --- Настройки ------------------------------------------------------------- */
.set-row { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.set-row + .set-row { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.set-row .label { flex: 1; min-width: 0; }
.set-row .label b { display: block; font-weight: 600; }
.set-row .label span { color: var(--hint); font-size: 13px; }
.time-input { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 7px 10px; font-weight: 600; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .2s; cursor: pointer; }
.switch span::before {
  content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.mrow { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.mrow + .mrow { border-top: 1px solid var(--line); }
.mrow .e { font-size: 20px; width: 28px; text-align: center; }
.mrow .t { flex: 1; min-width: 0; }
.mrow .t div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow .t small { color: var(--hint); }
.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 10px; background: var(--bg2); color: var(--text);
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn svg { width: 16px; height: 16px; }
.tip { font-size: 14px; color: var(--hint); }
.tip code { background: var(--bg2); border-radius: 6px; padding: 1px 5px; color: var(--text); font-size: 13px; }

/* --- Нижняя навигация ------------------------------------------------------ */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card);
  border-top: 1px solid var(--line); display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.nav-in { display: flex; width: 100%; max-width: 560px; }
.nav button {
  flex: 1; border: 0; background: none; color: var(--hint); cursor: pointer; padding: 4px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--accent); }

/* --- Нижний лист (редактор привычки) --------------------------------------- */
.sheet-bg {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 50; opacity: 0;
  transition: opacity .2s; display: flex; align-items: flex-end; justify-content: center;
}
.sheet-bg.show { opacity: 1; }
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto;
  transform: translateY(30px); transition: transform .22s ease;
}
.sheet-bg.show .sheet { transform: none; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 20px; margin-bottom: 14px; }
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; font-weight: 600; }
.emojis { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emojis button {
  aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--bg2); font-size: 21px; cursor: pointer;
  display: grid; place-items: center; padding: 0;
}
.emojis button.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.days button {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 0;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--hint);
}
.days button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.presets { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.sheet .actions { display: flex; gap: 8px; margin-top: 8px; }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.err { color: var(--danger); font-size: 13px; margin-top: 6px; min-height: 0; }

/* --- Онбординг ------------------------------------------------------------- */
.hero { text-align: center; padding: 18px 8px 8px; }
.hero .logo {
  width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 12px; display: grid; place-items: center;
  background: linear-gradient(140deg, #2bbf83, #128a5c); box-shadow: 0 8px 24px rgba(31, 157, 107, .35);
}
.hero .logo svg { width: 40px; height: 40px; }
.hero h1 { font-size: 26px; }
.hero p { color: var(--hint); margin: 6px auto 0; max-width: 340px; }
.steps { display: flex; gap: 6px; justify-content: center; margin: 14px 0 16px; }
.steps i { width: 22px; height: 4px; border-radius: 2px; background: var(--line); }
.steps i.on { background: var(--accent); }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick button {
  border: 1.5px solid transparent; background: var(--card); border-radius: 14px; padding: 12px; text-align: left;
  display: flex; align-items: center; gap: 10px; cursor: pointer; box-shadow: var(--shadow); font-size: 14px; line-height: 1.25;
}
.pick button .e { font-size: 22px; flex: none; }
.pick button.on { border-color: var(--accent); background: var(--accent-soft); }
.custom { display: flex; gap: 8px; margin-top: 10px; }
.times { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.times button {
  border: 1.5px solid transparent; background: var(--card); border-radius: 14px; padding: 14px 0; cursor: pointer;
  font-weight: 700; font-size: 16px; box-shadow: var(--shadow);
}
.times button small { display: block; font-weight: 500; font-size: 12px; color: var(--hint); margin-top: 2px; }
.times button.on { border-color: var(--accent); background: var(--accent-soft); }
.sticky-cta { position: sticky; bottom: 0; padding: 12px 0 8px; background: linear-gradient(transparent, var(--bg2) 30%); }

/* --- Скелетон -------------------------------------------------------------- */
.skel { background: var(--card); border-radius: var(--radius); height: 64px; margin-bottom: 8px; position: relative; overflow: hidden; }
.skel::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 6%, transparent), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

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

/* --- Согласие на рекламу (онбординг) -------------------------------------- */
.consent { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; font-size: 13px; color: var(--hint); line-height: 1.4; cursor: pointer; }
.consent input { width: 20px; height: 20px; flex: none; margin: 1px 0 0; accent-color: var(--accent); }
