/**
 * Workout App Theme
 * Friendly, bubbly fitness app with soft colors and playful interactions
 * Light theme optimized for approachability and joy in fitness
 */

@layer theme {
  :root {
    /* Typography - Friendly, approachable fonts */
    --font-family-base:
      'Inter', 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI',
      'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    --font-family-display:
      'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI',
      'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    --font-family-mono:
      'SF Mono', Monaco, 'Inconsolata', 'Roboto Mono', 'Source Code Pro',
      monospace;

    /* FONT SIZE - Clear hierarchy for workout data */
    --f-timer: 7rem;
    --f1: 1.5rem;
    --f2: 1.25rem;
    --f3: 1.125rem;
    --f4: 1rem;
    --f5: 0.875rem;
    --f6: 0.75rem;
    --f7: 0.625rem;

    /* SPACING - Consistent spacing system */
    --s0: 0;
    --s1: 0.25rem;
    --s2: 0.5rem;
    --s3: 1rem;
    --s4: 1.5rem;
    --s5: 2rem;
    --s6: 3rem;

    /* Layout - Responsive grid system */
    --max-width-md: 768px;
    --max-width-lg: 1024px;

    /* FONT WEIGHT - Clear hierarchy */
    --fw-normal: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;
    --fw-black: 800;

    /* LINE HEIGHT - Generous spacing for friendliness */
    --lh-tight: 1.3;
    --lh-base: 1.6;

    /* BORDER RADIUS - Rounded, bubbly design system */
    --br-sm: 6px;
    --br-base: 10px;
    --br-lg: 20px;
    --br-xl: 20px;
    --br-full: 9999px;

    /* Shadows - Enhanced depth for bubbly, elevated appearance */
    --shadow-sm:
      0 2px 4px 0 rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-base:
      0 4px 8px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.08);
    --shadow-md:
      0 8px 16px -2px rgba(0, 0, 0, 0.15), 0 4px 8px -2px rgba(0, 0, 0, 0.10);
    --shadow-lg:
      0 16px 32px -4px rgba(0, 0, 0, 0.18), 0 8px 16px -4px rgba(0, 0, 0, 0.12);
    --shadow-xl:
      0 24px 48px -6px rgba(0, 0, 0, 0.22), 0 12px 24px -6px rgba(
      0,
      0,
      0,
      0.15
    );
    --shadow-brand:
      0 8px 24px -4px rgba(88, 94, 181, 0.25), 0 4px 12px -2px rgba(
      88,
      94,
      181,
      0.15
    );

    /* Transitions - Smooth app-like animations */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --transition-spring: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* Z-index scale */
    --z-fixed: 1030;

    /* Friendly Fitness Color Palette - Soft, approachable, playful */

    /* Soft base colors - Light, friendly theme */
    --whiteH: 244;
    --whiteS: 20%;
    --whiteL: 98%;

    /* Friendly text colors - Softer contrast */
    --blackH: 237;
    --blackS: 25%;
    --blackL: 25%;

    /* Brand colors - Friendly primary palette */
    --brand-primaryH: 237;
    --brand-primaryS: 50%;
    --brand-primaryL: 65%;

    --brand-secondaryH: 244;
    --brand-secondaryS: 85%;
    --brand-secondaryL: 88%;

    /* Extended friendly palette */
    --brand-lightH: 244;
    --brand-lightS: 60%;
    --brand-lightL: 92%;

    --brand-softH: 240;
    --brand-softS: 35%;
    --brand-softL: 70%;

    /* Fitness accent colors - Vibrant and motivating */
    --greenH: 142;
    --greenS: 76%;
    --greenL: 36%;

    --yellowH: 45;
    --yellowS: 93%;
    --yellowL: 58%;

    --redH: 0;
    --redS: 84%;
    --redL: 60%;

    /* Semantic colors - Workout specific */
    --errorH: var(--redH);
    --errorS: var(--redS);
    --errorL: var(--redL);

    --warningH: var(--yellowH);
    --warningS: var(--yellowS);
    --warningL: var(--yellowL);

    --successH: var(--greenH);
    --successS: var(--greenS);
    --successL: var(--greenL);

    /* Application colors - Light, friendly theme */
    --backgroundH: var(--whiteH);
    --backgroundS: var(--whiteS);
    --backgroundL: var(--whiteL);

    --surfaceH: var(--brand-lightH);
    --surfaceS: var(--brand-lightS);
    --surfaceL: var(--brand-lightL);

    --bodyH: var(--blackH);
    --bodyS: var(--blackS);
    --bodyL: var(--blackL);

    --headingH: var(--brand-primaryH);
    --headingS: var(--brand-primaryS);
    --headingL: calc(var(--brand-primaryL) - 15%);

    --secondaryH: var(--brand-softH);
    --secondaryS: var(--brand-softS);
    --secondaryL: var(--brand-softL);

    --primaryH: var(--brand-primaryH);
    --primaryS: var(--brand-primaryS);
    --primaryL: var(--brand-primaryL);

    /* Border colors - Light mode friendly */
    --borderH: var(--brand-primaryH);
    --borderS: var(--brand-primaryS);
    --borderL: 80%;

    --border-lightH: var(--brand-primaryH);
    --border-lightS: var(--brand-primaryS);
    --border-lightL: 90%;
  }

  :root {
    --header-height: 56px;
    --footer-height: 64px;
    --main-padding: 0;
  }

  html {
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
  }

  /* ── Header ────────────────────────────────────────────────────────── */
  header {
    display: flex;
    align-items: center;
    gap: var(--s2);
    height: var(--header-height);
    padding: 0 var(--container-padding);
    border-bottom: 1px solid currentColor;
  }

  header strong {
    flex: 1;
    font-size: var(--f4);
    font-weight: var(--fw-semibold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* ── Fixed bottom tab bar ──────────────────────────────────────────── */
  footer[fixed] {
    padding: 0;
    height: var(--footer-height);
  }

  /* Icon sizing for bottom bar */
  ui-bottom-bar img {
    width: 24px;
    height: 24px;
  }

  /* Stopwatch running indicator in nav */
  .sw-running {
    color: var(--primary);
    font-variant-numeric: tabular-nums;
  }
}

/* ── Home: Benchmark browser ────────────────────────────────────────────── */

.bm-container {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
}

.bm-filters {
  padding: var(--s3);
  border-bottom: 1px solid currentColor;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  position: sticky;
  top: var(--header-height, 56px);
  background: var(--background);
  z-index: 10;
}

.bm-search-input {
  width: 100%;
  padding: var(--s2) var(--s3);
  border: 1px solid currentColor;
  border-radius: var(--br-full);
  font-size: var(--f5);
  background: transparent;
  color: inherit;
  margin: 0;
}

.bm-grade-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--f6);
}

