/* Hallmark · genre: atmospheric · macrostructure: Map / Diagram · theme: custom (see tokens.css)
 * enrichment: canvas particle ring (Tier A, hand-built) · nav: none · footer: none (Telegram supplies the chrome)
 * pre-emit critique: P4 H5 E4 S5 R4 V4
 * Экран приложения, не лендинг: сутки одним кольцом, отсчёт рядом, всё главное в половине экрана.
 */

*, *::before, *::after { box-sizing: border-box; }

html, body { overflow-x: clip; }

html {
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 100%;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(60% 46% at 88% 6%, var(--color-bloom), transparent 72%) fixed,
    var(--color-paper);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

p, h2, h3 { margin: 0; }
h2, h3 { font-style: normal; }

button, input {
  font: inherit;
  color: inherit;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button:disabled { opacity: 0.45; cursor: default; }
button[aria-busy="true"] { opacity: 0.6; cursor: progress; }

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.chev {
  width: 12px;
  height: 12px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- каркас ---------- */

.app {
  display: grid;
  gap: var(--space-sm);
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(var(--space-xs) + var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px))
    var(--space-md)
    calc(var(--space-lg) + var(--tg-safe-area-inset-bottom, 0px));
}

.app > * { min-width: 0; }

.app[aria-busy="true"] .read,
.app[aria-busy="true"] .place { visibility: hidden; }
.app[aria-busy="true"] .wins,
.app[aria-busy="true"] .note,
.app[aria-busy="true"] .set { display: none; }

.app.is-ready .read > *,
.app.is-ready .wins,
.app.is-ready .note,
.app.is-ready .set { animation: reveal var(--dur-long) var(--ease-out) backwards; }
.app.is-ready .cap { animation-delay: 50ms; }
.app.is-ready .count { animation-delay: 100ms; }
.app.is-ready .sub { animation-delay: 150ms; }
.app.is-ready .wins { animation-delay: 220ms; }
.app.is-ready .note { animation-delay: 280ms; }
.app.is-ready .set { animation-delay: 340ms; }

@keyframes reveal {
  from { opacity: 0; transform: translateY(8px); }
}

/* ---------- шапка: место и день ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  min-height: 44px;
}

.place {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  min-width: 0;
  padding: var(--space-xs) var(--space-2xs) var(--space-xs) 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--dur-short) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}

.place__q {
  flex: none;
  padding: 3px 9px 2px;
  border-radius: var(--radius-pill);
  background: var(--color-paper-3);
  color: var(--color-ink);
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.place__w {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place:active { transform: translateY(1px); }

.tabs {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: none;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-paper-2);
}

.tabs button {
  position: relative;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  transition: color var(--dur-short) var(--ease-out);
}

.tabs button[aria-selected="true"] { color: var(--color-ink); }

.tabs__ink {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: var(--radius-pill);
  background: var(--color-paper-3);
  transition: transform var(--dur-short) var(--ease-out);
}

.app[data-view="1"] .tabs__ink { transform: translateX(100%); }

/* ---------- главное: отсчёт и кольцо суток ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-sm);
}

.read { min-width: 0; }

.status {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-sm);
  font-weight: 600;
}

.dot {
  position: relative;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-light);
}

.status[data-s="off"] .dot { background: var(--color-accent); }

.dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  opacity: 0;
}

.status.is-pulse .dot::after { animation: pulse 900ms var(--ease-out) 1; }

@keyframes pulse {
  from { opacity: 0.7; transform: scale(1); }
  to { opacity: 0; transform: scale(3.4); }
}

.cap {
  margin-top: var(--space-xs);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.count {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  margin-top: 2px;
  font-family: var(--font-display);
  font-size: var(--text-display);
  font-weight: 700;
  line-height: 0.94;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.count.is-text {
  font-size: var(--text-display-s);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.count .u {
  margin: 0 0.5em 0 0.22em;
  color: var(--color-muted);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0;
}

.count .u:last-child { margin-right: 0; }

.dg {
  position: relative;
  display: inline-block;
  clip-path: inset(-6% 0);
}

.dg > span { display: inline-block; }
.dg > .is-in { animation: roll-in 380ms var(--ease-out); }
.dg > .is-out {
  position: absolute;
  top: 0;
  left: 0;
  animation: roll-out 260ms var(--ease-in) forwards;
}

@keyframes roll-in {
  from { opacity: 0; transform: translateY(58%); }
}

@keyframes roll-out {
  to { opacity: 0; transform: translateY(-58%); }
}

.sub {
  min-height: 1.35em;
  margin-top: var(--space-xs);
  font-size: var(--text-base);
  font-weight: 500;
}

.dial {
  position: relative;
  width: clamp(148px, 43vw, 184px);
  aspect-ratio: 1;
}

.dial canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.dial__clock {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--color-muted);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: none;
}

/* ---------- окна дня ---------- */

.wins {
  display: flex;
  gap: var(--space-xs);
  margin: 0 calc(-1 * var(--space-md));
  padding: 0 var(--space-md);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.wins::-webkit-scrollbar { display: none; }

.win {
  display: grid;
  flex: 0 0 auto;
  gap: 2px;
  min-width: 122px;
  padding: 10px var(--space-sm) 9px;
  border-radius: var(--radius-md);
  background: var(--color-paper-2);
  scroll-snap-align: start;
}

.win__t {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.win__t i {
  width: 9px;
  height: 2px;
  border-radius: 1px;
  background: var(--color-rule);
}

.win__d {
  color: var(--color-muted);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.win.is-past { opacity: 0.45; }
.win.is-maybe .win__t { color: var(--color-muted); }
.win.is-now {
  background: var(--color-paper-3);
  box-shadow: inset 0 0 0 1.5px var(--color-accent);
}
.win.is-now .win__d { color: var(--color-accent-ink); }

.msg {
  padding: var(--space-xs) 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.note {
  min-height: 1.3em;
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.note.is-stale { color: var(--color-accent-ink); }

/* ---------- настройки ---------- */

.set {
  display: grid;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  min-height: 58px;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  background: var(--color-paper-2);
  color: var(--color-ink);
  transition: background-color var(--dur-short) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}

button.row:active { transform: scale(0.985); }

@media (hover: hover) {
  button.row:hover, .opt:hover, .chip:hover, .pick:hover { background: var(--color-paper-3); }
  .place:hover { color: var(--color-ink); }
  .link:hover { color: var(--color-ink); }
}

.row__t {
  flex: 1;
  min-width: 0;
  font-size: var(--text-base);
  font-weight: 600;
}

.row__t small {
  display: block;
  margin-top: 1px;
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: 400;
}

.chev--r { color: var(--color-muted); }

.sw {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--color-paper-3);
  transition: background-color var(--dur-short) var(--ease-in-out);
}

.sw::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-muted);
  transition: transform var(--dur-short) var(--ease-in-out), background-color var(--dur-short) var(--ease-in-out);
}

[aria-checked="true"] .sw { background: var(--color-light); }
[aria-checked="true"] .sw::after {
  background: var(--color-paper);
  transform: translateX(18px);
}

.row--seg { flex-wrap: wrap; row-gap: var(--space-xs); }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: none;
  padding: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-paper);
}

.seg button {
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  transition: background-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out);
}

.seg button[aria-pressed="true"] {
  background: var(--color-paper-3);
  color: var(--color-ink);
}

.link {
  justify-self: start;
  padding: var(--space-xs) 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
  text-decoration: underline;
  text-decoration-color: var(--color-rule);
  text-underline-offset: 3px;
  white-space: nowrap;
  transition: color var(--dur-short) var(--ease-out);
}

.fail {
  display: grid;
  justify-items: start;
  gap: var(--space-sm);
  padding: var(--space-md) 0;
  color: var(--color-muted);
}

.btn {
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: var(--color-ink);
  color: var(--color-paper);
  font-weight: 600;
  white-space: nowrap;
  transition: transform var(--dur-micro) var(--ease-out);
}

.btn:active { transform: translateY(1px); }

/* ---------- развёрнуто на весь экран ---------- */

html.tall .hero {
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  padding: var(--space-xs) 0;
}

html.tall .dial {
  grid-area: 1 / 1;
  width: min(80vw, 340px);
}

html.tall .read {
  z-index: 1;
  display: grid;
  grid-area: 1 / 1;
  justify-items: center;
  align-self: center;
  max-width: 44%;
  text-align: center;
  pointer-events: none;
}

html.tall .count {
  justify-content: center;
  font-size: clamp(2.4rem, 12.5vw, 3.2rem);
}

html.tall .count.is-text { font-size: clamp(1.15rem, 5.4vw, 1.5rem); }
html.tall .cap { font-size: var(--text-xs); }
html.tall .sub { font-size: var(--text-sm); }
html.tall .dial__clock { display: none; }

html.tall .wins {
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  overflow: visible;
}

html.tall .win { flex: 1 1 calc(50% - var(--space-xs)); }

/* ---------- лист выбора ---------- */

.sheet {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-ink);
  overflow: hidden;
}

