:root {
  --sky-top: #0a1430;
  --sky-bottom: #1b3a5e;
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.12);
  --dialog: #1a2a4a;
  --amber: #ffc247;
  --on-amber: #2a1f00;
  --green: #3dd68c;
  --red: #ff6b6b;
  --blue: #8ab4ff;
  --text: #f1f4fa;
  --text-dim: #a7b4cc;
  --gutter: 20px;
  color-scheme: dark;
}

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

html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(var(--sky-top), var(--sky-bottom)) fixed;
  background-color: var(--sky-top);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, a { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { text-decoration: none; }

svg.i { width: 24px; height: 24px; fill: currentColor; flex: none; display: block; }
.dim { color: var(--text-dim); }
.inline-icon svg.i { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; color: var(--amber); }

h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 28px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
.display { font-size: 44px; font-weight: 300; }
.lead { color: var(--text-dim); font-size: 17px; max-width: 360px; }

/* Екрани */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + var(--gutter))
    calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + var(--gutter));
  max-width: 560px;
  margin: 0 auto;
}
.grow { flex: 1; min-height: 0; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.topbar { display: flex; align-items: center; gap: 8px; min-height: 52px; margin-bottom: 8px; }
.topbar .chip { margin-right: auto; }
.bar-title { font-size: 21px; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--text-dim); }
.icon-btn:active { background: var(--glass); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 10px 8px 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--glass-border);
  font-weight: 600; font-size: 15px; max-width: 75%;
}
.chip svg.i { width: 18px; height: 18px; }
.chip [data-icon="pin"] { color: var(--amber); }
#region-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 24px; border-radius: 999px; font-weight: 650; font-size: 17px;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary { width: 100%; background: var(--amber); color: var(--on-amber); }
.btn.tall { min-height: 68px; font-size: 20px; }
.btn.tonal { background: rgba(255, 194, 71, 0.16); color: var(--amber); }
.btn.text { color: var(--text); min-height: 48px; }
.btn.text.accent { color: var(--amber); }

/* Сфера стану */
.orb {
  --c: var(--blue);
  position: relative; width: 210px; height: 210px; flex: none;
  display: grid; place-items: center; border-radius: 50%;
  transition: transform .15s ease;
}
.orb.big { width: min(250px, 62vw); height: min(250px, 62vw); }
button.orb:active { transform: scale(0.93); }
.orb[data-phase="ALERT"] { --c: var(--red); }
.orb[data-phase="RINGING"], .orb[data-phase="SNOOZED"] { --c: var(--amber); }
.orb .ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--c) 28%, transparent);
  transform: scale(0.56); opacity: 0;
}
.orb[data-phase="IDLE"] .ring { animation: none; opacity: 1; transform: scale(0.86); background: color-mix(in srgb, var(--c) 7%, transparent); }
.orb[data-phase="IDLE"] .ring:nth-child(2) { transform: scale(1); background: color-mix(in srgb, var(--c) 5%, transparent); }
.orb[data-phase="IDLE"] .ring:nth-child(3) { display: none; }
.orb:not([data-phase="IDLE"]) .ring { animation: pulse var(--pulse, 2.8s) linear infinite; }
.orb .ring:nth-child(2) { animation-delay: calc(var(--pulse, 2.8s) / -3); }
.orb .ring:nth-child(3) { animation-delay: calc(var(--pulse, 2.8s) / -1.5); }
.orb[data-phase="ALERT"] { --pulse: 1.8s; }
.orb[data-phase="RINGING"] { --pulse: 1.1s; }
@keyframes pulse {
  from { transform: scale(0.56); opacity: 1; }
  to { transform: scale(1); opacity: 0; }
}
.orb .core {
  position: relative; width: 56%; height: 56%; border-radius: 50%;
  display: grid; place-items: center; color: var(--c);
  background: radial-gradient(color-mix(in srgb, var(--c) 32%, transparent), color-mix(in srgb, var(--c) 10%, transparent));
  border: 1.5px solid color-mix(in srgb, var(--c) 55%, transparent);
}
.orb .core svg.i { width: 43%; height: 43%; }

