/* La Sala Alchemica — stile condiviso da tutte le pagine
   Tema "bottega dello speziale": pergamena, legno e rame, bottoni pieni con ombra sotto. */

:root {
  /* sfondo della pagina e tavolo */
  --bg: #1f4e5f;
  --bg-dots: #24596b;
  --on-bg: #f6ecd6;
  --wood: #6b4528;
  --wood-dark: #4e311c;

  /* carta e inchiostro */
  --panel: #f3e3c3;
  --panel2: #e7d3ab;
  --paper-hi: #fffaf0;
  --ink: #3b2a1e;
  --muted: #7a6450;
  --line: #3b2a1e;
  --line-soft: rgba(59, 42, 30, .18);

  /* rame per le azioni, vetro blu per il secondario */
  --accent: #d9643a;
  --accent-dark: #a5441f;
  --accent-ink: #fff8ec;
  --blue: #3a7ca5;
  --blue-dark: #285a7a;

  --ok: #4f9a5b;
  --bad: #c8423b;
  --glow: #8fe0ff;
  --seen: #c58bff;

  /* dorso delle fiale coperte: tappo di sughero visto dall'alto */
  --vial-back1: #d9a86e;
  --vial-back2: #a8703f;
  --seal-bg: #f4e6c8;

  --font-title: "Fredoka", "Nunito", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, "Segoe UI", sans-serif;

  /* misura di partenza: board.js la ricalcola per far stare il tavolo nello schermo */
  --cell: 64px;
  --board-gap: 6px;
  --board-pad: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dots) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  color: var(--on-bg);
  font: 15px/1.45 var(--font-body);
}

a { color: var(--accent-dark); font-weight: 700; }
h2, h3 { font-family: var(--font-title); font-weight: 600; letter-spacing: .2px; }

/* ---------- intestazione del sito ---------- */

.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  color: var(--on-bg);
  background: var(--wood-dark);
  border-bottom: 4px solid #2e1d10;
}
.brand { font: 600 21px var(--font-title); color: var(--on-bg); text-decoration: none; }
.brand span { color: #f0a35e; }

/* selettore a pillola: binario scuro, voce attiva piena */
.main-nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  padding: 4px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .25);
}
.main-nav a {
  padding: 6px 14px;
  border-radius: 4px;
  color: #e3cfae;
  text-decoration: none;
  font: 600 15px var(--font-title);
}
.main-nav a:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.main-nav a.active { color: var(--accent-ink); background: var(--accent); box-shadow: 0 2px 0 var(--accent-dark); }

.account { display: flex; gap: 10px; align-items: center; }
.account form { margin: 0; }
.account a { text-decoration: none; color: var(--on-bg); }
.account a.btn { color: var(--accent-ink); }

