/* ========== RESET & BASE ========== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0a0a0a;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222;
  --bg-elevated: #1c1c1e;
  --text: #f5f5f7;
  --text-secondary: #8e8e93;
  --accent: #d4a843;
  --accent-dim: rgba(212, 168, 67, 0.15);
  --accent-glow: rgba(212, 168, 67, 0.3);
  --green: #30d158;
  --red: #ff453a;
  --border: #2c2c2e;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mini-player-h: 64px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ========== PROFILE SCREEN ========== */
.profile-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.profile-screen.hidden {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}

.profile-content {
  text-align: center;
  padding: 24px;
}

.profile-logo {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 4px;
  margin-bottom: 32px;
}

.profile-heading {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 40px;
}

.profile-cards {
  display: flex;
  gap: 32px;
  justify-content: center;
}

.profile-card {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 16px;
  transition: transform 0.2s, background 0.2s;
}

.profile-card:active {
  transform: scale(0.93);
  background: var(--bg-elevated);
}

.profile-avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  transition: box-shadow 0.2s;
}

.profile-card:hover .profile-avatar {
  box-shadow: 0 8px 30px rgba(212, 168, 67, 0.3);
}

.profile-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* App hidden until profile selected */
.app-hidden {
  display: none !important;
}

/* ========== HEADER ========== */
#header {
  flex-shrink: 0;
  padding: calc(var(--safe-top) + 8px) 16px 0;
  background: var(--bg);
  z-index: 10;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.portal-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: var(--text-secondary);
  font-size: 18px;
  text-decoration: none;
  transition: background 0.2s;
  flex-shrink: 0;
}

.portal-back-btn:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.header-top h1 {
  flex: 1;
  text-align: center;
  font-size: 16px;
}

.header-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #b8922e);
}

.header-profile-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.portal-link-profile {
  display: block;
  text-align: center;
  margin-top: 40px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.portal-link-profile:active {
  background: var(--bg-card-hover);
  color: var(--accent);
}

#header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  letter-spacing: -0.3px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 10px;
}

.tab {
  flex: 1;
  padding: 7px 4px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--accent);
  color: #000;
}

/* Search */
.search-bar {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-field {
  position: relative;
  flex: 1;
  min-width: 0;
}
.actions-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.actions-btn:hover, .actions-btn:active {
  background: var(--accent-glow, rgba(212,175,55,0.15));
  color: var(--text);
}
.actions-btn svg {
  width: 20px;
  height: 20px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}

#search {
  width: 100%;
  padding: 10px 36px 10px 38px;
  border: none;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

#search::placeholder {
  color: var(--text-secondary);
}

#search:focus {
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-secondary);
  color: var(--bg);
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
}

/* ========== EPISODE LIST ========== */
.episode-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 140px;
}

.episode-count {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 0 4px;
  font-weight: 500;
}

.episode-card {
  display: flex;
  align-items: center;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  gap: 12px;
  position: relative;
}

.episode-card:active {
  background: var(--bg-card-hover);
  transform: scale(0.98);
}

.episode-card.playing {
  background: var(--accent-dim);
  border: 1px solid var(--accent-glow);
}

.ep-number {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #b8922e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: #000;
  position: relative;
}

.ep-number.bonus {
  background: linear-gradient(135deg, #5e5ce6, #3634a3);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.ep-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ep-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Badge variant (ME, VU) devant le titre */
.ep-variant {
  display: inline-block;
  background: rgba(94, 92, 230, 0.2);
  color: #a6a4ff;
  padding: 0 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin-right: 6px;
  vertical-align: middle;
}

.ep-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.ep-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.badge-listened {
  background: rgba(48, 209, 88, 0.15);
  color: var(--green);
}

.badge-playing {
  background: var(--accent-dim);
  color: var(--accent);
}

/* Progress bar on episode card */
.ep-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0 0 14px 14px;
  overflow: hidden;
}

.ep-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 0 0 0 14px;
  transition: width 0.3s ease;
}

.badge-in-progress {
  background: rgba(212, 168, 67, 0.15);
  color: var(--accent);
}

.ep-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.fav-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s, transform 0.2s;
}

.fav-btn.is-fav {
  color: var(--red);
}

.fav-btn:active {
  transform: scale(1.3);
}

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

/* ========== MINI PLAYER ========== */
.mini-player {
  position: fixed;
  bottom: var(--safe-bottom);
  left: 0;
  right: 0;
  height: var(--mini-player-h);
  background: rgba(28, 28, 30, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  z-index: 50;
  transition: transform 0.3s ease;
}

.mini-player.hidden {
  transform: translateY(100%);
}

.mini-player-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  cursor: pointer;
}

