/* Palette e stili base IronHub */
:root {
  color-scheme: dark;

  --bg: #040713;
  --bg-accent: #120b2a;
  --panel-bg: rgba(13, 19, 45, 0.92);
  --panel-border: rgba(116, 61, 253, 0.45);
  --shadow: 0 32px 80px rgba(3, 6, 18, 0.75);

  --text-primary: #f5f8ff;
  --text-muted: #91a2d9;

  --green: #55ff55;
  --pink: #f626af;
  --purple: #713dfd;
  --blue: #1e4fff;

  --code-key: #55ff55;
  --code-operator: #94a4ff;
  --code-string: #ffc36d;
  --code-comment: #6f7ba8;
}

html, body {
  height: 100%;
}

/* Background html */
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  display: grid;
  place-items: center;
  overflow-y: hidden; /* evita scroll su mobile/desktop durante il gioco */
  overscroll-behavior: none; /* blocca rimbalzi */
  background:
    radial-gradient(circle at 15% 20%, rgba(246, 38, 175, 0.18), transparent 55%),
    radial-gradient(circle at 85% 10%, rgba(30, 79, 255, 0.22), transparent 60%),
    radial-gradient(circle at 10% 85%, rgba(85, 255, 85, 0.18), transparent 45%),
    linear-gradient(135deg, var(--bg), var(--bg-accent));
}

/* Desktop: riduci la griglia se serve */
@media (hover: hover) and (pointer: fine) {
  .code-body { padding-bottom: 1rem; }
  #game { max-width: 440px; }
}

.page {
  width: min(92vw, 820px);
  padding: 4vmin;
}

/* Code panel stile inspector macOS */
.code-panel {
  background: linear-gradient(140deg, rgba(19, 25, 58, 0.95), rgba(9, 13, 32, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 1.75rem;
  box-shadow: var(--shadow);
  overflow: hidden; /* ripristina look macOS (angoli netti) */
}

.code-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(15, 20, 44, 0.9);
}

.code-title {
  margin-left: 0.5rem;
  color: var(--text-muted);
  font-weight: 600;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1) inset, 0 1px 2px rgba(0,0,0,0.45);
}
.dot-red { background: #ff5f56; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #27c93f; }

.code-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow-x: hidden;
}

/* Layout canvas + legenda */
.game-wrap {
  display: grid;
  grid-template-columns: auto 260px;
  gap: 1.2rem;
  align-items: start;
}

@media (max-width: 760px) {
  .game-wrap {
    grid-template-columns: 1fr;
  }
}

/* Canvas */
#game {
  display: block;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  background: transparent; /* il bg viene disegnato da main.js */
  border-radius: 1rem;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06) inset;
  touch-action: none; /* abilita swipe e blocca scroll/pinch sul canvas */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.board {
  position: relative;
  display: grid;
  justify-items: center;
  touch-action: none;
}

/* iPhone SE (stretti): limita il canvas a 295px */
@media (max-width: 375px) {
  #game { max-width: 295px; }
}

/* Overlay Game Over */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(255,255,255,0.06), transparent 60%), rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
}
.overlay.hidden { display: none; }
.overlay-content {
  padding: 1rem 1.1rem 1.2rem;
  max-width: 420px;
}
.overlay .title {
  font-weight: 800;
  font-size: 1.4rem;
  margin: 0 0 0.6rem 0;
}
.overlay-actions {
  display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 0.4rem;
}
.overlay-note { color: var(--text-muted); margin: 0; font-size: 0.9rem; }

.hidden { display: none !important; }
/* Powerups bars */
.powerups-bars { width: 100%; max-width: 480px; display: grid; gap: 0.35rem; margin-top: 0.6rem; }
.pbar { display: grid; grid-template-columns: auto 1fr; gap: 0.5rem; align-items: center; }
.pbar .label { font-size: 0.9rem; color: var(--text-muted); }
.pbar .bar { height: 6px; background: rgba(255,255,255,0.12); border-radius: 999px; overflow: hidden; }
.pbar .bar i { display: block; height: 100%; background: var(--purple); border-radius: inherit; }

/* Card stile servizio + hover glow (da agents.md) */
.card {
  position: relative;
  display: block;
  border-radius: 1.2rem;
  background: rgba(11, 18, 38, 0.75);
  border: 1px solid rgba(113, 61, 253, 0.28);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border 0.25s ease;
}
.card::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: inherit;
  background: radial-gradient(circle at 20% -20%, rgba(246, 38, 175, 0.2), transparent 55%),
              radial-gradient(circle at 120% 50%, rgba(85, 255, 85, 0.2), transparent 65%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.card:hover,
.card:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(5, 10, 30, 0.65), 0 0 30px rgba(246, 38, 175, 0.2);
  border-color: rgba(85, 255, 85, 0.52);
}
.card:hover::after { opacity: 1; }

