:root {
  color-scheme: light;
  --bg: #f3f0e7;
  --surface: #fffdf7;
  --surface-strong: #f8f2e6;
  --ink: #1d2724;
  --muted: #6a716b;
  --jade: #163a36;
  --leaf: #2c6b58;
  --moss: #dce7d1;
  --gold: #c78d38;
  --gold-soft: #f4dfae;
  --rose: #bd6b59;
  --line: rgba(29, 39, 36, 0.12);
  --shadow: 0 22px 48px rgba(35, 48, 42, 0.16);
  --radius: 14px;
  --radius-sm: 10px;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  overflow-x: hidden;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 18% -4%, rgba(199, 141, 56, 0.28), transparent 32rem),
    radial-gradient(circle at 110% 14%, rgba(44, 107, 88, 0.22), transparent 28rem),
    linear-gradient(165deg, #f7f1e5 0%, #edf4e9 48%, #f7efe6 100%);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  display: block;
}

.app-shell {
  width: 100%;
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-content: start;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(22, 58, 54, 0.18);
  border-radius: 50%;
  background: linear-gradient(145deg, #fdf8eb, #dfead6);
  box-shadow: 0 10px 20px rgba(22, 58, 54, 0.16);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.brand-text {
  min-width: 0;
}

.brand-lockup h1,
.brand-lockup p,
.track-meta h2,
.track-meta p,
.browse-header h2,
.browse-header p,
.app-footer p {
  margin: 0;
}

.brand-lockup h1 {
  line-height: 1.1;
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--jade);
  letter-spacing: 0;
}

.brand-lockup p,
.library-pill,
.track-meta p,
.browse-header p,
.list-summary,
.app-footer p {
  color: var(--muted);
  font-size: 0.78rem;
}

.library-pill {
  flex: 0 0 auto;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.78);
  white-space: nowrap;
}

/* Search bar pinned full-width above the player so it is never clipped. */
.search-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -2px;
  padding: 4px 2px;
  background:
    linear-gradient(
      to bottom,
      rgba(247, 241, 229, 0.94) 0%,
      rgba(247, 241, 229, 0.85) 70%,
      rgba(247, 241, 229, 0) 100%
    );
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 6px 16px rgba(22, 58, 54, 0.08);
}

.search-box svg {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--leaf);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.search-box input {
  flex: 1 1 auto;
  min-width: 0;
  height: 46px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.98rem;
}

.search-box input::-webkit-search-cancel-button {
  display: none;
}

.clear-search {
  display: grid;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: rgba(22, 58, 54, 0.08);
  color: var(--jade);
}

.clear-search[hidden] {
  display: none;
}

.clear-search svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.player-panel,
.browse-panel {
  border: 1px solid rgba(22, 58, 54, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 253, 247, 0.9);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.player-panel {
  padding: 16px;
}

.visual-stage {
  position: relative;
  display: grid;
  min-height: 200px;
  margin-bottom: 16px;
  overflow: hidden;
  place-items: center;
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, rgba(22, 58, 54, 0.94), rgba(44, 107, 88, 0.78)),
    radial-gradient(circle at 50% 20%, rgba(244, 223, 174, 0.6), transparent 17rem);
}

.visual-stage::before {
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(244, 223, 174, 0.28);
  border-radius: var(--radius);
  content: "";
  pointer-events: none;
}

.disc {
  position: relative;
  width: 144px;
  height: 144px;
  border-radius: 50%;
  background:
    radial-gradient(circle, #f9ecc4 0 12%, rgba(255, 255, 255, 0.16) 13% 18%, transparent 19%),
    repeating-radial-gradient(circle, rgba(255, 255, 255, 0.2) 0 2px, rgba(255, 255, 255, 0.02) 2px 7px),
    linear-gradient(145deg, rgba(238, 192, 108, 0.92), rgba(28, 76, 67, 0.28));
  box-shadow: 0 22px 42px rgba(0, 0, 0, 0.28);
}

.disc span {
  position: absolute;
  inset: 36px;
  border: 1px solid rgba(255, 253, 247, 0.28);
  border-radius: 50%;
}

body.is-playing .disc {
  animation: spin 13s linear infinite;
}

.wave {
  position: absolute;
  right: 18px;
  bottom: 18px;
  display: flex;
  align-items: flex-end;
  gap: 5px;
  height: 46px;
}

.wave span {
  width: 6px;
  height: 15px;
  border-radius: 999px;
  background: var(--gold-soft);
  opacity: 0.85;
}

.wave span:nth-child(2) { height: 30px; }
.wave span:nth-child(3) { height: 22px; }
.wave span:nth-child(4) { height: 38px; }
.wave span:nth-child(5) { height: 18px; }

body.is-playing .wave span {
  animation: pulse 1.1s ease-in-out infinite;
}

body.is-playing .wave span:nth-child(2) { animation-delay: 0.1s; }
body.is-playing .wave span:nth-child(3) { animation-delay: 0.2s; }
body.is-playing .wave span:nth-child(4) { animation-delay: 0.3s; }
body.is-playing .wave span:nth-child(5) { animation-delay: 0.4s; }

.status-chip {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.92);
  color: var(--jade);
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

.status-chip[data-tone="error"] {
  background: rgba(189, 107, 89, 0.95);
  color: #fff;
}

.track-meta {
  display: grid;
  gap: 4px;
  text-align: center;
}

.track-meta h2 {
  min-height: 2.8em;
  color: var(--jade);
  font-size: 1.14rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#track-category {
  color: var(--leaf);
}

#loop-status {
  min-height: 1.2em;
}

