:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #5f6877;
  --line: #dfe5ed;
  --paper: #fbfcfe;
  --panel: #ffffff;
  --blue: #0f5ca8;
  --green: #25743a;
  --violet: #694091;
  --orange: #d96913;
  --red: #c9303a;
  --dark: #101820;
  --accent: #f3c623;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #eef3f8 0%, #ffffff 46%, #f4f7fb 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -18px -18px 18px;
  padding: 18px;
  color: #fff;
  background: var(--dark);
  box-shadow: 0 12px 32px rgba(16, 24, 32, 0.2);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 6vw, 3.4rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

.icon-button,
.back-button,
.timer-actions button,
.history-panel button,
.summary-actions button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  font-size: 1.25rem;
}

.routine-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
}

.routine-card {
  min-height: 178px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--routine-color), #fff 50%);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  text-align: left;
}

.routine-card strong {
  display: block;
  margin-bottom: 8px;
  color: var(--routine-color);
  font-size: 1.06rem;
}

.routine-card span {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.routine-card small {
  display: inline-flex;
  margin-top: 14px;
  padding: 5px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--routine-color), #fff 88%);
  color: var(--routine-color);
  font-weight: 800;
}

.workout-panel,
.summary-panel {
  display: grid;
  gap: 14px;
}

.session-heading,
.progress-block,
.exercise-card,
.entry-form,
.timer-panel,
.history-panel,
.summary-panel,
.login-panel,
.user-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.login-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 18px;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 14px;
}

.user-bar span {
  font-weight: 900;
}

.user-bar button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.status-text {
  min-height: 1.4em;
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

.status-card {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 900;
}

.status-card.success {
  border: 1px solid #b7dfc0;
  background: #ecf8ef;
  color: #1f6f37;
}

.status-card.error {
  border: 1px solid #f0b5b8;
  background: #fff0f1;
  color: #a1202a;
}

.session-heading {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
}

.back-button {
  min-width: 82px;
  min-height: 42px;
}

.progress-block {
  padding: 14px;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
}

.progress-copy strong {
  color: var(--ink);
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf3;
}

.progress-track div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--active-color, var(--blue));
  transition: width 250ms ease;
}

.exercise-card {
  display: grid;
  grid-template-columns: 1fr minmax(190px, 0.38fr);
  gap: 14px;
  padding: 18px;
}

.set-pill {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--active-color), #fff 84%);
  color: var(--active-color);
  font-weight: 900;
}

.exercise-main h3 {
  margin-bottom: 8px;
  font-size: clamp(1.45rem, 5vw, 2.55rem);
  line-height: 1.02;
}

#targetHint {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
}

#targetHint strong {
  color: var(--ink);
  font-size: 1.2em;
}

.previous-box {
  display: flex;
  min-height: 130px;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border-radius: 8px;
  background: #f5f7fa;
}

.previous-box span {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
}

.previous-box strong {
  font-size: 1.2rem;
  line-height: 1.2;
}

.entry-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}

label small {
  color: #7b8490;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
}

.unit-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  background: #fff;
}

.unit-input input {
  border: 0;
}

.unit-input span {
  padding-right: 12px;
  color: var(--muted);
  font-weight: 900;
}

.primary-button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--active-color, var(--blue));
  color: #fff;
  font-weight: 900;
}

.timer-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  background: var(--dark);
  color: #fff;
}

.timer-panel strong {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: clamp(3rem, 18vw, 7rem);
  line-height: 0.9;
}

.timer-actions {
  display: grid;
  gap: 10px;
}

.timer-actions button {
  min-width: 92px;
  min-height: 44px;
}

.history-panel {
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-title h3 {
  margin-bottom: 0;
}

.history-panel button {
  min-height: 38px;
  padding: 0 12px;
}

#todayLog {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

#todayLog li {
  padding: 8px 0;
  border-bottom: 1px solid #edf1f5;
}

.summary-panel {
  padding: 22px;
}

.summary-panel p {
  color: var(--muted);
}

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.summary-actions button {
  min-height: 44px;
  padding: 0 14px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.admin-user {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
}

.admin-user span,
.admin-user small {
  color: var(--muted);
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  padding: 10px;
  border-bottom: 1px solid #edf1f5;
  text-align: left;
}

.admin-table th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.maintenance-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.maintenance-form {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.maintenance-form button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
}

.danger-zone {
  border-color: #f0b5b8;
  background: #fff7f7;
}

.danger-zone button {
  border-color: #c9303a;
  color: #a1202a;
}

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .routine-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .exercise-card,
  .entry-form,
  .login-form,
  .maintenance-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    margin: -12px -12px 12px;
    padding: 14px 12px;
  }

  .routine-picker {
    grid-template-columns: 1fr;
  }

  .session-heading {
    align-items: flex-start;
  }

  .timer-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .timer-actions {
    grid-template-columns: 1fr 1fr;
  }
}
