/* ==========================================================================
   SportWebApp — Dark iOS "Liquid Glass" design system
   Тёмная, воздушная тема: полупрозрачные стеклянные панели с блюром,
   капсульные кнопки, крупные заголовки, нижний таб-бар как в iOS.
   ========================================================================== */

:root {
  --accent-blue: #0A84FF;
  --accent-green: #30D158;
  --accent-orange: #FF9F0A;
  --accent-red: #FF453A;
  --accent-purple: #BF5AF2;
  --accent-teal: #64D2FF;

  --bg-1: #050506;
  --bg-2: #0b0e16;
  --bg-3: #130c1c;

  --text-primary: #f5f5f7;
  --text-secondary: rgba(245, 245, 247, 0.6);
  --text-tertiary: rgba(245, 245, 247, 0.38);

  --glass-bg: rgba(30, 30, 36, 0.55);
  --glass-bg-strong: rgba(40, 40, 48, 0.68);
  --glass-border: rgba(255, 255, 255, 0.09);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 1px 1px rgba(0, 0, 0, 0.2);

  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-pill: 999px;

  --tabbar-height: 84px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--text-primary);
  background:
    radial-gradient(1100px 700px at 15% -10%, var(--bg-3), transparent 60%),
    radial-gradient(900px 700px at 110% 10%, var(--bg-2), transparent 55%),
    var(--bg-1);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; }
code { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }

.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(20px + var(--safe-top)) 18px calc(var(--tabbar-height) + 24px);
  position: relative;
}

/* ---------- Десктопная версия страницы "Печать" ---------- */
@media (min-width: 900px) {
  .app.app-wide {
    max-width: 820px;
    padding-top: calc(48px + var(--safe-top));
  }
  .app-wide .page-header h1 { font-size: 44px; }
  .app-wide .type-area {
    font-size: 28px;
    max-height: 200px;
  }
  .app-wide .type-live-stats { gap: 56px; margin-bottom: 22px; }
  .app-wide .type-live-stats .value { font-size: 40px; }
  .app-wide #type-test-box { padding: 36px 40px; }
  .app-wide .stat-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Профиль (верхняя плашка) ---------- */
.profile-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 8px 14px 8px 8px;
  margin-bottom: 16px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  width: fit-content;
}
.profile-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex: none;
}
.profile-name { font-weight: 600; font-size: 14px; }
.profile-chevron { width: 16px; height: 16px; color: var(--text-tertiary); }

/* ---------- Заголовок страницы (large title) ---------- */
.page-header {
  margin-bottom: 20px;
}
.page-header .eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 2px;
}
.page-header h1 {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}

/* ---------- Стеклянная карточка ---------- */
.glass-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  padding: 22px;
  margin-bottom: 16px;
}
.glass-card.tight { padding: 16px 18px; }
.glass-card.center { text-align: center; }

