/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #06121a;
  --text-primary: #f1f5f9;
  --text-secondary: #9fb9c8;
  --accent:       #38d5e6;
  --accent-2:     #f59e0b;
  --accent-glow:  rgba(56,213,230,0.34);
  --pool-deep:    #032f60;
  --pool-mid:     #075c8f;
  --pool-bright:  #10b7d7;
  --stone:        #d8e0dd;
  --danger:       #ef4444;
  --font:         'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: #071823;
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ── Video background ──────────────────────────────────────────────────────── */
.video-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -2;
}

.video-overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    180deg,
    rgba(4, 14, 35, 0.52) 0%,
    rgba(4, 14, 35, 0.30) 45%,
    rgba(4, 14, 35, 0.72) 100%
  );
}

/* ── App layout ────────────────────────────────────────────────────────────── */
.app-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
}

/* ── Landing screen ────────────────────────────────────────────────────────── */
.landing-screen {
  min-height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem 3rem;
  cursor: default;
}

.landing-screen.drag-over .btn-cta {
  box-shadow: 0 0 0 3px rgba(125,211,252,0.7), 0 8px 32px rgba(6,182,212,0.5);
}

/* ── Logo ──────────────────────────────────────────────────────────────────── */
.landing-header {
  position: fixed;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.35));
}

.logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.logo-accent { color: #7dd3fc; }

/* ── Hero ──────────────────────────────────────────────────────────────────── */
.landing-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 520px;
  width: 100%;
  gap: 0;
  background: rgba(4, 14, 36, 0.55);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 24px;
  padding: 2.5rem 2rem 2rem;
  box-shadow: 0 8px 48px rgba(0,0,0,0.45);
}

.landing-title {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.5px;
  margin-bottom: 1.25rem;
  text-shadow: 0 2px 16px rgba(0,0,0,0.55);
}

.landing-title em {
  font-style: normal;
  color: #7dd3fc;
}

.landing-sub {
  font-size: clamp(0.9rem, 2.5vw, 1.05rem);
  color: rgba(255,255,255,0.65);
  line-height: 1.65;
  margin-bottom: 2.5rem;
}

/* ── CTA button ────────────────────────────────────────────────────────────── */
.btn-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 2.5rem;
  background: linear-gradient(135deg, #0ea5e9, #06b6d4);
  color: white;
  border: none;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  box-shadow: 0 6px 24px rgba(6,182,212,0.45);
  transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 2.5rem;
  min-height: 52px;
}

.btn-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(6,182,212,0.55);
}

/* ── 3 Step indicator ──────────────────────────────────────────────────────── */
.landing-steps {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.landing-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.landing-step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(8px);
  border: 1.5px solid rgba(125,211,252,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #7dd3fc;
}

.landing-step-label {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.5);
  text-align: center;
  line-height: 1.3;
}

.landing-step-label strong {
  display: block;
  color: rgba(255,255,255,0.8);
  font-size: 0.75rem;
}

.landing-step-sep {
  color: rgba(255,255,255,0.2);
  font-size: 1rem;
  padding-bottom: 1.2rem;
}

/* ── Privacy ───────────────────────────────────────────────────────────────── */
.privacy-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  font-size: 0.78rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: color 0.15s;
}

.privacy-btn:hover { color: rgba(255,255,255,0.65); }