.mini-playing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  flex-shrink: 0;
}

.mini-playing-indicator span {
  display: block;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: soundbar 0.8s ease-in-out infinite;
}

.mini-playing-indicator span:nth-child(1) { height: 60%; animation-delay: 0s; }
.mini-playing-indicator span:nth-child(2) { height: 100%; animation-delay: 0.2s; }
.mini-playing-indicator span:nth-child(3) { height: 40%; animation-delay: 0.4s; }

.mini-player.paused .mini-playing-indicator span {
  animation: none;
  height: 4px;
}

@keyframes soundbar {
  0%, 100% { height: 40%; }
  50% { height: 100%; }
}

.mini-player-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.mini-player-number {
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
}

.mini-player-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-player-controls {
  flex-shrink: 0;
}

.mini-control-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 10px;
  cursor: pointer;
}

.mini-control-btn svg {
  width: 28px;
  height: 28px;
}

/* ========== FULL PLAYER ========== */
.full-player {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 24px calc(var(--safe-bottom) + 20px);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  transform: translateY(0);
  overflow: hidden;
}

.full-player.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.full-player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  cursor: pointer;
}

.close-btn svg {
  width: 28px;
  height: 28px;
}

.full-player-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.fav-header-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--text-secondary);
}

.fav-header-btn.is-fav {
  color: var(--red);
}

.fav-header-btn.is-fav .icon-heart-outline { display: none; }
.fav-header-btn.is-fav .icon-heart-filled { display: block; }
.fav-header-btn:not(.is-fav) .icon-heart-outline { display: block; }
.fav-header-btn:not(.is-fav) .icon-heart-filled { display: none; }

.fav-header-btn svg {
  width: 24px;
  height: 24px;
}

/* Artwork */
.full-player-artwork {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.artwork-circle {
  width: min(260px, 55vw);
  height: min(260px, 55vw);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8a6b1e);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 60px rgba(212, 168, 67, 0.2);
}

.artwork-number {
  font-size: min(72px, 18vw);
  font-weight: 900;
  color: #000;
  letter-spacing: -2px;
}

/* Info */
.full-player-info {
  text-align: center;
  padding: 20px 0 12px;
}

.full-player-info h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1.3;
}

.player-date {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Progress */
.progress-container {
  padding: 8px 0;
}

.progress-bar {
  position: relative;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
  touch-action: none;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
}

.progress-handle {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.2s;
}

.progress-bar:active .progress-handle,
.progress-bar.dragging .progress-handle {
  opacity: 1;
}

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* Controls */
.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 12px 0;
}

.control-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  position: relative;
  padding: 8px;
  transition: transform 0.15s;
}

.control-btn:active {
  transform: scale(0.9);
}

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

.play-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

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

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

.rewind-label, .forward-label {
  position: absolute;
  font-size: 9px;
  font-weight: 800;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin-top: 1px;
}

/* Speed */
.speed-control {
  text-align: center;
  padding-bottom: 8px;
}

.speed-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

/* ========== LOADING ========== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  gap: 16px;
  color: var(--text-secondary);
}

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

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

/* ========== EMPTY STATE ========== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 15px;
  font-weight: 500;
}

/* ========== SCROLLBAR ========== */
.episode-list::-webkit-scrollbar {
  width: 0;
}

/* ========== ANIMATIONS ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.episode-card {
  animation: fadeIn 0.3s ease forwards;
}

/* ========== MENU D'ACTIONS GROUPEES ========== */
.actions-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 180;
  animation: fadeIn 0.15s ease;
}
.actions-menu-backdrop.hidden { display: none; }

.actions-menu {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, 92vw);
  background: var(--bg-elevated);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  padding: 14px;
  z-index: 181;
  animation: fadeIn 0.18s ease;
}
.actions-menu.hidden { display: none; }

.actions-menu-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 4px 10px;
}

.actions-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 10px;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
  transition: background 0.12s;
}
.actions-menu-item:hover, .actions-menu-item:active {
  background: rgba(255,255,255,0.05);
}

.actions-menu-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(212,175,55,0.15);
  color: var(--accent, #d4af37);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.actions-menu-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.actions-menu-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ========== PLAYER : bouton nav prev/next ========== */
.control-btn-nav {
  opacity: 0.75;
}
.control-btn-nav:hover, .control-btn-nav:active {
  opacity: 1;
}

/* ========== MEDIA QUERIES ========== */
@media (min-width: 500px) {
  .episode-list {
    max-width: 480px;
    margin: 0 auto;
  }
  #header {
    max-width: 480px;
    margin: 0 auto;
  }
}
