/* ─────────────────────────────────────────────
   NFC MUSIC PLAYER — Mobile-First 2025
   Safari Compatible
───────────────────────────────────────────── */

:root {
  --bg: #0e0e0e;
  --card: #1a1a1a;
  --card-glass: rgba(26, 26, 26, 0.85);
  --accent: #ff6a00;
  --accent-glow: rgba(255, 106, 0, 0.4);
  --accent-hover: #ff8533;
  --text: #f0f0f0;
  --text-dim: #888;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  height: 100%;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  -webkit-text-size-adjust: 100%;
}

/* ─────────────────────────────────────────────
   STAGE & PLAYER CONTAINER
───────────────────────────────────────────── */
.stage {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  padding: 12px;
  padding-top: calc(12px + var(--safe-top));
  padding-bottom: calc(12px + var(--safe-bottom));
}

.player {
  width: 100%;
  max-width: 400px;
  height: 100%;
  max-height: 100%;
  background: var(--card-glass);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  -webkit-transition: box-shadow 0.4s ease;
  transition: box-shadow 0.4s ease;
}

/* Gap fallback for Safari <14.1 */
.player > * + * {
  margin-top: 12px;
}

.player.playing {
  box-shadow: 
    0 0 60px var(--accent-glow),
    0 8px 32px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ─────────────────────────────────────────────
   ALBUM ART
───────────────────────────────────────────── */
.album {
  position: relative;
  width: 100%;
  padding-top: 100%; /* Aspect ratio fallback */
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #111;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

/* Modern browsers with aspect-ratio */
@supports (aspect-ratio: 1) {
  .album {
    padding-top: 0;
    aspect-ratio: 1;
  }
}

.album.glow::before {
  content: "";
  position: absolute;
  top: -30%;
  left: -30%;
  right: -30%;
  bottom: -30%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  opacity: 0;
  -webkit-transition: opacity 0.5s ease;
  transition: opacity 0.5s ease;
  z-index: -1;
  -webkit-filter: blur(40px);
  filter: blur(40px);
}

.player.playing .album.glow::before {
  opacity: 1;
}

.album img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
  object-fit: cover;
  opacity: 0;
  -webkit-transition: opacity 0.4s ease;
  transition: opacity 0.4s ease;
}

.album img.loaded {
  opacity: 1;
}

.album .note {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  font-size: 48px;
  color: rgba(255, 255, 255, 0.15);
  pointer-events: none;
}

/* ─────────────────────────────────────────────
   INFO SECTION
───────────────────────────────────────────── */
.info {
  text-align: center;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.info > * + * {
  margin-top: 4px;
}

#title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  height: 1.5em;
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}

#title span {
  display: inline-block;
}

#title.scroll span {
  -webkit-animation: marquee 10s linear infinite;
  animation: marquee 10s linear infinite;
}

@-webkit-keyframes marquee {
  0%, 10% { -webkit-transform: translateX(0); transform: translateX(0); }
  90%, 100% { -webkit-transform: translateX(-100%); transform: translateX(-100%); }
}

@keyframes marquee {
  0%, 10% { transform: translateX(0); }
  90%, 100% { transform: translateX(-100%); }
}

#artist {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-dim);
}

#albuminfo {
  font-size: 12px;
  color: var(--text-dim);
  opacity: 0.7;
}

#comment {
  font-size: 11px;
  color: var(--accent);
  font-style: italic;
}

/* ─────────────────────────────────────────────
   PROGRESS BAR
───────────────────────────────────────────── */
.progress-section {
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.bar {
  position: relative;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
  -ms-touch-action: none;
  touch-action: none;
}

.bar .fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  background: -webkit-linear-gradient(left, var(--accent), var(--accent-hover));
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 3px;
  -webkit-transition: width 0.1s linear;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent-glow);
}

.time {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  padding: 0 2px;
}

/* ─────────────────────────────────────────────
   CONTROLS
───────────────────────────────────────────── */
.controls {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  padding: 8px 0;
}

/* Gap fallback */
.controls > * + * {
  margin-left: 12px;
}

