/* ============================================================
   EroideMusic — layout e componenti (1:1 dalle viste SwiftUI)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--background);
  color: var(--text-primary);
  font-family: "Manrope", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* i campi di testo devono restare selezionabili/scrivibili (iOS blocca la tastiera con user-select:none) */
input, textarea, [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
img { display: block; }

#app { position: fixed; inset: 0; background: var(--background); }

/* Icone Material */
.micon {
  font-family: "Material Icons Round";
  font-weight: normal; font-style: normal;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1; letter-spacing: normal; text-transform: none; white-space: nowrap;
  -webkit-font-feature-settings: "liga"; font-feature-settings: "liga";
  flex: none;
}
.micon.outlined { font-family: "Material Icons Outlined"; }

/* Tocco: leggera pressione (come PressableStyle) */
.pressable { transition: transform .12s ease-out, opacity .12s ease-out; }
.pressable:active { transform: scale(.92); opacity: .75; }
.press-row:active { background: rgba(255,255,255,.06); }

/* ---- Struttura schermo ---- */
.tabhost { position: absolute; inset: 0; }
.tab-page { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .22s ease-in-out; }
.tab-page.active { opacity: 1; pointer-events: auto; }
/* solo la schermata in cima dello stack del tab attivo riceve i tocchi */
.tab-page > .screen { opacity: 0; pointer-events: none; }
.tab-page.active > .screen.is-top { opacity: 1; pointer-events: auto; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--background); }
.scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--safe-top);
}
/* spazio in fondo per bottom bar (62 + inset) + mini player (60+6) */
.scroll-inner { padding-bottom: calc(62px + var(--safe-bottom) + var(--mini-pad, 0px) + 12px); }

::-webkit-scrollbar { width: 0; height: 0; }

/* ---- Barra in basso ---- */
.bottombar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(62px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: linear-gradient(to bottom, rgba(9,8,15,.92), rgba(9,8,15,1));
  z-index: 30;
}
.bottombar .tabbtn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-secondary);
}
.bottombar .tabbtn.sel { color: #fff; }
.bottombar .tabbtn .lbl { font: var(--t-label-small); letter-spacing: .6px; }

/* ---- Header grande schermata ---- */
.screen-head { padding: 10px 16px 4px; display: flex; align-items: flex-end; gap: 8px; }
.screen-head .title { flex: 1; }
.head-actions { display: flex; align-items: center; }
.icon-btn {
  width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-primary);
}
.icon-btn.secondary { color: var(--text-secondary); }

