:root {
      --bg: #FFFFFF;
      --bg-subtle: #FAFAFA;
      --bg-muted: #F4F4F5;
      --border: #E4E4E7;
      --border-strong: #D4D4D8;
      --fg: #09090B;
      --fg-secondary: #52525B;
      --fg-muted: #71717A;
      --fg-subtle: #A1A1AA;
      --primary: #09090B;
      --primary-hover: #27272A;
      --primary-fg: #FFFFFF;
      --green-bg: #F0FDF4;
      --green-border: #BBF7D0;
      --green-fg: #15803D;
      --red-bg: #FEF2F2;
      --red-border: #FECACA;
      --red-fg: #DC2626;
      --amber-fg: #D97706;
      --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
      --shadow-pop: 0 10px 28px -4px rgba(9, 9, 11, 0.14), 0 4px 10px -2px rgba(9, 9, 11, 0.06);
      --radius-md: 8px;
      --radius-lg: 12px;
      --radius-xl: 16px;
    }

    *, *::before, *::after {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      -webkit-tap-highlight-color: transparent;
    }

    html, body {
      height: 100%;
      width: 100%;
      background-color: var(--bg-subtle);
      color: var(--fg);
      overflow: hidden;
      overscroll-behavior: none;
      -webkit-font-smoothing: antialiased;
    }

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

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

    button {
      cursor: pointer;
      border: none;
      background: none;
      user-select: none;
    }

    /* 3-Part App Shell (100dvh, centered max-w 440px) */
    .app-shell {
      width: 100%;
      max-width: 440px;
      height: 100dvh;
      margin: 0 auto;
      background: var(--bg);
      border-left: 1px solid var(--border);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      position: relative;
      overflow: hidden;
    }

    @media (max-width: 440px) {
      .app-shell {
        border-left: none;
        border-right: none;
      }
    }

    /* Top Header */
    .app-header {
      flex-shrink: 0;
      background: var(--bg);
      padding: 14px 20px 10px 20px;
      border-bottom: 1px solid transparent;
      display: flex;
      flex-direction: column;
      gap: 14px;
      z-index: 10;
    }

    .progress-row {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .progress-track {
      flex: 1;
      height: 4px;
      background: var(--bg-muted);
      border-radius: 9999px;
      overflow: hidden;
    }

    .progress-fill {
      height: 100%;
      background: var(--primary);
      border-radius: 9999px;
      transition: width 0.4s ease, background-color 0.3s ease;
    }

    .progress-fill.warning {
      background: var(--amber-fg);
    }

    .session-pill-btn {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      font-size: 12px;
      font-weight: 500;
      color: var(--fg-muted);
      padding: 3px 6px;
      border-radius: 6px;
      transition: color 0.15s, background-color 0.15s;
    }

    .session-pill-btn:hover {
      color: var(--fg);
      background: var(--bg-muted);
    }

    .pulse-dot {
      width: 6px;
      height: 6px;
      border-radius: 50%;
      background: var(--primary);
      animation: pulseDot 1.4s infinite ease-in-out;
    }

    @keyframes pulseDot {
      0%, 100% { opacity: 1; transform: scale(1); }
      50% { opacity: 0.35; transform: scale(0.8); }
    }

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

    .page-title {
      font-size: 24px;
      font-weight: 800;
      letter-spacing: -0.025em;
      line-height: 1.15;
      color: var(--fg);
    }

    .page-subtitle {
      font-size: 12px;
      font-weight: 500;
      color: var(--fg-muted);
      margin-top: 2px;
    }

    .header-actions {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-shrink: 0;
    }

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

    .segmented.full-width {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      width: 100%;
    }

    .seg-btn {
      height: 28px;
      padding: 0 11px;
      border-radius: 7px;
      font-size: 12px;
      font-weight: 600;
      color: var(--fg-muted);
      transition: all 0.15s ease;
      white-space: nowrap;
    }

    .seg-btn:hover {
      color: var(--fg);
    }

    .seg-btn.active {
      background: var(--primary);
      color: var(--primary-fg);
      font-weight: 700;
      box-shadow: var(--shadow-sm);
    }

    .icon-btn {
      width: 34px;
      height: 34px;
      border-radius: 9px;
      border: 1px solid var(--border);
      background: var(--bg);
      color: var(--fg-secondary);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: background-color 0.15s, color 0.15s;
    }

    .icon-btn:hover {
      background: var(--bg-muted);
      color: var(--fg);
    }

    .icon-btn.sm {
      width: 30px;
      height: 30px;
      border-radius: 8px;
    }

    .icon-btn:disabled {
      opacity: 0.35;
      cursor: not-allowed;
    }

    /* Scrollable Main Viewport */
    .main-scroll {
      flex: 1;
      overflow-y: auto;
      padding: 8px 20px 20px 20px;
      scrollbar-width: none;
    }

    .main-scroll::-webkit-scrollbar {
      display: none;
    }

    .view-section {
      display: flex;
      flex-direction: column;
      gap: 14px;
    }

    .hidden {
      display: none !important;
    }

    /* Cards & Surfaces */
    .card {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius-xl);
      padding: 18px;
    }

    .card-compact {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      padding: 14px;
    }

    /* Exercise Top Row */
    .ex-top-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      margin-bottom: 12px;
    }

    .step-pill-btn {
      height: 30px;
      padding: 0 10px;
      border-radius: 8px;
      border: 1px solid var(--border);
      background: var(--bg-subtle);
      font-size: 12px;
      font-weight: 600;
      color: var(--fg-secondary);
      display: inline-flex;
      align-items: center;
      gap: 5px;
      transition: background-color 0.15s;
    }

    .step-pill-btn:hover {
      background: var(--bg-muted);
      color: var(--fg);
    }

    .nav-arrows {
      display: inline-flex;
      align-items: center;
      gap: 4px;
    }

    .ex-title-row {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      gap: 6px;
      margin-bottom: 14px;
    }

    .ex-title {
      font-size: 20px;
      font-weight: 800;
      letter-spacing: -0.02em;
      color: var(--fg);
    }

    .info-trigger {
      width: 24px;
      height: 24px;
      border-radius: 9999px;
      color: var(--fg-subtle);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: color 0.15s, background-color 0.15s;
    }

    .info-trigger:hover {
      color: var(--fg);
      background: var(--bg-muted);
    }

    .upgrade-pill {
      height: 24px;
      padding: 0 9px;
      border-radius: 9999px;
      background: var(--green-bg);
      border: 1px solid var(--green-border);
      color: var(--green-fg);
      font-size: 11px;
      font-weight: 700;
      display: inline-flex;
      align-items: center;
      gap: 3px;
      transition: filter 0.15s;
    }

    .upgrade-pill:hover {
      filter: brightness(0.96);
    }

    .muscle-pill {
      height: 24px;
      padding: 0 8px;
      border-radius: 6px;
      background: var(--bg-muted);
      border: 1px solid var(--border);
      color: var(--fg-secondary);
      font-size: 11px;
      font-weight: 600;
      display: inline-flex;
      align-items: center;
    }

    .swap-pill-btn {
      height: 26px;
      padding: 0 9px;
      border-radius: 7px;
      border: 1px solid var(--border);
      background: var(--bg);
      color: var(--fg-secondary);
      font-size: 11px;
      font-weight: 600;
      display: inline-flex;
      align-items: center;
      gap: 4px;
      transition: background-color 0.15s, color 0.15s;
    }

    .swap-pill-btn:hover {
      background: var(--bg-muted);
      color: var(--fg);
    }

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

    .set-done-btn {
      width: 100%;
      min-height: 48px;
      padding: 0 14px;
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      background: var(--bg);
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      font-weight: 500;
      color: var(--fg);
      transition: background-color 0.15s;
    }

    .set-done-btn:hover {
      background: var(--bg-subtle);
    }

    .check-badge {
      width: 24px;
      height: 24px;
      border-radius: 6px;
      background: var(--primary);
      color: var(--primary-fg);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }

    .active-set-box {
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      padding: 10px;
      background: var(--bg);
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .active-split-btn {
      display: flex;
      align-items: stretch;
      border-radius: 9px;
      background: var(--primary);
      overflow: hidden;
    }

    .active-complete-main {
      flex: 1;
      min-height: 50px;
      padding: 0 14px;
      text-align: left;
      color: var(--primary-fg);
      font-size: 14px;
      font-weight: 600;
      transition: background-color 0.15s;
    }

    .active-complete-main:hover {
      background: var(--primary-hover);
    }

    .active-tuner-toggle {
      width: 44px;
      min-height: 50px;
      border-left: 1px solid rgba(255, 255, 255, 0.14);
      color: #D4D4D8;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: background-color 0.15s, color 0.15s;
    }

    .active-tuner-toggle:hover {
      background: var(--primary-hover);
      color: #FFFFFF;
    }

    .inline-tuner {
      background: var(--bg-subtle);
      border: 1px solid var(--border);
      border-radius: 9px;
      padding: 10px 12px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .tuner-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 12px;
      font-weight: 600;
      color: var(--fg-secondary);
    }

    .stepper-group {
      display: inline-flex;
      align-items: center;
      gap: 6px;
    }

    .stepper-btn {
      width: 30px;
      height: 30px;
      border-radius: 7px;
      border: 1px solid var(--border);
      background: var(--bg);
      font-size: 14px;
      font-weight: 700;
      color: var(--fg);
      display: inline-flex;
      align-items: center;
      justify-content: center;
    }

    .stepper-btn:hover {
      background: var(--bg-muted);
    }

    .stepper-val {
      min-width: 58px;
      text-align: center;
      font-size: 12px;
      font-weight: 700;
      color: var(--fg);
    }

    .drop-set-btn {
      width: 100%;
      min-height: 42px;
      border-radius: 9px;
      border: 1px solid var(--border);
      background: var(--bg);
      font-size: 12px;
      font-weight: 600;
      color: var(--fg);
      transition: background-color 0.15s;
    }

    .drop-set-btn:hover {
      background: var(--bg-muted);
    }

    .set-upcoming {
      width: 100%;
      min-height: 44px;
      padding: 0 14px;
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      background: var(--bg-subtle);
      display: flex;
      align-items: center;
      font-size: 14px;
      font-weight: 500;
      color: var(--fg-subtle);
    }

    /* Docked Footer Stack (Rest Bar + Bottom Nav) */
    .docked-footer {
      flex-shrink: 0;
      background: var(--bg);
      z-index: 20;
    }

    .rest-bar-wrap {
      padding: 6px 20px 10px 20px;
    }

    .rest-bar {
      padding: 10px 14px;
      border-radius: var(--radius-lg);
      border: 1px solid var(--border);
      background: var(--bg-subtle);
      display: flex;
      align-items: center;
      justify-content: space-between;
      transition: border-color 0.25s, background-color 0.25s;
    }

    .rest-bar.flash-done {
      animation: restFlash 0.85s ease-in-out 3;
    }

    @keyframes restFlash {
      0%, 100% { border-color: var(--primary); background: var(--bg-muted); }
      50% { border-color: var(--green-fg); background: var(--green-bg); }
    }

    .rest-digits-btn {
      font-size: 28px;
      font-weight: 800;
      letter-spacing: -0.02em;
      line-height: 1;
      color: var(--fg);
      padding: 2px 4px;
      border-radius: 6px;
    }

    .rest-digits-btn:hover {
      background: var(--bg-muted);
    }

    .rest-plus-btn {
      height: 38px;
      padding: 0 14px;
      border-radius: 9px;
      border: 1px solid var(--border);
      background: var(--bg);
      font-size: 12px;
      font-weight: 700;
      color: var(--fg);
      box-shadow: var(--shadow-sm);
    }

    .rest-plus-btn:hover {
      background: var(--bg-muted);
    }

    /* Bottom 4-Tab Nav */
    .bottom-nav {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      border-top: 1px solid var(--border);
      background: var(--bg);
      padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .nav-btn {
      min-height: 56px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 4px;
      color: var(--fg-subtle);
      font-size: 11px;
      font-weight: 500;
      transition: color 0.15s;
    }

    .nav-btn:hover {
      color: var(--fg);
    }

    .nav-btn.active {
      color: var(--fg);
      font-weight: 700;
    }

    /* Viewport-Clamped Fixed Floating Popover Layer */
    .popover-backdrop {
      position: fixed;
      inset: 0;
      z-index: 45;
      background: transparent;
    }

    .floating-popover {
      position: fixed;
      z-index: 50;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 8px;
      box-shadow: var(--shadow-pop);
      min-width: 200px;
      max-width: min(290px, calc(100vw - 24px));
      animation: popScale 0.13s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes popScale {
      from { opacity: 0; transform: scale(0.96); }
      to { opacity: 1; transform: scale(1); }
    }

    .pop-label {
      font-size: 10px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      color: var(--fg-subtle);
      padding: 4px 8px;
    }

    .pop-item {
      width: 100%;
      min-height: 36px;
      padding: 6px 10px;
      border-radius: 8px;
      text-align: left;
      font-size: 12px;
      font-weight: 600;
      color: var(--fg);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    .pop-item:hover {
      background: var(--bg-muted);
    }

    .pop-item.active-row {
      background: var(--bg-muted);
      font-weight: 700;
    }

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

    /* Buttons & Inputs for Sub-Views */
    .btn-primary {
      height: 40px;
      padding: 0 16px;
      border-radius: 9px;
      background: var(--primary);
      color: var(--primary-fg);
      font-size: 12px;
      font-weight: 600;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      transition: background-color 0.15s;
    }

    .btn-primary:hover {
      background: var(--primary-hover);
    }

    .btn-primary.full {
      width: 100%;
      height: 44px;
    }

    .btn-outline {
      height: 38px;
      padding: 0 14px;
      border-radius: 9px;
      border: 1px solid var(--border);
      background: var(--bg);
      color: var(--fg);
      font-size: 12px;
      font-weight: 600;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
    }

    .btn-outline:hover {
      background: var(--bg-muted);
    }

    .btn-danger {
      width: 100%;
      height: 40px;
      border-radius: 9px;
      border: 1px solid var(--red-border);
      background: var(--red-bg);
      color: var(--red-fg);
      font-size: 12px;
      font-weight: 600;
    }

    .text-input {
      width: 100%;
      height: 38px;
      padding: 0 12px;
      border-radius: 9px;
      border: 1px solid var(--border);
      background: var(--bg);
      font-size: 13px;
      color: var(--fg);
      outline: none;
    }

    .text-input:focus {
      border-color: var(--primary);
    }

    /* Toggle Switch */
    .switch-btn {
      width: 42px;
      height: 24px;
      border-radius: 9999px;
      background: var(--border-strong);
      padding: 2px;
      transition: background-color 0.2s;
      flex-shrink: 0;
    }

    .switch-btn.on {
      background: var(--primary);
    }

    .switch-thumb {
      display: block;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background: #FFFFFF;
      transition: transform 0.2s;
    }

    .switch-btn.on .switch-thumb {
      transform: translateX(18px);
    }

    /* Sub-view Grids & Lists */
    .sub-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      padding-top: 6px;
    }

    .metrics-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
    }

    .metric-box {
      border: 1px solid var(--border);
      border-radius: var(--radius-lg);
      padding: 12px;
      background: var(--bg);
    }

    .metric-label {
      font-size: 11px;
      font-weight: 500;
      color: var(--fg-muted);
    }

    .metric-value {
      font-size: 17px;
      font-weight: 800;
      color: var(--fg);
      margin-top: 3px;
    }

    .setting-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 12px 0;
      border-bottom: 1px solid var(--border);
    }

    .setting-row:first-child {
      padding-top: 0;
    }

    .setting-row:last-child {
      border-bottom: none;
      padding-bottom: 0;
    }

    .setting-title {
      font-size: 13px;
      font-weight: 600;
      color: var(--fg);
    }

    .setting-desc {
      font-size: 11px;
      color: var(--fg-muted);
      margin-top: 2px;
    }

    /* Toast */
    .toast-pill {
      position: fixed;
      top: 16px;
      left: 50%;
      transform: translateX(-50%) translateY(-8px);
      z-index: 60;
      background: var(--primary);
      color: var(--primary-fg);
      padding: 8px 14px;
      border-radius: 9999px;
      font-size: 12px;
      font-weight: 600;
      box-shadow: var(--shadow-pop);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.18s ease, transform 0.18s ease;
      white-space: nowrap;
    }

    .toast-pill.show {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }
