:root {
  --bg: #0e1518;
  --panel: #162126;
  --panel-soft: #1b2a30;
  --ink: #e8f0ec;
  --muted: #95a9a3;
  --accent: #58e3a7;
  --danger: #ff7f6a;
  --line: #2f464e;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 10%, #1e3535 0%, #0d1517 40%, #090e10 100%);
  min-height: 100vh;
}

.bg-noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.03) 0.7px, transparent 0.7px);
  background-size: 4px 4px;
  opacity: 0.35;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: rgba(10, 16, 18, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 1.2rem;
  letter-spacing: 0.04em;
}

.shell {
  width: min(1300px, 96vw);
  margin: 1rem auto 2rem;
}

.card {
  background: linear-gradient(160deg, rgba(31, 47, 54, 0.9), rgba(18, 28, 33, 0.94));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  animation: fade-in 250ms ease-out;
}

.auth-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 0.8rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #0f1a1f;
  color: var(--ink);
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
}

button {
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #07291b;
  font-weight: 700;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  margin-top: 0.8rem;
  min-height: 44px;
}

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

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  margin: 0;
}

.hidden {
  display: none !important;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.tab {
  background: #0f1a1f;
  color: var(--ink);
  border: 1px solid var(--line);
}

.tab.active {
  background: var(--accent);
  color: #062415;
  border-color: transparent;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.program-name {
  width: min(420px, 100%);
  margin-top: 0;
}

.define-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: end;
  justify-content: flex-end;
  width: min(100%, 880px);
}

#load-define-program-btn {
  margin-top: 0;
}

.muted {
  color: var(--muted);
}

.exercise-grid {
  overflow: auto;
  margin-top: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  max-height: 62vh;
}

.selection-workout-builder {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: end;
  margin-top: 0.6rem;
}

#add-selection-workout-btn,
#remove-selection-workout-btn {
  margin-top: 0;
}

.exercise-grid table {
  border-collapse: collapse;
  width: 100%;
  min-width: 560px;
}

.exercise-grid th,
.exercise-grid td {
  border-bottom: 1px solid var(--line);
  padding: 0.45rem;
  text-align: center;
}

.exercise-grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #0f1a1f;
}

.exercise-grid tbody th {
  text-align: left;
  position: sticky;
  left: 0;
  background: #121f24;
  z-index: 1;
}

.category-row th {
  background: #21343c !important;
  color: #c8d9d5;
  letter-spacing: 0.04em;
}

.checkbox-cell input {
  width: 22px;
  height: 22px;
}

.one-rm {
  max-width: 85px;
}

.definition-day,
.daily-category,
.history-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 0.8rem;
  padding: 0.8rem;
}

.definition-day-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.daily-workout-title {
  margin-top: 0.3rem;
  margin-bottom: 0.6rem;
}

.definition-grid,
.daily-grid {
  display: grid;
  gap: 0.5rem;
  align-items: center;
}

.definition-grid {
  grid-template-columns: 2fr repeat(4, 1fr);
}

.definition-grid-head {
  font-size: 0.84rem;
}

.definition-grid-row {
  margin-top: 0.45rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(12, 21, 24, 0.4);
}

.def-cell {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.def-exercise .def-value {
  font-weight: 600;
}

.def-mobile-label {
  display: none;
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.daily-grid {
  grid-template-columns: 2fr repeat(5, 1fr);
}

.cardio-target {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.input-stack {
  display: grid;
  gap: 0.2rem;
}

.field-hint {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.2;
}

.daily-head {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.8rem;
}

.actions {
  margin-top: 0.9rem;
  display: flex;
  justify-content: flex-end;
}

.history-summary-controls {
  margin-top: 0.8rem;
}

.history-summary-controls label {
  max-width: 360px;
}

.summary-table-wrap {
  margin-top: 0.7rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

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

.summary-table th {
  background: #0f1a1f;
  position: sticky;
  top: 0;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: 360px;
  background: #102026;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.8rem;
  box-shadow: var(--shadow);
}

.toast.error {
  border-color: var(--danger);
}

.auth-strip {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 0.6rem;
  }

  .shell {
    width: 97vw;
  }

  .definition-grid,
  .daily-grid {
    grid-template-columns: 1fr;
  }

  .selection-workout-builder {
    width: 100%;
  }

  .selection-workout-builder .program-name {
    width: 100%;
  }

  #add-selection-workout-btn,
  #remove-selection-workout-btn {
    width: 100%;
  }

  .definition-grid-head {
    display: none;
  }

  .definition-grid-row {
    margin-top: 0.65rem;
    padding: 0.7rem;
  }

  .def-mobile-label {
    display: block;
  }

  .cardio-target {
    grid-template-columns: 1fr;
  }

  .define-toolbar {
    width: 100%;
  }

  .define-toolbar .program-name {
    width: 100%;
  }

  #load-define-program-btn {
    width: 100%;
  }
}