.bm-grade-label {
  font-weight: var(--fw-medium);
  display: block;
  margin: 0;
  flex-shrink: 0;
}

.bm-grade-select {
  flex: 1;
  padding: var(--s1) var(--s2);
  border: 1px solid currentColor;
  border-radius: var(--br-base);
  background: transparent;
  color: inherit;
  font-size: var(--f6);
  margin: 0;
}

.bm-grade-sep {
  opacity: 0.5;
  flex-shrink: 0;
}

.bm-log-filter {
  display: flex;
  gap: var(--s2);
  margin-top: var(--s2);
  margin-bottom: var(--s2);
}

.bm-list {
  flex: 1;
}

.bm-message {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s6);
  opacity: 0.6;
  margin: 0;
}

.bm-count {
  padding: var(--s2) var(--s3);
  font-size: var(--f6);
  opacity: 0.6;
  border-bottom: 1px solid currentColor;
}

.bm-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--s3);
  border: none;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background var(--transition-fast);
  border-radius: 0;
}

.bm-item:hover {
  background: var(--primary-dull);
  opacity: 1;
  transform: none;
}

.bm-item:active {
  transform: none;
}

.bm-item-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  margin-bottom: var(--s1);
}

.bm-name {
  font-weight: var(--fw-semibold);
  font-size: var(--f5);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-grade-pill {
  font-size: var(--f7);
  font-weight: var(--fw-semibold);
  padding: 2px var(--s2);
  border: 1px solid currentColor;
  border-radius: var(--br-full);
  white-space: nowrap;
  flex-shrink: 0;
}

.bm-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--f6);
  opacity: 0.6;
}

