:root {
  color-scheme: only light;
  --bg1: #d7efe6;
  --bg2: #f3ead8;
  --ink: #17362f;
  --ink-soft: #3b5c55;
  --paper: #fffdf8;
  --paper-2: #f6f1e6;
  --line: #e2d8c6;
  --teal: #1c8a78;
  --teal-deep: #14695c;
  --teal-soft: #d7f0ea;
  --coral: #e45b48;
  --coral-deep: #c44736;
  --gold: #e8b03a;
  --shadow: 0 8px 0 #d3c8b4, 0 14px 28px rgba(23, 54, 47, .12);
  --radius: clamp(16px, 2.2vmin, 24px);
  font-family: "Nunito", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background-color: #d7efe6;
  color: var(--ink);
}

body {
  background:
    radial-gradient(circle at 12% 0%, #fff6d8 0, transparent 36%),
    radial-gradient(circle at 100% 100%, #cce8de 0, transparent 42%),
    linear-gradient(165deg, var(--bg1), var(--bg2));
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  min-height: 100dvh;
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: only light; }
  html, body { background-color: #d7efe6; color: #17362f; }
  .player-card, .library-card, .open-btn, .chip, .loop-btn, .step-btn, .icon-btn {
    color-scheme: only light;
  }
}

button, input { font: inherit; color: inherit; }
button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }

#app {
  height: 100dvh;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 2vmin, 20px);
  overflow: hidden;
}

/* ---------- header */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.brand-icon {
  width: clamp(44px, 8vmin, 56px);
  height: clamp(44px, 8vmin, 56px);
  border-radius: 16px;
  box-shadow: 0 4px 0 #14695c55;
  flex-shrink: 0;
}
.brand-text h1 {
  margin: 0;
  font-size: clamp(22px, 4.2vmin, 34px);
  font-weight: 900;
  letter-spacing: -.03em;
  line-height: 1.1;
}
.tagline {
  margin: 2px 0 0;
  font-size: clamp(13px, 2vmin, 16px);
  font-weight: 700;
  color: var(--ink-soft);
}

.open-btn {
  min-height: 56px;
  min-width: 160px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--teal);
  color: #fffdf8;
  font-size: clamp(18px, 2.6vmin, 22px);
  font-weight: 900;
  box-shadow: 0 5px 0 var(--teal-deep);
}
.open-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--teal-deep); }

/* ---------- layout */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: clamp(12px, 2vmin, 20px);
}
@media (orientation: landscape) and (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, .9fr);
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }
  .library-card { max-height: none; min-height: 0; }
}

.player-card, .library-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: calc(var(--radius) * 1.2);
  box-shadow: var(--shadow);
  border: 2px solid #fff;
  min-width: 0;
}

.player-card { padding: clamp(16px, 3vmin, 28px); display: flex; flex-direction: column; overflow: auto; }

/* ---------- empty */
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 24px 8px;
  min-height: 220px;
}
.empty-art {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--teal-soft);
  color: var(--teal-deep);
  font-size: 52px;
  box-shadow: inset 0 -6px 0 #1c8a7822;
  margin-bottom: 8px;
}
.empty p { margin: 0; font-size: clamp(18px, 2.6vmin, 24px); font-weight: 800; max-width: 28em; line-height: 1.35; }
.empty-hint { color: var(--ink-soft); font-size: clamp(14px, 2vmin, 17px) !important; font-weight: 700 !important; }

/* ---------- now playing */
.now { display: flex; flex-direction: column; gap: clamp(12px, 2vmin, 20px); }
.now-meta { text-align: center; }
.track-badge {
  display: inline-block;
  background: var(--teal-soft);
  color: var(--teal-deep);
  font-weight: 900;
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.song-title {
  margin: 0;
  font-size: clamp(26px, 5vmin, 42px);
  font-weight: 900;
  letter-spacing: -.03em;
  line-height: 1.15;
}
.song-album, .song-artist {
  margin: 4px 0 0;
  font-size: clamp(14px, 2.1vmin, 18px);
  font-weight: 700;
  color: var(--ink-soft);
}
.song-artist { margin-top: 0; }

/* ---------- seek */
.seek-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}
.time {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(14px, 2vmin, 16px);
  min-width: 3.4em;
  color: var(--ink-soft);
}
#curTime { text-align: right; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 56px;
  background: transparent;
  margin: 0;
}
input[type="range"]:focus { outline: none; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 999px;
  background: var(--paper-2);
  box-shadow: inset 0 1px 3px #00000022;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 32px;
  height: 32px;
  margin-top: -10px;
  border-radius: 50%;
  background: var(--teal);
  border: 4px solid #fffdf8;
  box-shadow: 0 3px 0 #14695c66;
  cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 12px;
  border-radius: 999px;
  background: var(--paper-2);
}
input[type="range"]::-moz-range-thumb {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--teal);
  border: 4px solid #fffdf8;
  box-shadow: 0 3px 0 #14695c66;
}

