:root {
  --bg: #070a0f;
  --bg2: #0f1623;
  --panel: rgba(22, 27, 34, 0.92);
  --panel-solid: #161b22;
  --border: rgba(48, 54, 61, 0.9);
  --text: #f0f3f6;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-dim: rgba(88, 166, 255, 0.18);
  --accent2: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --glow: rgba(88, 166, 255, 0.35);
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --hero-time: clamp(5.25rem, 16vw + 12vmin, 11rem);
  --hero-action: clamp(1.45rem, 4.5vw + 1.8vmin, 2.35rem);
  --hero-meta: clamp(0.95rem, 2.8vw + 0.6vmin, 1.2rem);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(88, 166, 255, 0.12), transparent 55%),
    radial-gradient(900px 500px at 100% 40%, rgba(63, 185, 80, 0.06), transparent 50%),
    linear-gradient(180deg, var(--bg2) 0%, var(--bg) 45%);
  color: var(--text);
  line-height: 1.45;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.screen.screen--active {
  display: flex;
}

.main-header,
.header-settings {
  position: relative;
  z-index: 5;
  padding: calc(0.75rem + var(--safe-t)) calc(0.85rem + var(--safe-r)) 0.6rem calc(0.85rem + var(--safe-l));
  border-bottom: 1px solid var(--border);
  background: rgba(7, 10, 15, 0.65);
  backdrop-filter: blur(10px);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.header-top-spacer {
  width: 4.5rem;
  flex-shrink: 0;
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.header-settings .settings-title {
  flex: 1;
  text-align: center;
  font-size: 1.05rem;
  margin: 0;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  max-width: 100%;
}

.tabs--pill {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  gap: 0.35rem;
  padding-bottom: 2px;
}

.tabs--pill::-webkit-scrollbar {
  display: none;
}

.tabs--pill button {
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.55rem 1rem;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  font-size: clamp(0.82rem, 2.8vw, 0.95rem);
  white-space: nowrap;
  flex: 0 0 auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(88, 166, 255, 0.25);
  transition: color 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.2s;
}

.tabs--pill button:hover {
  color: var(--text);
  border-color: rgba(139, 148, 158, 0.55);
}

.tabs--pill button.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.25);
}

