:root {
  --bg: #0f172a;
  --glass: rgba(15, 23, 42, 0.75);
  --glass-border: rgba(255, 255, 255, 0.12);
  --ink: #f1f5f9;
  --accent: #0ea5e9;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  height: 100dvh;
  width: 100vw;
}

/* ─── Start overlay ─── */
.start-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #1e293b, #0f172a);
}

.start-card {
  text-align: center;
  max-width: 400px;
  padding: 40px 28px;
}

.start-card h1 {
  font-size: 2.2rem;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.start-sub {
  font-size: 1rem;
  opacity: 0.7;
  margin-bottom: 20px;
}

.start-desc {
  font-size: 0.9rem;
  opacity: 0.55;
  line-height: 1.5;
  margin-bottom: 28px;
}

.start-card button {
  border: none;
  border-radius: 12px;
  padding: 14px 40px;
  font-size: 1.1rem;
  font-weight: 600;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.start-card button:active {
  transform: scale(0.97);
}

.start-hint {
  font-size: 0.82rem;
  opacity: 0.5;
  margin-top: 14px;
}

.start-hint a {
  color: var(--accent);
  text-decoration: none;
}

/* ─── AR container fullscreen ─── */
.ar-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: transparent;
  overflow: hidden;
}

a-scene {
  position: fixed !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 0 !important;
  background: transparent !important;
}

a-scene video {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  object-fit: cover !important;
  z-index: 0 !important;
  background: #000;
  /* Fix Samsung: disattiva hardware overlay */
  border-radius: 0.1px !important;
}

a-scene canvas.a-canvas {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 1 !important;
  background: transparent !important;
}

.ar-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  padding: 24px;
  text-align: center;
}

/* ─── Idle message ─── */
.idle-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  text-align: center;
  pointer-events: none;
}

.idle-message p {
  font-size: 1.2rem;
  font-weight: 600;
  opacity: 0.85;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

.idle-sub {
  font-size: 0.85rem;
  opacity: 0.5;
  margin-top: 6px;
}

/* ─── Risk dashboard (glassmorphism) ─── */
.risk-dashboard {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 12px;
  right: 12px;
  z-index: 50;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 16px 20px 14px;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

.dash-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.dash-score {
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.score-number {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1;
  transition: color 0.3s;
}

.score-label {
  font-size: 1rem;
  opacity: 0.5;
}

.dash-class {
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: color 0.3s;
}

/* ─── Risk bar ─── */
.dash-bar-wrap {
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.1);
  overflow: hidden;
  margin-bottom: 12px;
}

.dash-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease, background 0.3s;
  background: var(--green);
}

/* ─── Marker dot indicators ─── */
.dash-markers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 8px;
  margin-bottom: 10px;
}

.marker-dot {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0.45;
  transition: opacity 0.3s;
  min-width: 0;
}

.marker-dot.active {
  opacity: 1;
}

.marker-dot .dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #64748b;
  transition: background 0.3s;
}

.marker-dot.active .dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.dot-label {
  font-size: 0.7rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── XAI notes ─── */
.dash-xai {
  list-style: none;
  padding: 0;
  margin: 0;
}

.dash-xai li {
  font-size: 0.8rem;
  opacity: 0.7;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.dash-xai li:last-child {
  border-bottom: none;
}

/* ─── Fall impact overlay ─── */
.fall-impact-overlay {
  position: fixed;
  inset: 0;
  background: #dc2626;
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 0.15s;
}

.fall-impact-overlay.flash {
  opacity: 0.5;
}

.fall-message-overlay {
  position: fixed;
  top: calc(50px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  z-index: 10000;
  pointer-events: none;
  text-align: center;
}

.fall-message-overlay .fall-message-text {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-align: center;
  max-width: 100%;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: fallMsgPulse 0.6s ease-in-out infinite alternate;
}

.fall-message-overlay .fall-message-text.crash {
  background: rgba(220, 38, 38, 0.85);
  color: #fff;
  box-shadow: 0 4px 24px rgba(220, 38, 38, 0.5);
}

.fall-message-overlay .fall-message-text.saved {
  background: rgba(22, 163, 74, 0.85);
  color: #fff;
  box-shadow: 0 4px 24px rgba(22, 163, 74, 0.5);
}

@keyframes fallMsgPulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* ─── Popup suggerimento DPI ─── */
.suggestion-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 800;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 20px 24px;
  max-width: 90vw;
  max-height: 60vh;
  overflow-y: auto;
  color: #e2e8f0;
  font-size: 0.85rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.suggestion-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f59e0b;
  margin-bottom: 10px;
}

.suggestion-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
}

.suggestion-list li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  line-height: 1.4;
}

.suggestion-list li:last-child {
  border-bottom: none;
}

.suggestion-close {
  display: block;
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #e2e8f0;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ─── Mobile tweaks ─── */
@media (max-width: 600px) {
  .start-card {
    padding: 28px 20px;
  }

  .start-card h1 {
    font-size: 1.8rem;
  }

  .start-sub {
    font-size: 0.9rem;
  }

  .start-desc {
    font-size: 0.82rem;
    margin-bottom: 20px;
  }

  .start-card button {
    padding: 12px 32px;
    font-size: 1rem;
  }

  .risk-dashboard {
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: 8px;
    right: 8px;
    padding: 10px 12px 8px;
    border-radius: 14px;
  }

  .score-number {
    font-size: 1.6rem;
  }

  .score-label {
    font-size: 0.85rem;
  }

  .dash-class {
    font-size: 0.95rem;
  }

  .dash-bar-wrap {
    margin-bottom: 8px;
  }

  .dash-markers {
    gap: 5px 6px;
  }

  .dot-label {
    font-size: 0.6rem;
  }

  .dash-xai li {
    font-size: 0.72rem;
  }

  .idle-message p {
    font-size: 1rem;
  }

  .fall-message-overlay {
    top: calc(40px + env(safe-area-inset-top, 0px));
  }

  .fall-message-overlay .fall-message-text {
    font-size: 0.95rem;
    padding: 8px 16px;
    border-radius: 10px;
  }
}

/* ─── Very small screens (iPhone SE, 320px) ─── */
@media (max-width: 380px) {
  .score-number {
    font-size: 1.4rem;
  }

  .dash-markers {
    gap: 4px 4px;
  }

  .dot-label {
    font-size: 0.52rem;
  }

  .start-card h1 {
    font-size: 1.5rem;
  }
}
