/* TickTalk в браузере. Токены — те же, что в Sources/Theme.swift и DESIGN.md. */

:root {
  --orange: #EC6A2E;
  --orange-pressed: #D45A22;
  --ink: #2A2A25;
  --ink-raised: #36362F;
  --sage: #D7DAC2;
  --sage-muted: #C5C8AE;
  --hatch: #B7BA9F;
  --cream: #F8F5E4;
  --text-on-dark: #F1EEE2;
  --text-on-dark-muted: #A6A594;
  --text-muted: #6E6F63;
  --divider: #E4E1CE;

  --radius-sheet: 28px;
  --radius-card: 20px;
  --radius-cell: 8px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Телефон: элементы крупнее, чтобы попадать пальцем. */
  --pill-h: 34px;
  --control-h: 34px;
  --circle: 40px;
  --play: clamp(76px, 11dvh, 92px);
  --tap: clamp(54px, 7.5dvh, 58px);
  --handle-h: calc(60px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text-on-dark);
  font: 13px/1.3 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body { overflow: hidden; overscroll-behavior: none; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation; /* без двойного тапа-зума: TAP жмут часто */
  transition: transform 0.1s ease-out, opacity 0.1s ease-out;
}
button:active { transform: scale(0.96); opacity: 0.85; }
button:focus-visible, [role="slider"]:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

svg.icon { width: 1em; height: 1em; display: block; fill: currentColor; }

/* ---------- Каркас: телефон (по умолчанию) ---------- */

/* На телефоне — во весь экран; в широком, но низком окне компьютера — колонкой по центру. */
.app { height: 100dvh; position: relative; max-width: 520px; margin: 0 auto; }

.stage {
  position: absolute;
  inset: 0 0 var(--handle-h) 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) calc(env(safe-area-inset-right) + 20px)
    clamp(14px, 3dvh, 28px) calc(env(safe-area-inset-left) + 20px);
}

.wide-only { display: none !important; }

/* ---------- Тёмная часть ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; }

.title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.star { width: 18px; height: 18px; fill: var(--text-on-dark); }

.mic-badge {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  font-size: 14px;
  background: var(--ink-raised);
  color: var(--text-on-dark-muted);
}
.mic-badge.on { background: var(--orange); color: var(--text-on-dark); }

.beats {
  display: flex; justify-content: center; align-items: center;
  gap: min(12px, 2.6vw);
  height: 28px;
}
.beat {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink-raised);
  transition: transform 0.12s ease-out;
}
.beat.accent { width: 20px; height: 20px; box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--orange) 70%, transparent); }
.beat.active { background: var(--text-on-dark); transform: scale(1.25); }
.beat.accent.active { background: var(--orange); box-shadow: none; }
/* Начало группы в размерах на восьмые (6/8: «раз» и «четыре»): зазор шире, точка поменьше первой. */
.beat.group-start { margin-left: min(6px, 1.4vw); }
.beat.group-accent { width: 17px; height: 17px; box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--orange) 45%, transparent); }
.beat.group-accent.active { background: var(--orange); box-shadow: none; }

.tempo { text-align: center; }
.bpm {
  font-size: clamp(72px, 14dvh, 112px);
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.tempo-name {
  margin-top: 4px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-on-dark-muted);
}