.btn-compact {
  padding: 0.5rem 0.85rem;
  min-height: 44px;
  font-size: 0.86rem;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  border-color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.main-workout {
  flex: 1;
  width: 100%;
  max-width: min(560px, 100%);
  margin: 0 auto;
  padding: clamp(0.6rem, 2.5vw, 1.1rem) clamp(0.75rem, 4vw, 1.35rem) max(1rem, var(--safe-b));
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.main-footer {
  text-align: center;
  padding: calc(0.55rem + var(--safe-b)) clamp(0.75rem, 4vw, 1.25rem);
  font-size: clamp(0.68rem, 2.4vw, 0.78rem);
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: rgba(7, 10, 15, 0.5);
}

.main-settings {
  flex: 1;
  max-width: min(720px, 100%);
  margin: 0 auto;
  padding: 0.85rem clamp(0.75rem, 4vw, 1.25rem) max(1.5rem, calc(1rem + var(--safe-b)));
  width: 100%;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel {
  display: none;
}

.panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  justify-content: center;
  min-height: 0;
  animation: fade 0.22s ease;
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
  animation: fade 0.22s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.15rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.card h2 {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.field {
  margin-bottom: 0.75rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.28rem;
}

.field input[type="number"],
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 0.52rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: clamp(0.95rem, 3.1vw, 1.02rem);
}

@media (max-width: 480px) {
  .field input[type="number"],
  .field input[type="text"],
  .field select,
  .field textarea {
    font-size: 16px;
  }
}

.field textarea {
  resize: vertical;
}

.field input[type="range"] {
  width: 100%;
  height: 2rem;
  accent-color: var(--accent);
}

.field small {
  display: block;
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.settings-hint {
  margin: 0 0 1rem;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.45;
}

.config-status {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--accent2);
}

.workout-hero {
  text-align: center;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(0.35rem, 2vmin, 1.25rem) 0;
  min-height: 45vh;
  min-height: min(52dvh, 420px);
}

.w-phase {
  margin: 0 0 clamp(0.35rem, 1.5vmin, 0.75rem);
  font-size: clamp(0.78rem, 2.6vw + 0.2rem, 0.95rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.95;
}

.w-time {
  margin: 0;
  font-size: var(--hero-time);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 0.95;
  text-shadow: 0 0 48px var(--glow), 0 10px 36px rgba(0, 0, 0, 0.5);
  padding: 0 clamp(0.15rem, 2vw, 0.5rem);
  word-break: keep-all;
}

.w-action {
  margin: clamp(0.55rem, 2.5vmin, 1rem) 0 0.2rem;
  min-height: 1.35em;
  font-size: var(--hero-action);
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  padding: 0 clamp(0.25rem, 3vw, 0.75rem);
}

.w-meta {
  margin: 0.4rem 0 0;
  min-height: 1.25em;
  font-size: var(--hero-meta);
  color: var(--muted);
  line-height: 1.35;
  padding: 0 clamp(0.35rem, 4vw, 1rem);
}

.w-bars {
  margin: clamp(0.85rem, 3.5vmin, 1.5rem) auto 0;
  width: min(100%, 420px);
  max-width: calc(100vw - 2rem - var(--safe-l) - var(--safe-r));
  text-align: left;
  padding: 0 clamp(0.25rem, 2vw, 0.5rem);
}

.wb-row {
  display: grid;
  grid-template-columns: minmax(3.4rem, 18vw) 1fr;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.wb-row:last-child {
  margin-bottom: 0;
}

.wb-label {
  font-size: clamp(0.68rem, 2.4vw, 0.8rem);
  color: var(--muted);
}

.wb-track {
  height: clamp(9px, 1.4vmin, 12px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.wb-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1f6feb, var(--accent));
  box-shadow: 0 0 16px rgba(88, 166, 255, 0.45);
  transition: width 0.18s ease-out;
}

.wb-fill--round {
  background: linear-gradient(90deg, #238636, var(--accent2));
  box-shadow: 0 0 14px rgba(63, 185, 80, 0.35);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
}

.actions--hero {
  margin-top: clamp(1rem, 4vmin, 1.75rem);
  width: 100%;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 clamp(0.25rem, 2vw, 0.5rem);
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 0.55rem 1.1rem;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(88, 166, 255, 0.2);
  transition: transform 0.1s, filter 0.15s, box-shadow 0.2s;
}

.btn-lg {
  padding: 0.85rem 1.25rem;
  min-height: 52px;
  min-width: 5.5rem;
  font-size: clamp(1rem, 3.8vw, 1.12rem);
  border-radius: 14px;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(180deg, #6ab8ff, var(--accent));
  color: #041018;
  box-shadow: 0 10px 28px rgba(88, 166, 255, 0.28);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: rgba(48, 54, 61, 0.95);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger {
  background: linear-gradient(180deg, #ff7b72, #da3633);
  color: #fff;
  box-shadow: 0 10px 26px rgba(248, 81, 73, 0.22);
}

.grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 720px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.chip-warn {
  color: var(--warn);
}

.u-hidden {
  display: none !important;
}

@media (max-width: 360px) {
  :root {
    --hero-time: clamp(4.75rem, 14vw + 11vmin, 9.5rem);
  }
}

@media (min-width: 480px) {
  :root {
    --hero-time: clamp(5.75rem, 12vw + 11vmin, 11.5rem);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .workout-hero {
    min-height: unset;
    padding: 0.25rem 0;
  }

  :root {
    --hero-time: clamp(3.75rem, 22vh, 6.5rem);
    --hero-action: clamp(1.1rem, 3.5vh, 1.65rem);
    --hero-meta: clamp(0.82rem, 2.2vh, 1rem);
  }

  .w-bars {
    margin-top: 0.55rem;
  }

  .actions--hero {
    margin-top: 0.65rem;
  }
}

@media (min-width: 600px) {
  .main-workout {
    max-width: 640px;
  }
}
