    :root {
      --bg: #f2f2f7;
      --surface: #ffffff;
      --text: #1c1c1e;
      --text-secondary: #8e8e93;
      --accent: #007aff;
      --danger: #ff3b30;
      --border: #d1d1d6;
      --safe-top: env(safe-area-inset-top, 0px);
      --safe-bottom: env(safe-area-inset-bottom, 0px);
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    html, body {
      height: 100%;
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
      background: var(--bg);
      color: var(--text);
      -webkit-font-smoothing: antialiased;
      overflow: hidden;
    }

    .app {
      display: flex;
      flex-direction: column;
      height: 100%;
      max-width: 430px;
      margin: 0 auto;
      background: var(--bg);
    }

    .header {
      padding: calc(12px + var(--safe-top)) 20px 12px;
      background: var(--surface);
      border-bottom: 0.5px solid var(--border);
    }

    .header h1 {
      font-size: 28px;
      font-weight: 700;
      letter-spacing: -0.4px;
    }

    .header-subtitle {
      font-size: 13px;
      color: var(--text-secondary);
      margin-top: 2px;
    }

    .content {
      flex: 1;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      padding: 16px 16px calc(16px + var(--safe-bottom));
    }

    .tab-panel {
      display: none;
    }

    .tab-panel.active {
      display: block;
    }

    .placeholder-card {
      background: var(--surface);
      border-radius: 12px;
      padding: 24px 20px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .placeholder-card h2 {
      font-size: 20px;
      font-weight: 600;
      margin-bottom: 8px;
    }

    .placeholder-card p {
      font-size: 15px;
      line-height: 1.5;
      color: var(--text-secondary);
    }

    .history-segment {
      display: flex;
      background: rgba(118, 118, 128, 0.12);
      border-radius: 10px;
      padding: 2px;
      margin-bottom: 16px;
    }

    .history-segment-btn {
      flex: 1;
      font-family: inherit;
      font-size: 14px;
      font-weight: 600;
      padding: 8px 12px;
      border: none;
      border-radius: 8px;
      background: none;
      color: var(--text-secondary);
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
    }

    .history-segment-btn.active {
      background: var(--surface);
      color: var(--text);
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    }

    .history-category {
      background: var(--surface);
      border-radius: 12px;
      padding: 16px;
      margin-bottom: 12px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .history-category h3 {
      font-size: 17px;
      font-weight: 600;
      margin-bottom: 10px;
    }

    .history-summary {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-bottom: 12px;
    }

    .history-stat {
      font-size: 13px;
      color: var(--text-secondary);
      background: var(--bg);
      border-radius: 8px;
      padding: 6px 10px;
    }

    .history-stat strong {
      color: var(--text);
      font-weight: 600;
    }

    .history-days {
      border-top: 0.5px solid var(--border);
      padding-top: 8px;
    }

    .history-day-row {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 12px;
      padding: 8px 0;
      border-bottom: 0.5px solid var(--border);
      font-size: 14px;
    }

    .history-day-row:last-child {
      border-bottom: none;
    }

    .history-day-label {
      color: var(--text-secondary);
      flex-shrink: 0;
      min-width: 72px;
    }

    .history-day-value {
      text-align: right;
      line-height: 1.35;
      flex: 1;
    }

    .history-day-value.empty,
    .history-day-value .empty {
      color: var(--text-secondary);
    }

    .history-goal-met {
      color: #34c759;
      font-weight: 600;
    }

    .history-empty {
      font-size: 15px;
      color: var(--text-secondary);
      text-align: center;
      padding: 32px 16px;
    }

    .date-nav {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: var(--surface);
      border-radius: 12px;
      padding: 12px 8px;
      margin-bottom: 16px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .date-nav-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      border: none;
      background: none;
      color: var(--accent);
      cursor: pointer;
      border-radius: 8px;
      -webkit-tap-highlight-color: transparent;
    }

    .date-nav-btn:disabled {
      color: var(--border);
      cursor: default;
    }

    .date-nav-btn:not(:disabled):active {
      background: rgba(0, 122, 255, 0.1);
    }

    .date-nav-btn svg {
      width: 22px;
      height: 22px;
      fill: currentColor;
    }

    .date-display {
      text-align: center;
      flex: 1;
      padding: 0 4px;
    }

    .date-display .date-primary {
      font-size: 17px;
      font-weight: 600;
      letter-spacing: -0.2px;
    }

    .date-display .date-secondary {
      font-size: 13px;
      color: var(--text-secondary);
      margin-top: 2px;
    }

    .date-metrics {
      display: flex;
      align-items: baseline;
      justify-content: space-between;
      gap: 12px;
      margin-top: 4px;
    }

    .date-fun {
      font-size: 13px;
      font-weight: 600;
      color: var(--text-secondary);
      text-align: left;
    }

    .date-progress {
      font-size: 15px;
      font-weight: 700;
      color: var(--text-secondary);
      text-align: right;
      margin-left: auto;
    }

    .date-progress.has-progress {
      color: #34c759;
    }

    .section-card {
      background: var(--surface);
      border-radius: 12px;
      padding: 16px;
      margin-bottom: 12px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .section-card.complete {
      background: #eaf8ef;
      box-shadow: 0 1px 3px rgba(52, 199, 89, 0.16);
    }

    .section-card.complete:not([data-habit="sleep"]),
    .section-card.complete.goal-met {
      background: #d4f4de;
      box-shadow: 0 1px 3px rgba(52, 199, 89, 0.28);
    }

    .section-card h3 {
      font-size: 17px;
      font-weight: 600;
      margin-bottom: 12px;
    }

    .subsection-title {
      font-size: 15px;
      font-weight: 600;
      color: var(--text);
      margin-bottom: 12px;
    }

    .section-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      margin-bottom: 12px;
    }

    .section-header h3 {
      margin-bottom: 0;
    }

    .section-title {
      display: flex;
      align-items: center;
      gap: 8px;
      min-width: 0;
    }

    .complete-check {
      width: 22px;
      height: 22px;
      fill: #34c759;
      flex-shrink: 0;
    }

    .section-card.complete.goal-met .complete-check,
    .section-card.complete:not([data-habit="sleep"]) .complete-check {
      fill: #248a3d;
    }

    .card-reset {
      font-family: inherit;
      font-size: 13px;
      font-weight: 600;
      color: var(--accent);
      background: none;
      border: none;
      padding: 4px 8px;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
      flex-shrink: 0;
    }

    .card-reset:active {
      opacity: 0.6;
    }

    .week-dots {
      display: flex;
      gap: 8px;
      margin: 0 0 12px;
    }

    .week-dot {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      border: 1.5px solid var(--border);
      background: transparent;
    }

    .week-dot.filled {
      background: #34c759;
      border-color: #34c759;
    }

    .week-dot.rest {
      background: transparent;
      border-color: #d1d1d6;
    }

    .sleep-average {
      font-size: 13px;
      color: var(--text-secondary);
      margin: -4px 0 12px;
    }

    .details-toggle {
      display: block;
      width: 100%;
      margin-top: 12px;
      padding: 10px 0 0;
      border: none;
      border-top: 0.5px solid var(--border);
      background: none;
      font-family: inherit;
      font-size: 15px;
      font-weight: 600;
      color: var(--accent);
      text-align: left;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
    }

    .details-toggle:active {
      opacity: 0.6;
    }

    .exercise-details {
      margin-top: 12px;
    }

    .field-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }

    .field-row label {
      font-size: 15px;
      line-height: 1.3;
      color: var(--text-secondary);
      flex: 1;
      min-width: 0;
      padding-right: 8px;
    }

    .field-row + .field-row {
      margin-top: 12px;
    }

    .field-row input,
    .field-row select {
      font-family: inherit;
      font-size: 17px;
      color: var(--text);
      border: none;
      background: var(--bg);
      border-radius: 8px;
      -webkit-appearance: none;
      appearance: none;
    }

    .field-row input {
      max-width: 120px;
      padding: 10px 12px;
      text-align: right;
    }

    .field-row > select,
    .dual-select select {
      min-width: 120px;
      max-width: 160px;
      padding: 10px 32px 10px 12px;
      text-align: right;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238e8e93' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 12px center;
    }

    .dual-select {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-shrink: 0;
    }

    .dual-select .kettlebell-metric-select {
      min-width: 48px;
      max-width: 56px;
      width: 56px;
      padding: 8px 22px 8px 6px;
      font-size: 16px;
      background-position: right 8px center;
    }

    .time-input {
      display: flex;
      align-items: center;
      gap: 4px;
      flex-shrink: 0;
    }

    .time-input select {
      width: 54px;
      min-width: 54px;
      max-width: 54px;
      flex: 0 0 54px;
      padding: 8px 2px;
      font-size: 16px;
      text-align: center;
      text-align-last: center;
      background-image: none;
    }

    .time-input .time-separator {
      font-size: 17px;
      font-weight: 600;
      color: var(--text-secondary);
    }

    .computed-value {
      font-size: 17px;
      font-weight: 600;
      color: var(--text);
      text-align: right;
      min-width: 80px;
    }

    .computed-value.empty {
      font-weight: 400;
      color: var(--text-secondary);
    }

    .entry-actions {
      display: flex;
      gap: 10px;
      margin-top: 8px;
      margin-bottom: 16px;
    }

    .btn {
      flex: 1;
      font-family: inherit;
      font-size: 17px;
      font-weight: 600;
      padding: 14px 16px;
      border: none;
      border-radius: 12px;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
    }

    .btn:active {
      opacity: 0.75;
    }

    .btn-primary {
      background: var(--accent);
      color: #fff;
    }

    .btn-secondary {
      background: var(--surface);
      color: var(--accent);
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .btn-danger-outline {
      background: var(--surface);
      color: var(--danger);
      border: 1px solid var(--danger);
      font-size: 15px;
      padding: 12px 16px;
      width: 100%;
    }

    .settings-card {
      background: var(--surface);
      border-radius: 12px;
      padding: 20px;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    }

    .settings-card h2 {
      font-size: 20px;
      font-weight: 600;
      margin-bottom: 8px;
    }

    .settings-card p {
      font-size: 15px;
      line-height: 1.5;
      color: var(--text-secondary);
      margin-bottom: 12px;
    }

    .settings-group {
      margin-bottom: 24px;
      padding-bottom: 24px;
      border-bottom: 0.5px solid var(--border);
    }

    .settings-group:last-child {
      margin-bottom: 0;
      padding-bottom: 0;
      border-bottom: none;
    }

    .settings-group h3 {
      font-size: 17px;
      font-weight: 600;
      margin-bottom: 6px;
    }

    .settings-group .btn {
      width: 100%;
      flex: none;
    }

    .settings-actions {
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .settings-actions .btn {
      flex: none;
      width: 100%;
    }

    .toast {
      position: fixed;
      bottom: calc(80px + var(--safe-bottom));
      left: 50%;
      transform: translateX(-50%) translateY(20px);
      background: rgba(28, 28, 30, 0.92);
      color: #fff;
      font-size: 15px;
      padding: 10px 20px;
      border-radius: 20px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease, transform 0.25s ease;
      z-index: 100;
      white-space: nowrap;
    }

    .toast.visible {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }

    .celebration-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.65);
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
      padding-top: calc(24px + var(--safe-top));
      padding-bottom: calc(24px + var(--safe-bottom));
      z-index: 200;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
    }

    .celebration-overlay.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .celebration-card {
      background: var(--surface);
      border-radius: 20px;
      padding: 16px;
      max-width: 320px;
      width: 100%;
      text-align: center;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
      transform: scale(0.92);
      transition: transform 0.3s ease;
    }

    .celebration-overlay.visible .celebration-card {
      transform: scale(1);
    }

    .celebration-card img {
      width: 100%;
      border-radius: 14px;
      display: block;
    }

    .celebration-title {
      font-size: 20px;
      font-weight: 700;
      margin: 14px 0 6px;
    }

    .celebration-message {
      font-size: 15px;
      color: var(--text-secondary);
      margin-bottom: 14px;
      line-height: 1.4;
    }

    .celebration-dismiss {
      width: 100%;
    }

    .tab-bar {
      display: flex;
      background: var(--surface);
      border-top: 0.5px solid var(--border);
      padding-bottom: var(--safe-bottom);
    }

    .tab-button {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 4px;
      padding: 8px 0 6px;
      border: none;
      background: none;
      color: var(--text-secondary);
      font-size: 10px;
      font-weight: 500;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
      transition: color 0.15s ease;
    }

    .tab-button.active {
      color: var(--accent);
    }

    .tab-button svg {
      width: 24px;
      height: 24px;
      fill: currentColor;
    }

    .tab-button:active {
      opacity: 0.6;
    }
  
