:root {
  --accent: #ef4444;
  --accent-strong: #dc2626;
  --accent-soft: rgba(239, 68, 68, 0.1);
  --accent-border: rgba(239, 68, 68, 0.42);
  --bg: #f4f4f4;
  --panel: #ffffff;
  --panel-soft: #f8f8f8;
  --field: #ffffff;
  --text: #111111;
  --muted: #6f6f6f;
  --dim: #929292;
  --border: #dddddd;
  --shadow: 0 10px 28px rgba(17, 17, 17, 0.08);
  --radius: 8px;
  color-scheme: light dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

@supports (overflow: clip) {
  html,
  body {
    overflow-x: clip;
  }
}

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 0.84rem;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  max-width: 100%;
  font: inherit;
}

button,
select,
input[type="date"],
input[type="checkbox"] {
  cursor: pointer;
}

button {
  border: 0;
}

[hidden] {
  display: none !important;
}

.shell {
  width: min(100%, 28rem);
  max-width: 100%;
  margin: 0 auto;
  padding:
    max(0.65rem, env(safe-area-inset-top))
    max(0.65rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom))
    max(0.65rem, env(safe-area-inset-left));
  overflow: visible;
}

.topbar {
  margin: 0.65rem 0;
  padding: 0 0.1rem;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 0.92rem;
  line-height: 1.15;
}

h2 {
  font-size: 0.94rem;
  line-height: 1.2;
}

h3 {
  font-size: 0.84rem;
  line-height: 1.2;
}

