/* =========================================================
   Treadmill Program Atlas — styles
   Friendly, rounded, warm, paper-like. Print-ready A4.
   ========================================================= */

:root {
  --paper: #FBF6EE;
  --paper-2: #F4EDE0;
  --paper-3: #EADFCB;
  --ink: #23201C;
  --ink-2: #4A443C;
  --ink-3: #766F63;
  --ink-muted: #A8A095;
  --line: #E3D8C3;
  --line-soft: #EEE4D0;

  --tier-easy: #4FA3B8;
  --tier-easy-soft: #DCEEF2;
  --tier-moderate: #8AB25A;
  --tier-moderate-soft: #E6EFD6;
  --tier-challenging: #E39A3C;
  --tier-challenging-soft: #F7E5C4;
  --tier-intense: #D35B3A;
  --tier-intense-soft: #F4D4C6;

  --speed: #D35B3A;
  --speed-dark: #A03E22;
  --incline: #4F7A4A;
  --incline-dark: #2F5430;

  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 0 rgba(35, 32, 28, 0.04), 0 8px 24px -14px rgba(35, 32, 28, 0.18);
  --shadow-pop: 0 2px 0 rgba(35, 32, 28, 0.04), 0 18px 40px -18px rgba(35, 32, 28, 0.28);

  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", "DM Sans", system-ui, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.45;
}
body.modal-open { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }
select { font: inherit; color: inherit; }

.app-status {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  color: var(--ink-2);
  font-family: var(--display);
  font-size: clamp(20px, 2.6vw, 30px);
}

.app-status.error {
  flex-direction: column;
  gap: 10px;
  max-width: 720px;
  margin: 0 auto;
  color: var(--speed-dark);
}

.app-status.error strong {
  font-size: clamp(22px, 3vw, 32px);
}

.app-status.error span {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
}

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 40px 32px 120px;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}
.masthead h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(28px, 3.5vw, 46px);
  line-height: 1;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.masthead .subtitle {
  color: var(--ink-3);
  font-size: 15px;
  max-width: 56ch;
}
.masthead .credit {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: right;
  line-height: 1.6;
}

.controls {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 18px 22px;
  margin-bottom: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 17px 21px;
  align-items: start;
}
.ctrl-label {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-2);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s ease;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}
.chip:hover { border-color: var(--ink-3); }
.chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chip .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex: 0 0 auto;
}

.duration {
  display: flex;
  align-items: center;
  gap: 12px;
}
.duration input[type="range"] {
  flex: 1;
  accent-color: var(--speed);
}
.duration-value {
  font-family: var(--display);
  font-weight: 500;
  font-size: 22px;
  min-width: 80px;
}
.duration-value .unit {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  margin-left: 3px;
}

.viz-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  background: var(--paper);
  gap: 0;
}
.viz-toggle button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
.viz-toggle button.active {
  background: var(--ink);
  color: var(--paper);
}

.ctrl-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}
.action-btn {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-weight: 500;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.action-btn.ghost { background: transparent; color: var(--ink); }
.action-btn:hover { transform: translateY(-1px); }

.results-line {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.tier-section { margin-bottom: 44px; page-break-after: always; break-after: page; }
.tier-section:last-child { page-break-after: auto; break-after: auto; }

.tier-head {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 18px;
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  color: var(--ink);
}
.tier-head-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.tier-head .badge {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink-2);
  white-space: nowrap;
}
.tier-head h2 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1;
}
.tier-head .count {
  font-family: var(--display);
  font-size: 30px;
  font-weight: 500;
  line-height: 1;
  opacity: 0.5;
}