/* Головний екран */
#home .hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 16px 0; }
.hint {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 12px;
  padding: 6px 14px; border-radius: 999px; background: rgba(255, 194, 71, 0.12);
  color: var(--amber); font-weight: 600; font-size: 14px;
}
.hint svg.i { width: 16px; height: 16px; }
.source { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--text-dim); font-size: 13px; font-weight: 500; }
.source i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.source.stale i { background: var(--red); }

.bottom { display: flex; flex-direction: column; gap: 12px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  text-align: left; padding: 16px; border-radius: 24px;
  background: var(--glass); border: 1px solid var(--glass-border);
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.tile [data-icon] { color: var(--amber); margin-bottom: 8px; }
.tile small { color: var(--text-dim); font-size: 13px; }
.tile b { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile:disabled { opacity: 0.5; }

.banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 20px;
  background: rgba(255, 194, 71, 0.10); border: 1px solid rgba(255, 194, 71, 0.35); font-size: 14px;
}
.banner > [data-icon] { color: var(--amber); }

/* Знайомство з програмою */
.steps { display: flex; gap: 6px; padding: 8px 0 4px; }
.steps i { flex: 1; height: 4px; border-radius: 4px; background: var(--glass-border); transition: background .3s; }
.steps i.on { background: var(--amber); }
.step { flex: 1; display: none; flex-direction: column; gap: 12px; min-height: 0; animation: step-in .35s ease; }
.step.active { display: flex; }
.step > h2 { margin-top: 20px; }
.step .scroll h2 { margin: 20px 0 10px; }
.step .scroll .lead { margin-bottom: 20px; }
@keyframes step-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  display: flex; gap: 14px; align-items: flex-start; padding: 16px;
  border-radius: 24px; background: var(--glass); border: 1px solid var(--glass-border);
}
.card h3 { font-size: 17px; font-weight: 600; margin-bottom: 2px; }
.card p { color: var(--text-dim); font-size: 15px; }
.card.done { background: rgba(61, 214, 140, 0.08); border-color: rgba(61, 214, 140, 0.35); }
.card.done .badge { color: var(--green); background: rgba(61, 214, 140, 0.16); }
.badge {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; color: var(--amber); background: rgba(255, 194, 71, 0.16);
}
.badge svg.i { width: 22px; height: 22px; }

/* Налаштування */
#settings h4 { margin: 22px 8px 8px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); }
.group { border-radius: 24px; background: var(--glass); border: 1px solid var(--glass-border); overflow: hidden; }
.row { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; text-align: left; }
.row + .row { border-top: 1px solid var(--glass-border); }
.row > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.row b { font-weight: 500; }
.row small { color: var(--text-dim); font-size: 14px; }
.row:disabled, .row.disabled { opacity: 0.45; pointer-events: none; }
.notice { margin-top: 8px; padding: 14px 16px; border-radius: 20px; background: rgba(138, 180, 255, 0.10); border: 1px solid rgba(138, 180, 255, 0.3); font-size: 15px; }
.foot { color: var(--text-dim); font-size: 13px; margin: 20px 8px 8px; }

.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 52px; height: 32px; border-radius: 999px; position: relative;
  background: rgba(255, 255, 255, 0.18); transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--text-dim); transition: transform .2s, background .2s;
}
.switch:checked { background: var(--amber); }
.switch:checked::after { transform: translateX(20px); background: var(--on-amber); }