.bm-setter {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-stats {
  flex-shrink: 0;
  white-space: nowrap;
}

.bm-load-more {
  display: block;
  width: 100%;
  padding: var(--s3);
  text-align: center;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  font-weight: var(--fw-medium);
  cursor: pointer;
  font-size: var(--f5);
}

/* Climb detail page */
.cp-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--footer-height));
  position: relative;
}

.cp-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--s3);
}

/* Climb detail sticky header bar */
.bm-dh-header {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid currentColor;
  flex-shrink: 0;
}

.bm-dh-back {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: var(--s1);
  cursor: pointer;
  border-radius: var(--br-base);
  flex-shrink: 0;
  opacity: 0.8;
  transition: opacity var(--transition-fast);
}

.bm-dh-back:hover {
  opacity: 1;
}

.bm-dh-back img {
  width: 20px;
  height: 20px;
  transform: scaleX(-1);
  display: block;
}

.bm-dh-info {
  flex: 1;
  min-width: 0;
}

.bm-dh-name {
  font-size: var(--f4);
  font-weight: var(--fw-bold);
  margin: 0;
  line-height: var(--lh-tight);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-dh-sub {
  font-size: var(--f7);
  opacity: 0.6;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bm-dh-meta {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: var(--f6);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  opacity: 0.8;
}

/* Board canvas container */
.bm-board-wrap {
  position: relative;
  max-width: 480px;
  margin: 0 auto var(--s3);
  border-radius: var(--br-base);
  overflow: hidden;
}

.bm-board-img {
  width: 100%;
  display: block;
}

.bm-board-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.bm-board-placeholder {
  background: #1a1a1a;
  aspect-ratio: 450 / 485;
  border-radius: var(--br-base);
  max-width: 480px;
  margin: 0 auto var(--s3);
  position: relative;
  overflow: hidden;
}

.bm-board-placeholder-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.bm-youtube-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  padding: var(--s3);
  border: 1px solid currentColor;
  border-radius: var(--br-base);
  text-decoration: none;
  color: inherit;
  font-weight: var(--fw-medium);
  transition: opacity var(--transition-base);
}

.bm-youtube-btn:hover {
  opacity: 0.7;
}

/* ── Settings page ───────────────────────────────────────────────────────── */

.st-container {
  padding: var(--s4) var(--s3);
  max-width: 600px;
  margin: 0 auto;
}

.st-section {
  margin-bottom: var(--s5);
}

.st-desc {
  opacity: 0.6;
  margin-bottom: var(--s3);
}

.st-options {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.st-option {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s3);
  border: 1px solid currentColor;
  border-radius: var(--br-base);
  cursor: pointer;
  font-weight: var(--fw-medium);
  transition: all var(--transition-base);
  margin: 0;
}

.st-option input[type='radio'] {
  margin: 0;
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  border: none;
  padding: 0;
  flex-shrink: 0;
}

.st-option-label {
  display: block;
  font-size: var(--f4);
}

.st-option-example {
  display: block;
  font-size: var(--f6);
  opacity: 0.6;
  font-weight: var(--fw-normal);
  margin-top: 2px;
}

.st-option--selected {
  border-color: var(--primary);
  background: var(--primary-dull);
}

/* ── Logbook: shared badges ─────────────────────────────────────────────── */

.lb-badge {
  display: inline-block;
  padding: 2px var(--s2);
  border-radius: var(--br-full);
  font-size: var(--f7);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
  flex-shrink: 0;
}

.lb-badge--sent {
  background: hsl(var(--greenH), var(--greenS), var(--greenL));
  color: #fff;
}

.lb-badge--project {
  border: 1px solid currentColor;
  opacity: 0.6;
}

.lb-entry-stars {
  letter-spacing: 0.05em;
}

/* ── Logbook: log section in climb detail ───────────────────────────────── */

.lb-log-section {
  margin-top: var(--s3);
  padding-top: var(--s3);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.lb-log-summary {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--f5);
  flex-wrap: wrap;
}

.lb-log-btn {
  display: block;
  width: 100%;
  padding: var(--s2) var(--s3);
  background: transparent;
  border: 1px solid currentColor;
  border-radius: var(--br-base);
  color: inherit;
  font-size: var(--f5);
  font-weight: var(--fw-medium);
  cursor: pointer;
  text-align: center;
  transition: opacity var(--transition-fast);
}

.lb-log-btn:hover {
  opacity: 0.7;
}

/* ── Logbook: session dialog ────────────────────────────────────────────── */

.lb-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: calc(var(--z-fixed) + 10);
  padding: var(--s3);
}