.icon-btn {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  -webkit-transition: all 0.2s ease;
  transition: all 0.2s ease;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.icon-btn:active {
  -webkit-transform: scale(0.92);
  transform: scale(0.92);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn.small {
  width: 40px;
  height: 40px;
}

.icon-btn.small svg {
  width: 18px;
  height: 18px;
}

/* Play button */
.icon-btn.play {
  width: 64px;
  height: 64px;
  background: -webkit-linear-gradient(315deg, var(--accent), var(--accent-hover));
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
  position: relative;
}

.icon-btn.play:hover {
  -webkit-transform: scale(1.05);
  transform: scale(1.05);
  box-shadow: 0 6px 30px var(--accent-glow);
}

.icon-btn.play svg {
  width: 28px;
  height: 28px;
  position: absolute;
  opacity: 0;
  -webkit-transition: opacity 0.2s ease;
  transition: opacity 0.2s ease;
}

.icon-btn.play .icon-play {
  opacity: 1;
  margin-left: 3px;
}

.player.playing .icon-btn.play .icon-play {
  opacity: 0;
}

.player.playing .icon-btn.play .icon-pause {
  opacity: 1;
}

.icon-btn.accent {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}

/* ─────────────────────────────────────────────
   VOLUME
───────────────────────────────────────────── */
.vol-wrap {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  padding: 0 4px;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.vol-wrap > * + * {
  margin-left: 10px;
}

.vol-wrap svg {
  width: 18px;
  height: 18px;
  fill: var(--text-dim);
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.bar.vol {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  height: 4px;
}

/* ─────────────────────────────────────────────
   TRACKLIST
───────────────────────────────────────────── */
.tracklist {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}

.tracklist::-webkit-scrollbar {
  width: 4px;
}

.tracklist::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 2px;
}

.tracklist::-webkit-scrollbar-track {
  background: transparent;
}

.track-item {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-transition: background 0.2s ease;
  transition: background 0.2s ease;
  font-size: 13px;
}

.track-item > * + * {
  margin-left: 10px;
}

.track-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.track-item.active {
  background: var(--accent);
  color: #000;
  font-weight: 600;
}

.track-item .num {
  width: 24px;
  text-align: right;
  opacity: 0.5;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.track-item .title {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  overflow: hidden;
  -o-text-overflow: ellipsis;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-item .artist {
  font-size: 11px;
  opacity: 0.6;
  -webkit-flex-shrink: 0;
  flex-shrink: 0;
}

.track-item.active .num,
.track-item.active .artist {
  opacity: 0.8;
}

/* ─────────────────────────────────────────────
   RANDOM BUTTON
───────────────────────────────────────────── */
.random-btn {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  z-index: 100;
}

.random-btn .icon-btn {
  width: 56px;
  height: 56px;
}

/* ─────────────────────────────────────────────
   LOADER
───────────────────────────────────────────── */
#loaderOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  flex-direction: column;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  z-index: 9999;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  -webkit-transition: opacity 0.3s ease;
  transition: opacity 0.3s ease;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  -webkit-animation: spin 0.8s linear infinite;
  animation: spin 0.8s linear infinite;
}

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

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

#loaderProgress {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ─────────────────────────────────────────────
   TAP OVERLAY
───────────────────────────────────────────── */
.tap-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  z-index: 9998;
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.tap-overlay span {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  padding: 16px 32px;
  border: 2px solid var(--accent);
  border-radius: 50px;
  -webkit-transition: all 0.2s ease;
  transition: all 0.2s ease;
}

.tap-overlay:active span {
  background: var(--accent);
  color: #000;
}

/* ─────────────────────────────────────────────
   MOBILE
───────────────────────────────────────────── */
@media (max-width: 480px) {
  .stage {
    padding: 8px;
    padding-top: calc(8px + var(--safe-top));
    padding-bottom: calc(8px + var(--safe-bottom));
  }

  .player {
    padding: 12px;
    border-radius: 12px;
  }

  .player > * + * {
    margin-top: 10px;
  }

  .album {
    border-radius: 8px;
  }

  #title {
    font-size: 16px;
  }

  #artist {
    font-size: 13px;
  }

  .controls > * + * {
    margin-left: 8px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .icon-btn svg {
    width: 20px;
    height: 20px;
  }

  .icon-btn.small {
    width: 36px;
    height: 36px;
  }

  .icon-btn.small svg {
    width: 16px;
    height: 16px;
  }

  .icon-btn.play {
    width: 56px;
    height: 56px;
  }

  .icon-btn.play svg {
    width: 24px;
    height: 24px;
  }

  .track-item {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* Small phones */
@media (max-width: 360px) {
  .player {
    padding: 10px;
  }

  .player > * + * {
    margin-top: 8px;
  }

  #title {
    font-size: 14px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }

  .icon-btn.play {
    width: 52px;
    height: 52px;
  }

  .controls > * + * {
    margin-left: 6px;
  }
}

/* Landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
  .player {
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -webkit-flex-direction: row;
    flex-direction: row;
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap;
    max-width: 100%;
  }

  .player > * + * {
    margin-top: 0;
    margin-left: 12px;
  }

  .album {
    width: 35%;
    max-width: 200px;
    padding-top: 35%;
  }

  @supports (aspect-ratio: 1) {
    .album {
      padding-top: 0;
    }
  }

  .info,
  .progress-section,
  .controls,
  .vol-wrap {
    -webkit-box-flex: 1;
    -webkit-flex: 1;
    flex: 1;
    min-width: 200px;
  }

  .tracklist {
    width: 100%;
    max-height: 120px;
  }
}

/* Tablets */
@media (min-width: 768px) {
  .player {
    max-width: 440px;
    padding: 24px;
  }

  .player > * + * {
    margin-top: 16px;
  }

  #title {
    font-size: 20px;
  }

  #artist {
    font-size: 15px;
  }

  .icon-btn {
    width: 52px;
    height: 52px;
  }

  .icon-btn.play {
    width: 72px;
    height: 72px;
  }

  .icon-btn.play svg {
    width: 32px;
    height: 32px;
  }
}