:root {
  --ink: #14202c;
  --ink-soft: #3d4f61;
  --mist: #d7e2ec;
  --horizon: #f0b48a;
  --glow: #ffe8c8;
  --foam: rgba(255, 252, 247, 0.88);
  --line: rgba(20, 32, 44, 0.12);
  --danger: #9b2c2c;
  --ok: #1f6b4a;
  --cat: #8DB4E2;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Outfit", system-ui, sans-serif;

  /* Category palette from running_plan_category_colors.md */
  --cat-light-blue: #bfe3f2;
  --cat-blue: #8db4e2;
  --cat-green: #a9d18e;
  --cat-yellow: #ffe699;
  --cat-orange: #f4b183;
  --cat-red: #f08080;
  --cat-purple: #c9a0dc;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #1a2a3a;
  min-height: 100dvh;
  overflow-x: hidden;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 90% 55% at 50% 100%, var(--horizon) 0%, transparent 55%),
    radial-gradient(ellipse 70% 40% at 70% 70%, var(--glow) 0%, transparent 50%),
    linear-gradient(180deg, #1a2a3a 0%, #3a5368 38%, #7f95a8 68%, #c9d6e0 100%);
  animation: sky-shift 18s ease-in-out infinite alternate;
}

@keyframes sky-shift {
  from {
    filter: saturate(1) brightness(1);
  }
  to {
    filter: saturate(1.08) brightness(1.04);
  }
}

.shell {
  position: relative;
  z-index: 1;
  width: 100%;
  min-width: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem 3rem;
}

.panel {
  width: min(34rem, 100%);
  max-width: 100%;
  min-width: 0;
  padding: 2rem 1.5rem 2.25rem;
  background: var(--foam);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 1.25rem;
  box-shadow: 0 24px 60px rgba(10, 20, 30, 0.28);
}

.gate {
  text-align: center;
  animation: rise 0.7s ease both;
}

.run {
  animation: rise 0.55s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.cat {
  display: inline-block;
  margin: 0;
  padding: 0.28rem 0.65rem;
  border-radius: 0.4rem;
  background: var(--cat);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.3;
  box-shadow: inset 0 0 0 1px rgba(20, 32, 44, 0.08);
}

.cat-phase {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 8vw, 3.4rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0.75rem 0 1.75rem;
  color: var(--ink-soft);
  font-weight: 300;
  font-size: 1.05rem;
}

.pin-form {
  display: grid;
  gap: 0.85rem;
  justify-items: center;
}

#pin {
  width: 9.5rem;
  padding: 0.85rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.7);
  font-family: var(--font-body);
  font-size: 1.65rem;
  font-weight: 500;
  letter-spacing: 0.35em;
  text-align: center;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#pin:focus {
  border-color: rgba(20, 32, 44, 0.35);
  box-shadow: 0 0 0 3px rgba(240, 180, 138, 0.45);
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 999px;
  padding: 0.8rem 1.5rem;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn.primary {
  background: var(--ink);
  color: #f7f3ec;
}

.btn.primary:hover:not(:disabled) {
  background: #243648;
}

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  padding-inline: 0.5rem;
}

.error {
  margin: 1rem 0 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.run-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 1.25rem;
}

.progress-block {
  text-align: right;
}

.progress-line {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.progress-done {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
  opacity: 0.85;
}

.run-id {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.session {
  margin: 0.35rem 0 0.75rem;
  padding-left: 0.75rem;
  border-left: 4px solid var(--cat, var(--cat-blue));
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 6vw, 2.45rem);
  font-weight: 700;
  line-height: 1.15;
}

.workout {
  margin: 0 0 1.5rem;
  font-size: 1.15rem;
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink);
}

.meta {
  display: grid;
  gap: 1rem;
  margin: 0 0 1.35rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.meta div {
  display: grid;
  gap: 0.2rem;
}

.meta dt {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.meta dd {
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
}

.notes {
  margin: 0 0 1.75rem;
  color: var(--ink-soft);
  font-size: 0.98rem;
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
}

.actions-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.btn.link {
  background: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  padding: 0.4rem 0;
  margin-left: auto;
}

.btn.link:hover {
  color: var(--ink);
}

.plan-view {
  width: 100%;
  max-width: min(64rem, 100%);
  min-width: 0;
  padding: 1.25rem 0.85rem 1.35rem;
  animation: rise 0.45s ease both;
  overflow: hidden;
}

.plan-view-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.plan-view-header .btn.link {
  margin-left: 0;
}

.plan-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
}

.plan-view .progress-block {
  text-align: left;
}

.table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  max-height: min(52dvh, 28rem);
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.35);
}

.plan-table {
  width: 42rem;
  min-width: 42rem;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.plan-table th,
.plan-table td {
  padding: 0.65rem 0.7rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.plan-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(255, 252, 247, 0.98);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}

.plan-table td.run-num {
  white-space: nowrap;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.plan-table td.phase-cell,
.plan-table td.session-cell,
.plan-table td.effect-cell {
  white-space: nowrap;
}

.plan-table td.workout-cell {
  min-width: 14rem;
  max-width: 18rem;
  white-space: normal;
}

.plan-table tr.done td {
  text-decoration: line-through;
  color: var(--ink-soft);
  opacity: 0.72;
}

.plan-table tr.current td {
  background: rgba(141, 180, 226, 0.22);
}

.plan-table .dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.4rem;
  border-radius: 0.15rem;
  vertical-align: middle;
  background: var(--cat, var(--cat-blue));
}

.pager {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.pager-status {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
  min-width: 0;
}

.pager .btn.ghost {
  text-decoration: none;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
}

.pager .btn.ghost:disabled {
  opacity: 0.35;
  text-decoration: none;
}

.all-done {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.8rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.run.flash {
  animation: flash-done 0.55s ease;
}

@keyframes flash-done {
  0% {
    box-shadow: 0 0 0 0 rgba(31, 107, 74, 0.35);
  }
  40% {
    box-shadow: 0 0 0 10px rgba(31, 107, 74, 0);
  }
  100% {
    box-shadow: 0 24px 60px rgba(10, 20, 30, 0.28);
  }
}

@media (min-width: 640px) {
  .panel {
    padding: 2.5rem 2.25rem 2.75rem;
  }

  .plan-view {
    padding: 2.5rem 2.25rem 2.75rem;
  }

  .table-wrap {
    max-height: min(60dvh, 36rem);
  }

  .plan-table {
    width: 100%;
    min-width: 48rem;
  }

  .meta {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 639px) {
  .shell {
    padding: 1rem 0.6rem 1.5rem;
    place-items: center stretch;
  }

  .plan-view {
    width: 100%;
    border-radius: 1rem;
  }

  .table-wrap {
    max-height: min(50dvh, 24rem);
  }

  .pager .btn.ghost {
    padding: 0.5rem 0.55rem;
  }
}
