:root {
  --page-bg: #eef3f8;
  --surface: #ffffff;
  --surface-soft: #f7fafc;
  --text: #1f2a36;
  --text-muted: #5f7286;
  --border: #cdd9e8;
  --green: #0b8f4d;
  --green-dark: #0a7f45;
  --blue-soft: #e8f0fa;
  --warn: #d08922;
  --error: #be4f4f;
  --neutral: #7a8897;
  --radius: 14px;
  --shadow: 0 8px 26px rgba(25, 48, 78, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  min-height: 100%;
  padding: 20px 18px 34px;
  transition: transform 700ms ease;
}

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar {
  position: sticky;
  top: 12px;
  z-index: 5;
  padding: 16px;
  margin-bottom: 16px;
  position: sticky;
}

.brand-title {
  margin: 0 0 12px;
  font-family: "Playfair Display", "Times New Roman", Georgia, serif;
  font-style: italic;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: #223143;
  font-size: 1.65rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 220px 108px 120px;
  gap: 10px;
  position: relative;
  align-items: center;
}

input,
select,
button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 11px 14px;
  font-size: 1rem;
  background: var(--surface-soft);
  color: var(--text);
}

input:focus,
select:focus,
button:focus,
.album-tile:focus,
.close-btn:focus,
.flip-btn:focus {
  outline: 3px solid rgba(11, 143, 77, 0.28);
  outline-offset: 2px;
}

button {
  cursor: pointer;
  border: 0;
  font-weight: 700;
  transition: transform 140ms ease, filter 150ms ease;
}

#randomBtn {
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  color: #fff;
}

.menu-btn {
  background: #e6edf6;
  color: #304055;
  border: 1px solid #ccdae8;
}

.secondary-btn {
  background: #eaf2fb;
  color: #314559;
  border: 1px solid #c8d8e8;
}

.list-menu {
  position: absolute;
  right: 132px;
  top: 52px;
  display: grid;
  gap: 6px;
  width: 130px;
  padding: 8px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 7;
}

.list-menu button {
  border-radius: 10px;
  border: 1px solid #d5e0ed;
  background: #f2f7fc;
  color: #2c3f54;
  padding: 8px 10px;
  text-align: left;
}

button:hover {
  filter: brightness(0.98);
}

button:active {
  transform: translateY(1px);
}

.status-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.top-menu-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid #ccdae8;
  background: #e6edf6;
  color: #304055;
  font-size: 1.1rem;
  line-height: 1;
}

.admin-menu {
  position: absolute;
  right: 14px;
  top: 56px;
  width: 210px;
  padding: 6px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 8;
  display: grid;
  gap: 2px;
}

.admin-menu button {
  border: 0;
  background: transparent;
  color: #2b3e54;
  text-align: left;
  border-radius: 8px;
  padding: 10px 10px;
  font-weight: 600;
}

.admin-menu button:hover {
  background: #eff4fa;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  border: 1px solid transparent;
}

.pill-good {
  color: #0b5b35;
  background: #dcf4e7;
  border-color: #bde9d2;
}

.pill-warn {
  color: #71470f;
  background: #ffeccd;
  border-color: #f2d6a6;
}

.pill-error {
  color: #6f2f2f;
  background: #f8dfdf;
  border-color: #ebc2c2;
}

.pill-neutral {
  color: #3d4b5a;
  background: #ecf2f9;
  border-color: #d5e1ef;
}

main > .section-card {
  padding: 14px;
}

.section-title {
  margin: 2px 0 12px;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.status {
  margin-bottom: 12px;
  background: #f8dfdf;
  border: 1px solid #ebc2c2;
  border-radius: 12px;
  padding: 12px;
  color: #642f2f;
}

.status p {
  margin: 0;
}

.status button {
  margin-top: 8px;
  background: var(--error);
  color: #fff;
}

.album-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.album-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-soft);
  cursor: pointer;
  padding: 0;
  color: inherit;
  text-align: left;
  display: grid;
  grid-template-rows: auto 1fr;
  transition: transform 140ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.album-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(27, 46, 72, 0.12);
  border-color: #b8cce3;
}

.album-tile img,
.cover-fallback {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
  background: #e9f0f7;
}