/* Filled tracks: --fill is set in JS (0%–100%). */
#seek { --track-fill: var(--teal); }
#speed { --track-fill: var(--gold); }
#seek::-webkit-slider-runnable-track,
#speed::-webkit-slider-runnable-track {
  background: linear-gradient(to right, var(--track-fill) var(--fill, 0%), var(--paper-2) var(--fill, 0%));
}
#seek::-moz-range-track,
#speed::-moz-range-track {
  background: linear-gradient(to right, var(--track-fill) var(--fill, 0%), var(--paper-2) var(--fill, 0%));
}
#speed::-webkit-slider-thumb { background: var(--gold); box-shadow: 0 3px 0 #b8860b66; }
#speed::-moz-range-thumb { background: var(--gold); box-shadow: 0 3px 0 #b8860b66; }

/* ---------- transport */
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3vmin, 28px);
}
.icon-btn, .step-btn, .loop-btn, .chip, .text-btn {
  min-height: 56px;
  min-width: 56px;
  border-radius: 18px;
  background: var(--paper-2);
  font-weight: 900;
  box-shadow: 0 4px 0 var(--line);
}
.icon-btn, .step-btn, .loop-btn, .chip, .open-btn, .play-btn, .text-btn {
  transition: transform .08s, box-shadow .08s;
}
.icon-btn:active, .step-btn:active, .loop-btn:active, .chip:active, .text-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--line);
}

.icon-btn {
  width: 72px;
  height: 64px;
  font-size: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  gap: 0;
}
.skip-num { font-size: 11px; letter-spacing: .04em; color: var(--ink-soft); }

.play-btn {
  width: 96px;
  height: 96px;
  min-width: 96px;
  min-height: 96px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  font-size: 40px;
  box-shadow: 0 7px 0 var(--coral-deep);
  display: grid;
  place-items: center;
}
.play-btn:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--coral-deep); }
.play-btn.playing #playIcon { font-size: 36px; }
.play-btn:focus-visible, .open-btn:focus-visible, .icon-btn:focus-visible,
.step-btn:focus-visible, .loop-btn:focus-visible, .chip:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 3px;
}

/* ---------- speed */
.speed-block, .loop-block {
  background: #fbf7ee;
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
}
.speed-head, .loop-head, .lib-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.speed-label { font-weight: 800; font-size: 15px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; }
.speed-value {
  font-size: clamp(28px, 5vmin, 36px);
  font-weight: 900;
  color: var(--teal-deep);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.04em;
  line-height: 1;
}
.speed-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}
.step-btn {
  min-width: 68px;
  padding: 0 10px;
  font-size: 18px;
  border-radius: 16px;
}
.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}
.chip {
  flex: 1 1 0;
  min-width: 56px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 16px;
  background: #fff;
}
.chip[aria-pressed="true"] {
  background: var(--teal);
  color: #fffdf8;
  box-shadow: 0 4px 0 var(--teal-deep);
}

