:root {
  color-scheme: dark;
  --bg: #0e1013;
  --surface: #171a20;
  --surface-2: #21252d;
  --line: #272b34;
  --fg: #eceef2;
  --muted: #8d93a0;
  --accent: #ff7a6e;
  --accent-soft: rgb(255 122 110 / 0.14);
  --cool: #6ec6d8;
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 60% at 50% -10%, #1c1f27 0%, var(--bg) 60%) fixed;
  color: var(--fg);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.muted { color: var(--muted); }

.top {
  display: flex;
  align-items: baseline;
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) 20px 6px;
}
.brand { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }

.view {
  max-width: 520px;
  margin: 0 auto;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 96px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h2 { margin: 0 0 8px; font-size: 13px; font-weight: 500; color: var(--muted); }

button {
  font: inherit;
  color: var(--fg);
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, .segmented label:has(:focus-visible) { outline: 2px solid var(--cool); outline-offset: 3px; }

/* переключатель режима */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 0;
  padding: 4px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented span {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 10px;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
}
.segmented input:checked + span { background: #353b47; color: var(--fg); font-weight: 600; box-shadow: 0 2px 8px rgb(0 0 0 / 0.3); }
.segmented:disabled { opacity: 0.45; }
.hint { margin: -4px 0 0; text-align: center; font-size: 14px; color: var(--muted); }

/* большая кнопка */
.pad {
  position: relative;
  align-self: center;
  margin: 12px 0 20px;
  width: min(72vw, 300px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-content: center;
  gap: 4px;
  background: radial-gradient(circle at 50% 35%, #2a2f39, var(--surface) 70%);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.45), inset 0 1px 0 rgb(255 255 255 / 0.06);
  transition: transform 0.45s cubic-bezier(0.3, 0.7, 0.3, 1), box-shadow 0.45s;
}
.recording .pad { box-shadow: 0 20px 70px var(--accent-soft), inset 0 1px 0 rgb(255 255 255 / 0.06); }
.pad.inhaled { transform: scale(1.07); box-shadow: 0 20px 80px rgb(110 198 216 / 0.18), inset 0 1px 0 rgb(255 255 255 / 0.06); }
.pad.tapped::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: ripple 0.5s ease-out forwards;
}
@keyframes ripple { from { opacity: 0.8; transform: scale(1); } to { opacity: 0; transform: scale(1.18); } }

.ring { position: absolute; inset: 0; transform: rotate(-90deg); pointer-events: none; }
.ring circle { fill: none; stroke-width: 2.5; stroke-dasharray: 1; }
.ring .track { stroke: var(--line); }
.ring .progress { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.2s linear; }
.pad.inhaled .progress { stroke: var(--cool); }

.pad-label { font-size: 34px; font-weight: 650; letter-spacing: -0.01em; }
.pad.inhaled .pad-label { color: var(--cool); }
.pad-time { font-size: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats div, .card {
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
}
.stats b, .card b { font-size: 30px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stats span, .card span { font-size: 13px; color: var(--muted); }

.panel { padding: 14px 10px 6px 6px; border-radius: var(--radius); background: var(--surface); }
.panel h2 { padding-left: 10px; }
.chart { width: 100%; }

.ghost { min-height: 48px; padding: 0 20px; border-radius: 14px; background: var(--surface-2); }
.primary { min-height: 48px; padding: 0 22px; border-radius: 14px; background: var(--accent); color: #1a0d0b; font-weight: 600; }

/* история */
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card { padding: 12px; }
.card b { font-size: 24px; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }
.log { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); background: var(--surface); }
.log li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.log li:first-child { border-top: 0; }
.log div { display: flex; flex-direction: column; }
.log span { font-size: 13px; color: var(--muted); }
.log b { font-size: 24px; font-variant-numeric: tabular-nums; }

/* нижние вкладки */
.tabs {
  position: fixed;
  inset: auto 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 8px);
  background: rgb(14 16 19 / 0.85);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button { min-height: 48px; background: none; color: var(--muted); font-size: 15px; border-radius: 12px; }
.tabs button[aria-current] { color: var(--fg); background: var(--surface); }
.recording .tabs { visibility: hidden; }

/* окно «загрузить?» */
dialog {
  width: min(92vw, 420px);
  padding: 20px;
  border: 0;
  border-radius: 22px;
  background: var(--surface);
  color: var(--fg);
}
dialog::backdrop { background: rgb(0 0 0 / 0.6); backdrop-filter: blur(4px); }
dialog h2 { font-size: 18px; color: var(--fg); }
.result { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 0; }
.result b { font-size: 52px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.result span { color: var(--muted); }
dialog .muted { margin: 0 0 12px; }
menu { display: flex; gap: 10px; justify-content: flex-end; padding: 0; margin: 16px 0 0; }

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