.glass-row {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 18px 0;
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-pill);
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent-blue); color: #fff; }
.btn-success { background: var(--accent-green); color: #06210f; }
.btn-danger  { background: var(--accent-red); color: #fff; }
.btn-ghost {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 14px; }
.btn-icon {
  width: 64px; height: 64px; border-radius: 50%;
  font-size: 28px; font-weight: 700; padding: 0;
}

/* ---------- Формы ---------- */
.ios-input {
  width: 100%;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
}
.ios-input:focus { border-color: var(--accent-blue); }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field-error { color: var(--accent-red); font-size: 12px; margin-top: 6px; font-weight: 600; }

.switch-field {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.switch-field label { margin: 0; }

.inline-add-form {
  display: flex; gap: 8px; align-items: center;
}
.inline-add-form .ios-input { flex: 1; }
.inline-add-form .btn { padding: 12px 18px; }

.checkbox-days {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.checkbox-days label {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
}
.checkbox-days input { accent-color: var(--accent-blue); }

/* ---------- Чипсы (пресеты времени, группы и т.п.) ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.chip {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.chip:active { transform: scale(0.94); }
.chip.active { background: var(--accent-blue); color: #fff; border-color: transparent; }
.chip-global { border-color: var(--accent-purple); color: var(--text-primary); }

/* ---------- Таймер: кольцо прогресса ---------- */
.timer-ring-wrap {
  position: relative;
  width: 260px; height: 260px;
  margin: 8px auto 18px;
  display: flex; align-items: center; justify-content: center;
}
.timer-ring-wrap svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer-ring-bg { fill: none; stroke: var(--glass-border); stroke-width: 14; }
.timer-ring-progress {
  fill: none;
  stroke: var(--accent-blue);
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear, stroke 0.3s ease;
}
.timer-center { position: absolute; text-align: center; }
.timer-center .time { font-size: 52px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.timer-center .label { font-size: 13px; color: var(--text-secondary); font-weight: 600; margin-top: 2px; }

.timer-controls { display: flex; gap: 14px; justify-content: center; align-items: center; margin-top: 6px; }

/* ---------- Счётчик повторений ---------- */
.counter-display {
  display: flex; align-items: center; justify-content: center; gap: 28px;
  margin: 6px 0 18px;
}
.counter-value {
  font-size: 76px; font-weight: 800; min-width: 130px; text-align: center;
  font-variant-numeric: tabular-nums; letter-spacing: -0.02em;
}
.counter-btn {
  width: 68px; height: 68px; border-radius: 50%;
  border: none; font-size: 34px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s ease;
}
.counter-btn:active { transform: scale(0.9); }
.counter-btn.plus { background: var(--accent-green); color: #06210f; }
.counter-btn.minus { background: var(--glass-bg-strong); border: 1px solid var(--glass-border); color: var(--text-primary); }

/* ---------- Статистика ---------- */
.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;
}
.stat-tile {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg); padding: 16px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}
.stat-tile .value { font-size: 28px; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat-tile .label { font-size: 13px; color: var(--text-secondary); font-weight: 600; margin-top: 2px; }
.stat-tile.accent-blue .value { color: var(--accent-blue); }
.stat-tile.accent-green .value { color: var(--accent-green); }
.stat-tile.accent-orange .value { color: var(--accent-orange); }
.stat-tile.accent-purple .value { color: var(--accent-purple); }

.chart-card canvas { width: 100% !important; }

.rank-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.rank-badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex: none;
}
.rank-name { flex: 1; font-weight: 600; }
.rank-value { color: var(--text-secondary); font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---------- Напоминания ---------- */
.reminder-row .time { font-size: 22px; font-weight: 800; min-width: 64px; font-variant-numeric: tabular-nums; }
.reminder-row .info { flex: 1; }
.reminder-row .title { font-weight: 700; }
.reminder-row .days { font-size: 13px; color: var(--text-secondary); }
.reminder-actions { display: flex; align-items: center; gap: 8px; }

.switch {
  position: relative; width: 48px; height: 28px; flex: none;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: rgba(120,120,128,0.32);
  border-radius: var(--radius-pill); transition: background 0.2s ease; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px;
  background: #fff; border-radius: 50%; transition: transform 0.2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.35);
}
.switch input:checked + .track { background: var(--accent-green); }
.switch input:checked + .track::before { transform: translateX(20px); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--glass-bg-strong); color: var(--accent-red);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.header-icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--glass-border);
  background: var(--glass-bg-strong); color: var(--accent-blue);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  flex: none; box-shadow: var(--glass-shadow);
}
.header-icon-btn svg { width: 22px; height: 22px; }
.header-icon-btn:active { transform: scale(0.92); }

/* ---------- Модалка ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 0 14px calc(14px + var(--safe-bottom));
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-card {
  width: 100%; max-width: 480px; margin-bottom: 0;
  max-height: 82vh; overflow-y: auto;
  transform: translateY(16px);
  transition: transform 0.2s ease;
}
.modal-overlay.open .modal-card { transform: translateY(0); }

/* ---------- select как .ios-input ---------- */
select.ios-input {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a8' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px;
  padding-right: 40px;
}
textarea.ios-input { resize: vertical; font-family: inherit; }

/* ---------- Строки подходов (список повторений) ---------- */
.reps-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.reps-row-num {
  width: 22px; text-align: center; flex: none;
  font-weight: 700; color: var(--text-secondary); font-size: 14px;
}
.reps-row .ios-input { flex: 1; }
.reps-row .remove-reps-row { flex: none; }

/* ---------- API-ключ ---------- */
.api-key-box {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 14px;
  word-break: break-all;
  color: var(--accent-teal);
}
.code-block {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-primary);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

/* ---------- История таймера ---------- */
.history-list { max-height: 260px; overflow-y: auto; }
.history-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--glass-border);
  font-variant-numeric: tabular-nums;
}
.history-row:last-child { border-bottom: none; }
.history-time { color: var(--text-secondary); font-weight: 600; font-size: 14px; }
.history-sec { font-weight: 700; }
.history-empty { text-align: center; color: var(--text-secondary); padding: 14px 0; }

/* ---------- Пустое состояние ---------- */
.empty-state { text-align: center; padding: 30px 10px; color: var(--text-secondary); }
.empty-state .emoji { font-size: 40px; margin-bottom: 8px; }

/* ---------- Flash-сообщения ---------- */
.flash {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-left: 4px solid var(--accent-green);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 14px;
}
.flash-error { border-left-color: var(--accent-red); }

/* ---------- Нижний таб-бар ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(94%, 520px);
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  z-index: 50;
}
.tab-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; flex: 1; height: 100%; cursor: pointer; color: var(--text-tertiary);
  transition: color 0.15s ease;
}
.tab-item svg { width: 21px; height: 21px; }
.tab-item span { font-size: 9.5px; font-weight: 600; }
.tab-item.active { color: var(--accent-blue); }
.tab-item.active .tab-pill {
  background: rgba(10, 132, 255, 0.16);
  border-radius: var(--radius-pill);
}

/* ---------- Авторизация ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; margin: 0; padding: 24px;
}
.auth-wrap { width: 100%; max-width: 380px; text-align: center; }
.auth-logo { font-size: 48px; margin-bottom: 8px; }
.auth-title { font-size: 30px; font-weight: 800; margin: 0 0 4px; letter-spacing: -0.02em; }
.auth-subtitle { color: var(--text-secondary); margin: 0 0 22px; font-size: 15px; }
.auth-switch { color: var(--text-secondary); font-size: 14px; margin-top: 18px; }
.auth-switch a { color: var(--accent-blue); font-weight: 600; }

/* ---------- Тест печати ---------- */
.type-live-stats {
  display: flex; gap: 32px; justify-content: center; margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}
.type-live-stats .item { text-align: center; }
.type-live-stats .value { font-size: 30px; font-weight: 800; color: var(--accent-blue); }
.type-live-stats .label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

.type-area {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 21px;
  line-height: 1.8;
  letter-spacing: 0.01em;
  user-select: none;
  -webkit-user-select: none;
  max-height: 150px;
  overflow: hidden;
  cursor: text;
}
.type-word { display: inline-block; margin: 0 8px 6px 0; }
.type-char { color: var(--text-tertiary); }
.type-char.correct { color: var(--text-primary); }
.type-char.incorrect { color: var(--accent-red); }
.type-char.extra { color: var(--accent-red); opacity: 0.55; }
.type-caret {
  display: inline-block; width: 2px; height: 1.1em; margin-left: -1px;
  background: var(--accent-blue);
  animation: type-blink 1s step-end infinite;
  vertical-align: text-bottom;
}
@keyframes type-blink { 50% { opacity: 0; } }

.type-hidden-input {
  position: absolute; opacity: 0; height: 1px; width: 1px; pointer-events: none;
}

/* ---------- Утилиты ---------- */
.text-center { text-align: center; }
.text-left { text-align: left; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.muted { color: var(--text-secondary); }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
