* { box-sizing: border-box; }

:root {
  --bg: #f6f1e8;
  --card: #fffaf1;
  --ink: #25201a;
  --muted: #756a5c;
  --line: #eadcc7;
  --accent: #8a5a32;
  --accent-dark: #5e3b1e;
  --shadow: 0 14px 38px rgba(74, 45, 18, 0.12);
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #f8efe0, #f4f0e8 58%, #efe3d2);
  color: var(--ink);
}

.app {
  width: min(1040px, 100% - 28px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 0 48px;
}

.hero { margin-bottom: 18px; }

.eyebrow {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin: 0 0 6px;
}

h1 {
  font-size: clamp(30px, 8vw, 54px);
  line-height: 1.12;
  letter-spacing: -0.03em;
  margin: 0;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

h2 { margin: 0 0 10px; font-size: clamp(20px, 5vw, 28px); }

.sub { color: var(--muted); max-width: 720px; line-height: 1.6; }

.panel, .player-card {
  background: rgba(255, 250, 241, .94);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: clamp(16px, 4vw, 22px);
  margin: 16px 0;
  box-shadow: var(--shadow);
}

.hint, .notes li { color: var(--muted); line-height: 1.7; }
.small { font-size: 13px; margin: 4px 0 0; }

button, .button {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 14px;
  padding: 11px 13px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  min-height: 46px;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
}

.primary, .big {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: stretch;
}

.action-grid button, .action-grid .button {
  display: grid;
  place-items: center;
  width: 100%;
}

.track-info {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

.label { color: var(--muted); margin: 0 0 3px; font-size: 13px; font-weight: 800; }

#trackTitle {
  margin: 0;
  font-size: clamp(19px, 5.5vw, 28px);
  overflow-wrap: anywhere;
}

.timebox {
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
  font-weight: 800;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 12px;
  white-space: nowrap;
}

.media-view {
  width: 100%;
  max-height: min(55vh, 520px);
  margin-top: 14px;
  border-radius: 18px;
  background: #111;
  display: block;
}

.media-view.audio-only {
  height: 58px;
  background: transparent;
}

.seek { width: 100%; margin: 18px 0; accent-color: var(--accent); }

.transport, .ab-buttons, .preset-row, .saved-head, .chain-controls, .playlist-head {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.transport { justify-content: center; }
.transport button { flex: 1 1 120px; }
.transport .big { flex: 1 1 180px; font-size: 18px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.control-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
}

.control-box h3 { margin: 0 0 10px; }

.ab-buttons button, .preset-row button { flex: 1 1 88px; }

.ab-display, .speed-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: 14px 0;
  flex-wrap: wrap;
}

.speed-row input { flex: 1; min-width: 160px; accent-color: var(--accent); }

.toggle {
  display: flex;
  gap: 8px;
  color: var(--muted);
  align-items: center;
  line-height: 1.5;
}

.saved-ab-box { margin-top: 16px; }
.saved-head { justify-content: space-between; align-items: flex-start; }
.saved-head > div { flex: 1 1 260px; }

.name-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
  margin: 10px 0 8px;
}

.chain-controls {
  padding: 12px;
  border: 1px dashed #d9c3a8;
  border-radius: 16px;
  background: #fffaf1;
  margin: 10px 0 14px;
}

.chain-controls button { flex: 1 1 160px; }
.chain-status { color: var(--accent-dark); font-weight: 900; flex: 1 1 100%; }

.saved-ab-list { display: grid; gap: 10px; margin-top: 10px; }
.saved-ab-list.empty { color: var(--muted); padding: 12px 0; }

.saved-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fffaf1;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}

.saved-index-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.saved-index {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #fff;
  display: grid;
  place-items: center;
  font-weight: 900;
  color: var(--accent);
  border: 1px solid var(--line);
}

.segment-check {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.saved-item-title { font-weight: 900; overflow-wrap: anywhere; }
.saved-item-time { color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 3px; }

.saved-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
}

.danger { color: #9c2f20; }
.active-segment { outline: 3px solid rgba(138, 90, 50, .25); }

.playlist-head { justify-content: space-between; }
.playlist { list-style: none; padding: 0; margin: 0; }

.playlist li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.playlist .active { color: var(--accent); font-weight: 900; }
.track-name { overflow-wrap: anywhere; }

@media (max-width: 520px) {
  .app { width: min(100% - 22px, 1040px); }
  .panel, .player-card { border-radius: 20px; }
  .action-grid { grid-template-columns: 1fr; }
  .track-info { grid-template-columns: 1fr; }
  .timebox { justify-self: start; }
  .playlist li { grid-template-columns: 1fr; }
  .chain-controls button { flex: 1 1 100%; }
}