/* Вибір регіону */
.picker { display: flex; flex-direction: column; min-height: 0; }
.search {
  display: flex; align-items: center; gap: 10px; padding: 0 14px; min-height: 52px; border-radius: 20px;
  background: var(--glass); border: 1px solid var(--glass-border);
}
.search:focus-within { border-color: var(--amber); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; font-size: 17px; }
.search input::placeholder { color: var(--text-dim); }
.search [data-icon] { color: var(--text-dim); }
.crumbs { display: inline-flex; align-items: center; gap: 4px; margin-top: 10px; padding: 6px 4px; color: var(--amber); font-weight: 600; font-size: 14px; }
.crumbs svg.i { width: 20px; height: 20px; }
.list { flex: 1; overflow-y: auto; margin-top: 6px; padding-bottom: 12px; -webkit-overflow-scrolling: touch; min-height: 200px; }
.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 12px; border-radius: 16px; text-align: left; }
.item:active { background: var(--glass); }
.item > span:first-child { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.item small { color: var(--text-dim); font-size: 13px; }
.item .check { color: var(--amber); }
.picker-note { color: var(--text-dim); font-size: 14px; padding: 12px 4px; }

/* Нічний режим */
#night {
  position: fixed; inset: 0; z-index: 20; background: #000;
  display: flex; align-items: center; justify-content: center; text-align: center;
}
.night-inner { transition: transform 2s ease; }
.night-clock { font-size: 64px; font-weight: 200; color: #3b4d6e; font-variant-numeric: tabular-nums; }
.night-status { color: #34435f; font-size: 15px; margin-top: 6px; }
.night-tip { color: #243049; font-size: 13px; margin-top: 24px; }

/* Будильник */
#alarm {
  position: fixed; inset: 0; z-index: 30;
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
  display: flex; flex-direction: column; justify-content: space-between; align-items: center; text-align: center;
  padding: calc(env(safe-area-inset-top) + 32px) calc(env(safe-area-inset-right) + 24px)
    calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 24px);
}
.alarm-clock { font-size: 84px; font-weight: 200; font-variant-numeric: tabular-nums; }
#alarm .center { gap: 10px; }
.alarm-actions { width: 100%; max-width: 480px; display: flex; flex-direction: column; align-items: center; gap: 8px; }

/* Діалог і сповіщення */
dialog {
  border: 0; border-radius: 28px; padding: 24px; width: min(360px, calc(100vw - 32px));
  background: var(--dialog); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h3 { font-size: 22px; font-weight: 600; margin-bottom: 10px; }
dialog p { color: var(--text-dim); font-size: 15px; margin-bottom: 18px; }
dialog input[type="time"] {
  display: block; width: 100%; font-size: 32px; text-align: center; padding: 10px; border-radius: 16px;
  background: var(--glass); border: 1px solid var(--glass-border); color: var(--text);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  z-index: 40; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 16px;
  background: #26395e; color: var(--text); font-size: 15px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .orb .ring { animation-duration: 6s !important; }
  .step { animation: none; }
}

/* Список регіонів прокручується всередині екрана, а не вся сторінка. */
#onboarding, #region { height: 100dvh; min-height: 0; overflow: hidden; }
#onboarding .step[data-step="2"] .picker { min-height: 0; }

/* Вбудований хрестик пошуку дублює власну кнопку очищення. */
.search input::-webkit-search-cancel-button,
.search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }

/* На невисоких екранах коло менше, щоб плитки вміщалися. */
.orb.big { width: min(250px, 62vw, 30dvh); height: min(250px, 62vw, 30dvh); }
#home .hero { padding: 8px 0; gap: 6px; }

.card a { color: var(--amber); font-weight: 600; }
.desktop-only { display: none; }

/* ---------- Комп'ютер ---------- */
@media (min-width: 900px) and (min-height: 560px) {
  /* margin: auto центрує, але не виштовхує вміст за верхній край, коли він вищий за екран. */
  body { display: flex; min-height: 100dvh; padding: 24px; }
  .desktop-only { display: revert; }

  /* Налаштування, вибір регіону й знайомство — панель по центру. */
  .screen {
    width: min(600px, 100%); max-width: none; min-height: 0; margin: auto;
    padding: 28px 32px 32px; border-radius: 32px;
    background: rgba(255, 255, 255, 0.035); border: 1px solid var(--glass-border);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  }
  #onboarding, #region { height: min(760px, calc(100dvh - 48px)); }
  #settings { max-height: calc(100dvh - 48px); overflow-y: auto; }
  #onboarding .step[data-step="0"] .orb, #onboarding .step[data-step="3"] .orb { width: 240px; height: 240px; }

  /* Головний екран: коло ліворуч, налаштування праворуч. */
  #home {
    width: min(1040px, 100%);
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    grid-template-rows: auto 1fr; column-gap: 56px;
    padding: 28px 40px 40px;
  }
  #home .topbar { grid-column: 1 / -1; margin-bottom: 12px; }
  #home .topbar .chip { margin-right: auto; }
  .brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 19px; margin-right: 12px; }
  .brand img { border-radius: 8px; }
  #home .hero { padding: 24px 0 8px; gap: 10px; }
  #home .orb.big { width: 300px; height: 300px; }
  #home .bottom { align-self: center; gap: 16px; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile { transition: background .15s, border-color .15s; }
  .tile:not(:disabled):hover, .row:not(:disabled):hover, .item:hover, .chip:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.11);
  }
  button.orb.big:hover .core { border-color: color-mix(in srgb, var(--c) 85%, transparent); }
  .btn.primary:hover { filter: brightness(1.06); }

  .how {
    margin: 4px 0 0; padding: 20px 20px 20px 22px; list-style: none; counter-reset: how;
    border-radius: 24px; border: 1px solid var(--glass-border);
    display: flex; flex-direction: column; gap: 16px;
  }
  .how li { counter-increment: how; display: grid; grid-template-columns: 32px 1fr; column-gap: 12px; }
  .how li::before {
    content: counter(how); grid-row: span 2; width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 700; font-size: 14px;
    color: var(--amber); background: rgba(255, 194, 71, 0.14);
  }
  .how b { font-weight: 600; }
  .how span { color: var(--text-dim); font-size: 14px; }

  .step > h2, .step .scroll h2 { margin-top: 12px; }
  #toast { bottom: 32px; }
}