.voice-line {
  min-height: 34px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--text-on-dark-muted);
}
.voice-line .text { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.voice-line.highlight { color: var(--orange); font-weight: 600; }

.slider-row { display: flex; align-items: center; gap: 12px; }

.circle {
  flex: none;
  width: var(--circle); height: var(--circle);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: calc(var(--circle) * 0.38);
  background: var(--ink-raised);
  color: var(--text-on-dark);
}

/* Слайдер: капсула-трек, оранжевая заливка, круглая ручка. */
.slider {
  --knob: 18px;
  --track: var(--sage-muted);
  --knob-color: #fff;
  position: relative;
  flex: 1;
  height: 36px;
  cursor: pointer;
  touch-action: none;
}
.slider.dark { --track: var(--ink-raised); --knob-color: var(--text-on-dark); }
.slider .track, .slider .fill {
  position: absolute; top: 50%; left: 0;
  height: 6px; margin-top: -3px;
  border-radius: 3px;
}
.slider .track { right: 0; background: var(--track); }
.slider .fill { background: var(--orange); }
.slider .knob {
  position: absolute; top: 50%; left: 0;
  width: var(--knob); height: var(--knob);
  margin-top: calc(var(--knob) / -2);
  border-radius: 50%;
  background: var(--knob-color);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
}

/* Вкладки-пилюли: выбранная — оранжевая капсула, остальные — просто текст. */
.pills { display: flex; gap: 2px; align-items: center; }
.pills.justified { justify-content: space-between; }
.pill {
  height: var(--pill-h);
  padding: 0 11px;
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  white-space: nowrap;
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.on-dark .pill { color: var(--text-on-dark); }
.pill.selected { background: var(--orange); color: var(--text-on-dark); font-weight: 600; }
.pill .icon { font-size: 8px; }

.controls { display: flex; align-items: center; justify-content: center; gap: 26px; }

.tap {
  width: var(--tap); height: var(--tap);
  border-radius: 50%;
  background: var(--ink-raised);
  font-size: 13px; font-weight: 700; letter-spacing: 1px;
}
.play {
  width: var(--play); height: var(--play);
  border-radius: 50%;
  background: var(--orange);
  display: grid; place-items: center;
  font-size: calc(var(--play) * 0.35);
  color: var(--text-on-dark);
}
.play.pulse { transform: scale(1.03); }
.play:active { background: var(--orange-pressed); }

.meter { width: var(--tap); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.meter-value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter-buttons { display: flex; gap: 6px; }
.meter-buttons button {
  width: 28px; height: 22px;
  border-radius: 999px;
  display: grid; place-items: center;
  font-size: 9px;
  background: var(--ink-raised);
}

/* ---------- Панель настроек ---------- */

.panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--sage);
  color: var(--ink);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  transform: translateY(calc(100% - var(--handle-h)));
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 2;
}
.sheet-open .panel { transform: none; }

.scrim {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--ink) 55%, transparent);
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s;
  z-index: 1;
}
.sheet-open .scrim { opacity: 1; pointer-events: auto; }

.sheet-handle {
  flex: none;
  height: var(--handle-h);
  padding: 0 20px env(safe-area-inset-bottom);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
}
.sheet-handle:active { transform: none; }
.sheet-open .sheet-handle { height: 52px; padding-bottom: 0; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--hatch); }
.sheet-summary {
  font-size: 13px; font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.sheet-summary .on { color: var(--orange); font-weight: 600; }

.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 14px;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 20px);
}

