:root {
  --bg: #FFFFFF;
  --surface: #F2F2F7;
  --surface-2: #E5E5EA;
  --text: #000000;
  --text-2: #6E6E73;
  --accent: #9C4235;
  --accent-15: rgba(156, 66, 53, 0.15);
  --record: #D32F2F;
  --separator: rgba(60, 60, 67, 0.18);
  --backdrop: rgba(0, 0, 0, 0.4);
  --dialog: #F2F2F7;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --text: #FFFFFF;
    --text-2: #98989F;
    --accent: #FFB4AB;
    --accent-15: rgba(255, 180, 171, 0.15);
    --record: #D32F2F;
    --separator: rgba(84, 84, 88, 0.6);
    --backdrop: rgba(0, 0, 0, 0.6);
    --dialog: #2C2C2E;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; overscroll-behavior: none; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { cursor: default; opacity: 0.35; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

svg { display: block; }

[hidden] { display: none !important; }

/* ---------- Grundlayout ---------- */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.top {
  flex: none;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 20px) 8px calc(env(safe-area-inset-left) + 20px);
}

.top h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.list-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px calc(env(safe-area-inset-right) + 16px) 24px calc(env(safe-area-inset-left) + 16px);
}

/* ---------- Installationshinweis ---------- */

.install-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 4px 4px 4px 16px;
  border-radius: 12px;
  background: var(--accent-15);
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
}
.install-hint p { margin: 8px 0; flex: 1; }

.hint-close {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  color: var(--text-2);
}
.hint-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

/* ---------- Leere Liste ---------- */

.empty {
  text-align: center;
  padding: 18vh 24px 0;
}
.empty-title { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.empty-text { margin: 0; font-size: 16px; color: var(--text-2); line-height: 1.4; }

/* ---------- Liste ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  column-gap: 12px;
  align-items: center;
  padding: 12px 4px 12px 12px;
  border-radius: 12px;
  background: var(--surface);
}

.play {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  background: var(--accent-15);
  color: var(--accent);
  display: grid;
  place-items: center;
  align-self: start;
}
.play svg { width: 20px; height: 20px; fill: currentColor; }
.play .icon-pause { display: none; }
.play[data-playing="true"] .icon-play { display: none; }
.play[data-playing="true"] .icon-pause { display: block; }

.info { min-width: 0; }

.date {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 2px;
}

.name {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.details {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.more {
  width: 44px;
  height: 44px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  color: var(--accent);
  align-self: start;
}
.more svg { width: 22px; height: 22px; fill: currentColor; }

.progress {
  grid-column: 2 / 4;
  padding-right: 12px;
  margin-top: 8px;
}

.seek {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  --pct: 0%;
}
.seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-2) var(--pct));
}
.seek::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
}
.seek::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}
.seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}
.seek::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}
.seek:focus-visible { outline-offset: 0; }

.times {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  margin-top: -8px;
}

/* ---------- Aufnahme-Bereich ---------- */

.recorder {
  flex: none;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 20px calc(env(safe-area-inset-right) + 24px) calc(8px + env(safe-area-inset-bottom)) calc(env(safe-area-inset-left) + 24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.timer {
  font-size: 48px;
  font-weight: 300;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.status {
  font-size: 15px;
  color: var(--text-2);
  margin-top: 2px;
}

.meter {
  display: block;
  width: 100%;
  height: 48px;
  margin: 12px 0 14px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  min-height: 80px;
  padding-bottom: 4px;
}

.btn-round {
  display: grid;
  place-items: center;
  border-radius: 50%;
  flex: none;
}

.btn-main {
  width: 72px;
  height: 72px;
  background: var(--record);
  color: #FFFFFF;
}
.btn-main svg { width: 32px; height: 32px; fill: currentColor; }
.btn-main .stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.btn-side {
  width: 56px;
  height: 56px;
  background: var(--surface-2);
  color: var(--text);
}
.btn-side svg { width: 24px; height: 24px; fill: currentColor; }
.btn-side .icon-resume { fill: var(--record); }
#btnPause .icon-resume { display: none; }
#btnPause[data-paused="true"] .icon-pause { display: none; }
#btnPause[data-paused="true"] .icon-resume { display: block; }

.placeholder { background: transparent; }

/* ---------- Meldungen ---------- */

.toast {
  position: fixed;
  inset: auto;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 50%;
  transform: translate(-50%, -8px);
  max-width: min(92vw, 420px);
  width: max-content;
  margin: 0;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  line-height: 1.3;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  overflow: visible;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  .toast, .toast.show { transition: none; transform: translate(-50%, 0); }
}

/* ---------- Dialoge ---------- */

dialog {
  color: var(--text);
  border: 0;
  padding: 0;
}
dialog::backdrop { background: var(--backdrop); }

.alert {
  width: min(300px, calc(100vw - 48px));
  border-radius: 14px;
  background: var(--dialog);
  text-align: center;
}
.alert form { margin: 0; }
.alert h2 {
  margin: 0;
  padding: 20px 16px 4px;
  font-size: 17px;
  font-weight: 600;
}
.alert p {
  margin: 0;
  padding: 0 16px 16px;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.field {
  display: block;
  padding: 8px 16px 16px;
  text-align: left;
}
.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--separator);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 17px; /* verhindert Zoom auf iOS */
}
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

.alert-actions {
  display: flex;
  border-top: 1px solid var(--separator);
}
.alert-btn {
  flex: 1;
  min-height: 44px;
  padding: 11px 8px;
  font-size: 17px;
  color: var(--accent);
}
.alert-btn + .alert-btn { border-left: 1px solid var(--separator); }
.alert-btn.bold { font-weight: 600; }
.alert-btn.danger { color: var(--record); }

/* Aktionsmenü als Sheet am unteren Rand */
.sheet {
  width: min(420px, calc(100vw - 16px));
  max-width: none;
  margin: auto auto calc(env(safe-area-inset-bottom) + 8px);
  background: transparent;
  overflow: visible;
}
.sheet form { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.sheet-group {
  border-radius: 14px;
  background: var(--dialog);
  overflow: hidden;
}
.sheet-title {
  margin: 0;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--separator);
}
.sheet-btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 16px;
  font-size: 20px;
  color: var(--accent);
  text-align: center;
}
.sheet-btn + .sheet-btn { border-top: 1px solid var(--separator); }
.sheet-btn.danger { color: var(--record); }
.sheet-btn.bold { font-weight: 600; }
.sheet-btn:focus-visible { outline-offset: -3px; }
