/* ====== SHAMBLE — interfaccia ====== */

:root {
  --bg: #05060a;
  --panel: rgba(18, 20, 26, 0.92);
  --panel-line: #3a3f4a;
  --text: #e8e6e0;
  --muted: #9a968a;
  --dim: #6f6c63;
  --blood: #c8102e;
  --blood-dark: #a3122a;
  --gold: #ffd27a;
  --ok: #4a8a3c;
  --warn: #c8a34a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
}

body.touch-mode #game { cursor: none; }

.hidden { display: none !important; }

/* ====== SFONDO DEL MENU ======
   Metti la tua immagine in  assets/ui/menu-bg.jpg
   (JPG o WEBP, 1920x1080 o 2560x1440, orizzontale).
   Se il file non esiste resta il gradiente qui sotto: nessun errore. */
.menu-bg {
  position: fixed;
  inset: 0;
  z-index: 1;
  background-color: #0a0b10;
  background-image:
    linear-gradient(180deg, rgba(5,6,10,0.35) 0%, rgba(5,6,10,0.58) 55%, rgba(5,6,10,0.88) 100%),
    radial-gradient(ellipse at 50% 30%, rgba(120,20,30,0.28), transparent 60%),
    url('../assets/ui/menu-bg.jpg');
  background-size: cover, cover, cover;
  background-position: center, center, center;
  background-repeat: no-repeat;
  animation: bgDrift 40s ease-in-out infinite alternate;
}

@keyframes bgDrift {
  from { background-size: cover, cover, 104%; }
  to   { background-size: cover, cover, 112%; }
}

/* ====== SCHERMATE ====== */
.screen {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 10, 0.84);
  padding: 20px;
}

/* ====== MENU PRINCIPALE ====== */
.menu-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 42px;
  animation: fadeUp .5s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.brand { text-align: center; }

.title {
  font-size: clamp(34px, 7vw, 64px);
  font-weight: 800;
  letter-spacing: 8px;
  color: var(--blood);
  text-shadow: 0 0 34px rgba(200, 16, 46, 0.55), 0 3px 0 rgba(0,0,0,0.6);
  margin: 0;
}

.title.small {
  font-size: clamp(20px, 3.4vw, 30px);
  letter-spacing: 4px;
}

.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(420px, 86vw);
}

.menu-item {
  width: 100%;
  padding: 17px 24px;
  font-size: 17px;
  letter-spacing: 3px;
}

/* ====== BOTTONI ====== */
.btn {
  padding: 13px 26px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text);
  background: rgba(35, 38, 46, 0.9);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: rgba(52, 56, 66, 0.95); border-color: #59606e; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary {
  background: var(--blood-dark);
  border-color: transparent;
  box-shadow: 0 4px 18px rgba(163, 18, 42, 0.45);
}
.btn.primary:hover { background: var(--blood); }

.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.btn.wide { width: 100%; margin-top: 10px; }
.btn.tiny { padding: 7px 14px; font-size: 12px; letter-spacing: 1px; }

/* ====== PANNELLI ====== */
.panel {
  position: relative;
  z-index: 6;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 26px 30px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  animation: fadeUp .3s ease both;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.panel.narrow { width: min(440px, 92vw); }
.panel.wide-panel { width: min(680px, 94vw); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}
.panel-head.sub-head { margin: 22px 0 10px; }

.sub { font-size: 14px; color: var(--muted); margin: 0 0 16px; line-height: 1.5; }
.hint { font-size: 12.5px; color: var(--dim); line-height: 1.6; margin: 10px 0; }
.hint.warn { color: var(--warn); }
.err { font-size: 13px; color: #ff6a5e; min-height: 18px; margin: 6px 0; }
.mono { font-family: 'Consolas', 'SF Mono', monospace; letter-spacing: 1px; }
hr { border: none; border-top: 1px solid var(--panel-line); margin: 20px 0; }

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--gold);
  text-transform: uppercase;
  margin: 18px 0 10px;
}

/* ====== CAMPI ====== */
.field {
  width: 100%;
  padding: 13px 15px;
  margin: 8px 0;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: rgba(8, 9, 13, 0.9);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.field:focus { border-color: var(--blood); }
.field.inline { width: 210px; margin: 0; padding: 9px 12px; font-size: 13px; }
.field.code {
  text-transform: uppercase;
  letter-spacing: 8px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  font-family: 'Consolas', monospace;
}

/* ====== RIGHE IMPOSTAZIONI ====== */
.tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.tab {
  flex: 1;
  padding: 11px 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--panel-line);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--gold); border-bottom-color: var(--blood); }

