:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #16a34a;
  --primary-hover: #15803d;
  --primary-contrast: #ffffff;
  --primary-rgb: 22, 163, 74;
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --warning: #eab308;
  --warning-soft: #fef9c3;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 1px rgba(15, 23, 42, .04);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, .10);
  --transition: 200ms ease;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #172033;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #22c55e;
  --primary-hover: #4ade80;
  --primary-contrast: #052e13;
  --primary-rgb: 34, 197, 94;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, .16);
  --warning: #eab308;
  --warning-soft: rgba(234, 179, 8, .16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, .4);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  transition: background var(--transition), color var(--transition);
}

body { -webkit-tap-highlight-color: transparent; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  color: var(--primary);
}

.brand-credit {
  display: block;
  margin: 2px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition);
}
.pill-btn:hover { border-color: var(--primary); }

.icon-toggle {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  margin-bottom: 20px;
}

.tab-btn {
  flex: 1 1 0;
  white-space: nowrap;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Cards / Panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.panel { display: none; }
.panel.active { display: block; }

.card h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.hint {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 20px;
}

.field { margin-bottom: 18px; }
.field-row { display: flex; gap: 14px; margin-bottom: 18px; }
.field-row .field { flex: 1; margin-bottom: 0; }

.field label,
.field legend {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
  padding: 0;
}

.field-hint {
  color: var(--text-muted);
  font-size: 12px;
  margin: 6px 0 0;
}

input[type="number"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  transition: border-color var(--transition);
}
input[type="number"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; }

/* Stepper (+/-) for numeric fields */
.stepper {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
  transition: border-color var(--transition);
}
.stepper:focus-within { border-color: var(--primary); }

.stepper input[type="number"] {
  flex: 1;
  min-width: 0;
  text-align: center;
  border: none;
  border-radius: 0;
  background: transparent;
  -moz-appearance: textfield;
}
.stepper input[type="number"]:focus { border-color: transparent; }
.stepper input[type="number"]::-webkit-inner-spin-button,
.stepper input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper-btn {
  flex-shrink: 0;
  width: 44px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}
.stepper-btn:first-child { border-right: 1px solid var(--border); }
.stepper-btn:last-child { border-left: 1px solid var(--border); }
.stepper-btn:hover { background: var(--border); }
.stepper-btn:disabled { opacity: .35; cursor: not-allowed; background: transparent; }

.toggle-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.toggle-field input[type="checkbox"] { width: 18px; height: 18px; }

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.switch-field label { margin: 0; font-weight: 600; }
.switch-field input[type="checkbox"] { width: 20px; height: 20px; }

.install-row { margin-bottom: 22px; }
.install-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 13px;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-contrast);
  background: linear-gradient(90deg, var(--primary), var(--accent));
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.install-btn:active { transform: scale(0.98); }

fieldset.field {
  border: none;
  padding: 0;
  margin: 0 0 18px;
}
fieldset.field legend {
  padding: 0;
  margin-bottom: 8px;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.radio-opt {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.radio-opt input { accent-color: var(--primary); }

/* Collapsible "Configurare" section (default minimized) */
.config-details {
  margin-bottom: 18px;
}

.config-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  user-select: none;
}
.config-summary::-webkit-details-marker { display: none; }

.config-summary::after {
  content: '▾';
  font-size: 14px;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.config-details[open] .config-summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
.config-details[open] .config-summary::after {
  transform: rotate(180deg);
}

.config-fields {
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  padding: 18px 16px 4px;
}
.config-fields .field:last-child,
.config-fields .field-row:last-child { margin-bottom: 0; }

/* Start button */
.start-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--primary-contrast);
  background: linear-gradient(90deg, var(--primary), var(--accent));
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--transition), opacity var(--transition);
}
.start-btn:active { transform: scale(0.98); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 28px 24px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-card h2 { margin: 0 0 18px; font-size: 20px; }

.close-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Timer card */
.timer-card { text-align: center; max-width: 380px; }

.ring-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 8px auto 20px;
}

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

