:root {
  --bg: #090d16;
  --surface: #111827;
  --surface-2: #1a2335;
  --surface-3: #222d44;
  --border: #263248;
  --border-strong: #374766;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --volt: #b6ff2e;
  --volt-dim: rgba(182, 255, 46, 0.14);
  --volt-ink: #090d16;
  --orange: #ff6b2b;
  --orange-dim: rgba(255, 107, 43, 0.16);
  --cyan: #38bdf8;
  --cyan-dim: rgba(56, 189, 248, 0.14);
  --emerald: #22c55e;
  --emerald-dim: rgba(34, 197, 94, 0.16);
  --amber: #eab308;
  --amber-dim: rgba(234, 179, 8, 0.16);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.16);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --nav-height: 68px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

a {
  color: var(--cyan);
}

.app-shell {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 92px);
}

/* Top Sticky Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(9, 13, 22, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + var(--safe-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  color: var(--volt);
  flex-shrink: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wakelock-pill {
  min-height: 36px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.wakelock-pill.is-active {
  background: var(--volt-dim);
  border-color: var(--volt);
  color: var(--volt);
}

.wakelock-pill.is-unsupported {
  opacity: 0.65;
}

/* Main Content */
.main-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
}

.card-elevated {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--border-strong);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0;
}

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

.small {
  font-size: 12px;
}

/* Cycle Strip */
.cycle-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.cycle-node {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 7px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cycle-node.is-current {
  border-color: var(--volt);
  background: var(--volt-dim);
}

.cycle-node.is-rest {
  border-style: dashed;
}

.cycle-node-code {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
}

.cycle-node.is-current .cycle-node-code {
  color: var(--volt);
}

.cycle-node-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
}

/* Hero Banner */
.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.badge-volt {
  background: var(--volt);
  color: var(--volt-ink);
}

.badge-orange {
  background: var(--orange-dim);
  color: var(--orange);
  border: 1px solid rgba(255, 107, 43, 0.45);
}