.sheet::backdrop {
  background: var(--color-scrim);
  animation: fade 300ms var(--ease-out);
}

.sheet__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-width: 560px;
  height: min(92%, 720px);
  margin: 0 auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--color-paper-2);
  box-shadow: 0 -12px 40px var(--color-shadow);
  animation: sheet-in 320ms var(--ease-out);
}

.sheet.is-closing .sheet__panel { animation: sheet-out 220ms var(--ease-in) forwards; }
.sheet.is-closing::backdrop { animation: fade 220ms var(--ease-in) reverse forwards; }

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(28px); }
}

@keyframes sheet-out {
  to { opacity: 0; transform: translateY(28px); }
}

@keyframes fade {
  from { opacity: 0; }
}

.sheet__head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  padding: var(--space-xs) var(--space-xs) var(--space-2xs);
}

.sheet__head h2 {
  overflow: hidden;
  font-size: var(--text-base);
  font-weight: 600;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: var(--color-muted);
  transition: transform var(--dur-micro) var(--ease-out);
}

.icon .chev { width: 14px; height: 14px; }
.icon:active { transform: scale(0.92); }
.icon[hidden] + h2 { grid-column: 2; }

.sheet__body {
  padding: var(--space-2xs) var(--space-md) calc(var(--space-lg) + var(--tg-safe-area-inset-bottom, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet__body > * { animation: reveal 260ms var(--ease-out) backwards; }

.grid2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-xs);
}

.opt, .pick {
  min-height: 46px;
  padding: 11px var(--space-sm);
  border-radius: var(--radius-sm);
  background: var(--color-paper-3);
  font-size: var(--text-sm);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color var(--dur-short) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}

.opt:active, .pick:active, .chip:active { transform: scale(0.97); }
.opt.is-on, .chip.is-on { box-shadow: inset 0 0 0 1.5px var(--color-light); }
.opt.is-off { color: var(--color-muted); }

.list {
  display: grid;
  gap: var(--space-xs);
  transition: opacity var(--dur-short) var(--ease-out);
}

.list.is-wait, .chips.is-wait { opacity: 0.4; pointer-events: none; }
.list--houses { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
.list--houses .pick { text-align: center; }

.chips {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: var(--space-xs);
  transition: opacity var(--dur-short) var(--ease-out);
}

.chip {
  padding: 12px 0 11px;
  border-radius: var(--radius-sm);
  background: var(--color-paper-3);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  transition: background-color var(--dur-short) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}

.lead {
  margin-bottom: var(--space-2xs);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.2;
}

.hint {
  margin: var(--space-xs) 0 var(--space-sm);
  color: var(--color-muted);
  font-size: var(--text-sm);
  white-space: pre-line;
}

.field {
  display: block;
  width: 100%;
  margin-bottom: var(--space-sm);
  padding: 13px 14px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--color-paper-3);
  color: var(--color-ink);
  font-size: var(--text-base);
  transition: border-color var(--dur-short) var(--ease-out);
}

.field::placeholder { color: var(--color-muted); }
.field:focus { border-color: var(--color-focus); outline: none; }

.wide {
  display: block;
  width: 100%;
  margin: var(--space-sm) 0;
  text-align: center;
}

/* ---------- сообщение об ошибке ---------- */

.toast {
  position: fixed;
  right: var(--space-md);
  bottom: calc(var(--space-md) + var(--tg-safe-area-inset-bottom, 0px));
  left: var(--space-md);
  z-index: 5;
  max-width: 420px;
  margin: 0 auto;
  padding: 12px var(--space-md);
  border-radius: var(--radius-sm);
  background: var(--color-paper-3);
  box-shadow: 0 8px 28px var(--color-shadow);
  font-size: var(--text-sm);
  animation: reveal var(--dur-long) var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 120ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 120ms !important;
  }
  @keyframes reveal { from { opacity: 0; } }
  @keyframes roll-in { from { opacity: 0; } }
  @keyframes roll-out { to { opacity: 0; } }
  @keyframes sheet-in { from { opacity: 0; } }
  @keyframes sheet-out { to { opacity: 0; } }
  @keyframes pulse { from { opacity: 0; } to { opacity: 0; } }
}
