:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #202124;
  --muted: #636b74;
  --border: #d9dee5;
  --accent: #087f8c;
  --accent-strong: #06636e;
  --danger: #c44536;
  --warning: #f2c14e;
  --shadow: 0 12px 30px rgba(20, 28, 38, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

body {
  min-height: 100svh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

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

button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100svh;
  margin: 0 auto;
  padding: 12px 10px 24px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 12px;
}

.eyebrow,
.header-label,
.count-badge {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

h3 {
  margin: 0;
  font-size: 0.96rem;
}

.app-main {
  display: grid;
  gap: 10px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

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

.section-heading h2,
.subsection-heading h3 {
  min-width: 0;
}

.heading-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
}

.panel-toggle-button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7f8fa;
  color: var(--text);
  padding: 6px 9px;
  font-size: 0.78rem;
  line-height: 1.1;
  white-space: nowrap;
}

.panel.is-collapsed {
  box-shadow: none;
}

.panel.is-collapsed > .section-heading {
  margin-bottom: 0;
}

.exercise-form,
.workout-form,
.settings-form {
  display: grid;
  gap: 10px;
}

.exercise-form label,
.workout-form label,
.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.option-combobox-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.option-combobox {
  position: relative;
}

.option-combobox-control {
  display: grid;
  grid-template-columns: 1fr 42px;
}

.option-combobox-control input {
  border-radius: 8px 0 0 8px;
}

.option-combobox-toggle {
  min-height: auto;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  background: #ffffff;
  color: var(--muted);
  padding: 0;
  font-size: 0.8rem;
}

.option-combobox-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 4px;
}

.option-combobox-option {
  width: 100%;
  min-height: 36px;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  text-align: left;
  font-weight: 700;
}

.option-combobox-option:hover,
.option-combobox-option:focus-visible {
  background: #eefafb;
}

.option-combobox-empty {
  margin: 0;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 0.82rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus,
button:focus-visible,
.exercise-card:focus-visible,
.selected-summary:focus-visible {
  outline: 3px solid rgba(8, 127, 140, 0.2);
  outline-offset: 2px;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:not(:disabled):active {
  background: var(--accent-strong);
}

.secondary-button {
  border: 1px solid var(--accent);
  background: #eefafb;
  color: var(--accent-strong);
}

.ghost-button {
  border: 1px solid var(--border);
  background: #f7f8fa;
  color: var(--text);
}

.count-badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
}

.empty-state {
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 12px;
  text-align: center;
}

.exercise-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.exercise-card-shell {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: stretch;
}

.card-actions {
  display: grid;
  gap: 8px;
  align-content: stretch;
}

.exercise-card {
  width: 100%;
  min-height: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.exercise-card.is-active {
  border-color: var(--accent);
  background: #eefafb;
}

.exercise-card strong,
.exercise-card span {
  display: block;
}

.exercise-card strong {
  margin-bottom: 4px;
  font-size: 1rem;
}

.exercise-card span {
  color: var(--muted);
  font-size: 0.86rem;
}

.edit-card-button,
.delete-card-button {
  min-width: 64px;
  min-height: 46px;
  padding: 0 12px;
}

.edit-card-button {
  border: 1px solid var(--accent);
  background: #eefafb;
  color: var(--accent-strong);
}

.delete-card-button {
  border: 1px solid #e2b8b2;
  background: #fff7f5;
  color: var(--danger);
}

.counter-panel {
  scroll-margin-top: 12px;
}

.selected-summary {
  min-height: 76px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
}

.selected-title {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 800;
}

.selected-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.workout-form {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.subsection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.subsection-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.set-results-section,
.set-results-list {
  display: grid;
  gap: 10px;
}

.set-result-row {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.set-result-row.is-attention {
  border-color: var(--danger);
  background: #fff7f5;
}

.set-result-title {
  margin: 0;
  font-weight: 800;
}

input.needs-input {
  border-color: var(--danger);
  background: #fffafa;
}

.selected-meta div {
  min-width: 0;
}

.selected-meta dt {
  font-weight: 800;
}

.selected-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.counter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.counter-tile {
  min-height: 66px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.counter-tile span,
.counter-tile strong {
  display: block;
}

.counter-tile span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.counter-tile strong {
  margin-top: 6px;
  font-size: 1.22rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.phase-meter {
  height: 10px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf2;
}

.phase-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--warning);
  transition: width 160ms ease;
}

.voice-guide-control {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.voice-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
}

.voice-toggle input {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  accent-color: var(--primary);
}

.compact-toggle {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.84rem;
}

.settings-toggle {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 9px 10px;
  color: var(--text) !important;
  font-size: 0.86rem !important;
  font-weight: 800 !important;
}

.settings-toggle input {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.data-management-section {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.data-management-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.data-target-group {
  display: grid;
  gap: 7px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.data-target-group legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.data-target-group label,
.data-target-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
}

.data-target-group input,
.data-target-list input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.import-data-control {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.import-data-control input {
  background: #ffffff;
}

.import-target-section {
  display: grid;
  gap: 8px;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.data-target-list {
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.option-master-section {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.option-master-section.is-collapsed {
  gap: 0;
}

.option-master-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.option-master-list {
  display: grid;
  gap: 10px;
}

.option-master-group {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.option-master-title {
  margin: 0;
  font-weight: 800;
}

.option-master-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.option-master-add button {
  min-height: 40px;
  padding: 0 12px;
}

.option-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.option-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f7f8fa;
  padding: 5px 6px 5px 10px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.option-chip.is-default {
  background: #eef5ff;
  border-color: #c9ddff;
}

.option-chip span {
  overflow-wrap: anywhere;
}

.option-chip small {
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  padding: 2px 6px;
  font-size: 0.68rem;
  line-height: 1;
}

.option-chip button {
  min-width: 28px;
  min-height: 28px;
  border: 1px solid #e2b8b2;
  border-radius: 999px;
  background: #fff7f5;
  color: var(--danger);
  padding: 0;
  font-size: 0.78rem;
  line-height: 1;
}

.cue-custom-section {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.cue-custom-section .panel-body {
  display: grid;
  gap: 8px;
}

.cue-custom-section.is-collapsed {
  gap: 0;
}

.compact-button {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 0.82rem;
}

.cue-assignment-list {
  display: grid;
  gap: 8px;
}

.cue-assignment-row {
  display: grid;
  grid-template-columns: minmax(84px, 0.8fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.cue-assignment-row strong,
.cue-assignment-row label {
  min-width: 0;
  font-size: 0.8rem;
}

.cue-assignment-row strong {
  color: var(--text);
}

.cue-assignment-row label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 800;
}

.cue-assignment-row select {
  min-width: 0;
  padding: 8px 9px;
}

.status-message {
  min-height: 24px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.control-grid button:first-child,
.control-grid button:last-child {
  grid-column: 1 / -1;
}

.log-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-list {
  display: grid;
  gap: 14px;
}

.history-day {
  display: grid;
  gap: 10px;
}

.history-date {
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.history-entry-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.log-card-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.log-card strong,
.log-card span {
  display: block;
}

.log-card strong {
  font-size: 0.98rem;
}

.delete-log-button {
  min-height: 34px;
  border: 1px solid #e2b8b2;
  border-radius: 8px;
  background: #fff7f5;
  color: var(--danger);
  padding: 0 10px;
  font-size: 0.8rem;
  line-height: 1;
}

.log-card span {
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

@media (min-width: 460px) {
  .control-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .control-grid button:first-child {
    grid-column: span 2;
  }

  .control-grid button:last-child {
    grid-column: auto;
  }
}