.badge-cyan {
  background: var(--cyan-dim);
  color: var(--cyan);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.badge-emerald {
  background: var(--emerald-dim);
  color: var(--emerald);
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.badge-muted {
  background: var(--surface-3);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.hero-title {
  margin: 6px 0 2px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.01em;
}

.hero-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

/* Buttons */
.btn {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--volt);
  color: var(--volt-ink);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-orange {
  background: var(--orange);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

/* Progress Bar */
.progress-wrap {
  margin-top: 10px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.progress-track {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--volt), #84cc16);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* Exercise Card */
.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.exercise-card.is-all-done {
  border-color: rgba(34, 197, 94, 0.5);
}

.exercise-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.exercise-code {
  font-size: 11px;
  font-weight: 800;
  color: var(--volt);
  background: var(--volt-dim);
  padding: 2px 7px;
  border-radius: 6px;
  margin-right: 6px;
}

.exercise-name {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.3;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.exercise-subrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* Venue Segmented Control */
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.segmented-btn {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.segmented-btn.is-active {
  background: var(--surface-3);
  color: var(--volt);
  border: 1px solid var(--border-strong);
}

/* Callouts */
.callout {
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.callout-overload {
  background: var(--cyan-dim);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #bae6fd;
}

.callout-pr {
  background: var(--orange-dim);
  border: 1px solid rgba(255, 107, 43, 0.5);
  color: #fed7aa;
}

/* Plate Calculator Pill */
.plate-box {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--cyan);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.plate-label {
  color: var(--cyan);
  font-weight: 800;
}

.plate-box.is-warn {
  border-left-color: var(--amber);
}

.plate-box.is-warn .plate-label {
  color: var(--amber);
}

/* Set Rows */
.sets-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.set-row {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.set-row.is-completed {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.45);
}

.set-main {
  display: grid;
  grid-template-columns: 34px 1fr 1fr 48px;
  gap: 8px;
  align-items: center;
}

.set-index {
  font-size: 12px;
  font-weight: 900;
  color: var(--text-muted);
  text-align: center;
}

.input-group {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 44px;
}

.step-btn {
  width: 32px;
  min-height: 44px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 16px;
  color: var(--text-muted);
  background: var(--surface);
  flex-shrink: 0;
}

.step-btn:active {
  background: var(--surface-3);
  color: var(--volt);
}

.num-input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  padding: 6px 2px;
  outline: none;
}

.num-unit {
  font-size: 11px;
  color: var(--text-dim);
  padding-right: 6px;
  font-weight: 700;
  flex-shrink: 0;
}

.check-btn {
  width: 48px;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-strong);
  background: var(--bg);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.check-btn.is-checked {
  background: var(--emerald);
  border-color: var(--emerald);
  color: #052e16;
}

.set-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rpe-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  flex: 1;
}

.rpe-btn {
  min-height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.rpe-btn.is-easy.is-active {
  background: var(--emerald-dim);
  border-color: var(--emerald);
  color: var(--emerald);
}

.rpe-btn.is-just.is-active {
  background: var(--amber-dim);
  border-color: var(--amber);
  color: var(--amber);
}

.rpe-btn.is-fail.is-active {
  background: var(--orange-dim);
  border-color: var(--orange);
  color: var(--orange);
}

.set-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Sticky Rest Timer Bar */
.timer-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
  width: calc(100% - 20px);
  max-width: 540px;
  z-index: 35;
  background: rgba(17, 24, 39, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--volt);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timer-bar.is-done {
  border-color: var(--orange);
  background: rgba(42, 20, 12, 0.96);
}

.timer-left {
  display: flex;
  flex-direction: column;
}

.timer-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
}

.timer-clock {
  font-size: 24px;
  font-weight: 900;
  color: var(--volt);
  line-height: 1.1;
}

.timer-bar.is-done .timer-clock {
  color: var(--orange);
}

.timer-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(9, 13, 22, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + var(--safe-bottom));
}

.bottom-nav-inner {
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.nav-item {
  min-height: 54px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.nav-item.is-active {
  color: var(--volt);
  background: var(--volt-dim);
}

/* Forms & Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

@media (min-width: 520px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 580px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-sheet > * {
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title {
  font-size: 18px;
  font-weight: 900;
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.text-input, .select-input, .textarea-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}

.textarea-input {
  min-height: 80px;
  resize: vertical;
}

.text-input:focus, .select-input:focus, .textarea-input:focus {
  border-color: var(--volt);
}

.media-box {
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.diagram-svg {
  width: 100%;
  height: auto;
  aspect-ratio: 320 / 185;
  min-height: 185px;
  display: block;
}

.media-iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 0;
  display: block;
}

.media-img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  display: block;
  background: #05080f;
}

/* Hybrid Infographic Card */
.infographic-card {
  flex-shrink: 0;
  background: linear-gradient(180deg, #131c2e 0%, #0b111e 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.demo-photo-wrap {
  flex-shrink: 0;
  width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0b101b;
}

.demo-photo,
.demo-photo-svg {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.phase-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.phase-item {
  background: rgba(9, 13, 22, 0.78);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 8px;
}

.phase-title {
  font-size: 12px;
  font-weight: 800;
  color: var(--volt);
  margin-bottom: 3px;
}

.phase-desc {
  font-size: 11px;
  line-height: 1.38;
  color: var(--text-muted);
}

.guide-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

@media (min-width: 440px) {
  .guide-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.guide-box {
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  border: 1px solid var(--border);
  background: rgba(9, 13, 22, 0.72);
}

.guide-box-good {
  border-color: rgba(34, 197, 94, 0.4);
  background: rgba(34, 197, 94, 0.07);
}

.guide-box-warn {
  border-color: rgba(255, 107, 43, 0.45);
  background: rgba(255, 107, 43, 0.08);
}

.guide-heading {
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 5px;
}

.guide-box-good .guide-heading {
  color: var(--emerald);
}

.guide-box-warn .guide-heading {
  color: var(--orange);
}

.guide-list {
  margin: 0;
  padding-left: 15px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text);
}

.coach-tip-box {
  background: var(--cyan-dim);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  color: #e0f2fe;
}

/* Stats & Chart */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.stat-value {
  font-size: 22px;
  font-weight: 900;
  color: var(--volt);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.chart-wrap {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 8px 6px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.chip.is-active {
  background: var(--volt);
  border-color: var(--volt);
  color: var(--volt-ink);
}

/* Toast */
.toast-container {
  position: fixed;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 28px);
  max-width: 480px;
  pointer-events: none;
}

.toast {
  background: var(--surface-3);
  border: 1px solid var(--volt);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  text-align: center;
}

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

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
