:root {
  --bg: #0c0f16;
  --panel: rgba(20, 25, 38, 0.94);
  --border: rgba(255, 255, 255, 0.14);
  --text: #f3f6ff;
  --muted: #9aa7c2;
  --accent: #ff7b00;
  --accent2: #00d4ff;
  --p1: #38bdf8;
  --p2: #fb7185;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 10px) 12px env(safe-area-inset-bottom, 10px);
  overflow-y: auto;
  touch-action: pan-y;
}

.screen.active {
  display: flex;
}

#screen-arena {
  padding: 0;
  overflow: hidden;
  touch-action: none;
}

.panel {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ff9d2e, #ff4d4d, #38bdf8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}

.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.seg-btn {
  padding: 11px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.seg-btn.active {
  background: linear-gradient(135deg, #ff6b00, #ff3d00);
  border-color: #ffaa44;
  box-shadow: 0 0 16px rgba(255, 107, 0, 0.35);
}

.arena-preview {
  width: 100%;
  height: 120px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 50%, #263147 0%, #101521 100%);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  font-size: 0.82rem;
  color: var(--muted);
  text-shadow: 0 1px 4px #000;
}

.camera-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #000;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

#camera-video {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 8px;
}

.cam-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.btn, .icon-btn {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 8px;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.btn.primary {
  background: linear-gradient(135deg, #ff7b00, #e63900);
  border-color: #ffaa44;
}

.btn.secondary {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.45);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.04);
}

.btn.small {
  padding: 6px 10px;
  font-size: 0.76rem;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.big-cta {
  padding: 14px;
  font-size: 1rem;
  letter-spacing: 0.03em;
}

.file-label input {
  display: none;
}

.status-note {
  margin: 0;
  min-height: 16px;
  font-size: 0.76rem;
  color: #fbbf24;
}

/* Selezione Titani */
.select-panel {
  max-height: 96vh;
  gap: 10px;
}

.select-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent2);
  text-transform: uppercase;
}

.pick-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pick-slot {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(255, 255, 255, 0.04);
}

.p1-slot { border-color: rgba(56, 189, 248, 0.45); }
.p2-slot { border-color: rgba(251, 113, 133, 0.45); }

.slot-tag {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
}

.titan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  overflow-y: auto;
  max-height: 52vh;
  padding-right: 2px;
}

.titan-card {
  position: relative;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
}

.titan-card.p1-picked {
  border-color: var(--p1);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.35);
}

.titan-card.p2-picked {
  border-color: var(--p2);
  box-shadow: 0 0 14px rgba(251, 113, 133, 0.35);
}

.titan-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.titan-swatch {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

.titan-name {
  font-weight: 800;
  font-size: 0.92rem;
}

.titan-elem {
  font-size: 0.72rem;
  color: var(--muted);
}

.titan-moves {
  font-size: 0.68rem;
  color: #cbd5e1;
  line-height: 1.25;
}

.pick-pill {
  position: absolute;
  top: -7px;
  right: 8px;
  font-size: 0.65rem;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 999px;
  color: #081018;
}

.pick-pill.p1 { background: var(--p1); }
.pick-pill.p2 { background: var(--p2); }

/* Arena & HUD */
#arena-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 8px 10px;
  gap: 8px;
  z-index: 5;
}

.hud-bottom {
  bottom: env(safe-area-inset-bottom, 0px);
}

.hud-top {
  top: env(safe-area-inset-top, 0px);
  align-items: flex-start;
}

.hud-top.rotated-180 {
  transform: rotate(180deg);
  align-items: flex-end;
}

.hud-top.cpu-mode .atk-cluster {
  display: none;
}

.hud-bars {
  width: 44%;
  max-width: 210px;
  background: rgba(10, 14, 22, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 5px 7px;
  backdrop-filter: blur(4px);
}

.hud-name-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 800;
  margin-bottom: 3px;
}

.hp-track, .ultra-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.ultra-track {
  height: 6px;
  margin-top: 4px;
}

.hp-fill {
  height: 100%;
  width: 100%;
  transition: width 0.08s linear;
}

.p1-fill { background: linear-gradient(90deg, #0284c7, #38bdf8); }
.p2-fill { background: linear-gradient(90deg, #e11d48, #fb7185); }

.ultra-fill {
  height: 100%;
  width: 100%;
}

.ultra-fill.rainbow {
  background: linear-gradient(90deg, #ff3b30, #ffcc00, #34c759, #00c7be, #007aff, #af52de);
}

.ultra-fill.gold {
  background: linear-gradient(90deg, #b45309, #fbbf24, #fef08a);
}

.atk-cluster {
  pointer-events: auto;
  display: grid;
  grid-template-columns: repeat(2, 62px);
  gap: 6px;
  touch-action: none;
}

.atk-btn {
  position: relative;
  width: 62px;
  height: 52px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(15, 20, 32, 0.85);
  color: #fff;
  font-weight: 800;
  font-size: 0.62rem;
  line-height: 1.05;
  padding: 3px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  touch-action: none;
  cursor: pointer;
}

.atk-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: conic-gradient(rgba(0, 0, 0, 0.72) var(--cd-deg, 0deg), transparent 0deg);
  pointer-events: none;
}

.atk-btn.ready {
  border-color: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.atk-btn.on-cd {
  opacity: 0.78;
}

.atk-label {
  position: relative;
  z-index: 1;
  pointer-events: none;
}

.atk-cd {
  position: absolute;
  z-index: 2;
  font-size: 0.92rem;
  font-weight: 900;
  color: #fde047;
  text-shadow: 0 1px 4px #000;
  pointer-events: none;
}

.btn-ultra {
  grid-column: span 2;
  width: 100%;
  height: 44px;
  font-size: 0.72rem;
}

.btn-ultra.ultra-rainbow {
  background: linear-gradient(90deg, #ff3b30, #ff9500, #34c759, #007aff, #af52de);
  border-color: #fff;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.55);
}

.btn-ultra.ultra-gold {
  background: linear-gradient(135deg, #92400e, #f59e0b, #fde047);
  color: #1c1000;
  border-color: #fef08a;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.65);
}

.exit-pill {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  z-index: 8;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(12, 16, 26, 0.72);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
}

.gameover-panel {
  text-align: center;
  align-items: center;
}

.gameover-titan {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent2);
}

.gameover-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
