:root {
  --primary: #000000;
  --bg: #ffffff;
  --surface: #f4f4f4;
  --text: #000000;
  --muted: #2f2f2f;
  --accent: #ff0088;
  --cta: #fa8334;
  --line: #000000;
  --danger: #b92828;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, rgba(250, 131, 52, 0.13) 0%, transparent 38%),
    radial-gradient(circle at 88% 22%, rgba(255, 0, 136, 0.1) 0%, transparent 42%),
    var(--bg);
}

.app {
  width: min(1120px, 92%);
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  font-family: "Space Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #fff;
}

.header h1 {
  margin: 0;
  font-family: "Cinzel Decorative", serif;
  font-size: clamp(2.1rem, 6vw, 4.7rem);
}

.header p {
  margin: 0.4rem 0 0;
  font-size: 1.14rem;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 1rem;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.card-top h2 {
  margin: 0;
  font-family: "Newsreader", serif;
  font-size: clamp(2rem, 4.2vw, 3.4rem);
}

#session-form {
  display: flex;
  flex-direction: column;
}

.session-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.meta-field {
  display: grid;
  gap: 0.35rem;
  max-width: 320px;
}

.meta-label,
.session-meta label {
  font-family: "Space Mono", monospace;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.unit-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  width: fit-content;
  flex-shrink: 0;
}

.unit-btn {
  background: #fff;
  border: 0;
  border-right: 1px solid var(--line);
  min-width: 56px;
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
}

.unit-btn:last-child {
  border-right: 0;
}

.unit-btn.is-active {
  background: var(--cta);
}

.rows-header {
  margin-bottom: 0.5rem;
}

.rows-header h3 {
  margin: 0;
  font-family: "Newsreader", serif;
  font-size: 1.5rem;
}

.exercise-blocks-container {
  display: grid;
  gap: 0.8rem;
}

.exercise-block {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.75rem;
}

.exercise-top {
  display: grid;
  grid-template-columns: 2fr auto;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.6rem;
}

.exercise-top-actions {
  display: inline-flex;
  gap: 0.45rem;
}

.sets-container {
  display: grid;
  gap: 0.5rem;
}

.set-row {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr auto;
  gap: 0.55rem;
  align-items: center;
}

.set-field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

input,
button {
  border-radius: 0;
  border: 1px solid var(--line);
  padding: 0.55rem 0.65rem;
  background: #fff;
}

input {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.04rem;
}

button {
  font-family: "Space Mono", monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #b8beaf;
}

.stepper {
  display: grid;
  grid-template-columns: 30px 1fr 30px;
  align-items: center;
  border: 1px solid var(--line);
  background: #fff;
}

.stepper input {
  border: 0;
  text-align: center;
  width: 100%;
}

.stepper .step-btn {
  border: 0;
  border-right: 1px solid var(--line);
  height: 100%;
  min-height: 40px;
  padding: 0;
  background: #fff;
  font-size: 0.92rem;
  letter-spacing: 0;
}

.stepper .step-btn:last-child {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.set-field .unit-btn {
  min-width: 42px;
  padding: 0.47rem 0.45rem;
  font-size: 0.56rem;
}

#save-session-btn,
#add-row-btn,
#reload-history-btn,
.add-set-btn {
  background: var(--cta);
  color: #111;
  border-color: var(--line);
}

.remove-set-btn,
.remove-exercise-btn,
.delete-session-btn {
  background: #fff;
  color: var(--danger);
  border-color: var(--line);
}

.remove-set-btn.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

.add-row-lane {
  margin: 0.8rem 0 0.9rem;
}

#add-row-btn {
  justify-self: start;
}

.actions {
  margin-top: 0.6rem;
  margin-bottom: 0;
}

#save-session-btn {
  width: 100%;
  padding: 0.82rem 0.65rem;
}

.status-message {
  min-height: 1.4rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
}

.status-message.error {
  color: var(--danger);
}

.status-message.ok {
  color: #0f7a2a;
}

.progress-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}

.progress-card {
  border: 1px solid var(--line);
  background: #fff;
  padding: 0.55rem 0.6rem;
}

.progress-card h4 {
  margin: 0 0 0.18rem;
  font-family: "Space Mono", monospace;
  font-size: 0.58rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.progress-card .value {
  margin: 0;
  font-family: "Newsreader", serif;
  font-size: 1.45rem;
  line-height: 1.1;
}

.progress-card .hint {
  margin: 0.18rem 0 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.progress-card.is-empty {
  grid-column: 1 / -1;
}

.history-container {
  display: grid;
  gap: 0.8rem;
}

.session-item {
  border: 1px solid var(--line);
  overflow: hidden;
}

.session-head {
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0.9rem;
}

.session-body {
  padding: 0.6rem 0.8rem 0.8rem;
}

.history-exercise {
  margin-bottom: 0.8rem;
}

.history-exercise h4 {
  margin: 0 0 0.35rem;
  font-family: "Newsreader", serif;
  font-size: 1.25rem;
}

.entry-table {
  width: 100%;
  border-collapse: collapse;
}

.entry-table th,
.entry-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.35rem;
  text-align: left;
}

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  z-index: 20;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(460px, 92%);
  background: #fff;
  border: 1px solid var(--line);
  padding: 1rem;
}

.modal-card h2 {
  margin: 0 0 0.4rem;
  font-family: "Newsreader", serif;
}

.modal-card p {
  margin: 0.2rem 0 0.8rem;
}

.modal-card label {
  display: block;
  margin-bottom: 0.35rem;
}

#api-key-modal-input {
  width: 100%;
  margin-bottom: 0.75rem;
}

#api-key-modal-save-btn {
  width: 100%;
}

.modal-status {
  min-height: 1.2rem;
  margin-top: 0.6rem;
  color: var(--muted);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  .session-meta {
    grid-template-columns: 1fr;
  }

  .meta-field {
    max-width: 100%;
  }
}

@media (max-width: 780px) {
  .header-brand {
    gap: 0.45rem;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
  }

  .card-top {
    flex-direction: column;
  }

  .column-heads {
    display: none;
  }

  .exercise-top {
    grid-template-columns: 1fr;
  }

  .exercise-top-actions {
    justify-content: stretch;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .set-row {
    grid-template-columns: 1fr;
  }

  .set-field {
    width: 100%;
  }

  .set-field .stepper {
    flex: 1;
  }

  .add-row-lane,
  #add-row-btn {
    width: 100%;
  }

  #add-row-btn {
    justify-self: stretch;
  }

  .entry-table {
    font-size: 0.92rem;
  }
}
