:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dde1e7;
  --text: #1a1d24;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4fd1;
  --danger: #dc2626;
  --tiktok-1: #00f2ea;
  --tiktok-2: #ff0050;
  --tiktok-grad: linear-gradient(135deg, var(--tiktok-1), var(--tiktok-2));
  --instagram-grad: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.eyebrow {
  display: inline-block;
  background: #eef0f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.brand h1 {
  margin: 0;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  background: linear-gradient(90deg, var(--tiktok-1) 0%, var(--tiktok-2) 42%, #833ab4 55%, #fd1d1d 72%, #fcb045 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.stats {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  min-width: 220px;
}
.stats-row { display: flex; align-items: baseline; gap: 6px; }
.stats-row span { font-weight: 800; font-size: 20px; color: var(--accent); }
.stats-row small { color: var(--muted); font-size: 12px; }
.progress-bar {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: #eef0f3;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #7c3aed);
  border-radius: 999px;
  transition: width 0.6s ease;
}

.trust-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  padding: 12px 28px;
  background: #eff6ff;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.trust-bar span { display: flex; align-items: center; }
.trust-bar .check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-right: 7px;
  color: #16a34a;
  font-size: 13px;
  font-style: normal;
  font-weight: 700;
  flex-shrink: 0;
}

.how-it-works {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding: 24px 28px 4px;
}
.step-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f1f2f4;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
}
.step-card h3 { margin: 0 0 6px; font-size: 15px; }
.step-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.battle-bar {
  padding: 18px 28px;
  background: #14161c;
  border-bottom: 1px solid var(--border);
}
.battle-heading {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 12px;
}
.battle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 760px;
  margin: 0 auto;
}
.battle-team {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.battle-team-instagram { flex-direction: row-reverse; }
.team-emoji { font-size: 16px; }
.team-count { font-variant-numeric: tabular-nums; opacity: 0.85; }
.battle-track {
  flex: 1;
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: #2a2e38;
}
.battle-fill { height: 100%; transition: width 0.6s ease; }
.battle-fill-tiktok { width: 50%; background: var(--tiktok-grad); }
.battle-fill-instagram { width: 50%; background: var(--instagram-grad); }
.battle-hint {
  text-align: center;
  color: #9aa0ac;
  font-size: 12px;
  margin: 10px 0 0;
}

.team-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  margin: -4px 0 14px;
  color: #fff;
}
.team-badge-tiktok { background: var(--tiktok-grad); }
.team-badge-instagram { background: var(--instagram-grad); }

.mini-map {
  position: relative;
  width: 100%;
  max-width: 220px;
  margin: 0 auto 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  line-height: 0;
}
#miniMap { display: block; width: 100%; height: auto; }
.mini-map-marker {
  position: absolute;
  border: 2px solid #fff;
  outline: 1px solid var(--accent);
  background: rgba(37, 99, 235, 0.35);
  pointer-events: none;
  min-width: 3px;
  min-height: 3px;
}
.mini-map-hint {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin: 0 0 16px;
}

main { padding: 20px 28px 60px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
}
.zoom-controls button {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #eef0f3;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}
.zoom-controls button:hover { background: #e2e5ea; }
#zoomLabel { font-size: 13px; color: var(--muted); min-width: 44px; text-align: center; }

.hint { color: var(--muted); font-size: 13px; margin: 0; }

.viewport {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
  max-height: 75vh;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(45deg, #e9ebee 25%, transparent 25%),
    linear-gradient(-45deg, #e9ebee 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9ebee 75%),
    linear-gradient(-45deg, transparent 75%, #e9ebee 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #ffffff;
}

.canvas-wrap {
  position: relative;
  width: max-content;
}

#gridBg {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  position: relative;
  z-index: 0;
}

#gridBlocks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 2;
}

.watermark {
  position: absolute;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.16);
  font-weight: 800;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  z-index: 1;
  display: none;
}

.grid-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 3;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.3) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.3) 1px, transparent 1px);
}

.selection-box {
  position: absolute;
  z-index: 4;
  border: 2px dashed var(--accent);
  background: rgba(37, 99, 235, 0.15);
  pointer-events: none;
}

.focus-marker {
  position: absolute;
  z-index: 6;
  border: 3px solid #fff;
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-radius: 3px;
  pointer-events: none;
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6);
  animation: focus-pulse 1s ease-out 4;
}
@keyframes focus-pulse {
  0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6); }
  100% { box-shadow: 0 0 0 16px rgba(37, 99, 235, 0); }
}

.selection-confirm {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(20, 22, 30, 0.15);
  font-size: 13px;
  white-space: nowrap;
}
#selectionInfo { color: var(--text); }
#confirmBuyBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
#confirmBuyBtn:hover { background: var(--accent-hover); }
#cancelSelectionBtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.block-tooltip {
  position: absolute;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--text);
  color: #fff;
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  margin-top: -8px;
  box-shadow: 0 6px 18px rgba(20, 22, 30, 0.25);
  pointer-events: auto;
}
.block-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
}
#blockTooltipName:empty { display: none; }
#blockTooltipLink {
  color: #93c5fd;
  text-decoration: none;
  font-weight: 700;
}
#blockTooltipLink:hover { text-decoration: underline; }
#blockTooltipLink[hidden] { display: none; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}
.coords-row { display: flex; gap: 12px; }
.field { flex: 1; margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input {
  width: 100%;
  background: #f9fafb;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
.field-hint { margin: 5px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f9fafb;
  cursor: pointer;
}
#fieldColorHex { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; text-transform: uppercase; }
.availability { font-size: 13px; margin: -6px 0 14px; }
.availability.ok { color: #16a34a; }
.availability.bad { color: var(--danger); }

.legal-note { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 10px 0 16px; }
.legal-note a { color: var(--accent); }

.price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  margin-bottom: 16px;
}

#submitBtn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#submitBtn:hover { background: var(--accent-hover); }
#submitBtn:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

.about {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  padding: 32px 28px 8px;
  border-top: 1px solid var(--border);
}
.about-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}
.about-card h2 { margin: 0 0 10px; font-size: 17px; }
.about-card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

footer {
  padding: 20px 28px 40px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}
footer a { color: var(--accent); }

/* Smartphone: layout impilato e bersagli touch più grandi */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; padding: 16px; }
  .brand h1 { font-size: 30px; }
  .stats { width: 100%; }

  .trust-bar { flex-direction: column; gap: 8px; padding: 12px 16px; }

  .how-it-works { padding: 16px 16px 4px; }

  .battle-bar { padding: 14px 16px; }
  .battle-row { flex-wrap: wrap; row-gap: 10px; }
  .battle-track { order: 3; flex-basis: 100%; }

  main { padding: 16px 16px 40px; }
  .toolbar { gap: 10px; }
  .zoom-controls button { width: 38px; height: 38px; font-size: 18px; }
  #zoomLabel { min-width: 52px; }

  .about { padding: 24px 16px 8px; grid-template-columns: 1fr; }

  .modal { padding: 18px; }
  .coords-row { flex-direction: column; gap: 0; }
  .field input { font-size: 16px; } /* evita lo zoom automatico di iOS sui campi al focus */

  .selection-confirm { flex-wrap: wrap; max-width: calc(100vw - 32px); }
}
