:root {
  /* Цвета флага Аргентины: celeste, белый, солнце (Sol de Mayo) */
  --flag-celeste: #74acdf;
  --flag-white: #ffffff;
  --flag-sun: #f6b40e;

  --bg: #f3f8fd;
  --surface: #ffffff;
  --text: #0f2236;
  --muted: #5b6b7d;
  --border: #dbe7f3;
  --accent: var(--flag-celeste);
  --accent-text: #0b2540;
  --accent-strong: #1d6aa8;
  --accent-soft: #e2effa;
  --sun: var(--flag-sun);
  --danger: #c62828;
  --tabs-bg: #e2edf8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 18px;
  color-scheme: light;
}

/* Тёмная тема: по системе (если не выбрана светлая вручную) или по выбору пользователя */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c141d;
    --surface: #15202c;
    --text: #eef4fa;
    --muted: #93a4b6;
    --border: #23344a;
    --accent: var(--flag-celeste);
    --accent-text: #0b2540;
    --accent-strong: #95c4ee;
    --accent-soft: #1a3048;
    --danger: #ff8a80;
    --tabs-bg: #15202c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0c141d;
  --surface: #15202c;
  --text: #eef4fa;
  --muted: #93a4b6;
  --border: #23344a;
  --accent: var(--flag-celeste);
  --accent-text: #0b2540;
  --accent-strong: #95c4ee;
  --accent-soft: #1a3048;
  --danger: #ff8a80;
  --tabs-bg: #15202c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: env(safe-area-inset-top) 0 12px;
  background: var(--bg);
}

.header::before {
  content: "";
  display: block;
  height: 14px;
  margin: 0 -16px 12px;
  background: linear-gradient(var(--flag-celeste) 0 33.3%, var(--flag-white) 0 66.6%, var(--flag-celeste) 0);
}

.header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s;
}

.theme-toggle:active { transform: scale(.94); }

.theme-toggle:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -.02em;
}

.brand::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--sun) 25%, transparent);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--tabs-bg);
}

.tab {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .2s, color .2s, box-shadow .2s;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

button:focus-visible,
.field__input:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.panel { padding-top: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.field { display: grid; gap: 6px; }

.field__hint {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field__input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
  transition: border-color .2s;
}

.field__input:focus { border-color: var(--accent); outline: none; }

.field__input[aria-invalid="true"] { border-color: var(--danger); }

.form__error {
  margin: -4px 0 0;
  font-size: 13px;
  color: var(--danger);
}

.btn-primary {
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s, opacity .2s;
}

.btn-primary:active { transform: scale(.98); }

.list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 28px 4px 12px;
}

.list-title { margin: 0; font-size: 18px; font-weight: 700; }

.badge {
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--sun);
  color: #3d2a00;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 14px 8px 14px 16px;
  animation: appear .25s ease-out;
}

@keyframes appear {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.item__text { flex: 1; min-width: 0; }

.item__ru,
.item__es {
  margin: 0;
  overflow-wrap: anywhere;
}

.item__ru {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--muted);
}

.item {
  border-left: 4px solid var(--accent);
}

.item__es {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 750;
  line-height: 1.25;
  letter-spacing: -.01em;
  color: var(--accent-strong);
}

.btn-delete {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .2s, color .2s;
}

.btn-delete:hover { color: var(--danger); }

.btn-delete[data-confirm="true"] {
  background: var(--danger);
  color: #fff;
}

.btn-delete svg { width: 20px; height: 20px; }

.list-status {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
}

.list-status p { margin: 0; }

.list-status .btn-secondary { padding: 0 24px; }

/* ---------- Загрузка и вход ---------- */

.boot {
  margin: 0;
  padding: 64px 16px;
  text-align: center;
  color: var(--muted);
}

.auth { padding-top: 8px; }

.auth__text {
  margin: -6px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.form__ok {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 600;
}

.auth__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
}

.link-btn {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-strong);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.link-btn:focus-visible,
.btn-ghost:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-ghost {
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:disabled,
.btn-secondary:disabled,
.btn-ghost:disabled {
  opacity: .6;
  cursor: default;
}

/* ---------- Перенос фраз из браузера ---------- */

.migrate {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 16px;
  border-left: 4px solid var(--sun);
}

.migrate__text {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
}

.migrate .btn-row { max-width: none; width: 100%; }

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.btn-block {
  display: block;
  width: 100%;
  max-width: 528px;
  margin: 0 auto;
}

#panel-training { padding-bottom: 96px; }

.placeholder {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.placeholder__icon { font-size: 40px; margin-bottom: 8px; }

[hidden] { display: none !important; }

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

/* ---------- Тренировка ---------- */

.item__time {
  margin: 8px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}

.time-pickers {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
}

.time-pickers__sep {
  padding-bottom: 12px;
  font-size: 28px;
  font-weight: 700;
  color: var(--muted);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 60px;
  padding-right: 36px;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  text-align-last: center;
  resize: none;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}

.btn-secondary {
  min-height: 50px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s;
}

.btn-secondary:active { transform: scale(.98); }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
  max-width: 528px;
  margin: 0 auto;
}

.round-info {
  margin: 4px 4px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.phrase-card {
  padding: 22px 20px;
  border-top: 4px solid var(--accent);
}

.phrase-card__es {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.015em;
  color: var(--accent-strong);
  overflow-wrap: anywhere;
}

.phrase-card__ru {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.time-chip {
  display: inline-block;
  margin: 14px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.timer {
  position: relative;
  width: min(64vw, 240px);
  aspect-ratio: 1;
  margin: 28px auto 0;
}

.timer__ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer__track,
.timer__bar {
  fill: none;
  stroke-width: 8;
}

.timer__track { stroke: var(--accent-soft); }

.timer__bar {
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .25s linear;
}

.timer[data-state="running"] .timer__bar { stroke: var(--sun); }

.timer__value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(36px, 13vw, 52px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}

.timer[data-state="paused"] .timer__value { color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  animation: appear .25s ease-out;
}
