@import url("https://fonts.googleapis.com/css2?family=Dosis:wght@300;900&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;500&display=swap");

:root {
  --bg: #F6F7FB;
  --text: #22194D;
  --card-bg: #fff;
  --border: #ddd;
  --muted: #555;
  --accent: #5DADD5;
  --hover: #FC1500;
}

/* ===============================
   RESET & BASE
================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Dosis', sans-serif;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }

/* ===============================
   LAYOUT
================================ */
main {
  flex: 1;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
}

/* ===============================
   PROGRESS BAR
================================ */
.guided-progress {
  width: 100%;
  height: 6px;
  background: #e6e6ef;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 2px;
}

#guided-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s linear;
}

/* ===============================
   WORKOUT DISPLAY
================================ */
#workout-display {
  width: 100%;
  background: linear-gradient(180deg, #f9fafc 0%, #ffffff 100%);
  border-radius: 16px;
  border: 1px solid var(--border);
  margin: 6px 0 14px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
  overflow: hidden;
}

/* ===============================
   WORKOUT HEADER
================================ */
.workout-header {
  background-color: #f4f4f4;
  text-align: center;
  padding: 8px;
  border-bottom: 1px solid #ddd;
}

.workout-header h2 {
  font-weight: 900;
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.workout-header h2 a {
  color: #22194D !important;
}

/* ===============================
   CONTENT
================================ */
.workout-content { padding: 12px; }

.status {
  font-size: clamp(1rem, 3vw, 1.25rem);
  color: var(--muted);
  margin-bottom: 0.25rem;
}

/* ===============================
   META
================================ */
.workout-meta.aligned {
  display: flex;
  flex-direction: column;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  margin: 0.2em 0;
}

.meta-item {
  display: grid;
  grid-template-columns: 95px 1fr;
  gap: 2px;
  padding: 2px 0;
  font-size: clamp(0.95rem, 3vw, 1.25rem);
}

.meta-label {
  font-weight: 900;
  color: var(--text);
}

.meta-value {
  line-height: 1.5;
}

/* ===============================
   EXERCISE LIST — CORE SYSTEM
================================ */
.exercise-list,
ul.exercise-list {
  width: 100%;
  list-style: none;
  margin: 0px 0;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ✅ ABSOLUTELY FIXED GRID */
.exercise-item.flight-row {
  display: grid;
  grid-template-columns:
    48px   /* round */
    48px   /* index */
    40px   /* left */
    40px   /* right */
    52px   /* reps */
    minmax(0, 1fr);
  align-items: center;
  column-gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
}

.exercise-item:last-child { border-bottom: none; }

.exercise-time,
.exercise-round,
.exercise-rep,
.sideL,
.sideR,
.exercise-desc {
  font-size: clamp(1.5rem, 3vw, 1.5rem);
  font-weight: 900;
  height: 34px;
  background: #f4f4f4;
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #22194D;
}

.exercise-desc {
  justify-content: flex-start;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.exercise-desc a {
  color: var(--text) !important;
  border-bottom: dotted 1px;
}

/* ✅ ABSOLUTE COLOR LOCK */
.exercise-item.flight-row,
.exercise-item.flight-row *,
.exercise-item.active.flight-row,
.exercise-item.active.flight-row * {
  color: #22194D !important;
}

/* ===============================
   WEIGHT COLORS (COLOR HIGHLIGHTING)
================================ */
.weight-8  { --weight-bg: #EA899A; }
.weight-12 { --weight-bg: #2271B3; }
.weight-16 { --weight-bg: #EC7C26; }
.weight-20 { --weight-bg: #8E81AA; }
.weight-24 { --weight-bg: #4C9141; }
.weight-28 { --weight-bg: #ff7a00; }
.weight-32 { --weight-bg: #CC0605; }

/* ===============================
   SIDE FILL SYSTEM
================================ */
.sideL,
.sideR {
  position: relative;
  overflow: hidden;
}

.sideL::before,
.sideR::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.sideL::after,
.sideR::after {
  content: attr(data-side);
  position: relative;
  z-index: 2;
}

.sideL.filled::before,
.sideR.filled::before {
  background: var(--weight-bg, #f4f4f4);
}

.sideL.half-diag::before,
.sideR.half-diag::before {
  background: linear-gradient(
    135deg,
    var(--weight-bg, #f4f4f4) 50%,
    transparent 50%
  );
}

/* ===============================
   ACTIVE EXERCISE HIGHLIGHT
================================ */
.exercise-item.active.flight-row .exercise-round,
.exercise-item.active.flight-row .exercise-time,
.exercise-item.active.flight-row .exercise-rep,
.exercise-item.active.flight-row .exercise-desc {
  background-color: var(--weight-bg, #f4f4f4);
}

  .exercise-time,
  .exercise-round {
    height: 32px;
    font-size: 1.1rem;
    padding: 4px 6px;
}

  .sideL,
  .sideR,
  .exercise-rep 
  .exercise-desc {
    font-size: 1.5rem;
    height: 32px;
    padding: 4px 6px;
}

/* ===============================
   GUIDED MODE (MOST IMPORTANT)
================================ */
.guided {
  width: 100%;
  margin-bottom: 8px;
}

.guided-timer {
  text-align: center;
  font-size: clamp(2.25rem, 7.5vw, 3.25rem);
  line-height: 1.0;
  font-weight: 500;
  font-family: 'Roboto', sans-serif;
}

.guided-list-wrapper {
  max-height: 45vh;
  overflow-y: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

.guided-list {
  width: 100%;
  padding: 10px;
  list-style: none;
}

.guided-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.guided-label {
  font-size: clamp(0.7rem, 3vw, 0.85rem);
  font-weight: 900;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  min-width: 70px;
  text-align: center;
  background: #f4f4f4;
}

.guided-controls {
  width: 100%;
  display: flex;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

/* ===============================
   BUTTON SYSTEM + HOVER COLORS
================================ */
#generate-btn,
#start-guided-btn,
#pause-btn {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f4f4f4;
  font-weight: 900;
  font-size: 1rem;
  text-transform: uppercase;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  transition: background 0.2s, color 0.2s, box-shadow 0.2s, transform 0.1s;
}

#minus-btn,
#plus-btn {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f4f4f4;
  color: var(--text);
  font-weight: 900;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
}

/* Hover / Active Highlighting */
#minus-btn:hover,
#plus-btn:hover,
#generate-btn:hover,
#start-guided-btn:hover,
#pause-btn:hover {
  background: #8E81AA;
  color: #fff;
  transform: translateY(-1px);
}

#minus-btn:active,
#plus-btn:active,
#generate-btn:active,
#start-guided-btn:active,
#pause-btn:active {
  background: var(--hover);
  color: #fff;
  transform: scale(0.95);
}

/* ===============================
   CONTROLS
================================ */
.controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.controls .range-label {
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  color: var(--text);
}

.controls #workout-slider {
  width: 100%;
  height: 18px;
  accent-color: #8E81AA;
}

.controls .stepper {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 8px;
  align-items: center;
}

.controls #workout-number {
  width: 100%;
  height: 48px;
  text-align: center;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--text);
  background: var(--card-bg);
}

/* ===============================
   FOOTER
================================ */
.footer {
  font-size: 0.85rem;
  color: #999;
  text-align: center;
  padding: 10px;
  border-top: 1px solid var(--border);
}

/* ===============================
   MOBILE LANDSCAPE TUNING
================================ */
@media (max-width: 900px) and (orientation: landscape) {

  /* ✅ PAGE MUST ALWAYS SCROLL */
  html, body {
    height: auto !important;
    min-height: 100vh !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  /* ✅ MAIN NEVER CLIPS */
  main {
    min-height: auto !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* ✅ EXERCISE LIST MUST NOT OWN A SCROLLBAR */
  .exercise-list,
  ul.exercise-list {
    max-height: none !important;
    overflow: visible !important;
  }

  /* ✅ GUIDED LIST STILL SCROLLS INTERNALLY (INTENTIONAL) */
  .guided-list-wrapper {
    max-height: 45vh;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ✅ GRID COMPRESSION ONLY (NO CLIPPING) */
  .exercise-item.flight-row {
    grid-template-columns:
      minmax(40px, 32px)
      minmax(40px, 32px)
      minmax(40px, 22px)
      minmax(40px, 22px)
      minmax(40px, 22px)
      minmax(0, 1fr);
    column-gap: 6px;
    padding: 4px 0;
  }

  .exercise-time,
  .exercise-round,
  .exercise-rep,
  .sideL,
  .sideR,
  .exercise-desc {
    font-size: 0.9rem;
    height: 32px;
    padding: 4px 6px;
  }

  .sideL, .sideR {
    font-size: clamp(1.05rem, 2.8vw, 1.45rem) !important;
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .exercise-rep {
    font-size: clamp(1.05rem, 2.8vw, 1.45rem) !important;
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .exercise-desc {
    font-size: clamp(1.05rem, 2.8vw, 1.45rem) !important;
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ✅ CONTROLS NEVER BLOCK SCROLL */
  .controls {
    max-height: none !important;
    overflow: visible !important;
    gap: 6px;
    margin-bottom: 8px;
  }

  #generate-btn,
  #start-guided-btn,
  #pause-btn {
    height: 40px;
    font-size: 0.95rem;
  }

  #minus-btn,
  #plus-btn {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }

  /* ✅ STICKY GUIDED CONTROLS WITHOUT PAGE LOCK */
  .guided-controls {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 10;
  }
}

/* Safe area support */
@supports (padding: env(safe-area-inset-bottom)) {
  main { padding-bottom: env(safe-area-inset-bottom); }
  .guided-controls { padding-bottom: env(safe-area-inset-bottom); }
}
