:root {
  --bg: var(--tg-bg, #fafafa);
  --fg: var(--tg-text, #111);
  --muted: var(--tg-hint, #666);
  --accent: var(--tg-button, #1a73e8);
  --accent-fg: var(--tg-button-text, #fff);
  --border: #d0d0d0;
  --surface: var(--tg-section-bg, #fff);
  --surface-hover: var(--tg-secondary-bg, #f0f4ff);
  --ring-track: #e5e5e5;
  --ring-arc: var(--tg-button, #1a73e8);
  --warn: var(--tg-destructive, #b26500);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-bg, #0f1113);
    --fg: var(--tg-text, #eaeaea);
    --muted: var(--tg-hint, #9aa0a6);
    --accent: var(--tg-button, #4c8bf5);
    --border: #2a2d31;
    --surface: var(--tg-section-bg, #15181b);
    --surface-hover: var(--tg-secondary-bg, #1f2429);
    --ring-track: #2a2d31;
    --ring-arc: var(--tg-button, #4c8bf5);
    --warn: var(--tg-destructive, #d79a57);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
}

/* Перекрываем .view {display:flex} - иначе атрибут `hidden` визуально не работает. */
.view[hidden] {
  display: none !important;
}

#question.view {
  justify-content: space-between;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.progress-text {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.progress-bar {
  height: 3px;
  background: var(--ring-track);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 200ms ease;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 32px;
  padding: 20px 0;
}

.question-text {
  font-size: clamp(20px, 4.5vw, 28px);
  font-weight: 500;
  line-height: 1.35;
  margin: 0;
  letter-spacing: -0.01em;
}

.scale {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  min-height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
  -webkit-appearance: none;
  appearance: none;
  font-weight: 400;
}

.choice:hover,
.choice:focus-visible {
  background: var(--surface-hover);
  border-color: var(--accent);
  outline: none;
}

.choice:active {
  transform: scale(0.995);
}

.choice.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
}

.choice .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid currentColor;
  opacity: 0.9;
}

.choice .label {
  font-size: 15px;
  letter-spacing: 0.01em;
}

.hint {
  font-size: 12px;
  text-align: center;
}

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

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.bottombar {
  display: flex;
  justify-content: center;
  padding-top: 16px;
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.timer-ring {
  width: 28px;
  height: 28px;
}

.timer-track { stroke: var(--ring-track); }
.timer-arc   { stroke: var(--ring-arc); transition: stroke-dashoffset 200ms linear, stroke 200ms ease; }

.timer.warn .timer-arc { stroke: var(--warn); }
.timer.warn .timer-text { color: var(--warn); }

h1 {
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 500;
  margin: 0 0 12px;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}

button.primary,
button.ghost {
  padding: 12px 20px;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background 120ms ease, border-color 120ms ease;
}

button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid var(--accent);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: inherit;
}

button.primary:hover,
button.primary:focus-visible { filter: brightness(1.05); outline: none; }
button.ghost:hover,
button.ghost:focus-visible { background: var(--surface-hover); outline: none; }

.view.fade-out { opacity: 0; transition: opacity 120ms ease; }
.view.fade-in  { animation: fade-in 160ms ease forwards; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .view.fade-out,
  .view.fade-in,
  .progress-fill,
  .timer-arc { transition: none; animation: none; }
}

@media (max-width: 480px) {
  .view { padding: 16px 14px; }
  .choice { padding: 14px 16px; min-height: 52px; }
  .hint { display: none; }
}


/* Подсказки про клавиатуру — только для устройств с hover/точным указателем (десктоп). */
@media (hover: none), (pointer: coarse) {
  .desktop-only { display: none; }
}

#intro .stage { gap: 20px; }
#intro h1 { margin-bottom: 4px; }
#intro .bottombar { padding-bottom: 8px; }
#start-btn { min-width: 200px; padding: 14px 28px; font-size: 16px; }

#confirm .stage { gap: 18px; }
#confirm-feedback {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-top: 8px;
}
#confirm-feedback ul {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}
#confirm-feedback li {
  padding: 6px 0;
  font-size: 14px;
  line-height: 1.45;
}
#confirm-feedback li b {
  color: var(--accent);
  font-weight: 500;
}
.feedback-intro { margin: 0 0 4px; font-size: 13px; }
.feedback-disclaimer { margin: 4px 0 0; font-size: 12px; }
#confirm-btn { min-width: 200px; padding: 14px 28px; font-size: 16px; }

.intro-note { font-size: 13px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