.timeline {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.time-row,
.browse-header,
.volume-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.time-row {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.range-control {
  --progress: 0%;
  width: 100%;
  height: 28px;
  margin: 0;
  appearance: none;
  background: transparent;
}

.range-control::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) var(--progress), rgba(22, 58, 54, 0.14) var(--progress));
}

.range-control::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(22, 58, 54, 0.14);
}

.range-control::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--gold);
}

.range-control::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -8px;
  appearance: none;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--jade);
  box-shadow: 0 4px 12px rgba(22, 58, 54, 0.28);
}

.range-control::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--jade);
  box-shadow: 0 4px 12px rgba(22, 58, 54, 0.28);
}

.transport {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: center;
  justify-items: center;
  gap: 4px;
  margin-top: 16px;
}

.icon-button,
.play-button,
.text-button,
.category-tab,
.track-button,
.clear-search {
  -webkit-tap-highlight-color: transparent;
}

.icon-button,
.play-button {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--jade);
  background: var(--surface-strong);
  box-shadow: inset 0 0 0 1px rgba(22, 58, 54, 0.1);
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.icon-button {
  width: 46px;
  height: 46px;
}

.icon-button.compact {
  width: 40px;
  height: 40px;
}

.icon-button svg,
.play-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.skip-label {
  position: absolute;
  bottom: 7px;
  font-size: 9px;
  font-weight: 700;
  color: var(--jade);
  letter-spacing: 0;
}

.play-button {
  width: 70px;
  height: 70px;
  color: #fffdf7;
  background: linear-gradient(145deg, var(--jade), var(--leaf));
  box-shadow: 0 14px 24px rgba(22, 58, 54, 0.32);
}

.play-button svg {
  fill: currentColor;
  stroke: none;
  width: 26px;
  height: 26px;
}

.play-button .loading-icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 18 60;
}

.pause-icon,
.muted-icon,
.loading-icon,
body.is-playing .play-icon,
body.is-muted .volume-icon {
  display: none;
}

body.is-playing .pause-icon,
body.is-muted .muted-icon {
  display: block;
}

body.is-loading .play-icon,
body.is-loading .pause-icon {
  display: none;
}

body.is-loading .loading-icon {
  display: block;
  animation: spin 0.95s linear infinite;
}

.icon-button:active,
.play-button:active,
.text-button:active,
.category-tab:active,
.track-button:active {
  transform: scale(0.96);
}

.icon-button.is-active {
  color: var(--surface);
  background: var(--rose);
}

.icon-button.is-active .skip-label {
  color: var(--surface);
}

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

.control-cell {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.loop-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 6px;
}

.loop-row select,
.loop-row input {
  min-width: 0;
}

.loop-row input[hidden] {
  display: none;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  outline: 0;
}

select:focus-visible,
input[type="number"]:focus-visible {
  border-color: var(--gold);
}

.volume-row {
  gap: 8px;
  margin-top: 12px;
}

.browse-panel {
  padding: 14px;
}

.browse-header {
  gap: 10px;
  margin-bottom: 12px;
}

.browse-header h2 {
  color: var(--jade);
  font-size: 1rem;
}

.text-button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-strong);
  color: var(--jade);
  font-size: 0.85rem;
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 0;
  padding: 0 0 4px;
}

.category-tab {
  flex: 0 1 auto;
  max-width: 100%;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.8);
  color: var(--jade);
  font-size: 0.82rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-tab[aria-selected="true"] {
  border-color: transparent;
  background: var(--jade);
  color: var(--surface);
}

.list-summary {
  margin: 12px 0 8px;
}

.track-list {
  display: grid;
  gap: 9px;
}

.category-group {
  display: grid;
  gap: 8px;
}

.category-heading {
  position: sticky;
  top: 60px;
  z-index: 1;
  margin: 4px -2px 0;
  padding: 8px 2px 6px;
  color: var(--leaf);
  background: rgba(255, 253, 247, 0.94);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.track-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  transition: border-color 140ms ease, background 140ms ease;
}

.track-button[aria-current="true"] {
  border-color: rgba(199, 141, 56, 0.72);
  background: linear-gradient(135deg, rgba(244, 223, 174, 0.7), rgba(220, 231, 209, 0.72));
}

.track-button[aria-current="true"] .track-play-symbol {
  color: var(--gold);
}

.track-number {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--moss);
  color: var(--jade);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.track-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.track-name {
  min-width: 0;
  font-weight: 700;
  line-height: 1.28;
  overflow-wrap: anywhere;
}

.track-category {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.track-play-symbol {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: var(--leaf);
}

.track-play-symbol svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.empty-state {
  padding: 20px 14px;
  border: 1px dashed rgba(22, 58, 54, 0.28);
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-align: center;
}

.app-footer {
  margin-top: 4px;
  text-align: center;
  display: grid;
  gap: 2px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(199, 141, 56, 0.42);
  outline-offset: 2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%, 100% { transform: scaleY(0.55); }
  50% { transform: scaleY(1); }
}

@media (max-width: 360px) {
  .app-shell {
    padding-inline: 10px;
  }

  .brand-lockup h1 {
    font-size: 1.18rem;
  }

  .library-pill {
    display: none;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .play-button {
    width: 64px;
    height: 64px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.is-playing .disc,
  body.is-playing .wave span,
  body.is-loading .loading-icon {
    animation: none;
  }
}
