/* ============================================================
   BASE
   ============================================================ */
html, body {
  touch-action: manipulation;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  background: #eae7d7;
  color: black;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.screen {
  display: none;
  width: 100%;
}

/* Start/Workout/End-Screens: immer genau eine Bildschirmhöhe, nicht scrollbar */
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh; /* iOS-Safe */
  overflow: hidden;
  box-sizing: border-box;
}

#workoutScreen.active {
  display: block;
}

/* Settings dürfen scrollen */
.settings-screen.active {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ============================================================
   START SCREEN
   ============================================================ */

#startScreen {
  position: relative;
  padding: 20px;
  box-sizing: border-box;
}

.settings-icon {
  position: absolute;
  top: 20px;
  right: 20px;
  background: transparent;
  border: none;
  padding: 8px;
  margin: 0;
  color: #666563;
  cursor: pointer;
  z-index: 10;
}
.settings-icon svg {
  display: block;
}

.workout-selector {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.5);
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 16px;
  margin: -10px 0 10px;
  cursor: pointer;
  user-select: none;
}
.workout-selector .chevron {
  font-size: 12px;
  opacity: 0.6;
}

/* GRID — flex, damit Bilder als Gruppe zentriert sind */
#grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 20px 0;
  width: 100%;
  max-width: 360px;
}

#grid img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 10px;
  background: transparent;
}

/* ============================================================
   WORKOUT SCREEN (Layout UNVERÄNDERT)
   ============================================================ */

.container {
  text-align: center;
  width: 90%;
  max-width: 400px;
  margin-top: 20px;
  margin-left: auto;
  margin-right: auto;
}

#image {
  width: 100%;
  border-radius: 20px;
  margin-bottom: 0px;
}

.image-wrapper {
  position: relative;
  margin-top: 20px;
}

#progress-container {
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 8px;
  background: white;
  border-radius: 4px;
  overflow: hidden;
}

#progress-container::after {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: #666563;
  transition: width 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

#counter {
  position: absolute;
  top: 10px;
  left: 0px;
  background: rgba(0,0,0,0.6);
  color: white;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 16px;
}

.close-workout {
  position: absolute;
  top: 10px;
  right: 0;
  width: 42px;
  height: 42px;
  padding: 0;
  margin: 0;
  background: rgba(0,0,0,0.6);
  color: white;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1 {
  font-size: 64px;
  font-weight: 200;
  margin: 10px 0;
  text-align: center;
}

#timer {
  font-size: 80px;
  font-weight: 800;
}

h2 {
  font-weight: 400;
  opacity: 0.8;
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0px;
  margin-top: 15px;
}

/* ============================================================
   BUTTONS (Original-Verhalten)
   ============================================================ */

button {
  padding: 15px 30px;
  margin: 10px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease-out;
  transform: translateZ(0);
  will-change: transform;
  z-index: 0;
  font-family: inherit;
}

button::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  border-radius: inherit;
  transition: opacity 0.1s ease;
  z-index: -1;
}

button:active::after { opacity: 1; }
button:active { transform: scale(0.96); transition: transform 0.05s ease-in; }
.skip:active { transform: scale(0.94); }

.play {
  width: 140px;
  height: 80px;
  font-size: 18px;
  background: #22c55e;
  color: white;
}
.stop {
  width: 140px;
  height: 80px;
  font-size: 18px;
  background: #666563;
  color: white;
}
.skip {
  width: 60px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  background-color: white;
  color: #eae7d7;
}

.label {
  font-size: 14px;
  opacity: 0.7;
  height: 20px;
  display: block;
  font-weight: 800;
}

.badge-inline {
  font-size: 0.7em;
  opacity: 0.6;
  margin-left: 4px;
}

.pulsing {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

#image, #exercise {
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.25s ease;
}
.zoom-out { transform: scale(0.1); opacity: 0; }
.zoom-in  { transform: scale(1); opacity: 1; }

/* ============================================================
   SETTINGS SCREENS
   ============================================================ */

.settings-screen.active {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0;
  min-height: 100vh;
  box-sizing: border-box;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  background: #eae7d7;
  z-index: 5;
}
.settings-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  opacity: 1;
  flex: 1;
  text-align: center;
}
.back-btn, .add-btn, .save-btn {
  width: 60px;
  height: 44px;
  padding: 0;
  margin: 0;
  background: transparent;
  color: #333;
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.add-btn, .save-btn {
  color: #22c55e;
}

.settings-body {
  padding: 20px;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.settings-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  background: white;
  padding: 18px 20px;
  margin: 0 0 12px 0;
  border-radius: 14px;
}
.tile-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}
.tile-desc {
  font-size: 13px;
  opacity: 0.6;
}

/* Listen-Karten */
.list-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: white;
  padding: 14px;
  margin: 0 0 10px 0;
  border-radius: 12px;
  text-align: left;
}
.list-card-text {
  display: flex;
  flex-direction: column;
  flex: 1;
}
.list-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}
.list-card-meta {
  font-size: 12px;
  opacity: 0.6;
}
.list-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

/* Felder */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.7;
  margin: 18px 0 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.text-input {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  background: white;
  font-family: inherit;
}
.text-input:focus {
  outline: none;
  border-color: #22c55e;
}

/* Browser-Standard-Pfeile in Zahlenfeldern ausblenden */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
.help-text {
  font-size: 12px;
  opacity: 0.6;
  margin: 6px 0 0 0;
}