.privacy-info-icon {
  font-size: 0.65rem;
  border: 1px solid currentColor;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.privacy-tooltip {
  margin-top: 0.5rem;
  background: rgba(10,20,40,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(125,211,252,0.2);
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.6);
  max-width: 300px;
  text-align: center;
  line-height: 1.6;
}

/* ── Pool wrapper ──────────────────────────────────────────────────────────── */
.pool-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* ── Pool container ────────────────────────────────────────────────────────── */
.pool-container {
  position: relative;
  border-radius: 18px 18px 0 0;
  overflow: hidden;
  box-shadow:
    0 0 0 3px rgba(77,184,204,0.45),
    0 20px 60px rgba(0,0,0,0.55),
    0 0 80px rgba(0,140,200,0.12);
}

/* ── Pool edges ────────────────────────────────────────────────────────────── */
.pool-edge {
  height: 70px;
  background:
    url('images/pool-edge.png') center / cover no-repeat,
    linear-gradient(180deg, #8ed8e8 0%, #0c789b 100%);
  position: relative;
  z-index: 10;
}

.pool-edge-bottom {
  transform: scaleY(-1);
}

/* ── Salvaggente ───────────────────────────────────────────────────────────── */
.lifebuoy {
  position: absolute;
  right: -16px;
  top: 50%;
  transform: translateY(-50%) rotate(12deg);
  width: 100px;
  height: 100px;
  object-fit: contain;
  z-index: 40;
  filter: drop-shadow(-3px 4px 12px rgba(0,0,0,0.65));
  pointer-events: none;
}

/* ── Lanes container ───────────────────────────────────────────────────────── */
.lanes-container {
  position: relative;
  background-color: #075c8f;
  background-image:
    url('images/pool-water.png'),
    radial-gradient(circle at 18% 22%, rgba(92,224,255,0.5), transparent 28%),
    linear-gradient(135deg, #0797bf 0%, #064f83 52%, #032f60 100%);
  background-size: 420px 420px, cover, cover;
  background-position: center, center, center;
}

.lanes-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0,35,75,0.54);
  pointer-events: none;
  z-index: 0;
}

/* ── Lane rope divider ─────────────────────────────────────────────────────── */
.lane-rope {
  position: relative;
  z-index: 5;
  height: 32px;
  overflow: hidden;
  line-height: 0;
}

.lane-rope img {
  width: 100%;
  height: 32px;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* ── Single lane ───────────────────────────────────────────────────────────── */
.lane {
  position: relative;
  z-index: 2;
  padding: 12px 120px 12px 16px;
}

.lane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.lane-badge {
  font-size: 0.6rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.lane-badge-output {
  background: var(--accent-2);
  color: #120800;
  box-shadow: 0 2px 8px rgba(245,158,11,0.4);
}

.lane-badge-source {
  background: rgba(255,255,255,0.14);
  color: rgba(255,255,255,0.8);
  border: 1px solid rgba(255,255,255,0.2);
}

.lane-name {
  font-size: 0.82rem;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.lane-count {
  font-size: 0.65rem;
  opacity: 0.4;
  margin-left: auto;
  margin-right: 10px;
  flex-shrink: 0;
}

/* ── Pages row ─────────────────────────────────────────────────────────────── */
.pages-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  align-items: flex-end;
  padding: 4px 2px 6px;
  min-height: 110px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.18) transparent;
}

.pages-row::-webkit-scrollbar { height: 4px; }
.pages-row::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }

/* ── Page card ─────────────────────────────────────────────────────────────── */
.page-card {
  flex-shrink: 0;
  text-align: center;
  position: relative;
  cursor: grab;
  user-select: none;
}

.page-card:active { cursor: grabbing; }

.page-face {
  width: 64px;
  height: 84px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}

.page-card:hover .page-face {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 10px 24px rgba(0,0,0,0.55);
}

.page-face.output-face {
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.28);
  backdrop-filter: blur(4px);
}

.page-face.source-face {
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(3px);
}

.page-face canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
  border-radius: 4px;
}

.page-face .page-placeholder {
  font-size: 0.58rem;
  color: rgba(255,255,255,0.5);
  text-align: center;
  padding: 4px;
}

.page-num {
  font-size: 0.58rem;
  margin-top: 4px;
  opacity: 0.45;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9);
}

/* ── Remove button (Risultato only) ────────────────────────────────────────── */
.page-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: var(--danger);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  z-index: 10;
  line-height: 1;
  padding: 0;
}

.page-card:hover .page-remove-btn {
  display: flex;
}