.card {
  background: var(--cream);
  border-radius: var(--radius-card);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.divider { height: 1px; background: var(--divider); }

.row { display: flex; align-items: center; gap: 10px; padding: 0 11px; min-height: var(--control-h); }
.trainer-settings .row { gap: 6px; flex-wrap: wrap; }
.spacer { flex: 1 1 8px; }
.label { font-size: 13px; }
.hint { font-size: 12px; color: var(--text-muted); }

.accent-volume .slider { flex: 0 1 150px; }
.speaker { font-size: 11px; color: var(--text-muted); }

/* Переключатель: оранжевый, когда включён. */
.switch {
  flex: none;
  width: 36px; height: 20px;
  border-radius: 999px;
  background: var(--sage-muted);
  position: relative;
}
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch.on { background: var(--orange); }
.switch.on::after { transform: translateX(16px); }
.switch:active { transform: none; }

.trainer-status {
  font-size: 12px; font-weight: 500;
  color: var(--orange);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.trainer:not(.enabled) .trainer-settings { display: none; }
.trainer-settings { display: flex; flex-direction: column; gap: 10px; }

/* Компактный счётчик «− значение +» в капсуле. */
.stepper {
  display: inline-flex; align-items: center;
  height: var(--control-h);
  border-radius: 999px;
  background: color-mix(in srgb, var(--sage) 55%, transparent);
}
.stepper button {
  width: 30px; height: 100%;
  display: grid; place-items: center;
  font-size: 9px;
  color: var(--text-muted);
}
.stepper .value { min-width: 32px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

/* «Ещё» со звуками на телефоне: пилюля, поверх неё прозрачный системный список. */
.more-select { position: relative; cursor: pointer; }
.more-select select {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  appearance: none; -webkit-appearance: none;
  border: 0;
  font: 16px var(--font);
  cursor: pointer;
}
.more-select:has(select:focus-visible) { outline: 2px solid var(--orange); outline-offset: 2px; }

/* Меню «Ещё» со звуками (широкий экран) */
.more { position: relative; }
.more-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 140px;
  padding: 6px;
  border-radius: 14px;
  background: var(--cream);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
  display: none; flex-direction: column;
  z-index: 5;
}
.more.open .more-menu { display: flex; }
.more-menu button {
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--radius-cell);
  font-size: 13px;
  color: var(--ink);
}
.more-menu button:hover { background: var(--sage); }
.more-menu button.selected { color: var(--orange); font-weight: 600; }

/* Список размеров: открывается вверх над кнопкой размера, по три в ряд. */
.more.open .meter-options { display: grid; }
.meter-options {
  top: auto; bottom: calc(100% + 8px);
  min-width: 0;
  grid-template-columns: repeat(3, 56px);
  gap: 2px;
}
.meter-options button {
  height: var(--pill-h);
  padding: 0;
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.meter-options hr { grid-column: 1 / -1; width: 100%; height: 1px; margin: 3px 0; border: 0; background: var(--divider); }

/* Телефон: карточки чуть плотнее, чтобы ряды разгона влезали в одну строку. */
.card { padding: 16px 12px; }
.row { padding-left: 8px; padding-right: 8px; }
.stepper button { width: 26px; }
.stepper .value { min-width: 28px; }
.trainer-settings .row { gap: 4px; }
[data-group="unit"] { gap: 0; }
.trainer-settings .spacer { flex-basis: 0; }
[data-group="unit"] .pill { padding: 0 9px; }

/* Совсем низкий экран телефона (iPhone SE в браузере): ужимаем вертикальные отступы. */
@media (max-height: 620px) {
  .bpm { font-size: clamp(60px, 12dvh, 84px); }
  .voice-line { min-height: 22px; }
  .controls { gap: 22px; }
}

/* ---------- Широкий экран: раскладка «Классика», как на Mac ---------- */

@media (min-width: 860px) and (min-height: 480px) {
  :root {
    --pill-h: 28px;
    --control-h: 28px;
    --circle: 34px;
    --play: 92px;
    --tap: 58px;
  }

  .narrow-only { display: none !important; }
  .wide-only { display: revert !important; }
  .pills.wide-only { display: flex !important; }

  /* Окно метронома — ровно по центру страницы. */
  body {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
  }

  .app {
    height: auto;
    display: flex;
    align-items: stretch;
    width: 830px;
    max-width: none;
    margin: auto;
  }

  .stage {
    position: static;
    width: 400px;
    gap: 0;
    padding: 24px 28px 26px;
    justify-content: flex-start;
  }
  .beats { margin-top: 26px; }
  .tempo { margin-top: 4px; }
  .bpm { font-size: 104px; }
  .voice-line { margin-top: 8px; min-height: 26px; }
  .slider-row { margin-top: 16px; }
  .controls { margin-top: 24px; }
  .mic-badge { width: 24px; height: 24px; border-radius: 6px; font-size: 11px; }

  .panel {
    position: static;
    width: 430px;
    max-width: none;
    margin: 0;
    max-height: none;
    transform: none;
    transition: none;
    border-radius: var(--radius-sheet);
    padding: 20px;
  }
  .panel-body { padding: 0; overflow: visible; }
  .card { padding: 16px 18px; }
  .row { padding-left: 11px; padding-right: 11px; }
  .stepper .value { min-width: 32px; }
  .trainer-settings .row { gap: 6px; }
  [data-group="unit"] .pill { padding: 0 11px; }
  .pills.justified .pill:first-child { margin-left: 0; }
  .accent-volume .slider { flex-basis: 130px; }
  .slider { height: 22px; }
}