.entry-toggle svg,
.date-control svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.compact-field,
.profile-field {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.compact-field > span,
.profile-field > span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.entry-panel,
.history {
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.entry-panel {
  padding: 0.7rem;
}

.panel-title-row,
.history-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.date-control {
  position: relative;
  width: 2.75rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
}

.date-control svg {
  width: 1.15rem;
  height: 1.15rem;
}

.date-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  opacity: 0;
}

form {
  min-width: 0;
  display: grid;
  gap: 0.6rem;
  margin-top: 0.58rem;
}

.exercise-presets {
  min-width: 0;
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.exercise-preset {
  min-width: 0;
  min-height: 2.55rem;
  padding: 0 0.3rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--field);
  color: var(--text);
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exercise-preset.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.numbers-row {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0 0.72rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--field);
  color: var(--text);
  outline: 0;
  font-size: 1rem;
  font-weight: 750;
}

select {
  appearance: none;
  padding-right: 2rem;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position:
    calc(100% - 1rem) 50%,
    calc(100% - 0.72rem) 50%;
  background-repeat: no-repeat;
  background-size: 0.32rem 0.32rem;
}

input::placeholder {
  color: var(--dim);
  opacity: 1;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.detail-toggle {
  min-width: 0;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.3rem 0.42rem 0.3rem 0.72rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 800;
}

.detail-toggle input {
  position: relative;
  width: 2.55rem;
  min-width: 2.55rem;
  min-height: 1.45rem;
  height: 1.45rem;
  appearance: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}

.detail-toggle input::before {
  content: "";
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 1.02rem;
  height: 1.02rem;
  border-radius: 50%;
  background: var(--dim);
  transition: transform 160ms ease, background 160ms ease;
}

.detail-toggle input:checked {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.detail-toggle input:checked::before {
  transform: translateX(1.08rem);
  background: var(--accent);
}

.manual-set-editor {
  min-width: 0;
  display: grid;
  gap: 0.45rem;
}

.manual-set-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.74rem;
}

.manual-set-head > strong {
  color: var(--text);
}

.manual-set-list {
  min-width: 0;
  display: grid;
  gap: 0.38rem;
}

.manual-set-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 3.4rem minmax(0, 1fr) 5.4rem;
  gap: 0.38rem;
  align-items: end;
  padding: 0.48rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.manual-set-number {
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 850;
}

.manual-set-field {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.manual-set-field > span {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
}

.manual-set-field select,
.manual-set-field input {
  min-height: 2.5rem;
}

.routine-editor {
  min-width: 0;
  display: grid;
  gap: 0.55rem;
}

.routine-editor-head {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
  align-items: end;
}

.routine-name-field,
.routine-number-field,
.routine-rounds-field {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.routine-name-field > span,
.routine-number-field > span,
.routine-rounds-field > span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
}

.routine-rounds-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: 0.45rem;
  align-items: end;
}

.routine-rounds-field select,
.routine-total {
  min-height: 2.5rem;
}

.routine-total {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 0.72rem;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 850;
  white-space: nowrap;
}

.routine-template-button {
  min-width: 6.4rem;
  padding: 0 0.65rem;
}

.routine-steps-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.routine-steps-head > strong {
  font-size: 0.74rem;
}

.add-routine-step {
  min-height: 2.35rem;
  padding: 0 0.72rem;
}

.routine-step-list {
  min-width: 0;
  display: grid;
  gap: 0.38rem;
}

.routine-step {
  min-width: 0;
  display: grid;
  gap: 0.45rem;
  padding: 0.48rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.routine-step-top {
  min-width: 0;
  display: grid;
  grid-template-columns: 1.35rem minmax(0, 1fr) auto;
  gap: 0.35rem;
  align-items: center;
}

.routine-step-number {
  color: var(--accent-strong);
  font-size: 0.72rem;
  text-align: center;
}

.routine-step-label {
  min-height: 2.5rem;
  padding: 0 0.55rem;
}

.routine-step-actions {
  display: flex;
  gap: 0.18rem;
}

.routine-step-actions button {
  width: 2.05rem;
  min-width: 2.05rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--field);
  color: var(--muted);
}

.routine-step-actions button:disabled {
  opacity: 0.3;
}

.routine-step-actions svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.routine-step-delete {
  color: var(--accent-strong) !important;
}

.routine-step-settings {
  min-width: 0;
  display: grid;
  grid-template-columns: 4rem minmax(4.6rem, 1fr) 4rem 2rem;
  gap: 0.35rem;
  align-items: end;
}

.routine-number-field input {
  min-height: 2.5rem;
  padding: 0 0.4rem;
  text-align: center;
}

.routine-unit {
  min-width: 0;
  min-height: 2.5rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0.18rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--field);
}

.routine-unit button {
  min-width: 0;
  min-height: 2.1rem;
  padding: 0 0.2rem;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 850;
}

.routine-unit button.is-active {
  background: var(--accent);
  color: #ffffff;
}

.routine-rest-unit {
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.66rem;
}

.suffix-input {
  position: relative;
  display: block;
}

.suffix-input input {
  padding-right: 3.25rem;
}

.suffix-input strong {
  position: absolute;
  top: 50%;
  right: 0.8rem;
  transform: translateY(-50%);
  color: var(--accent-strong);
  font-size: 0.72rem;
  pointer-events: none;
}

.setup-actions {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.primary-button,
.secondary-button,
.history-limit-button,
.entry-actions button {
  min-height: 2.75rem;
  border-radius: var(--radius);
  font-size: 0.74rem;
  font-weight: 850;
}

.primary-button {
  flex: 1 1 10rem;
  background: var(--accent);
  color: #ffffff;
}

.primary-button:disabled {
  cursor: default;
  opacity: 0.58;
}

.secondary-button,
.history-limit-button,
.entry-actions button {
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
}

.setup-actions .secondary-button {
  flex: 1 1 7rem;
}

.history {
  margin-top: 0.65rem;
  padding: 0.7rem;
}

.history-limit-button {
  min-height: 2.35rem;
  padding: 0 0.65rem;
  border-radius: 999px;
  font-size: 0.66rem;
}

.empty {
  margin-top: 0.7rem;
  color: var(--muted);
  font-size: 0.74rem;
}

.log-list {
  min-width: 0;
  display: grid;
  gap: 0.42rem;
  margin-top: 0.58rem;
}

.entry-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--field);
}

.entry-card.is-open {
  border-radius: var(--radius);
}

