:root {
  --bg: #f5f1e9;
  --surface: #fffdf8;
  --surface-soft: #ece4d7;
  --ink: #342d28;
  --muted: #75695f;
  --accent: #657963;
  --accent-dark: #435843;
  --accent-soft: #dfe8dd;
  --line: rgba(90, 75, 60, .14);
  --shadow: 0 14px 36px rgba(70, 54, 35, .10);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: linear-gradient(135deg, #f8f3ea 0%, #f5f2e9 52%, #edf5ee 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Yu Gothic", Arial, sans-serif;
}

button,
input { font: inherit; }

button { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(101, 121, 99, .38);
  outline-offset: 3px;
}

.app {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 32px 20px max(56px, env(safe-area-inset-bottom));
}

.view { display: none; }
.view.active { display: block; }

.home-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}

h1,
h2,
h3 { color: var(--ink); }

h1 {
  margin: 0 0 12px;
  font-size: clamp(38px, 7vw, 54px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.04em;
}

h2 {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -.03em;
}

h3 { margin: 0; font-size: 20px; }

.lead {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.primary-action {
  flex: 0 0 auto;
  min-height: 56px;
  padding: 14px 22px;
  border: 0;
  border-radius: 16px;
  color: white;
  background: var(--accent-dark);
  box-shadow: var(--shadow);
  font-weight: 800;
  cursor: pointer;
}

.primary-action:hover { background: #354a36; }

.header-actions {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.secondary-action {
  min-height: 56px;
  padding: 13px 18px;
  border: 1px solid rgba(67, 88, 67, .24);
  border-radius: 16px;
  color: var(--accent-dark);
  background: rgba(255, 253, 248, .78);
  font-weight: 800;
  cursor: pointer;
}

.secondary-action[hidden] { display: none; }

.library-heading,
.track-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin: 0 0 14px;
}

.library-heading p,
.track-heading span {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.album-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 24px;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(90, 75, 60, .08);
  border-radius: 20px;
  color: var(--ink);
  background: rgba(255, 253, 248, .82);
  box-shadow: 0 8px 24px rgba(70, 54, 35, .06);
  text-align: left;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}

.album-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.album-card img {
  display: block;
  width: 72px;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background: var(--surface-soft);
  object-fit: cover;
}

.album-info { min-width: 0; }

.album-title {
  display: block;
  overflow: hidden;
  font-size: 16px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.album-count {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.card-arrow { color: var(--accent); font-size: 30px; line-height: 1; }

.mini-player {
  position: sticky;
  z-index: 5;
  top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 26px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 253, 248, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.mini-player[hidden] { display: none; }

.mini-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.mini-main img { width: 50px; height: 50px; border-radius: 11px; object-fit: cover; }
.mini-main span { min-width: 0; }
.mini-main small { display: block; color: var(--accent); font-size: 11px; font-weight: 800; }
.mini-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mini-play {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--accent-dark);
  cursor: pointer;
}

.back-btn {
  min-height: 44px;
  margin: 0 0 18px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface-soft);
  font-weight: 700;
  cursor: pointer;
}

.player-card {
  display: grid;
  grid-template-columns: minmax(180px, 300px) minmax(0, 1fr);
  gap: 8px 32px;
  padding: 24px;
  border: 1px solid rgba(90, 75, 60, .08);
  border-radius: 28px;
  background: rgba(255, 253, 248, .78);
  box-shadow: var(--shadow);
}

.cover {
  display: block;
  grid-row: 1 / span 6;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  background: var(--surface-soft);
  object-fit: cover;
}

.player-copy { align-self: end; min-width: 0; }

.track-title {
  overflow: hidden;
  margin: 9px 0 0;
  font-size: 19px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.controls button {
  min-width: 64px;
  height: 52px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface-soft);
  font-weight: 800;
  cursor: pointer;
}

.controls .play {
  min-width: 70px;
  height: 70px;
  color: white;
  background: var(--accent-dark);
  font-size: 24px;
}

.toggle-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toggle-row button {
  min-height: 46px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--muted);
  background: var(--surface);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.toggle-row button.is-active {
  border-color: rgba(101, 121, 99, .4);
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.range-block { margin: 8px 0 2px; }

.time-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
}

input[type="range"] {
  width: 100%;
  min-height: 28px;
  margin: 0;
  accent-color: var(--accent-dark);
  cursor: pointer;
}

.volume-block label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.player-message { min-height: 1.4em; margin: 2px 0 0; color: #9a4d40; font-size: 13px; }

.reliability-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 5px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.health-badge {
  display: inline-flex;
  min-height: 30px;
  padding: 5px 9px;
  align-items: center;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 11px;
  font-weight: 800;
}

.health-badge.is-good {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.health-badge.is-warning {
  color: #8b4a32;
  background: #f6dfd5;
}

.log-button {
  min-height: 34px;
  margin-left: auto;
  padding: 6px 10px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.track-heading { align-items: center; margin-top: 28px; }

.track-list {
  margin: 0;
  padding: 8px;
  border: 1px solid rgba(90, 75, 60, .08);
  border-radius: 22px;
  background: rgba(255, 253, 248, .66);
  list-style: none;
  counter-reset: track;
}

.track-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px;
  border-bottom: 1px solid var(--line);
  counter-increment: track;
}

.track-list li:last-child { border-bottom: 0; }

.track-list li::before {
  min-width: 34px;
  color: #9a8a7a;
  content: counter(track, decimal-leading-zero);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.track-list button {
  width: 100%;
  min-height: 48px;
  padding: 8px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.track-list li.active {
  border-bottom-color: transparent;
  border-radius: 14px;
  background: var(--accent-soft);
}

.track-list li.active::before { color: var(--accent-dark); }

.empty {
  padding: 20px;
  border-radius: 20px;
  background: rgba(255, 253, 248, .7);
  line-height: 1.7;
}

code { padding: 2px 6px; border-radius: 6px; background: var(--surface-soft); }

@media (max-width: 700px) {
  .app { padding: 24px 16px max(48px, env(safe-area-inset-bottom)); }
  .home-header { display: block; }
  .header-actions { display: grid; margin-top: 22px; }
  .primary-action,
  .secondary-action { width: 100%; }
  .album-grid { grid-template-columns: 1fr; }
  .player-card { display: block; padding: 18px; }
  .cover { width: min(70vw, 300px); margin: 0 auto 20px; }
  .player-copy { text-align: center; }
  .range-block { margin-top: 20px; }
  .controls { margin: 12px 0; }
  .volume-block { margin-top: 14px; }
  .log-button { width: 100%; margin-left: 0; text-align: center; }
}

@media (max-width: 380px) {
  .toggle-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