.row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  font-size: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.row > span:first-child { flex: 1; color: #cfcbbf; }
.row .val { min-width: 44px; text-align: right; color: var(--gold); font-size: 13px; }

input[type=range] {
  width: 190px;
  height: 4px;
  background: var(--panel-line);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--blood);
  border: 2px solid #1a1c22;
  cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--blood);
  border: 2px solid #1a1c22;
  cursor: pointer;
}

/* interruttore on/off */
.switch-row { cursor: pointer; }
.switch-row input[type=checkbox] { display: none; }
.switch {
  position: relative;
  width: 46px; height: 24px;
  background: var(--panel-line);
  border-radius: 12px;
  transition: background .2s;
  flex-shrink: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #cfcbbf;
  border-radius: 50%;
  transition: transform .2s;
}
.switch-row input:checked ~ .switch { background: var(--blood-dark); }
.switch-row input:checked ~ .switch::after { transform: translateX(22px); background: #fff; }

/* selettore a segmenti */
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button {
  padding: 8px 13px;
  font-family: inherit;
  font-size: 12px;
  color: var(--muted);
  background: rgba(8,9,13,0.7);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--blood-dark); color: #fff; border-color: transparent; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ====== PROFILO ====== */
.prof-grid { display: flex; flex-direction: column; gap: 10px; }
.prof-line {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  padding: 10px 12px;
  background: rgba(8,9,13,0.55);
  border-radius: 8px;
}
.prof-line > span:first-child { color: var(--muted); min-width: 110px; }
.prof-line > b { flex: 1; word-break: break-all; -webkit-user-select: text; user-select: text; }

.level-box {
  margin: 22px 0 8px;
  padding: 16px;
  background: rgba(8,9,13,0.55);
  border-radius: 10px;
}
.level-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.lvl-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px; height: 46px;
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(145deg, var(--blood), #6d0d1d);
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(200,16,46,0.4);
}
.level-meta { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.level-meta b { font-size: 16px; color: var(--gold); }

.xp-bar {
  height: 9px;
  background: #23262e;
  border-radius: 5px;
  overflow: hidden;
}
.xp-bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--blood-dark), var(--gold));
  border-radius: 5px;
  transition: width .8s cubic-bezier(.2,.9,.3,1);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}
.stat-grid > div {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  background: rgba(8,9,13,0.5);
  border-radius: 7px;
}
.stat-grid span { color: var(--muted); }
.stat-grid b { color: var(--gold); }

/* ====== MULTIPLAYER ====== */
.mp-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.mp-card {
  padding: 16px;
  background: rgba(8,9,13,0.5);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
}
.mp-card .hint { margin-bottom: 0; }
.code-row { display: flex; gap: 8px; }
.code-row .field { margin: 0; }

.room-list { display: flex; flex-direction: column; gap: 6px; max-height: 210px; overflow-y: auto; }
.room-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  font-size: 13px;
  background: rgba(8,9,13,0.55);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.room-row:hover { border-color: var(--blood); background: rgba(30,14,18,0.65); }
.room-row .rcode { font-family: Consolas, monospace; font-weight: 700; font-size: 16px; color: var(--gold); letter-spacing: 3px; }
.room-row .rhost { flex: 1; color: #cfcbbf; }
.room-row .rtag { font-size: 11px; color: var(--muted); }

/* ====== LOBBY ====== */
.code-badge {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: rgba(8,9,13,0.6);
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
}
.mono.big { font-size: 30px; letter-spacing: 10px; color: var(--gold); font-weight: 800; }

.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(8,9,13,0.55);
  border-left: 3px solid var(--panel-line);
  border-radius: 8px;
  font-size: 14px;
}
.player-row.me { border-left-color: var(--blood); }
.player-row .pname { flex: 1; font-weight: 600; }
.player-row .plvl {
  font-size: 11px;
  padding: 3px 8px;
  background: rgba(255,210,122,0.15);
  color: var(--gold);
  border-radius: 10px;
}
.player-row .ptag {
  font-size: 10px;
  letter-spacing: 2px;
  padding: 3px 8px;
  background: var(--blood-dark);
  color: #fff;
  border-radius: 4px;
}
.player-row.empty { opacity: .4; font-style: italic; }

