:root {
  --bg: #090b12;
  --surface: #101421;
  --panel: #171d2b;
  --panel-soft: #20283a;
  --ink: #f8fbff;
  --muted: #a9b7c9;
  --line: rgba(255, 255, 255, 0.13);
  --line-strong: rgba(255, 255, 255, 0.24);
  --green: #21d19f;
  --green-dark: #9fffe0;
  --blue: #4ba3ff;
  --amber: #ffd166;
  --pink: #ff4fd8;
  --purple: #9d6bff;
  --red: #ff6b6b;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.35), 0 0 32px rgba(75, 163, 255, 0.1);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(75, 163, 255, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(33, 209, 159, 0.07) 1px, transparent 1px),
    linear-gradient(135deg, rgba(255, 79, 216, 0.16), transparent 36%),
    linear-gradient(225deg, rgba(33, 209, 159, 0.12), transparent 34%),
    var(--surface);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--green);
  color: #05110e;
  cursor: pointer;
  font-weight: 750;
}

button:hover { filter: brightness(1.04); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(36, 79, 131, 0.24);
  outline-offset: 2px;
}

button.secondary,
.icon-button.secondary {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
}

button.danger,
.icon-button.danger {
  background: var(--panel);
  color: var(--red);
  border-color: rgba(161, 58, 51, 0.35);
}

button.primary { background: var(--green); }

button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

.app-shell {
  width: min(1480px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 0 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 { font-size: clamp(2rem, 4vw, 3.25rem); }
h2 { font-size: 1.3rem; }

.top-actions,
.toolbar-actions,
.row-actions,
.panel-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-heading { justify-content: space-between; }

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  flex: 0 0 auto;
}

.file-label {
  position: relative;
  overflow: hidden;
}

.file-label input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 18px;
  align-items: start;
}

.sidebar {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 18px;
}

.panel,
.workout-page {
  background: rgba(23, 29, 43, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel { padding: 16px; }

.lift-inputs {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.field input,
.field select,
.field textarea,
.table-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 11, 18, 0.66);
  color: var(--ink);
  padding: 9px 10px;
}

.field textarea { resize: vertical; }

.lift-row {
  display: grid;
  grid-template-columns: minmax(95px, 1fr) 92px 84px;
  gap: 8px;
  align-items: end;
}

.lift-row strong {
  font-size: 0.92rem;
  line-height: 1.2;
}

.lift-row small {
  color: var(--muted);
  font-weight: 750;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 14px;
}

.segmented button {
  border-radius: 0;
  border: 0;
  background: var(--panel);
  color: var(--muted);
}

.segmented button.active {
  background: linear-gradient(90deg, var(--blue), var(--purple));
  color: #fff;
}

.full {
  width: 100%;
  margin-top: 14px;
}

.cycle-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.cycle-actions .full {
  margin-top: 0;
}

.progression-preview {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.progression-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: baseline;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--panel-soft);
}

.progression-row strong {
  font-size: 0.9rem;
}

.progression-row span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.cycle-nav {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.week-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  overflow: hidden;
}

.week-block h3 {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--line);
}

.day-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.day-button {
  justify-content: flex-start;
  min-height: 46px;
  padding: 9px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 750;
}

.day-button:nth-child(odd) { border-right: 1px solid var(--line); }
.day-button:nth-child(-n+2) { border-bottom: 1px solid var(--line); }

.day-button.active {
  background: linear-gradient(90deg, var(--green), var(--blue));
  color: #05110e;
}

.day-button.complete::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.75;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(23, 107, 91, 0.1);
  color: var(--green-dark);
  border: 1px solid rgba(33, 209, 159, 0.34);
  font-weight: 800;
  font-size: 0.82rem;
}

.workspace {
  min-width: 0;
  display: grid;
  gap: 14px;
}

.page-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  background: rgba(16, 20, 33, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}

.workout-page { padding: 18px; }

.page-meta {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 180px 120px;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.check-field {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-weight: 800;
  background: var(--panel-soft);
}

.check-field input {
  width: 18px;
  height: 18px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.workout-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: linear-gradient(90deg, #0b0f1a, #151b2b);
  color: #fff;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tbody tr:last-child td { border-bottom: 0; }

.done-col {
  width: 54px;
  text-align: center;
}

.row-kind-main td:first-child { border-left: 4px solid var(--green); }
.row-kind-assistance td:first-child { border-left: 4px solid var(--pink); }
.row-kind-accessory td:first-child { border-left: 4px solid var(--amber); }

.table-input {
  min-height: 36px;
  padding: 7px 8px;
}

.narrow-input { max-width: 80px; }
.exercise-input { min-width: 150px; }
.notes-input { min-width: 180px; }

.row-actions {
  margin: 14px 0 16px;
}

.notes-field textarea {
  min-height: 120px;
  line-height: 1.45;
}

.history-dialog {
  width: min(720px, calc(100% - 32px));
  max-height: min(720px, calc(100vh - 48px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.history-dialog::backdrop {
  background: rgba(3, 5, 10, 0.68);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.history-list {
  display: grid;
  gap: 10px;
  padding: 16px;
  overflow: auto;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-soft);
}

.history-item h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.92rem;
}

.history-item code {
  color: var(--green-dark);
  font-weight: 800;
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .sidebar,
  .page-toolbar,
  .history-dialog,
  .row-actions,
  .done-col button,
  .done-col:last-child {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    margin: 0;
  }

  .layout {
    display: block;
  }

  .workout-page {
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  .table-wrap {
    overflow: visible;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 1480px);
    margin-top: 12px;
  }

  .topbar,
  .page-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-meta,
  .lift-row {
    grid-template-columns: 1fr;
  }
}