/* Legenda */
.legend {
  padding: 1rem 1rem 1.1rem;
}
.legend-header {
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 0.4rem;
}
.legend-list {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0 0.75rem;
  display: grid;
  gap: 0.35rem 0.4rem;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
}
.legend-list li {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  justify-items: center;
  gap: 0;
  padding: 0.25rem 0.35rem;
  border-radius: 0.6rem;
  position: relative;
}
.legend-list li.legend-toggle { cursor: pointer; user-select: none; }
.legend-list li.legend-toggle.off { opacity: 0.55; }
.legend-list .emoji {
  font-size: 1.25rem;
  display: grid;
  place-items: center;
}
.legend-list .legend-swatch {
  width: 18px; height: 18px; display: inline-block; position: relative;
}
.legend-list .legend-swatch.gate {
  background: var(--pink);
  border: 2px solid rgba(246, 38, 175, 0.9);
  border-radius: 4px;
}
.legend-list .legend-swatch.belt {
  background: rgba(30, 79, 255, 0.25);
  border: 1px solid #1e4fff;
  border-radius: 4px;
}
.legend-list .legend-swatch.belt::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-30%, -50%);
  width: 0; height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 9px solid #1e4fff;
}
.legend-list .desc { display: none; }
.legend-list li[data-tip]:hover::after,
.legend-list li[data-tip].tip-on::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 20, 44, 0.95);
  color: var(--text-primary);
  padding: 0.3rem 0.5rem;
  border: 1px solid rgba(113, 61, 253, 0.4);
  border-radius: 0.5rem;
  font-size: 0.8rem;
  white-space: normal; /* consenti a capo */
  max-width: 280px;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 20px rgba(5,10,30,0.45);
  pointer-events: none;
  z-index: 3;
}

/* Disabilita il tooltip pseudo-elemento; usiamo solo il floating-tip JS */
.legend-list li[data-tip]:hover::after,
.legend-list li[data-tip].tip-on::after {
  content: none !important;
}

/* Floating tooltip per mobile/hover (append to body) */
.floating-tip {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -100%);
  background: rgba(15, 20, 44, 0.98);
  color: var(--text-primary);
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(113, 61, 253, 0.45);
  border-radius: 0.5rem;
  font-size: 0.82rem;
  white-space: normal; /* consenti a capo */
  max-width: min(80vw, 360px);
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 10px 28px rgba(5,10,30,0.55);
  pointer-events: none;
  z-index: 9999;
}
.legend-keys {
  display: grid;
  gap: 0.25rem;
}
.legend-keys .kb {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Actions + Buttons (palette coerente) */
.actions {
  display: flex;
  gap: 0.8rem;
  margin-top: 1rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-radius: 0.9rem;
  border: 1px solid rgba(113, 61, 253, 0.28);
  background: rgba(11, 18, 38, 0.75);
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(5, 10, 30, 0.35);
  transition: transform 0.15s ease, box-shadow 0.25s ease, border 0.25s ease, background-color 0.25s ease;
}

.btn:hover,
.btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(5, 10, 30, 0.55);
}

.btn:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.btn:active {
  transform: translateY(0);
}

.btn[disabled],
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Varianti accento */
.btn.play:hover,
.btn.play:focus-visible {
  border-color: rgba(85, 255, 85, 0.52);
  box-shadow: 0 10px 22px rgba(5, 10, 30, 0.55), 0 0 26px rgba(85, 255, 85, 0.28);
}

.btn.pause:hover,
.btn.pause:focus-visible {
  border-color: rgba(30, 79, 255, 0.52);
  box-shadow: 0 10px 22px rgba(5, 10, 30, 0.55), 0 0 26px rgba(30, 79, 255, 0.28);
}

.btn.restart:hover,
.btn.restart:focus-visible {
  border-color: rgba(113, 61, 253, 0.52);
  box-shadow: 0 10px 22px rgba(5, 10, 30, 0.55), 0 0 26px rgba(113, 61, 253, 0.28);
}

/* Segmented speed control */
.segmented {
  display: inline-flex;
  border-radius: 0.8rem;
  padding: 0.15rem;
  background: rgba(11, 18, 38, 0.65);
  border: 1px solid rgba(113, 61, 253, 0.28);
  margin-left: 0.5rem;
}
.btn.seg {
  padding: 0.4rem 0.6rem;
  border-radius: 0.6rem;
  border: none;
  background: transparent;
  box-shadow: none;
  min-width: 2.25rem;
}
.btn.seg.active {
  background: rgba(19, 25, 58, 0.95);
  border: 1px solid rgba(85, 255, 85, 0.52);
}

.inside-board { margin-top: 0.75rem; }

/* Canvas responsive sizing on small screens */
@media (max-width: 600px) {
  #game { width: 86vw; height: 86vw; }
}
@media (max-width: 380px) {
  #game { width: 92vw; height: 92vw; }
}

/* Stats */
.stats {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.pill {
  background: rgba(11, 18, 38, 0.6);
  border: 1px solid rgba(113, 61, 253, 0.28);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