.entry-toggle {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  display: grid;
  grid-template-columns: 5.1rem minmax(0, 1fr) auto 1rem;
  gap: 0.3rem;
  align-items: center;
  padding: 0 0.48rem 0 0.62rem;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.entry-date {
  color: var(--accent-strong);
  font-size: 0.66rem;
  font-weight: 850;
  white-space: nowrap;
}

.exercise {
  min-width: 0;
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-quick-meta {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 800;
  white-space: nowrap;
}

.entry-toggle svg {
  width: 0.9rem;
  height: 0.9rem;
  transition: transform 160ms ease;
}

.entry-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.entry-details {
  min-width: 0;
  display: grid;
  gap: 0.55rem;
  margin: 0 0.42rem 0.42rem;
  padding: 0.58rem;
  border-top: 1px solid var(--border);
}

.entry-summary {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.4;
}

.history-set-list {
  min-width: 0;
  display: grid;
  gap: 0.25rem;
}

.history-set-row,
.history-pair-row,
.history-aggregate-row {
  min-width: 0;
  min-height: 2.15rem;
  display: grid;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.48rem;
  border-radius: 6px;
  background: var(--panel-soft);
  font-size: 0.7rem;
}

.history-set-row {
  grid-template-columns: 1.25rem minmax(0, 1fr) auto;
}

.history-round-row {
  margin-top: 0.2rem;
  padding: 0 0.48rem;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-round-row:first-child {
  margin-top: 0;
}

.history-set-row > span:first-child {
  color: var(--accent-strong);
  font-weight: 850;
}

.history-set-row > span:last-child {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.history-set-row.is-sequence > span:last-child {
  max-width: 8.8rem;
  font-size: 0.62rem;
  line-height: 1.25;
  text-align: right;
  white-space: normal;
}

.history-pair-row {
  grid-template-columns: minmax(4.4rem, 0.8fr) 1fr 1fr;
}

.history-pair-row span {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.history-aggregate-row {
  display: flex;
  color: var(--text);
  font-weight: 800;
}

.entry-actions {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

.entry-actions button {
  min-height: 2.45rem;
  padding: 0 0.3rem;
  font-size: 0.66rem;
}

.entry-actions .delete-entry {
  border-color: var(--accent-border);
  color: var(--accent-strong);
}

.status {
  position: fixed;
  left: 50%;
  bottom: max(0.9rem, env(safe-area-inset-bottom));
  z-index: 60;
  min-width: min(18rem, calc(100vw - 1.4rem));
  max-width: calc(100vw - 1.4rem);
  min-height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 0.48rem 0.58rem 0.48rem 0.82rem;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #111111;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-size: 0.74rem;
  font-weight: 800;
}

.status span {
  min-width: 0;
  flex: 1 1 auto;
  text-align: center;
}

.status button {
  min-height: 2rem;
  flex: 0 0 auto;
  padding: 0 0.7rem;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 850;
}

@media (hover: hover) {
  .secondary-button:hover,
  .history-limit-button:hover,
  .entry-actions button:hover,
  .completed-row:hover,
  .entry-toggle:hover {
    border-color: var(--accent-border);
    background-color: var(--panel-soft);
  }

  .primary-button:hover,
  .exercise-preset.is-active:hover {
    background: var(--accent-strong);
  }
}

@media (max-width: 23rem) {
  .shell {
    padding-right: max(0.55rem, env(safe-area-inset-right));
    padding-left: max(0.55rem, env(safe-area-inset-left));
  }

  .entry-panel,
  .history {
    padding: 0.6rem;
  }

  .exercise-preset {
    font-size: 0.61rem;
  }

  .entry-toggle {
    grid-template-columns: 4.8rem minmax(0, 1fr) auto 0.9rem;
    padding-left: 0.5rem;
  }

  .routine-step-top {
    grid-template-columns: 1.35rem minmax(0, 1fr);
  }

  .routine-step-actions {
    grid-column: 2;
    justify-self: end;
  }

  .routine-step-actions button {
    height: 2.15rem;
  }
}

@media (min-width: 48rem) {
  .shell {
    padding-top: 1.25rem;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent-soft: rgba(239, 68, 68, 0.18);
    --accent-border: rgba(239, 68, 68, 0.5);
    --bg: #121214;
    --panel: #1c1c20;
    --panel-soft: #242429;
    --field: #1c1c20;
    --text: #f2f2f2;
    --muted: #a0a0a6;
    --dim: #6d6d73;
    --border: #35353c;
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  }

}