.ring-bg {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 10;
}

.ring-fg {
  fill: none;
  stroke: var(--primary);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 628.3185;
  stroke-dashoffset: 628.3185;
  transition: stroke-dashoffset 250ms linear, stroke 300ms ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-time {
  font-size: 42px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.ring-phase {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.timer-title {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 800;
}

.timer-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.timer-next {
  margin: 2px 0 20px;
  color: var(--text-muted);
  font-size: 13px;
  min-height: 18px;
}

.timer-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* AMRAP rounds counter */
.rounds-box {
  margin: 4px 0 20px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
}

.rounds-readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.rounds-count {
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  line-height: 1;
}

.rounds-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.rounds-btns {
  display: flex;
  gap: 8px;
}

.rounds-btn {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
}

.rounds-minus {
  flex-shrink: 0;
  width: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
}
.rounds-minus:hover { background: var(--border); }

.rounds-plus {
  flex: 1;
  padding: 12px;
  font-size: 15px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  color: var(--primary-contrast);
  box-shadow: var(--shadow-sm);
}
.rounds-plus:active { transform: scale(0.98); }

.timer-credit {
  margin: 18px 0 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .3px;
  color: var(--primary);
  transition: color 250ms linear;
}

.control-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.control-btn.primary {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  color: var(--primary-contrast);
  border: none;
}

/* Result card */
.result-card { text-align: center; max-width: 380px; }
.result-emoji { font-size: 44px; }
.result-time {
  font-size: 44px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  margin: 10px 0;
}
.result-detail { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }

/* Phase label color (ring-fg stroke and timer-credit color are driven
   continuously by JS — they fade from a start color to an end color as
   each phase progresses, see updateRingCountDown/updateRingCountUp) */
.phase-rest .ring-phase { color: var(--warning); }
.phase-prep .ring-phase,
.phase-warmup .ring-phase { color: var(--accent); }
.phase-urgent .ring-phase { color: var(--danger); }

@media (max-width: 420px) {
  .brand h1 { font-size: 24px; }
}

/* Stack Minute/Secunde steppers on mobile — side by side they're too
   narrow to fit two-digit values (e.g. "10") next to the +/- buttons. */
@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 18px; }
}

/* Full-screen timer on mobile: the running cronometru takes over the
   whole viewport instead of sitting in a small centered card, with a
   bigger ring and bigger time readout. */
@media (max-width: 600px) {
  #timerOverlay { padding: 0; }

  #timerOverlay .timer-card {
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: max(28px, env(safe-area-inset-top)) 24px max(28px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  #timerOverlay .close-x {
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
  }

  #timerOverlay .ring-wrap {
    width: min(90vw, 380px);
    height: min(90vw, 380px);
    margin: 8px auto 32px;
  }

  #timerOverlay .ring-time {
    font-size: clamp(48px, 18vw, 78px);
  }

  #timerOverlay .ring-phase {
    font-size: 17px;
    margin-top: 8px;
  }

  #timerOverlay .timer-title {
    font-size: 32px;
    margin-bottom: 8px;
  }

  #timerOverlay .timer-meta {
    font-size: 19px;
  }

  #timerOverlay .timer-next {
    font-size: 17px;
    margin-bottom: 28px;
  }

  #timerOverlay .control-btn {
    font-size: 18px;
    padding: 15px 26px;
  }

  #timerOverlay .timer-credit {
    font-size: 17px;
    margin-top: 26px;
  }

  #timerOverlay .rounds-box {
    width: 100%;
    padding: 20px;
    margin-bottom: 26px;
  }

  #timerOverlay .rounds-count { font-size: 46px; }
  #timerOverlay .rounds-label { font-size: 15px; }

  #timerOverlay .rounds-minus {
    width: 56px;
    font-size: 24px;
  }

  #timerOverlay .rounds-plus {
    padding: 16px;
    font-size: 18px;
  }
}