/* ---- Chip ---- */
.chip {
  height: 32px; padding: 0 16px; border-radius: 16px;
  font: var(--t-label-large); font-weight: 600; letter-spacing: .1px;
  color: var(--text-primary); background: var(--surface-high);
  display: inline-flex; align-items: center; white-space: nowrap;
}
.chip.sel { background: var(--violet); color: #fff; }
.chip.square { border-radius: 8px; background: transparent; border: 1px solid var(--outline); }
.chip.square.sel { background: var(--violet); border-color: transparent; color: #fff; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 6px; }

/* ---- Riga brano (TrackRow) ---- */
.track-row { display: flex; align-items: center; padding: 7px 4px 7px 16px; gap: 0; }
.track-row .idx { width: 30px; flex: none; color: var(--text-secondary); font: var(--t-body-medium); }
.track-row .art { width: 52px; height: 52px; margin-right: 12px; flex: none; border-radius: 6px; overflow: hidden; position: relative; }
.track-row .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.track-row .ttl { font: var(--t-title-small); font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-row .ttl.current { color: var(--violet); }
.track-row .sub { display: flex; align-items: center; gap: 0; font: var(--t-body-small); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-row .sub .micon { margin-right: 4px; }

.src-badge {
  font: var(--t-label-small); letter-spacing: .6px; text-transform: uppercase;
  color: var(--background); background: var(--text-secondary);
  padding: 1px 4px; border-radius: 3px; margin-right: 6px;
}

/* ---- Artwork / placeholder ---- */
.artwork { width: 100%; height: 100%; background: var(--surface-high); position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.artwork img { width: 100%; height: 100%; object-fit: cover; }
.artwork .ph-icon { color: rgba(255,255,255,.85); }
.artwork.circle { border-radius: 50%; }

/* ---- MediaCard / carousel ---- */
.carousel { display: flex; gap: 14px; overflow-x: auto; padding: 0 16px; }
.media-card { width: 148px; flex: none; display: flex; flex-direction: column; }
.media-card.circle { align-items: center; text-align: center; }
.media-card .cover { width: 148px; height: 148px; border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.media-card.circle .cover { border-radius: 50%; }
.media-card .mc-title { font: var(--t-title-small); color: var(--text-primary); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; }
.media-card .mc-title.two { -webkit-line-clamp: 2; }
.media-card .mc-title.current { color: var(--violet); }
.media-card .mc-sub { font: var(--t-body-small); color: var(--text-secondary); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

/* ---- SectionHeader ---- */
.section-head { display: flex; align-items: flex-end; padding: 22px 8px 10px 16px; }
.section-head .sh-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.section-head .sh-sub { font: var(--t-label-small); letter-spacing: .6px; text-transform: uppercase; color: var(--text-secondary); }
.section-head .sh-title { font: var(--t-title-large); letter-spacing: -.2px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-btn { font: var(--t-label-large); letter-spacing: .1px; color: var(--violet); padding: 10px 12px; }
.text-btn.secondary { color: var(--text-secondary); }

/* ---- Quick grid (Home) ---- */
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 16px; }
.quick-item { display: flex; align-items: center; gap: 12px; height: 56px; background: var(--surface-high); border-radius: 8px; overflow: hidden; padding-right: 10px; }
.quick-item .qi-art { width: 56px; height: 56px; flex: none; }
.quick-item .qi-title { font: var(--t-title-small); font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

/* ---- GradientIconTile ---- */
.gtile { display: flex; align-items: center; justify-content: center; color: #fff; }
.gtile.round { border-radius: 50%; }

/* ---- Card generiche (Offline/Welcome) ---- */
.card { margin: 0 16px; padding: 16px; border-radius: 14px; background: var(--surface); }
.card.offline { display: flex; align-items: center; gap: 12px; background: var(--surface-high); }
.card.offline .micon { color: var(--offline-green); }
.card-welcome { background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.card-welcome .cw-title { font: var(--t-title-large); letter-spacing: -.2px; }
.card-welcome .cw-sub { font: var(--t-body-medium); color: var(--text-secondary); }

/* ---- Stati vuoti/errore/caricamento ---- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 40px 32px; }
.empty-state .es-icon { width: 72px; height: 72px; margin-bottom: 18px; }
.empty-state .es-title { font: var(--t-title-large); letter-spacing: -.2px; margin-bottom: 6px; }
.empty-state .es-msg { font: var(--t-body-medium); color: var(--text-secondary); }
.empty-state .es-btn { margin-top: 18px; height: 40px; padding: 0 24px; border-radius: 20px; background: #fff; color: #000; font: var(--t-label-large); letter-spacing: .1px; }

/* Skeleton */
.skeleton { animation: pulse .7s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .35; } to { opacity: .8; } }
.sk-row { display: flex; gap: 12px; padding: 8px 16px; align-items: center; }
.sk-art { width: 52px; height: 52px; border-radius: 6px; background: var(--surface-highest); flex: none; }
.sk-line { height: 12px; border-radius: 4px; background: var(--surface-highest); }
.sk-line.sm { height: 10px; background: var(--surface-high); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--surface-highest); border-top-color: var(--violet); border-radius: 50%; animation: spin .9s linear infinite; margin: 32px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- ActionRow / Divider ---- */
.action-row { display: flex; align-items: center; gap: 18px; padding: 14px 24px; }
.action-row .micon { flex: none; }
.action-row .ar-label { font: var(--t-body-large); }
.divider { height: 1px; background: var(--outline); }

/* ---- Mini player ---- */
.mini-player {
  position: absolute; left: 8px; right: 8px;
  bottom: calc(62px + var(--safe-bottom) + 6px);
  height: 60px; border-radius: 14px; overflow: hidden;
  background: var(--surface-high);
  display: flex; align-items: center; gap: 10px; padding: 0 8px 0 8px;
  z-index: 25; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.mini-player .mp-art { width: 44px; height: 44px; border-radius: 8px; overflow: hidden; flex: none; }
.mini-player .mp-meta { flex: 1; min-width: 0; }
.mini-player .mp-title { font: var(--t-title-small); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-player .mp-sub { font: var(--t-body-small); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-player .mp-progress { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--violet); }

/* ---- Player full ---- */
.player-full {
  position: absolute; inset: 0; z-index: 40; background: var(--background);
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .32s cubic-bezier(.4,0,.2,1);
  padding: var(--safe-top) 24px var(--safe-bottom);
  overflow-y: auto; overscroll-behavior: contain;
}
.player-full.open { transform: translateY(0); }
.pf-top { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.pf-context { text-align: center; flex: 1; }
.pf-context .pf-from { font: var(--t-label-small); letter-spacing: .6px; color: var(--text-secondary); }
.pf-context .pf-ctx { font: var(--t-label-large); }
.pf-art { flex: 1 1 auto; min-height: 120px; display: flex; align-items: center; justify-content: center; padding: 16px 0; }
.pf-art .pf-cover { width: min(78vw, 38vh, 360px); height: min(78vw, 38vh, 360px); flex: none; border-radius: 16px; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,.5); }
.pf-info { display: flex; align-items: center; gap: 12px; margin: 8px 0 14px; }
.pf-info .pf-meta { flex: 1; min-width: 0; }
.pf-info .pf-title { font: var(--t-headline-small); letter-spacing: -.3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-info .pf-artist { font: var(--t-body-large); color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seekbar { height: 4px; border-radius: 2px; background: var(--surface-highest); position: relative; margin: 6px 0 4px; }
.seekbar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; background: var(--brand-horizontal); }
.seek-times { display: flex; justify-content: space-between; font: var(--t-label-small); color: var(--text-secondary); }
.pf-controls { display: flex; align-items: center; justify-content: space-between; margin: 18px 0; }
.pf-controls .big-play { width: 72px; height: 72px; border-radius: 50%; background: var(--brand); display: flex; align-items: center; justify-content: center; color: #fff; }
.source-chip { display: inline-flex; align-items: center; gap: 8px; align-self: center; margin-bottom: 10px; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--surface-high); color: var(--text-secondary); font: var(--t-label-large); }
.pf-bottom { display: flex; align-items: center; justify-content: space-around; padding-top: 6px; }
.pf-bottom .pb-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text-secondary); font: var(--t-label-small); letter-spacing: .4px; padding: 6px 10px; }
.ctrl { color: var(--text-primary); }
.ctrl.accent { color: var(--violet); }

/* ---- Sheet (bottom) e dialog ---- */
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.55); z-index: 50; opacity: 0; transition: opacity .25s ease; }
.scrim.show { opacity: 1; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 51;
  pointer-events: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 10px 0 calc(16px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
  max-height: 88%; display: flex; flex-direction: column;
}
.sheet.show { transform: translateY(0); }
.sheet .grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--surface-highest); margin: 4px auto 10px; }
.sheet .sheet-title { font: var(--t-title-large); letter-spacing: -.2px; padding: 4px 24px 12px; }
.sheet .sheet-scroll { overflow-y: auto; }
.sheet-item { display: flex; align-items: center; gap: 18px; padding: 14px 24px; }
.sheet-item .micon { flex: none; }
.sheet-item .si-label { font: var(--t-body-large); flex: 1; }
.sheet-item .si-trail { color: var(--text-secondary); font: var(--t-body-medium); }
.sheet-item.danger .si-label, .sheet-item.danger .micon { color: var(--error); }

.dialog-wrap { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 32px; }
.dialog { position: relative; z-index: 60; width: 100%; max-width: 340px; background: var(--surface-high); border-radius: 20px; padding: 22px; }
.dialog .dlg-title { font: var(--t-title-large); letter-spacing: -.2px; margin-bottom: 8px; }
.dialog .dlg-msg { font: var(--t-body-medium); color: var(--text-secondary); margin-bottom: 16px; }
.dialog input { width: 100%; height: 44px; border-radius: 10px; background: var(--surface-highest); border: 1px solid var(--outline); color: var(--text-primary); padding: 0 14px; font: var(--t-body-large); margin-bottom: 16px; }
.dialog input:focus { outline: none; border-color: var(--violet); }
.dialog .dlg-actions { display: flex; justify-content: flex-end; gap: 4px; }

/* ---- Snackbar ---- */
.snackbar {
  position: absolute; left: 16px; right: 16px; z-index: 55;
  bottom: calc(62px + var(--safe-bottom) + 70px);
  background: var(--surface-highest); border-radius: 12px; padding: 14px 16px;
  font: var(--t-body-medium); box-shadow: 0 8px 24px rgba(0,0,0,.5);
  display: flex; align-items: center; gap: 12px;
  animation: snack-in .25s ease;
}
.snackbar .sb-action { color: var(--violet); font: var(--t-label-large); letter-spacing: .1px; margin-left: auto; }
@keyframes snack-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---- Toggle (Switch) ---- */
.switch { width: 46px; height: 28px; border-radius: 14px; background: var(--surface-highest); position: relative; flex: none; transition: background .2s; }
.switch.on { background: var(--violet); }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on .knob { transform: translateX(18px); }

/* ---- Impostazioni ---- */
.settings-group-label { font: var(--t-label-medium); letter-spacing: .2px; text-transform: uppercase; color: var(--violet); padding: 22px 24px 8px; }
.setting-row { display: flex; align-items: center; gap: 16px; padding: 14px 24px; }
.setting-row .sr-text { flex: 1; min-width: 0; }
.setting-row .sr-title { font: var(--t-body-large); }
.setting-row .sr-sub { font: var(--t-body-small); color: var(--text-secondary); margin-top: 2px; }
.setting-row .sr-value { font: var(--t-body-medium); color: var(--text-secondary); }
.info-text { font: var(--t-body-small); color: var(--text-tertiary); padding: 12px 24px 0; line-height: 18px; }

/* Equalizzatore */
.eq-wrap { padding: 8px 24px 4px; }
.eq-bands { display: flex; align-items: flex-end; justify-content: space-between; height: 160px; gap: 6px; }
.eq-band { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.eq-slider { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; }
.eq-slider input[type=range] { writing-mode: vertical-lr; direction: rtl; width: 6px; height: 120px; accent-color: var(--violet); }
.eq-band .eq-hz { font: var(--t-label-small); color: var(--text-tertiary); margin-top: 6px; }

/* ---- DetailHeader ---- */
.detail-head { padding: calc(var(--safe-top) + 4px) 8px 0; }
.detail-head .dh-cover { width: 180px; height: 180px; border-radius: 12px; overflow: hidden; margin: 8px auto 16px; box-shadow: 0 12px 32px rgba(0,0,0,.4); }
.detail-head .dh-cover.big { background: var(--brand); }
.detail-head .dh-title { font: var(--t-headline-medium); letter-spacing: -.5px; text-align: center; padding: 0 16px; }
.detail-head .dh-sub { font: var(--t-body-medium); color: var(--text-secondary); text-align: center; margin-top: 6px; }
.detail-actions { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px; }
.btn-play-lg { height: 48px; padding: 0 28px; border-radius: 24px; background: var(--brand); color: #fff; display: inline-flex; align-items: center; gap: 8px; font: var(--t-label-large); letter-spacing: .1px; }
.btn-ghost { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--outline); display: inline-flex; align-items: center; justify-content: center; color: var(--text-primary); }

/* ---- Esplora generi (griglia tiles) ---- */
.explore-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 16px; }
.explore-tile { height: 84px; border-radius: 12px; padding: 12px; display: flex; align-items: flex-start; color: #fff; font: var(--t-title-medium); letter-spacing: -.1px; position: relative; overflow: hidden; }

/* ---- Campo di ricerca ---- */
.search-field { margin: 4px 16px 6px; height: 46px; border-radius: 23px; background: var(--surface-high); display: flex; align-items: center; gap: 10px; padding: 0 16px; }
.search-field input { flex: 1; min-width: 0; background: none; border: none; outline: none; color: var(--text-primary); font: var(--t-body-large); }
.search-field input::placeholder { color: var(--text-tertiary); }

/* ---- Intro ---- */
.intro { position: absolute; inset: 0; z-index: 100; background: var(--background); display: flex; align-items: center; justify-content: center; flex-direction: column; }
.intro .intro-glow { position: absolute; width: 70vmin; height: 70vmin; border-radius: 50%; background: radial-gradient(circle, rgba(124,58,237,.42), transparent 62%); }
.intro .intro-logo { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; }
.intro .intro-word { display: flex; font: 800 38px/40px "Manrope"; letter-spacing: -.8px; margin-top: 26px; }
.intro .intro-word span { opacity: 0; transform: translateY(22px); }
.intro .intro-tagline { font: var(--t-body-medium); color: var(--text-secondary); margin-top: 8px; opacity: 0; }

/* utilità */
.row { display: flex; align-items: center; }
.grow { flex: 1; min-width: 0; }
.hpad { padding-left: 16px; padding-right: 16px; }
.hidden { display: none !important; }

/* ---- Marquee per titoli lunghi nel player ---- */
.pf-info .pf-title.scrolling { text-overflow: clip; }
.pf-info .pf-title.scrolling > span {
  display: inline-block; white-space: nowrap; will-change: transform;
  animation: pf-marquee var(--marquee-dur, 8s) ease-in-out infinite;
}
@keyframes pf-marquee {
  0%, 12% { transform: translateX(0); }
  50%, 62% { transform: translateX(var(--shift, -40px)); }
  100% { transform: translateX(0); }
}