/* Вибір звуку */
.sound-row .play { color: var(--amber); }
.row .check { color: var(--amber); }
.upload { width: 100%; margin-top: 14px; cursor: pointer; }
.upload svg.i { width: 20px; height: 20px; }
#onboarding-sounds { margin-top: 4px; }

/* Екрани для Android та iPhone */
.app-icon { border-radius: 22px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35); }
.actions { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.steps-list { text-align: left; margin: 8px 0 0; padding-left: 22px; color: var(--text-dim); max-width: 360px; }
.steps-list li { margin: 6px 0; }
.steps-list b { color: var(--text); }
.ios-head { margin: 12px 0 20px; }
.badge.num { font-weight: 700; font-size: 18px; }
.phone-card { padding: 18px 20px; border-radius: 24px; border: 1px solid var(--glass-border); }
.phone-card h3 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.phone-card p { color: var(--text-dim); font-size: 14px; margin-bottom: 12px; }
.phone-links { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; gap: 6px; }
.btn.small svg.i { width: 18px; height: 18px; }

/* QR-коди на комп'ютері */
.qr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.qr-grid figure { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.qr-grid img { width: 100%; max-width: 148px; height: auto; border-radius: 14px; background: #fff; padding: 6px; }
.qr-grid figcaption { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text-dim); }
.qr-grid figcaption b { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 15px; font-weight: 600; }
.qr-grid figcaption b svg.i { width: 18px; height: 18px; color: var(--amber); }
.link { color: var(--amber); font-weight: 600; font-size: 13px; text-align: left; padding: 2px 0; }

@media (min-width: 900px) and (max-height: 1000px) {
  .how { display: none !important; }
}

@media (min-width: 900px) and (min-height: 560px) {
  .icon-btn.desktop-only { display: grid; }
}