/* ---------- loop */
.loop-times { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--teal-deep); }
.loop-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 8px 0; }
.loop-btn { font-size: 16px; }
.loop-btn.on {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 4px 0 var(--teal-deep);
}
.loop-btn.ghost { background: #fff; }
.loop-btn.danger { background: var(--coral); color: #fff; box-shadow: 0 4px 0 var(--coral-deep); }
.slow-build {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  font-weight: 800;
  font-size: clamp(15px, 2vmin, 17px);
  cursor: pointer;
}
.slow-build input {
  width: 28px;
  height: 28px;
  accent-color: var(--teal);
  flex-shrink: 0;
}

/* ---------- library */
.library-card {
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  min-height: 132px;
  max-height: min(34dvh, 480px);
}
.lib-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.text-btn {
  background: transparent;
  box-shadow: none;
  min-width: auto;
  padding: 0 12px;
  color: var(--coral-deep);
  font-size: 15px;
}
.text-btn:active { box-shadow: none; }
.confirm {
  background: #fff3ee;
  border: 2px solid #f3c2b8;
  border-radius: 16px;
  padding: 12px;
  margin: 8px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.confirm p { margin: 0; flex: 1 1 100%; font-weight: 800; }
.lib-empty { margin: 16px 8px; color: var(--ink-soft); font-weight: 700; }
.song-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 0;
  overscroll-behavior: contain;
}
.song-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 8px 6px 8px 10px;
  border-radius: 16px;
  background: transparent;
  min-height: 64px;
}
.song-item:active { background: var(--paper-2); }
.song-item.current {
  background: var(--teal-soft);
}
.song-num {
  font-weight: 900;
  color: var(--teal-deep);
  min-width: 1.6em;
  font-variant-numeric: tabular-nums;
}
.song-info { min-width: 0; }
.song-info .name,
.song-info .sub {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.song-info .name {
  font-weight: 900;
  font-size: 17px;
}
.song-info .sub {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}
.song-speed {
  font-weight: 900;
  font-size: 14px;
  color: var(--teal-deep);
  font-variant-numeric: tabular-nums;
}
.remove-btn {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 16px;
  background: transparent;
  font-size: 22px;
  color: var(--ink-soft);
  font-weight: 900;
}
.remove-btn:active { background: #fde8e4; color: var(--coral-deep); }

/* ---------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  width: min(560px, calc(100% - 32px));
  background: #17362f;
  color: #fffdf8;
  font-weight: 800;
  padding: 12px 16px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 6px 20px #0003;
}
.toast[hidden], .empty[hidden], .now[hidden], .confirm[hidden],
#clearAll[hidden], .lib-empty[hidden], .track-badge[hidden] { display: none !important; }
.toast.error { background: #8a2f24; }

/* Playing pulse on the play button — calm, not flashy */
.play-btn.playing { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse {
  50% { box-shadow: 0 7px 0 var(--coral-deep), 0 0 0 8px #e45b4830; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* Short viewports (Fold inner CSS px, landscape phones) */
@media (max-height: 820px) and (orientation: portrait) {
  .player-card { padding: 10px 12px; }
  .now { gap: 4px; }
  .song-title { font-size: 22px; }
  .song-album, .song-artist { font-size: 13px; }
  .play-btn { width: 72px; height: 72px; min-width: 72px; min-height: 72px; font-size: 30px; }
  .icon-btn { width: 64px; height: 56px; }
  .library-card { max-height: 22dvh; min-height: 120px; }
  .empty { min-height: 120px; padding: 8px; }
  .tagline { display: none; }
  .speed-block, .loop-block { padding: 6px 10px 8px; }
  .loop-row { margin: 4px 0; }
  .slow-build { min-height: 40px; font-size: 14px; gap: 8px; }
  .track-badge { margin-bottom: 2px; }
  .song-artist { display: none; }
  input[type="range"] { height: 44px; }
  .transport { gap: 10px; }
}

@media (max-width: 420px) {
  .open-btn { width: 100%; }
  .loop-row { grid-template-columns: 1fr 1fr; }
  #clearLoop { grid-column: 1 / -1; }
}

@media (orientation: landscape) and (min-width: 900px) {
  .library-card { max-height: none; height: auto; align-self: stretch; min-height: 0; }
}

@media (orientation: landscape) and (max-height: 850px) {
  .player-card { padding: 12px 18px 14px; }
  .now { gap: 6px; }
  .song-title { font-size: clamp(22px, 4.4vh, 34px); }
  .play-btn { width: 80px; height: 80px; min-width: 80px; min-height: 80px; font-size: 32px; }
  .speed-block, .loop-block { padding: 8px 12px 10px; }
  .slow-build { min-height: 48px; }
}