.lb-overlay[hidden] {
  display: none;
}

.lb-dialog {
  background: var(--background);
  border: 1px solid currentColor;
  border-radius: var(--br-lg);
  padding: var(--s4);
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}

.lb-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.lb-dialog-title {
  font-weight: var(--fw-semibold);
  font-size: var(--f3);
}

.lb-dialog-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--f3);
  opacity: 0.6;
  padding: var(--s1);
  line-height: 1;
  color: inherit;
}

.lb-dialog-close:hover {
  opacity: 1;
}

.lb-field {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
}

.lb-field--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.lb-field-label {
  font-size: var(--f6);
  font-weight: var(--fw-medium);
  opacity: 0.7;
}

.lb-counter {
  display: flex;
  align-items: stretch;
  gap: var(--s2);
  height: 40px;
}

.lb-counter-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid currentColor;
  border-radius: var(--br-base);
  background: transparent;
  color: inherit;
  font-size: var(--f2);
  cursor: pointer;
  flex-shrink: 0;
}

.lb-counter-input {
  flex: 1;
  text-align: center;
  border: 1px solid currentColor;
  border-radius: var(--br-base);
  background: transparent;
  color: inherit;
  font-size: var(--f3);
  font-weight: var(--fw-semibold);
  padding: 0;
  margin: 0;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.lb-counter-input::-webkit-inner-spin-button,
.lb-counter-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.lb-checkbox {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.lb-star-row {
  display: flex;
  gap: var(--s1);
}

.lb-star-btn {
  background: none;
  border: none;
  font-size: 1.75rem;
  cursor: pointer;
  color: var(--border);
  padding: 0 var(--s1);
  line-height: 1;
  transition: color var(--transition-fast);
}

.lb-star-btn--active {
  color: hsl(var(--yellowH), var(--yellowS), var(--yellowL));
}

.lb-submit-btn {
  width: 100%;
  padding: var(--s3);
  background: var(--primary);
  color: var(--background);
  border: none;
  border-radius: var(--br-base);
  font-size: var(--f4);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.lb-submit-btn:hover {
  opacity: 0.85;
}

/* ── Library page ────────────────────────────────────────────────────────── */

.lb-page {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
}

.lb-filter-bar {
  display: flex;
  gap: var(--s2);
  padding: var(--s3);
  border-bottom: 1px solid currentColor;
  position: sticky;
  top: var(--header-height, 56px);
  background: var(--background);
  z-index: 10;
}

.lb-filter-btn {
  flex: 1;
  padding: var(--s2);
  border: 1px solid currentColor;
  border-radius: var(--br-full);
  background: transparent;
  color: inherit;
  font-size: var(--f6);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.lb-filter-btn--active {
  background: var(--primary);
  color: var(--background);
  border-color: var(--primary);
}

.lb-empty {
  padding: var(--s6) var(--s3);
  text-align: center;
  opacity: 0.6;
  line-height: var(--lh-base);
}

.lb-entry {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  gap: var(--s1);
  padding: var(--s3);
  border: none;
  border-bottom: 1px solid currentColor;
  border-radius: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.lb-entry:hover {
  background: var(--primary-dull);
}

.lb-entry-row {
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.lb-entry-name {
  flex: 1;
  font-weight: var(--fw-semibold);
  font-size: var(--f5);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-grade-pill {
  font-size: var(--f7);
  font-weight: var(--fw-semibold);
  padding: 2px var(--s2);
  border: 1px solid currentColor;
  border-radius: var(--br-full);
  white-space: nowrap;
  flex-shrink: 0;
}

.lb-entry-meta {
  display: flex;
  align-items: center;
  gap: var(--s2);
  font-size: var(--f6);
  opacity: 0.6;
  flex-wrap: wrap;
}

.lb-entry-date {
  margin-left: auto;
}
