/* Уютик: тёмная «вечерняя» тема из прототипа. Вёрстка под iPhone 15 (393×852),
   Mini App на весь экран. Отступы под «островок» и кнопки Telegram берём из
   переменных, которые выставляет telegram-web-app.js. */

:root {
  --bg: #17120f;
  --surface: #241c17;
  --glass: rgba(60, 44, 34, .62);
  --glass-line: rgba(255, 226, 196, .14);
  --ink: #f3e6d8;
  --muted: #b39f8e;
  --line: #3b2f27;
  --cream: #f3dcc0;
  --amber: #f0b46a;
  --ember: #e07a4f;
  --sage: #8fb08a;
  --plum: #9a83b8;
  --sky: #7fa4d6;
  --pink: #f2a0b8;
  --danger: #e0645a;
  --display: "Comfortaa", "Nunito", system-ui, sans-serif;
  --body: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Сверху: системный отступ (часы, «островок») + место под кнопки Telegram «Закрыть» и «⋯» */
  --safe-top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px))
                 + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)), 8px);
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); }
body {
  color: var(--ink);
  font: 15px/1.45 var(--body);
  min-height: 100dvh;
  background-image:
    radial-gradient(600px 380px at 15% -10%, rgba(240, 180, 106, .14), transparent 60%),
    radial-gradient(500px 400px at 110% 35%, rgba(154, 131, 184, .10), transparent 60%);
  background-attachment: fixed;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
h1, h2 { font-family: var(--display); margin: 0; }

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-radius: 22px;
}