.tier-Easy .tier-head { background: var(--tier-easy-soft); }
.tier-Easy .tier-head .badge { color: #2C6876; }
.tier-Moderate .tier-head { background: var(--tier-moderate-soft); }
.tier-Moderate .tier-head .badge { color: #4B6B2E; }
.tier-Challenging .tier-head { background: var(--tier-challenging-soft); }
.tier-Challenging .tier-head .badge { color: #8A5818; }
.tier-Intense .tier-head { background: var(--tier-intense-soft); }
.tier-Intense .tier-head .badge { color: #8B3418; }

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

.prog {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.prog::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--tier-color, var(--ink));
  border-radius: 5px 0 0 5px;
}
.tier-Easy .prog { --tier-color: var(--tier-easy); }
.tier-Moderate .prog { --tier-color: var(--tier-moderate); }
.tier-Challenging .prog { --tier-color: var(--tier-challenging); }
.tier-Intense .prog { --tier-color: var(--tier-intense); }

.prog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.prog-id {
  font-family: var(--display);
  font-weight: 500;
  font-size: 24px;
  line-height: 1;
  letter-spacing: -0.01em;
}
.prog-id .p { color: var(--ink-3); font-weight: 400; }
.prog-type {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--paper-2);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  background: var(--paper-2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.metric { text-align: center; }
.metric .label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: block;
  margin-bottom: 2px;
}
.metric .value {
  font-family: var(--display);
  font-weight: 500;
  font-size: 20px;
  line-height: 1;
}
.metric .value .unit {
  font-family: var(--sans);
  font-size: 10px;
  color: var(--ink-3);
  font-weight: 500;
  margin-left: 1px;
}
.metric.speed .value { color: var(--speed-dark); }
.metric.incline .value { color: var(--incline-dark); }

.duration-note {
  font-size: 11px;
  color: var(--ink-3);
  font-family: var(--mono);
  letter-spacing: 0.08em;
  margin-top: 4px;
}

.prog-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--ink-3);
}
.effort-value {
  margin-left: 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
}
.effort-bar {
  flex: 1;
  height: 6px;
  background: var(--line-soft);
  border-radius: var(--radius-pill);
  margin-left: 10px;
  position: relative;
  overflow: hidden;
}
.effort-bar .fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, var(--tier-easy), var(--tier-moderate) 33%, var(--tier-challenging) 66%, var(--tier-intense));
  width: 100%;
}
.effort-bar .mask {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  background: var(--line-soft);
}

.viz {
  position: relative;
  height: 140px;
  background: var(--paper-2);
  border-radius: var(--radius-md);
  padding: 10px 10px 22px;
  overflow: hidden;
}
.viz svg { width: 100%; height: 100%; display: block; }
.stage-axis {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 4px;
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
}

.legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 2px 0 0;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(35, 32, 28, 0.42);
  backdrop-filter: blur(3px);
}
.manual-modal {
  position: relative;
  width: min(1080px, 100%);
  height: min(88vh, 860px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.manual-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}
.manual-head h2 {
  margin: 0 0 4px;
  font-family: var(--display);
  font-size: 24px;
  line-height: 1;
}
.manual-head p {
  margin: 0;
  color: var(--ink-3);
  font-size: 14px;
  max-width: 54ch;
}
.manual-frame-wrap {
  flex: 1;
  background: #d7d1c7;
}
.manual-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--ink-3);
  font-family: var(--display);
  font-size: 22px;
}

.print-footer { display: none; }

@media (max-width: 1080px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  .controls { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .page { padding: 26px 18px 80px; }
  .masthead {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }
  .masthead .credit { text-align: left; }
  .controls { grid-template-columns: 1fr; }
  .ctrl-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .card-grid { grid-template-columns: 1fr; }
  .legend {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .modal-shell { padding: 12px; }
  .manual-modal { height: min(92vh, 920px); }
  .manual-head {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .page { padding: 24px 16px 80px; }
  .masthead { gap: 8px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: white; font-size: 10.5pt; }
  .page { max-width: none; padding: 0; }
  .modal-shell,
  .controls,
  .masthead .credit,
  .ctrl-actions {
    display: none !important;
  }
  .masthead {
    border-bottom: 1.5px solid var(--ink);
    padding-bottom: 8mm;
    margin-bottom: 6mm;
  }
  .masthead h1 { font-size: 26pt; }
  .tier-section { page-break-after: always; break-after: page; margin-bottom: 0; }
  .tier-section:last-child { page-break-after: auto; }
  .tier-head { padding: 8px 12px; margin-bottom: 8px; }
  .tier-head h2 { font-size: 14pt; }
  .tier-head .count { font-size: 20pt; }
  .card-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .prog {
    padding: 10px 10px 8px;
    gap: 8px;
    box-shadow: none;
    border-color: var(--line);
    break-inside: avoid;
  }
  .prog-id { font-size: 17pt; }
  .prog-type { font-size: 8pt; padding: 2px 7px; }
  .metrics { padding: 6px 8px; gap: 4px; }
  .metric .value { font-size: 13pt; }
  .metric .label { font-size: 6.5pt; }
  .viz { height: 88px; padding: 6px 8px 16px; }
  .stage-axis { font-size: 6.5pt; }
  .prog-meta { font-size: 8pt; }
  .print-footer {
    display: block;
    position: running(footer);
    font-family: var(--mono);
    font-size: 8pt;
    color: var(--ink-3);
    text-align: center;
    margin-top: 6mm;
    padding-top: 2mm;
    border-top: 0.5px solid var(--line);
  }
}