/* tabella comandi (menu di pausa) */
.controls {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}
.controls b { color: var(--text); font-weight: 600; text-align: right; white-space: nowrap; }

/* ====== GAME OVER ====== */
.gameover-title {
  font-size: clamp(36px, 6vw, 58px);
  font-weight: 900;
  color: var(--blood);
  text-shadow: 0 0 40px rgba(200, 16, 46, 0.7);
  margin: 0 0 18px;
  text-align: center;
}
.result-grid { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.result-grid > div {
  display: flex;
  justify-content: space-between;
  padding: 9px 12px;
  font-size: 14px;
  background: rgba(8,9,13,0.5);
  border-radius: 7px;
}
.result-grid span { color: var(--muted); }
.result-grid b { color: var(--text); }
.xp-result { margin: 14px 0 18px; padding: 14px; background: rgba(8,9,13,0.5); border-radius: 10px; }
.levelup {
  margin-top: 10px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--gold);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .65; } 50% { opacity: 1; } }

/* ====== ANGOLI DEL MENU ====== */
.corner-card {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  background: rgba(18,20,26,0.85);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}
.corner-card:hover { border-color: var(--blood); }
.corner-card .lvl-badge { width: 34px; height: 34px; font-size: 15px; }
.corner-card .cname { font-weight: 700; }
.corner-card .cuid { font-size: 10.5px; color: var(--dim); font-family: Consolas, monospace; }
.corner-note {
  position: fixed;
  bottom: 16px; right: 20px;
  z-index: 6;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 1px;
}

/* ====== TOAST ====== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  z-index: 40;
  padding: 12px 22px;
  font-size: 14px;
  background: rgba(18,20,26,0.96);
  border: 1px solid var(--panel-line);
  border-left: 3px solid var(--blood);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  animation: fadeUp .25s ease both;
}

/* ====== COMANDI TOUCH ====== */
.touch-layer {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  touch-action: none;
}
.touch-layer .stick-zone {
  position: absolute;
  bottom: 0; left: 0;
  width: 46%;
  height: 55%;
  padding-bottom: env(safe-area-inset-bottom);
  pointer-events: auto;
  touch-action: none;
}
.touch-layer .stick-zone.right { left: auto; right: 0; }

.touch-layer .stick {
  position: fixed;
  width: 124px; height: 124px;
  margin: -62px 0 0 -62px;
  border: 2px solid rgba(255,255,255,0.16);
  border-radius: 50%;
  background: rgba(10,12,18,0.28);
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.touch-layer .stick.on { opacity: 1; }
.touch-layer .stick-knob {
  position: absolute;
  top: 50%; left: 50%;
  width: 54px; height: 54px;
  margin: 0;
  transform: translate(-50%, -50%);
  background: rgba(230,230,230,0.35);
  border: 2px solid rgba(255,255,255,0.45);
  border-radius: 50%;
}

/* azioni: griglia 2x2 in basso a destra, sopra la zona dello stick di mira */
.touch-buttons {
  position: absolute;
  right: 14px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 56px);
  gap: 10px;
  pointer-events: auto;
}
.tbtn {
  width: 58px; height: 58px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  background: rgba(20,22,30,0.6);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
}
.tbtn.on { background: rgba(163,18,42,0.75); border-color: var(--blood); }
.tbtn { width: 56px; height: 56px; }
.tbtn.small { font-size: 13px; }
.tbtn.pause {
  position: absolute;
  top: 12px; left: 12px;
  width: 42px; height: 42px;
  font-size: 13px;
}

/* ====== TARGHETTA MODALITA' SVILUPPO ====== */
.dev-badge {
  position: fixed;
  left: 10px; bottom: 10px;
  z-index: 70;
  padding: 4px 9px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #0a0b10;
  background: #4a8a3c;
  border-radius: 4px;
  opacity: .75;
  pointer-events: none;
}
.dev-badge.off { background: var(--blood); color: #fff; }

/* ====== SCHERMI PICCOLI ====== */
@media (max-width: 640px) {
  .panel { padding: 20px 18px; border-radius: 12px; }
  .title { letter-spacing: 4px; }
  .row { flex-wrap: wrap; }
  input[type=range] { width: 100%; }
  .row .val { min-width: 36px; }
  .corner-card { top: 12px; right: 12px; padding: 8px 12px; }
  .menu-wrap { gap: 28px; }
}

@media (max-height: 520px) {
  .menu-wrap { gap: 18px; }
  .menu-item { padding: 12px 20px; font-size: 14px; }
}