/* selettore di lingua: tre sigle, quella attiva evidenziata */
.lang-switch { display: flex; gap: 2px; padding: 2px; border-radius: 6px; background: rgba(0, 0, 0, .25); }
.lang-switch button {
  padding: 3px 7px;
  font: 700 12px var(--font-body);
  color: #e3cfae;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.lang-switch button:hover { color: #fff; filter: none; }
.lang-switch button:active { transform: none; box-shadow: none; }
.lang-switch button.active { color: var(--accent-ink); background: var(--accent); }

.messages { max-width: 760px; margin: 12px auto 0; padding: 0 16px; }
.msg {
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--panel);
  margin-bottom: 6px;
}
.msg.error { background: #f4cdc4; }
.msg.success { background: #cfe6c4; }

/* ---------- pagine generiche ---------- */

.page { max-width: 760px; margin: 0 auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; }
.page.narrow { max-width: 440px; }
.panel {
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .25);
}
.panel h2, .panel h3 { margin-top: 0; }
.panel.hero {
  background:
    repeating-linear-gradient(-45deg, transparent 0 14px, rgba(217, 100, 58, .07) 14px 28px),
    var(--panel);
}
.centered { text-align: center; }

.info { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.center { justify-content: center; }

.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.room-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel2);
  border: 2px solid var(--line);
  border-radius: 6px;
}
.room-list form { margin: 0 0 0 auto; }
.room-list a { margin-left: auto; }
.code { font-family: ui-monospace, Consolas, monospace; font-weight: 700; letter-spacing: 2px; color: var(--accent-dark); }
.tag {
  padding: 1px 8px;
  border: 2px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  background: #e0c99c;
}
.tag.active { background: #bcd6e8; }
.tag.win { background: #c5e3bf; }
.tag.loss { background: #f0bfb7; }
.tag.draw { background: #ecd9a0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; text-align: center; }
.stats div { background: var(--panel2); border: 2px solid var(--line); border-radius: 6px; padding: 10px 4px; }
.stats b { display: block; font: 600 28px var(--font-title); color: var(--accent-dark); }
.stats span { font-size: 13px; color: var(--muted); }

.share-link code {
  display: block;
  padding: 8px;
  border: 2px dashed var(--line);
  border-radius: 6px;
  background: var(--paper-hi);
  word-break: break-all;
  user-select: all;
}

/* ---------- moduli ---------- */

.form { display: flex; flex-direction: column; gap: 4px; }
.form button { margin-top: 12px; align-self: flex-start; }
.field small { display: block; margin-top: 4px; }
.field small ul { margin: 4px 0; padding-left: 18px; }
.field-error, .form-errors { color: var(--bad); font-size: 13px; font-weight: 700; margin: 4px 0; }

/* bottone pieno: ombra sotto che sparisce quando si preme */
button, .btn {
  display: inline-block;
  padding: 9px 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  font: 600 16px/1.2 var(--font-title);
  letter-spacing: .2px;
  color: var(--accent-ink);
  background: var(--accent);
  box-shadow: 0 4px 0 var(--accent-dark);
  text-decoration: none;
  cursor: pointer;
  transition: transform .06s, box-shadow .06s, filter .1s;
}
button:hover, .btn:hover { filter: brightness(1.06); }
button:active, .btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
button.sec, .btn.sec { color: var(--ink); background: var(--panel2); box-shadow: 0 4px 0 #b89c6c; }
button.sec:active, .btn.sec:active { box-shadow: 0 1px 0 #b89c6c; }
button.small, .btn.small { padding: 5px 11px; font-size: 14px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }

input, select {
  width: 100%;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
  background: var(--paper-hi);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(58, 124, 165, .45); outline-offset: 1px; }
label { display: block; margin: 8px 0 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.prow { display: grid; grid-template-columns: 1fr 130px; gap: 8px; }

/* ---------- tavolo alchemico ---------- */

.table-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  padding: 16px;
  justify-content: center;
  align-items: flex-start;
}

#boardWrap {
  flex: 1 1 420px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* riga in cima al tavolo: turno e cosa fare a sinistra, pulsanti a destra */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
#status { font-size: 14px; color: var(--muted); }
#status b { color: var(--accent-dark); }
#status .hint { color: var(--ink); font-weight: 700; }
#actions:empty { display: none; }
#error { flex-basis: 100%; text-align: center; color: var(--bad); font-size: 13px; font-weight: 700; }

/* mazzo cliccabile quando è il momento di scoprire un Sigillo */
.seal.deck.ready { cursor: pointer; box-shadow: 0 0 0 3px var(--accent); animation: deck-pulse 1.6s ease-in-out infinite; }
.seal.deck.ready:hover { filter: brightness(1.15); }
@keyframes deck-pulse { 50% { box-shadow: 0 0 0 6px rgba(217, 100, 58, .35); } }
@media (prefers-reduced-motion: reduce) { .seal.deck.ready { animation: none; } }

/* il tavolo: assi di legno con bordo scuro */
#board {
  display: grid;
  gap: var(--board-gap);
  padding: var(--board-pad);
  touch-action: manipulation;  /* niente zoom col doppio tocco */
  max-width: 100%;
  overflow: auto;
  background:
    repeating-linear-gradient(90deg, transparent 0 calc(var(--cell) * 2 - 2px), rgba(0, 0, 0, .18) calc(var(--cell) * 2 - 2px) calc(var(--cell) * 2)),
    linear-gradient(180deg, #74502f, var(--wood));
  border: 4px solid var(--line);
  border-radius: 12px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12), 0 6px 0 rgba(0, 0, 0, .3);
}

/* le caselle riempiono la propria riga/colonna (quelle vuote ai bordi sono più sottili) */
.cell { width: 100%; height: 100%; min-width: 0; min-height: 0; border-radius: 8px; }
.empty { border: 2px dashed transparent; }
.target { border-color: #f0a35e; background: rgba(240, 163, 94, .18); cursor: pointer; }
.target:hover { background: rgba(240, 163, 94, .38); }

.vial {
  position: relative;
  overflow: hidden;
  border: 3px solid var(--line);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  transition: transform .12s;
}
.vial.back {
  background: radial-gradient(circle at 35% 30%, var(--vial-back1), var(--vial-back2));
  border-color: var(--line);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .25), 0 3px 0 rgba(0, 0, 0, .35);
}
/* anelli del tappo */
.vial.back::before, .vial.back::after {
  content: "";
  position: absolute;
  inset: 20%;
  border: 2px solid rgba(59, 42, 30, .35);
  border-radius: 50%;
}
.vial.back::after { inset: 36%; background: rgba(59, 42, 30, .15); }
.vial svg { display: block; width: 100%; height: 100%; }
.vial.clickable { cursor: pointer; }
.vial.clickable:hover { transform: translateY(-3px); }
.vial.sel { outline: 3px solid #f0a35e; outline-offset: 2px; }
.vial.last { box-shadow: 0 0 0 3px var(--glow); }
.vial.misplaced { box-shadow: 0 0 0 3px var(--bad); }
.vial.peeking { box-shadow: 0 0 0 3px var(--glow), 0 0 18px var(--glow); transform: translateY(-3px); }
.vial.seen { box-shadow: 0 0 0 3px var(--seen), 0 0 14px var(--seen); }
.vial.seen .vial-num { background: var(--seen); color: #1a0f24; }
.vial.flash { outline: 3px solid #fff; outline-offset: 2px; transform: scale(1.08); z-index: 3; }

/* viaggio dell'ultima fiala spostata */
.vial.travelling { z-index: 5; box-shadow: 0 0 0 3px var(--glow), 0 10px 24px rgba(0, 0, 0, .6); }
/* casella da cui è partita l'ultima fiala spostata: solo il contorno */
.cell.origin {
  border: 2px dashed var(--glow);
  background: rgba(143, 224, 255, .08);
}

/* numero fisso della fiala, in basso a sinistra */
.vial-num {
  position: absolute;
  left: 3px; bottom: 3px;
  z-index: 2;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 4px;
  font: 800 10px/15px var(--font-body);
  text-align: center;
  color: #fff;
  background: rgba(59, 42, 30, .8);
}

/* carta-sigillo: colore pieno, una fascia per ingrediente */
.seal-card {
  display: flex;
  overflow: hidden;
  border: 2px solid var(--paper-hi);
  border-radius: 4px;
  box-shadow: 0 0 0 1.5px var(--line), 0 3px 0 rgba(0, 0, 0, .35);
}
.seal-band {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 1px #000;
}
.seal-band + .seal-band { border-left: 1px solid rgba(255, 255, 255, .7); }
/* convenzione: le fasce che non contano restano visibili ma tratteggiate */
.seal-band.ignored {
  background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, .5) 0 3px, transparent 3px 6px);
}
.seal-card.narrowed { border-color: var(--accent); }

/* appoggiata sopra la fiala, in alto a destra, leggermente ruotata */
.seal-card.on-vial {
  position: absolute;
  top: 3px; right: 3px;
  z-index: 2;
  width: 48%;
  height: 38%;
  transform: rotate(6deg);
}
/* nella riserva */
.seal-card.in-pool { width: 46px; height: 32px; }

.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); }

/* ---------- barra laterale ---------- */

aside {
  flex: 0 1 300px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.box {
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
.box h3 {
  margin: -12px -14px 10px;
  padding: 6px 14px;
  font: 600 14px var(--font-title);
  color: var(--accent-ink);
  background: var(--wood);
  border-bottom: 3px solid var(--line);
  border-radius: 7px 7px 0 0;
  letter-spacing: .4px;
}

.seals { display: flex; flex-wrap: wrap; gap: 8px; }
.seal {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 3px;
  border: 2px solid transparent;
  border-radius: 6px;
}
.seal.clickable { cursor: pointer; }
.seal.clickable:hover { border-color: rgba(217, 100, 58, .6); }
.seal.sel { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.seal.deck {
  padding: 8px 12px;
  color: var(--accent-ink);
  font: 600 14px var(--font-title);
  border-color: var(--line);
  border-radius: 6px;
  background: repeating-linear-gradient(45deg, var(--accent) 0 6px, var(--accent-dark) 6px 12px);
  text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
}

.formula div { display: flex; align-items: center; gap: 8px; }
.formula .dot { width: 16px; height: 16px; }
.formula-box { border-color: var(--accent-dark); }
.formula-box h3 { background: var(--accent); }
.formula { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }

.log { max-height: 240px; overflow: auto; font-size: 13px; color: var(--muted); }
.log-turn { padding: 6px 0; border-top: 2px dotted var(--line-soft); }
.log-turn:first-child { border-top: 0; padding-top: 0; }
.log-turn-title { font: 600 12px var(--font-title); letter-spacing: .5px; color: var(--accent-dark); }
.log-turn:first-child .log-entry { color: var(--ink); }
.log-entry { padding: 2px 0; }
.vial-chip {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  margin: 0 1px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  font-weight: 800;
  font-size: 12px;
  text-align: center;
  color: var(--ink);
  background: #e0c99c;
  cursor: help;
}
.vial-chip:hover { background: var(--accent); color: var(--accent-ink); }

/* ---------- commenti ---------- */

.comment-pick {
  margin-left: 4px;
  padding: 0 4px;
  border: 0;
  font-size: 11px;
  line-height: 16px;
  background: transparent;
  box-shadow: none;
  opacity: .35;
}
.comment-pick:active { transform: none; box-shadow: none; }
.log-entry:hover .comment-pick, .log-entry.picked .comment-pick { opacity: 1; }
.log-entry.picked { background: rgba(217, 100, 58, .15); border-radius: 4px; }
.log-comment {
  margin: 2px 0 4px 12px;
  padding: 4px 8px;
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  background: rgba(217, 100, 58, .1);
  color: var(--ink);
  font-style: italic;
}
.log-comment b { font-style: normal; color: var(--accent-dark); }
.comment-box textarea {
  width: 100%;
  margin: 6px 0;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--ink);
  background: var(--paper-hi);
  resize: vertical;
}

/* ---------- finestre ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 38, 46, .88);
}
.overlay[hidden] { display: none; }

.dialog {
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow: auto;
  padding: 28px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .35);
}
.dialog.centered { text-align: center; }
.dialog h2 { margin-top: 0; font-size: 26px; }
.dialog ol, .dialog ul { padding-left: 20px; margin: 6px 0; text-align: left; }
.dialog form { margin: 0; }
.setup-footer { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 18px; }
.score { font: 600 30px var(--font-title); margin: 6px 0; }

.score-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.score-table th, .score-table td { padding: 6px; border-bottom: 2px solid var(--line-soft); text-align: left; }
.score-table th { font: 600 13px var(--font-title); color: var(--muted); }
.score-table .total { font: 600 19px var(--font-title); color: var(--accent-dark); }
.score-table tr.winner td { background: rgba(217, 100, 58, .12); }

/* ---------- allenamento AI ---------- */

.training-bar {
  max-width: 980px;
  margin: 16px auto 0;
  padding: 14px 18px;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
.training-title { margin: 0 0 4px; }
.training-controls { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-end; }
.training-controls label { margin: 0; }
.training-controls select { width: auto; min-width: 150px; margin-top: 4px; }
.training-status { font-weight: 700; color: var(--accent-dark); margin: 8px 0; }
.training-results { max-height: 220px; overflow: auto; }
.bot-formula { display: flex; flex-direction: column; gap: 3px; padding: 6px 0; border-bottom: 2px dotted var(--line-soft); }
.bot-formula:last-child { border-bottom: 0; }
.notes { max-height: 320px; }

/* ---------- telefono ---------- */

button, .seal, .comment-pick { touch-action: manipulation; }

@media (max-width: 640px) {
  :root { --board-gap: 4px; --board-pad: 6px; }

  /* intestazione compatta */
  .site-header {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
    padding: 8px 10px;
  }
  .site-header .brand { grid-column: 1; grid-row: 1; }
  .site-header .account { grid-column: 2; grid-row: 1; }
  .site-header .main-nav { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
  .brand { font-size: 17px; }
  .main-nav a { padding: 4px 8px; font-size: 13px; }
  .account { font-size: 13px; gap: 8px; }

  /* il tavolo usa tutta la larghezza */
  .table-layout { padding: 6px 8px 16px; gap: 10px; }
  #boardWrap { flex-basis: 100%; gap: 8px; }
  #board { border-width: 3px; border-radius: 10px; }
  .cell { border-radius: 6px; }
  .vial { border-width: 2px; box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
  .vial-num { left: 2px; bottom: 2px; min-width: 13px; padding: 0 3px; font-size: 9px; line-height: 13px; }

  /* barra del turno sempre visibile: testo sopra, pulsanti sotto */
  .toolbar { padding: 6px 8px; gap: 6px; }
  #status { flex-basis: 100%; font-size: 13px; line-height: 1.3; }
  .toolbar > .row { width: 100%; justify-content: flex-end; }

  /* barra laterale sotto il tavolo, essenziale */
  aside { min-width: 0; flex-basis: 100%; gap: 10px; }
  .box { padding: 10px 12px; }
  .box h3 { margin: -10px -12px 8px; padding: 5px 12px; }
  .log { max-height: 150px; }
  .seal-card.in-pool { width: 52px; height: 36px; }  /* più facile da toccare */

  .stats { grid-template-columns: repeat(2, 1fr); }
  .panel { padding: 16px; }
  .dialog { padding: 18px; }
  .training-controls select { min-width: 0; width: 100%; }
}