.image-preview-wrap {
  margin-top: 10px;
  background: white;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  justify-content: center;
}
.image-preview-wrap img {
  max-width: 200px;
  max-height: 200px;
  width: auto;
  height: auto;
  border-radius: 0;
}

/* Segmented control */
.segmented {
  display: flex;
  background: white;
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}
.seg-btn {
  flex: 1;
  padding: 10px;
  margin: 0;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #666;
}
.seg-btn.active {
  background: #22c55e;
  color: white;
  font-weight: 600;
}

/* Workout-Editor: Übungsliste */
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.exercise-list-in-workout {
  margin-top: 12px;
}
.we-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  padding: 10px;
  border-radius: 12px;
  margin-bottom: 8px;
}
.we-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.we-info {
  flex: 1;
  min-width: 0;
}
.we-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.we-dur {
  font-size: 12px;
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 4px;
}
.we-dur-input {
  width: 50px;
  padding: 4px 6px;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
}
.we-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.icon-btn {
  width: 30px;
  height: 24px;
  padding: 0;
  margin: 0;
  background: rgba(0,0,0,0.05);
  font-size: 11px;
  border-radius: 6px;
  color: #333;
}
.icon-btn.danger {
  color: #ef4444;
  margin-top: 4px;
}

/* Sided-Badge nur im aktiven Workout-Modus */
.sided-workout {
  display: inline-block;
  background: rgba(34, 197, 94, 0.18);
  color: #16a34a;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 8px;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

.meta-pill {
  display: inline-block;
  background: rgba(0,0,0,0.06);
  color: #555;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 500;
}
.we-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0 6px 0;
}
.we-times {
  display: flex;
  gap: 14px;
  font-size: 12px;
  opacity: 0.85;
}
.we-times label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.we-num-input {
  width: 50px;
  padding: 4px 6px;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
  font-family: inherit;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.two-col .field-label {
  margin-top: 18px;
}
.three-col {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.three-col .field-label {
  margin-top: 18px;
  font-size: 11px; /* etwas kleiner damit es in drei Spalten passt */
}
.three-col .text-input {
  padding: 12px 8px;
  text-align: center;
}

.filter-row {
  display: flex;
  gap: 6px;
  margin: 10px 0 14px 0;
  flex-wrap: wrap;
}
.filter-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 9px 10px 9px 12px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  border: none;
  border-radius: 10px;
  background-color: white;
  font-family: inherit;
  cursor: pointer;
}
.filter-btn .filter-btn-label {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  flex: 1;
  text-align: left;
}
.filter-btn .filter-btn-chevron {
  font-size: 10px;
  opacity: 0.5;
  flex-shrink: 0;
}
.filter-btn.active {
  background-color: #22c55e;
  color: white;
}
.filter-btn.active .filter-btn-chevron {
  opacity: 0.85;
}

/* Filter-Picker Optionsliste */
.filter-option {
  justify-content: space-between !important;
  font-weight: 500;
  font-size: 15px;
  padding: 14px !important;
}
.filter-option .check {
  color: #22c55e;
  font-weight: 700;
  font-size: 16px;
}
.filter-option.selected {
  background: rgba(34, 197, 94, 0.1) !important;
  color: #16a34a !important;
}
.filter-option.selected .check {
  color: #16a34a;
}
.picker-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
}

.btn-small {
  padding: 8px 14px;
  margin: 0;
  font-size: 13px;
  background: #333;
  color: white;
  border-radius: 8px;
  font-weight: 500;
}
.btn-primary {
  padding: 12px 24px;
  margin: 0;
  font-size: 15px;
  background: #22c55e;
  color: white;
  border-radius: 10px;
  font-weight: 600;
}
.btn-secondary {
  padding: 12px 24px;
  margin: 0;
  font-size: 15px;
  background: rgba(0,0,0,0.08);
  color: #333;
  border-radius: 10px;
  font-weight: 500;
}
.btn-danger {
  padding: 12px 24px;
  margin: 0;
  font-size: 15px;
  background: #ef4444;
  color: white;
  border-radius: 10px;
  font-weight: 500;
  width: 100%;
}

/* Zwei Buttons nebeneinander, je 50% */
.row-actions {
  display: flex;
  gap: 10px;
}
.row-actions > button {
  flex: 1;
  width: auto;
}
.row-actions > .btn-primary {
  padding: 12px 24px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  justify-content: center;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
}
.modal.open {
  display: flex;
}
.modal-content {
  background: #eae7d7;
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-sizing: border-box;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-content.tall {
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-content h2 {
  margin: 0 0 16px 0;
  font-size: 20px;
  font-weight: 600;
  opacity: 1;
  text-align: center;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
}
.error-msg {
  color: #ef4444;
  font-size: 14px;
  margin: 8px 0 0 0;
  text-align: center;
}

.confirm-msg {
  font-size: 15px;
  text-align: center;
  margin: 8px 0 4px 0;
  opacity: 0.85;
  line-height: 1.4;
}

/* Im Confirm-Modal sollen beide Buttons gleich breit nebeneinander stehen */
#confirmModal .modal-actions {
  justify-content: stretch;
  gap: 10px;
}
#confirmModal .modal-actions > button {
  flex: 1;
}

.picker-list {
  margin: 12px 0;
  max-height: 50vh;
  overflow-y: auto;
}
.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  padding: 10px;
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 14px;
}
.picker-item.selected {
  background: #22c55e;
  color: white;
}
.picker-item:active {
  opacity: 0.7;
}
.picker-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}
.picker-info {
  flex: 1;
}
.picker-meta {
  font-size: 11px;
  opacity: 0.6;
}