/* ── Drag states ───────────────────────────────────────────────────────────── */
.page-card.dragging .page-face {
  opacity: 0.4;
  transform: scale(0.95);
}

.drop-indicator {
  flex-shrink: 0;
  width: 8px;
  height: 84px;
  background: var(--accent-2);
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, width 0.15s;
  align-self: flex-end;
}

.drop-indicator.active {
  opacity: 1;
  width: 12px;
}

/* Risultato lane drop highlight */
.lane.output-lane.drag-target-over .pages-row {
  background: rgba(245,158,11,0.08);
  border-radius: 8px;
}

/* ── Pool add bar ──────────────────────────────────────────────────────────── */
.pool-add-bar {
  position: relative;
  z-index: 5;
  display: flex;
  justify-content: center;
  padding: 10px 16px;
  background: rgba(0,0,0,0.15);
}

.add-pdf-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: rgba(255,255,255,0.07);
  border: 1.5px dashed rgba(255,255,255,0.22);
  border-radius: 10px;
  color: rgba(255,255,255,0.6);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.add-pdf-btn:hover {
  background: rgba(56,213,230,0.1);
  border-color: rgba(56,213,230,0.42);
  color: var(--accent);
}

/* ── Download bar ──────────────────────────────────────────────────────────── */
.dl-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: rgba(8,8,15,0.85);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.07);
  border-top: none;
  border-radius: 0 0 18px 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.dl-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.dl-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  background: var(--accent-2);
  color: #000;
  font-weight: 800;
  font-size: 0.88rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font);
  box-shadow: 0 4px 16px rgba(245,158,11,0.35);
  transition: opacity 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

.dl-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

.dl-btn:not(:disabled):hover {
  box-shadow: 0 6px 24px rgba(245,158,11,0.55);
}

.dl-btn-loader {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0,0,0,0.25);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.dl-btn.loading .dl-btn-text { opacity: 0; }
.dl-btn.loading .dl-btn-loader { display: block; position: absolute; }

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

/* ── Status toast ──────────────────────────────────────────────────────────── */
.status-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(30,30,40,0.95);
  border: 1px solid rgba(255,255,255,0.1);
}

.status-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.status-toast.success { border-color: rgba(52,211,153,0.4); color: #34d399; }
.status-toast.error   { border-color: rgba(248,113,113,0.4); color: #f87171; }

/* ── Risultato vuoto ───────────────────────────────────────────────────────── */
.output-empty-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 84px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.3);
  font-style: italic;
  border: 1.5px dashed rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 0 16px;
  flex-shrink: 0;
  min-width: 180px;
}

/* ── Tuffo overlay ─────────────────────────────────────────────────────────── */
.tuffo-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: tuffoEnter 0.4s cubic-bezier(0.4,0,0.2,1) forwards;
}

@keyframes tuffoEnter {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Acqua che sale dal basso e inghiotte lo schermo */
.tuffo-water {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    #0a3a6e 0%,
    #0d5a9e 30%,
    #1070c0 60%,
    #0e87d4 100%
  );
  transform: translateY(100%);
  animation: waterRise 1.0s cubic-bezier(0.4,0,0.2,1) 0.1s forwards;
}

@keyframes waterRise {
  0%   { transform: translateY(100%); }
  100% { transform: translateY(0%); }
}

/* Caustiche luminose sott'acqua */
.tuffo-water::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    120deg,
    transparent 0px,
    rgba(255,255,255,0.04) 40px,
    transparent 80px
  );
  animation: caustics 1.2s ease-in-out infinite alternate;
}

@keyframes caustics {
  from { transform: scaleX(1) rotate(0deg); opacity: 0.5; }
  to   { transform: scaleX(1.08) rotate(1deg); opacity: 1; }
}

/* Bolle che salgono */
.tuffo-bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tuffo-bubbles span {
  position: absolute;
  bottom: -60px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(2px);
  animation: bubbleRise var(--dur, 1.2s) ease-in var(--delay, 0s) forwards;
}