.cover-fallback {
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.album-meta {
  padding: 10px 11px 12px;
  height: 136px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  align-content: start;
  overflow: hidden;
}

.album-artist {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.35;
  color: #1f2a38;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.album-title {
  margin: 4px 0 0;
  font-size: 0.87rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-badges {
  margin-top: 0;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  align-self: end;
  overflow: hidden;
}

.tile-badges .pill {
  min-width: 78px;
  height: 32px;
  padding: 0 10px;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(25, 37, 53, 0.44);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}

#editOverlay {
  z-index: 30;
}

.edit-card {
  width: min(92vw, 560px);
  padding: 16px;
}

.edit-card h3 {
  margin: 0 0 12px;
}

.edit-form {
  display: grid;
  gap: 12px;
}

.edit-form label {
  display: grid;
  gap: 6px;
  color: #304255;
  font-size: 0.92rem;
  font-weight: 600;
}

.edit-form input {
  border-radius: 10px;
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.wanted-card {
  width: min(94vw, 720px);
  max-height: min(88vh, 860px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wanted-card h3 {
  margin: 0;
}

.wanted-search-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.wanted-search-status {
  margin: 0;
  color: #3c5167;
  font-size: 0.9rem;
}

.wanted-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.wanted-filters label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: #314559;
  font-size: 0.9rem;
}

.wanted-filters input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--green);
}

.wanted-search-results {
  overflow: auto;
  border: 1px solid #d5e1ef;
  border-radius: 12px;
  background: #f9fcff;
  min-height: 100px;
  max-height: min(60vh, 520px);
}

.wanted-result {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #e2ebf5;
}

.wanted-result:last-child {
  border-bottom: 0;
}

.wanted-thumb {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: #e9f0f7;
  border: 1px solid #d5e1ef;
}

.wanted-meta {
  min-width: 0;
}

.wanted-title {
  margin: 0;
  font-weight: 700;
  color: #203247;
}

.wanted-subtitle {
  margin: 3px 0 0;
  color: #5c6f83;
  font-size: 0.9rem;
}

.wanted-empty {
  padding: 18px 14px;
  color: #5c6f83;
}

.wanted-add-btn {
  justify-self: end;
  min-width: 138px;
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid #0a7f45;
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  color: #fff;
  font-weight: 700;
}

.wanted-add-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.detail-card {
  position: relative;
  width: min(94vw, 760px);
  height: min(88vh, 760px);
  perspective: 1200px;
}

.detail-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(242, 247, 252, 0.9);
  border: 1px solid #c8d5e6;
  box-shadow: 0 6px 16px rgba(28, 44, 66, 0.18);
  backdrop-filter: blur(2px);
}

.flip-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 450ms ease;
  transform-style: preserve-3d;
}

.flip-inner.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--surface);
}

.card-front img {
  width: 100%;
  max-height: 70%;
  object-fit: contain;
  background: #eef3f8;
}

.detail-meta {
  padding: 16px;
}

.detail-meta h2 {
  margin: 0;
  font-size: 1.25rem;
}

.detail-meta p {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.card-back {
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.card-back-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--border);
  background: #f2f7fc;
  flex-shrink: 0;
}

.card-back h3 {
  margin: 0;
  font-size: 1.15rem;
}

.track-list {
  flex: 1;
  overflow: auto;
  padding: 8px 14px 16px;
  background: #fff;
}

.track-group-title {
  margin: 14px 0 8px;
  color: #315a7f;
  font-size: 0.92rem;
}

.track-row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 8px;
  padding: 7px 2px;
  border-bottom: 1px solid #e3ecf5;
  color: #243445;
  font-size: 0.92rem;
}

.track-row:hover {
  background: #f5f9fd;
}

.track-no,
.track-duration {
  color: var(--text-muted);
}

.close-btn,
.flip-btn {
  border-radius: 999px;
  height: 38px;
  display: grid;
  place-items: center;
  outline: none;
}

.close-btn {
  width: 38px;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  border: 1px solid #deb6b6;
  background: #f3e6e6;
  color: #8b4040;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 120ms ease;
}

.close-btn:hover {
  background: #d56666;
  color: #fff;
  border-color: #d56666;
}

.flip-btn {
  width: auto;
  padding: 0 15px;
  border: 1px solid #567497;
  background: #5a7597;
  color: #fff;
}

