/* =========================
   Theme & base
========================= */
:root{
  --bg:#0b0b11; --panel:#131323; --ink:#eaeaf6; --muted:#9aa0b3;
  --accent:#9d7cff; --accent2:#00e5ff; --warn:#ff7885; --gold:#ffd24d;
}
*{ box-sizing:border-box; }

body{
  margin:0;
  background:linear-gradient(180deg,#0b0b11 0%,#0f1022 100%);
  color:var(--ink);
  font:14px/1.45 system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;
}

.mono{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size:12.5px;
}

/* =========================
   Page shell
========================= */
.wrap{ width:min(98vw, 1740px); margin:24px auto; padding:0 16px; }

.panel{
  background:var(--panel);
  border:1px solid #222446;
  border-radius:16px;
  box-shadow:0 10px 30px rgba(0,0,0,0.35);
  padding:14px;
}

/* Header */
.header{ position:relative; text-align:center; margin-bottom:8px; }
.header-row{
  display:flex; align-items:center; justify-content:center; gap:12px;
  flex-wrap:wrap;
}
/* Keep language toggle fixed to top-right while title is centered */
.header .lang-switch{ position:absolute; right:0; top:0; }
.page-title{ margin:0 0 6px; font-size:32px; line-height:1.15; letter-spacing:.2px; }

/* Language switch */
.lang-switch{
  display:inline-flex; gap:6px; padding:4px; border:1px solid #2b2e5a; border-radius:999px;
  background:#0f1130;
}
.lang-btn{
  appearance:none; border:0; padding:6px 10px; border-radius:999px; cursor:pointer; font-weight:800;
  background:transparent; color:var(--ink);
}
.lang-btn.active{ background:#1a1d46; outline:2px solid #3a3f7b; }
.lang-btn:focus-visible{ outline:2px solid var(--accent); }

/* =========================
   3-column layout
========================= */
.layout3{
  display:grid;
  grid-template-columns: clamp(380px, 28vw, 440px) 1fr clamp(380px, 28vw, 440px);
  gap:20px;
}
@media (max-width:1200px){
  .layout3{ grid-template-columns:1fr; }
}

/* =========================
   Left column (text)
========================= */
.left{ max-height:965px; overflow:auto; hyphens:auto; }
.sec{ margin:10px 0 12px; }
.sec h3{ margin:0 0 8px; font-size:16px; line-height:1.2; text-transform:uppercase; letter-spacing:.3px; color:#ffe166; }
.bullets{ padding-left:18px; margin:0; color:#dfe5ff; }
.bullets li{ margin:8px 0; line-height:1.55; }
.hl{ color:#ffe166; font-weight:800; }

/* Callout formula (PTR) */
.callout{
  background:#101231; border:1px solid #343869; border-radius:12px;
  padding:10px 12px; margin:8px 0;
}
.callout-title{
  font-size:12px; font-weight:900; letter-spacing:.25px; text-transform:uppercase;
  color:#ffe166; margin:0 0 4px;
}
.callout-formula{ font-size:15px; }
.callout-hint{ color:#cfd3ff; font-size:12.5px; margin:6px 0 0; }

/* Mapping grid */
.mapgrid{
  display:grid; grid-template-columns:170px 1fr; gap:6px 10px;
  background:#0f1130; border:1px solid #262a59; border-radius:10px; padding:10px;
}
.map-l{ color:#ffe166; font-weight:900; }
.map-r{ color:#e9ecff; line-height:1.5; }

/* Greek chips */
.chip{
  display:inline-flex; align-items:center; justify-content:center;
  min-width:20px; height:20px; padding:0 6px; margin-right:6px;
  border-radius:999px; font-weight:900; font-size:12px; letter-spacing:.2px;
  background:#1b1e48; border:1px solid #2a2f6b; color:#eaeaf6;
}
.chip-tau{   background:rgba(157,124,255,.18); border-color:#6d59d9; color:#cabcff; }
.chip-eta{   background:rgba(0,229,255,.18);   border-color:#2fbfd0; color:#aef7ff; }
.chip-alpha{ background:rgba(255,210,77,.18);  border-color:#caa63c; color:#ffe48c; }
.chip-beta{  background:rgba(255,210,77,.18);  border-color:#caa63c; color:#ffe48c; }
.chip-rho{   background:rgba(234,234,246,.1);  border-color:#6a6f8f; color:#eaeaf6; }

/* =========================
   Center (canvas)
========================= */
#canvasBox{ position:relative; overflow:hidden; border-radius:16px; }
canvas{
  display:block; width:100%; height:700px;
  background:radial-gradient(1600px 700px at 50% 0%, #151744 0%, #0d0f2a 60%, #0b0b11 100%);
}
.hud{
  position:absolute; right:10px; top:10px;
  background:rgba(9,10,30,0.65); backdrop-filter: blur(6px);
  border:1px solid #2b2e5a; padding:8px 10px; border-radius:10px; font-size:13px;
}
.hud b{ color:var(--accent2); }

/* Playbar sotto al canvas */
.playbar{
  display:flex; flex-wrap:wrap; gap:10px;
  justify-content:center; align-items:center;
  margin:12px 0 4px;
}
.playbar button{
  appearance:none; border:1px solid #3a3f7b; background:#171a3d; color:var(--ink);
  padding:10px 14px; border-radius:12px; cursor:pointer; font-weight:800;
  min-width: 160px; text-align:center;
}
.playbar button:hover{ border-color:#646cd6; }

/* KPI */
.kpi{
  display:flex; flex-wrap:wrap; gap:10px; margin-top:10px;
  justify-content:center; align-items:stretch;
}
.kpi > div{
  background:#0f1130; border:1px solid #262a59; border-radius:10px;
  padding:8px 12px; font-size:13px;
  min-width: 240px; max-width: 320px;
}

/* =========================
   Right column (legend + controls)
========================= */
.legend-card{
  background:#0f1130; border:1px solid #262a59; border-radius:12px; padding:12px 14px; margin-bottom:12px;
}
.legend-card h3{ margin:0 0 8px; font-size:16px; letter-spacing:.2px; }
.legend-note{ margin-top:8px; color:#cfd3ff; font-size:12.5px; }

/* Legend list */
.leg{ list-style:none; padding:0; margin:0; display:grid; gap:8px; }
.leg li{ display:flex; align-items:center; gap:8px; color:#e6eaff; line-height:1.25; }
.sw{ width:14px; height:14px; border-radius:50%; display:inline-block; border:2px solid #0b0b11; box-shadow:0 0 0 1px #2b2e5a inset; }
.sw-coop{ background:#00e5ff; }
.sw-comp{ background:#ffd24d; }
.sw-start{ background:#16e0a0; }
.sw-goal{ background:#ff5a7f; }
.diamond{ transform: rotate(45deg); border-radius:0; }

.edge{ flex-wrap:wrap; gap:10px; }
.edge-bar{ display:inline-block; height:4px; width:72px; background:rgba(157,124,255,0.7); border-radius:3px; box-shadow:0 0 0 1px rgba(157,124,255,0.25); }
.edge-bar.thin{ height:4px; opacity:.55; }
.edge-bar.thick{ height:8px; opacity:.9; }
.edge-label{ font-size:12px; color:#cfd3ff; margin-right:8px; }

.damage .dash{
  position:relative; height:0; width:70px; border-top:3px dashed var(--warn); display:inline-block;
}

/* Controls */
.controls{ display:grid; grid-template-columns:1fr; gap:10px 16px; align-content:start; }
.ctrl{
  background:#0f1130; border:1px solid #262a59; padding:10px 12px; border-radius:12px;
}
.ctrl label{
  display:flex; justify-content:space-between; align-items:flex-start; gap:10px;
  font-weight:700; line-height:1.25;
}
.ctrl small{ color:var(--muted); font-weight:700; }
input[type=range]{ width:100%; }

/* ========== Responsive tweaks ========== */

/* Laptop medio: stringi colonne laterali, riduci font e canvas */
@media (max-width: 1400px){
  .layout3{
    grid-template-columns: 320px 1fr 340px;
    gap:16px;
  }
  .page-title{ font-size:28px; }
  canvas{ height: clamp(460px, 60vh, 680px); }
  .kpi{ justify-content:center; }
}

/* Laptop 13" e tablet orizzontale: passa a layout a UNA colonna.
   Ordine: Canvas (centro) -> Controlli (destra) -> Spiegazione (sinistra). */
@media (max-width: 1150px){
  .layout3{ grid-template-columns: 1fr; align-items: stretch; }

  .panel.center{ order: 1; }
  .panel.right { order: 2; }
  .panel.left  { order: 3; }

  /* Canvas più basso per evitare che i bottoni escano dallo schermo */
  canvas{ height: clamp(380px, 54vh, 620px); }

  /* Playbar sempre visibile sotto al canvas */
  .playbar{
    position: sticky; bottom: 0; z-index: 5;
    background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(10,12,30,0.75) 40%);
    backdrop-filter: blur(6px);
    padding-top: 8px;
    margin-top: 8px;
    border-top: 1px solid #2b2e5a;
    justify-content:center;
  }

  /* Compatta i pannelli e i controlli */
  .panel{ padding:12px; }
  .controls{ gap:8px; }
  .ctrl{ padding:8px 10px; }
  .ctrl label{ font-size: 14px; }
  .mono.tiny{ font-size: 12px; }
  .lang-switch{ align-self:flex-start; }
  .header-row{ align-items:flex-start; }
  .page-title{ margin-bottom:0; }
  .header{ text-align:left; }
  .header .subtitle{ display:none; }
  .left{ max-height:none; }
  .legend-card{ margin-top:8px; }
  .controls{ margin-top:8px; }
  .panel.right{ position:relative; }
}

/* Telefono verticale / schermi molto piccoli: ancora più compatti */
@media (max-width: 720px){
  .page-title{ font-size:22px; }
  canvas{ height: clamp(320px, 48vh, 560px); }
  .kpi{ justify-content:center; }
  .legend-card h3{ font-size: 14px; }
  .sec h3{ font-size: 14px; }
  .bullets li{ margin:6px 0; }
}

/* Icona omino per la legenda */
.ico-person{
  width: 16px;
  height: 16px;
  margin-right: 8px;
  vertical-align: -2px;
  display: inline-block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ico-person .head{
  fill: currentColor;   /* testa piena */
  stroke: none;
}

/* Colori coerenti con il canvas */
.ico-person.coop{ color: var(--accent2); }  /* azzurro coop */
.ico-person.comp{ color: var(--gold); }     /* giallo comp */