.tuffo-bubbles span:nth-child(1) { left: 15%; width: 18px; height: 18px; --dur: 1.4s; --delay: 0.5s; }
.tuffo-bubbles span:nth-child(2) { left: 35%; width: 10px; height: 10px; --dur: 1.1s; --delay: 0.7s; }
.tuffo-bubbles span:nth-child(3) { left: 55%; width: 24px; height: 24px; --dur: 1.6s; --delay: 0.4s; }
.tuffo-bubbles span:nth-child(4) { left: 70%; width: 12px; height: 12px; --dur: 1.2s; --delay: 0.9s; }
.tuffo-bubbles span:nth-child(5) { left: 82%; width: 8px;  height: 8px;  --dur: 1.0s; --delay: 0.6s; }
.tuffo-bubbles span:nth-child(6) { left: 25%; width: 16px; height: 16px; --dur: 1.3s; --delay: 1.0s; }

@keyframes bubbleRise {
  0%   { transform: translateY(0) scale(1); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-110vh) scale(0.5); opacity: 0; }
}

/* Flash bianco risalita */
.tuffo-overlay.surface-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  animation: surfaceFlash 0.45s ease-out forwards;
  pointer-events: none;
  z-index: 10;
}

@keyframes surfaceFlash {
  0%   { opacity: 0; }
  20%  { opacity: 0.9; }
  100% { opacity: 0; }
}

.tuffo-overlay.tuffo-fade-out {
  animation: tuffoExit 0.55s cubic-bezier(0.4,0,0.2,1) forwards;
}

@keyframes tuffoExit {
  0%   { opacity: 1; filter: brightness(1); }
  30%  { filter: brightness(2); }
  100% { opacity: 0; filter: brightness(1); }
}

/* ── Transizioni landing → pool ────────────────────────────────────────────── */
.fade-out {
  animation: landingExit 0.5s cubic-bezier(0.4,0,1,1) forwards;
}

@keyframes landingExit {
  0%   { opacity: 1; transform: scale(1)    filter: blur(0); }
  100% { opacity: 0; transform: scale(0.96); filter: blur(4px); }
}

.fade-in {
  animation: poolEnter 0.65s cubic-bezier(0,0,0.2,1) forwards;
}

@keyframes poolEnter {
  0%   { opacity: 0; transform: translateY(24px) scale(0.98); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── CTA button animations ─────────────────────────────────────────────────── */
.btn-cta {
  position: relative;
  overflow: hidden;
}

/* Onda idle sul bottone */
.btn-cta::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.15) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: btnShimmer 2.8s ease-in-out infinite;
}

@keyframes btnShimmer {
  0%   { transform: translateX(-100%); }
  60%  { transform: translateX(100%); }
  100% { transform: translateX(100%); }
}

/* Ripple al click */
.btn-cta .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.35);
  transform: scale(0);
  animation: rippleExpand 0.6s linear forwards;
  pointer-events: none;
}

@keyframes rippleExpand {
  to { transform: scale(4); opacity: 0; }
}

/* Bounce emoji onda */
.btn-cta .wave-emoji {
  display: inline-block;
  animation: waveFloat 1.8s ease-in-out infinite;
}

@keyframes waveFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%       { transform: translateY(-3px) rotate(-8deg); }
  60%       { transform: translateY(1px) rotate(4deg); }
}

/* ── Pool mode: sfondo blu neutro ──────────────────────────────────────────── */
body.pool-mode .video-bg,
body.pool-mode .video-overlay {
  display: none;
}

body.pool-mode {
  background: linear-gradient(180deg, #071d3a 0%, #0a2748 50%, #061424 100%);
}

@media (max-width: 680px) {
  .landing-title {
    font-size: 1.75rem;
  }

  .landing-sub {
    font-size: 0.9rem;
  }

  .btn-cta {
    width: 100%;
    justify-content: center;
  }

  .pool-wrapper {
    padding: 1.25rem 0.75rem 3rem;
  }
}