.flip-btn:focus-visible,
.close-btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(11, 143, 77, 0.28);
}

.detail-actions {
  border-top: 1px solid var(--border);
  background: #f2f7fc;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  flex-shrink: 0;
}

.detail-actions button {
  border-radius: 10px;
  height: 40px;
  padding: 0 10px;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#markPurchasedBtn {
  background: linear-gradient(180deg, var(--green), var(--green-dark));
  color: #fff;
}

#markSoldBtn {
  background: #c08129;
  color: #fff;
  border: 1px solid #b67421;
}

.idle-overlay {
  position: fixed;
  inset: 0;
  background: #050607;
  z-index: 40;
}

.idle-slides {
  position: absolute;
  inset: 0;
}

.idle-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 1400ms ease;
  filter: brightness(0.38) contrast(1.06);
}

.idle-slide.active {
  opacity: 1;
}

.idle-info {
  position: absolute;
  z-index: 3;
  color: #dde4f5;
  font-size: 0.95rem;
  text-shadow: 0 0 18px rgba(0, 0, 0, 0.8);
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(8, 12, 20, 0.4);
}

.idle-time {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.idle-dim {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  transition: opacity 1s ease;
  pointer-events: none;
}

.idle-overlay.dimmed .idle-dim {
  opacity: 0.4;
}

.corner-top-left {
  top: 20px;
  left: 20px;
}

.corner-top-right {
  top: 20px;
  right: 20px;
}

.corner-bottom-left {
  bottom: 20px;
  left: 20px;
}

.corner-bottom-right {
  bottom: 20px;
  right: 20px;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .app {
    padding: 12px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #searchInput,
  #artistFilter,
  #randomBtn {
    grid-column: 1 / -1;
  }

  #listModeBtn,
  #listModeBtn {
    grid-column: span 1;
  }

  .list-menu {
    position: static;
    width: 100%;
    box-shadow: none;
    background: #f6f9fd;
    border-radius: 10px;
  }

  .album-grid {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 12px;
  }

  .top-menu-btn {
    top: 10px;
    right: 12px;
    width: 38px;
    height: 38px;
  }

  .admin-menu {
    top: 52px;
    right: 12px;
    width: min(86vw, 260px);
  }

  .detail-card {
    width: min(96vw, 700px);
    height: min(88vh, 700px);
  }

  .card-front img {
    max-height: 62%;
  }
}

@media (max-width: 640px) {
  .topbar {
    top: 8px;
    padding: 12px;
  }

  .brand-title {
    font-size: 1.45rem;
    margin-bottom: 10px;
    padding-right: 46px;
  }

  .status-row {
    gap: 6px;
  }

  .status-row .pill {
    font-size: 0.8rem;
  }

  .album-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .album-meta {
    height: 124px;
    padding: 9px 9px 10px;
  }

  .album-artist {
    font-size: 0.88rem;
  }

  .album-title {
    font-size: 0.8rem;
  }

  .tile-badges .pill {
    min-width: 70px;
    height: 30px;
    font-size: 0.78rem;
    padding: 0 8px;
  }

  .modal-overlay {
    padding: 10px;
  }

  .detail-card {
    width: 100%;
    height: min(90vh, 780px);
  }

  .close-btn {
    width: 36px;
    height: 36px;
  }

  .flip-btn {
    height: 36px;
    padding: 0 13px;
  }

  .detail-toolbar {
    top: 8px;
    right: 8px;
    gap: 6px;
    padding: 5px;
  }

  .detail-meta h2 {
    font-size: 1.1rem;
  }

  .track-list {
    padding: 8px 10px 12px;
  }

  .card-back-header {
    padding: 7px 8px 7px 12px;
  }

  .card-back h3 {
    font-size: 1.15rem;
  }

  .detail-actions {
    grid-template-columns: 1fr;
  }

  .wanted-search-form {
    grid-template-columns: 1fr;
  }

  .wanted-filters {
    gap: 8px;
  }

  .wanted-result {
    grid-template-columns: 46px 1fr;
  }

  .wanted-result button {
    grid-column: 1 / -1;
  }

  .wanted-add-btn {
    justify-self: stretch;
    min-width: 0;
  }

  .wanted-thumb {
    width: 46px;
    height: 46px;
  }
}