.app { max-width: 480px; margin: 0 auto; }
.screen {
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- шапка --- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 4px; }
.title h1 { font-size: 28px; line-height: 1.1; color: #f6dcc0; }
.title span { display: block; color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.title span::first-letter { text-transform: uppercase; }
.streak { padding: 8px 14px; font-size: 15px; border-radius: 99px; white-space: nowrap; }
.streak b { font-family: var(--display); }

/* --- итог дня --- */
.summary { display: flex; align-items: center; gap: 16px; padding: 14px 16px; }
.ring { width: 76px; height: 76px; flex: none; }
.ring circle { fill: none; stroke-width: 9; }
.ring-bg { stroke: rgba(255, 255, 255, .08); }
.ring-fg { stroke: var(--amber); stroke-linecap: round; stroke-dasharray: 0 201.06; transition: stroke-dasharray .6s ease; }
.summary-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.summary-text b { font-family: var(--display); font-size: 28px; line-height: 1.1; }
.summary-text span { color: var(--muted); font-size: 13px; }
.summary-text .mood { color: var(--ink); margin-top: 2px; }

/* --- «сейчас» / «дальше» --- */
.focus { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.focus.now { border-color: rgba(240, 180, 106, .5); }
.ic {
  width: 42px; height: 42px; flex: none; border-radius: 14px;
  display: grid; place-items: center; font-size: 20px;
  background: color-mix(in srgb, var(--kc, var(--amber)) 22%, transparent);
}
.focus-text { display: flex; flex-direction: column; min-width: 0; }
.focus-text b { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.focus-text span:last-child { color: var(--muted); font-size: 12.5px; }
.label { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--amber); font-weight: 600; }

/* --- план --- */
.section { font-size: 16px; margin: 8px 4px 0; }
.plan { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: 46px 42px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 10px;
  border-radius: 20px;
  background: rgba(36, 28, 23, .78);
  border: 1px solid var(--line);
  width: 100%;
  text-align: left;
}
.item time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; text-align: center; }
.item time small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
.item .txt { min-width: 0; display: flex; flex-direction: column; }
.item .txt b { font-weight: 500; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .txt span { color: var(--muted); font-size: 12px; }
.item.upcoming { opacity: .62; }
.item.now { border-color: rgba(240, 180, 106, .55); background: rgba(60, 44, 34, .8); }
.item.marked .txt b { color: var(--muted); }
.item:active:not(:disabled) { transform: scale(.985); }
.item:disabled { cursor: default; }

.chip { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 99px; white-space: nowrap; }
.chip.ask { background: var(--cream); color: #2a1d14; }
.chip.wait { color: var(--muted); padding-inline: 4px; }
.chip.done { background: rgba(143, 176, 138, .2); color: var(--sage); }
.chip.partial { background: rgba(240, 180, 106, .18); color: var(--amber); }
.chip.skipped { background: rgba(224, 100, 90, .18); color: var(--danger); }

.k-study { --kc: var(--sky); }
.k-gym { --kc: var(--ember); }
.k-food { --kc: var(--sage); }
.k-morning { --kc: var(--pink); }
.k-rest { --kc: var(--amber); }
.k-sleep { --kc: var(--plum); }

.k-bath { --kc: var(--sky); }
.k-phone { --kc: var(--plum); }
.k-away { --kc: var(--sage); }

/* распорядок Уютика на вкладке «Дом» */
.routine .item { grid-template-columns: 46px 42px 1fr auto; }
.routine .item.past { opacity: .5; }
.routine .chip.here { background: rgba(240, 180, 106, .18); color: var(--amber); }

.empty { text-align: center; color: var(--muted); margin: 24px 0; }
.empty b { color: var(--ink); }
.error { padding: 14px 16px; margin: 0; border-color: rgba(224, 100, 90, .45); }

/* --- заглушки вкладок --- */
/* --- экран «Дом» --- */
/* Комната занимает первый экран между шапкой и нижним меню, ниже листается распорядок */
.house {
  position: relative; flex: none; min-height: 320px;
  height: calc(100dvh - var(--safe-top) - var(--nav-h) - var(--safe-bottom) - 196px); overflow: hidden; border-radius: 28px;
  background: radial-gradient(120% 80% at 50% 40%, #3a2a20 0%, #1d1612 70%);
}
#house { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.rooms {
  position: absolute; left: 10px; right: 10px; top: 10px; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; padding: 4px; border-radius: 99px;
}
.arrow { width: 38px; height: 38px; border-radius: 50%; background: rgba(255, 255, 255, .08); font-size: 22px; line-height: 1; }
.arrow:active { background: rgba(255, 255, 255, .16); }
.rname { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.rname b { font-family: var(--display); font-size: 15px; }
.dots { display: flex; gap: 6px; align-items: center; }
.dots button { width: 8px; height: 8px; border-radius: 9px; background: rgba(255, 255, 255, .25); transition: width .2s; }
.dots button.on { background: var(--cream); width: 18px; }
.dots button.here { box-shadow: 0 0 0 2px var(--sage); }
.away {
  position: absolute; left: 50%; top: 66px; transform: translateX(-50%); z-index: 2;
  font-size: 12px; font-weight: 500; padding: 6px 12px; border-radius: 99px; white-space: nowrap;
}
.zzz { position: absolute; left: 64%; top: 36%; font-family: var(--display); color: var(--sky); font-size: 18px; pointer-events: none; }
.zzz span { position: absolute; animation: zz 2.8s ease-out infinite; opacity: 0; }
.zzz span:nth-child(2) { animation-delay: .9s; font-size: 14px; left: 10px; }
.zzz span:nth-child(3) { animation-delay: 1.8s; font-size: 11px; left: 18px; }
@keyframes zz { 0% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(14px, -30px); } }
.bubble {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2;
  padding: 8px 12px; font-size: 12.5px; text-align: center; border-color: rgba(224, 100, 90, .4);
}
/* Деревянная табличка «На учёбе», пока Уютика нет дома */
.sign {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%) rotate(-3deg); z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 18px;
  background: #8a6544; border: 3px solid #5b3f2c; border-radius: 10px; box-shadow: 0 8px 18px rgba(0, 0, 0, .45);
  color: #fbeedd; pointer-events: none; white-space: nowrap;
}
.sign::before { content: ""; position: absolute; top: -26px; left: 50%; width: 46px; height: 24px; transform: translateX(-50%);
  border: 2px solid #3b2a20; border-bottom: 0; border-radius: 24px 24px 0 0; }
.sign b { font: 700 17px var(--display); }
.sign span { font-size: 12.5px; opacity: .85; }
.level { font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 99px; white-space: nowrap; }
.level[data-l="0"] { background: rgba(242, 160, 184, .18); color: var(--pink); }
.level[data-l="1"] { background: rgba(240, 180, 106, .18); color: var(--amber); }
.level[data-l="2"], .level[data-l="3"] { background: rgba(224, 100, 90, .2); color: var(--danger); }

.soon { min-height: 100dvh; justify-content: center; }
.soon-card { padding: 28px 22px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.soon-ic { font-size: 44px; }
.soon-card h1 { font-size: 22px; }
.soon-card p { margin: 0; color: var(--muted); max-width: 30ch; }

/* --- нижнее меню --- */
.nav {
  position: fixed;
  left: 12px; right: 12px;
  bottom: var(--safe-bottom);
  max-width: 456px;
  margin: 0 auto;
  height: var(--nav-h);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  border-radius: 26px;
  z-index: 10;
}
.nav button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); border-radius: 20px;
}
.nav button.on { background: var(--cream); color: #2a1d14; }
.nav svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* --- шторка --- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); animation: fade .2s ease; }
.sheet-panel {
  position: relative; width: 100%; max-width: 480px; margin: 0 auto;
  background: var(--surface); border-top: 1px solid var(--glass-line);
  border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 14px);
  display: flex; flex-direction: column; gap: 6px;
  animation: up .25s ease;
}
.grip { width: 40px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .2); margin: 0 auto 10px; }
.sheet-panel h2 { font-size: 20px; margin-bottom: 10px; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choices button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 4px; border-radius: 18px; background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line); font-weight: 500; font-size: 14px;
}
.choices button span { font-size: 24px; }
.choices button.current { border-color: var(--cream); }
.choices button:active { transform: scale(.97); }
.cancel { margin-top: 6px; padding: 12px; color: var(--muted); border-radius: 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px);
  padding: 9px 16px; border-radius: 99px; background: var(--cream); color: #2a1d14;
  font-size: 13.5px; font-weight: 500; z-index: 30; white-space: nowrap;
  animation: fade .2s ease;
}

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .zzz span { opacity: 1; }
}
