:root {
  --ink: #2b4a8b;        /* inchiostro: accento del gioco */
  --seal: #a13327;       /* ceralacca: lettera obbligatoria */
  --ink-soft: #dfe5f2;
  --paper: #faf7f0;      /* carta */
  --gray: #e6e6e6;
  --dark: #22222a;
  --border: #ddd8cc;
  --green: #2e7d32;
  --red: #c62828;
  font-family: Georgia, "Times New Roman", -apple-system, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  color: var(--dark);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden; /* scorrono solo le colonne laterali, mai il fiore */
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  flex-wrap: wrap;
  gap: 8px;
}
.header-left { display: flex; align-items: baseline; gap: 12px; }
h1 { font-size: 1.35rem; font-weight: 700; }
#puzzle-date { color: #666; font-size: 0.9rem; }
.header-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.header-right button, .header-right select {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
.header-right button:hover { background: #f5f5f5; }

/* ---- punteggio centrato in alto ---- */
.rank-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px 4px;
}
.rank-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(620px, 92vw);
}
#rank-label { font-weight: 700; min-width: 110px; font-size: 0.95rem; }
.rank-track {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  height: 24px;
}
.rank-track::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 1px;
  background: var(--border);
}
.rank-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gray);
  position: relative;
  z-index: 1;
}
.rank-dot.reached { background: var(--ink); }
.rank-dot.current {
  background: var(--ink);
  color: #fff;
  transform: scale(1.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6px;
  font-weight: 700;
}
#score-label { font-weight: 700; min-width: 40px; text-align: right; font-size: 0.95rem; }
#found-summary { color: #777; font-size: 0.85rem; }

/* ---- tre colonne: liste laterali scorrevoli, fiore fisso ---- */
main.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(300px, 400px) 1fr;
  gap: 12px;
  padding: 4px 16px 12px;
}
.side-wrap {
  overflow-y: auto;
  min-height: 0;
  padding: 4px 6px;
}
.side-list { list-style: none; }
.side-list li {
  padding: 5px 4px;
  border-bottom: 1px solid #eee9dd;
  font-size: 0.92rem;
  cursor: default;
}
.side-wrap.left .side-list li { text-align: right; }
.side-list li.pangram { font-weight: 700; color: var(--ink); }
.side-list li.unofficial { color: #999; font-style: italic; }

.panel-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

/* ---- messaggi ---- */
.message {
  height: 24px;
  font-weight: 700;
  font-size: 0.95rem;
}
.message.ok { color: var(--green); }
.message.err { color: var(--red); }

/* ---- box "argomenta" ---- */
.dispute {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
  color: #444;
  background: var(--ink-soft);
  border: 1px solid #c3cfe8;
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 440px;
  /* sopra i pallini del rango (z-index 1), che altrimenti gli si
     disegnano attraverso quando il box tocca la barra del punteggio */
  position: relative;
  z-index: 20;
}
.dispute.hidden { display: none; }
.dispute-head { display: flex; align-items: baseline; gap: 10px; }
.dispute-x {
  margin-left: auto;
  border: none !important;
  background: transparent !important;
  color: #888;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0 2px;
}
.dispute-x:hover { color: var(--dark); }
.dispute-head strong { font-size: 1rem; }
.dispute-head span { color: #666; font-style: italic; }
.dispute-def {
  margin: 0;
  padding: 6px 10px;
  background: #fff;
  border-radius: 6px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: #333;
  max-height: 96px;
  overflow-y: auto;
}
.dispute-def.hidden { display: none; }
.dispute-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dispute a { color: #1a6fb0; }
.dispute button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
}
.dispute button:hover:not(:disabled) { background: #f5f5f5; }
.dispute button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---- parola corrente ---- */
.current-word {
  height: 36px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
}
.current-word .center-letter { color: var(--seal); }
.caret {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background: var(--ink);
  animation: blink 1s step-end infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---- corolla delle sette lettere ---- */
.ring {
  position: relative;
  width: 240px;
  height: 240px;
  user-select: none;
  flex-shrink: 0;
}
.cell {
  position: absolute;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(34, 34, 42, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.06s;
}
.cell:active { transform: scale(0.92); }
/* niente attesa doppio-tap su mobile: il tap scatta subito */
.cell, button { touch-action: manipulation; }
.cell.center {
  width: 76px;
  height: 76px;
  background: var(--seal);
  border-color: var(--seal);
  color: #fff;
}

/* ---- bottoni: tutti della stessa identica forma ---- */
.controls { display: flex; gap: 12px; }
.controls button {
  width: 118px;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 23px;
  background: #fff;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
}
.controls button:hover { background: #f5f5f5; }
.controls button:active { background: #ececec; }

.hints { color: #888; font-size: 0.85rem; text-align: center; }

.btn-answers {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  color: #666;
  cursor: pointer;
}
.btn-answers:hover { background: #f5f5f5; }

/* ---- tooltip definizione/traduzione ---- */
.word-tip {
  position: fixed;
  z-index: 30;
  max-width: 320px;
  background: var(--dark);
  color: #f5f2ea;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  line-height: 1.45;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.word-tip.hidden { display: none; }
.word-tip img {
  float: right;
  width: 64px;
  height: 64px;
  object-fit: cover;
  margin: 0 0 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}

/* ---- overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: #fff;
  border-radius: 12px;
  padding: 30px 36px;
  text-align: center;
  max-width: 420px;
}
.overlay-card h2 { margin-bottom: 12px; }
.overlay-card p { margin-bottom: 20px; color: #555; }
.overlay-card button {
  padding: 10px 24px;
  border: none;
  border-radius: 24px;
  background: var(--dark);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
}
.confirm-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-secondary {
  background: #fff !important;
  color: var(--dark) !important;
  border: 1px solid var(--border) !important;
}

/* ---- modalità studio ---- */
.studio-card { max-width: 540px; width: 92vw; max-height: 86vh; overflow-y: auto; text-align: left; }
.studio-card h2, .studio-card > p { text-align: center; }
.studio-card input[type="text"], .studio-card textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.9rem;
  margin-bottom: 10px;
  background: var(--paper);
}
.studio-mode { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; font-size: 0.88rem; }
.studio-feedback { min-height: 22px; font-size: 0.85rem; color: var(--ink); margin-bottom: 8px; }
.studio-saved { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.studio-saved h3 { font-size: 0.9rem; margin-bottom: 6px; }
.studio-saved .theme-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.88rem;
}
.theme-row .theme-name { flex: 1; }
.theme-row button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
}
.theme-row button:hover { background: #f5f5f5; }

.side-list li.theme-word { color: #b8860b; font-weight: 700; }
#answers-list li.theme-word { color: #b8860b; font-weight: 700; }

.theme-banner {
  background: #fdf3d7;
  border: 1px solid #ecd9a0;
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.theme-banner button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: #888;
  font-size: 0.85rem;
}
.theme-banner.hidden { display: none; }
.theme-banner button.hidden { display: none; }

/* ---- Sfida tra esperti ---- */
.sfida-box { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.sfida-box h3 { font-size: 0.9rem; margin-bottom: 6px; }
.sfida-hint { font-size: 0.82rem; color: #555; margin-bottom: 8px; }
.sfida-hint code { font-family: Menlo, Consolas, monospace; font-size: 0.78rem; }
.sfida-box .confirm-row { align-items: center; }
.sfida-box .studio-feedback { flex: 1; margin-bottom: 0; text-align: left; }
.share-card { max-width: 520px; width: 92vw; text-align: left; }
.share-card h2, .share-card p { text-align: center; }
#share-text {
  width: 100%;
  font-family: Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  color: var(--dark);
  resize: vertical;
  margin-bottom: 14px;
}

.archive-list {
  list-style: none;
  overflow-y: auto;
  text-align: left;
  margin-bottom: 20px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  max-height: 50vh;
}
.archive-list li {
  padding: 7px 6px;
  border-bottom: 1px solid #eee9dd;
  font-size: 0.9rem;
  cursor: pointer;
}
.archive-list li:hover { background: var(--paper); }

.answers-card {
  max-width: 500px;
  width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.answers-card p { margin-bottom: 12px; }
#answers-list {
  list-style: none;
  overflow-y: auto;
  columns: 3;
  gap: 12px;
  text-align: left;
  margin-bottom: 20px;
  padding: 4px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
#answers-list li {
  padding: 3px 0;
  font-size: 0.9rem;
  break-inside: avoid;
  color: #999;
}
#answers-list li.found-word { color: var(--dark); }
#answers-list li.found-word::after { content: " ✓"; color: var(--green); }
#answers-list li.pangram { font-weight: 700; color: var(--ink); }
#answers-close { align-self: center; }

/* ---- Gioca con me (partita in due) ---- */
/* colore per giocatore: blu = chi invita, rosso = ospite (uguale sui due schermi) */
.side-list li.by-p0 { color: var(--ink); }
.side-list li.by-p1 { color: var(--seal); }
.col-ink { color: var(--ink); }
.col-seal { color: var(--seal); }

.match-card { max-width: 660px; }
.match-cols { display: flex; gap: 18px; margin-bottom: 8px; }
.match-cols > div {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--paper);
}
.match-cols h3 { font-size: 0.9rem; }
.match-cols p { font-size: 0.78rem; color: #555; margin: 0; text-align: left; }
.match-cols textarea {
  width: 100%;
  font-family: Menlo, Consolas, monospace;
  font-size: 0.62rem;
  line-height: 1.35;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  background: #fff;
  resize: vertical;
  margin-bottom: 0;
}
.match-cols button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--dark);
  align-self: flex-start;
}
.match-cols button:hover { background: #f5f5f5; }

.match-chat {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 274px;
  z-index: 15;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(34, 34, 42, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.match-chat.hidden { display: none; }
.chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 700;
}
#chat-status { font-weight: 400; font-size: 0.72rem; }
#chat-status.on { color: var(--green); }
#chat-status.off { color: #999; }
#match-leave {
  margin-left: auto;
  border: none;
  background: transparent;
  cursor: pointer;
  color: #888;
  font-size: 0.9rem;
  padding: 0 2px;
}
#match-leave:hover { color: var(--dark); }
#chat-msgs {
  height: 190px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--paper);
}
.chat-msg {
  max-width: 86%;
  padding: 4px 9px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.35;
  overflow-wrap: break-word;
}
.chat-msg.me { align-self: flex-end; background: var(--ink-soft); }
.chat-msg.peer { align-self: flex-start; background: #f3ddd9; }
.chat-msg.sys {
  align-self: center;
  background: transparent;
  color: #888;
  font-style: italic;
  font-size: 0.72rem;
  text-align: center;
}
.chat-row { display: flex; border-top: 1px solid var(--border); }
#chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  background: #fff;
  outline: none;
}
#chat-send {
  border: none;
  background: #fff;
  cursor: pointer;
  padding: 0 12px;
  color: var(--ink);
  font-weight: 700;
  font-family: inherit;
  font-size: 0.85rem;
}
#chat-send:hover { background: #f5f5f5; }

/* ---- schermi stretti (cellulare verticale): UNA colonna — fiore a tutta
   larghezza in alto, parole trovate su due colonne SOTTO. Le vecchie liste
   laterali stringevano la colonna centrale sotto la larghezza di fiore e
   bottoni: il pannello scorreva in orizzontale, tagliava "Invio" e rubava
   i tap alle lettere (il browser attendeva per decidere tap/trascinamento) */
@media (max-width: 700px) {
  main.layout {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "center center" "left right";
    grid-auto-rows: min-content;
    gap: 0 8px;
    padding: 4px 8px 8px;
    overflow-y: auto;   /* scorre tutta la pagina, SOLO in verticale */
    overflow-x: hidden;
  }
  .panel-center { grid-area: center; }
  .side-wrap.left { grid-area: left; }
  .side-wrap.right { grid-area: right; }
  .side-wrap { overflow: visible; padding: 2px; }
  .side-wrap.left .side-list li { text-align: left; } /* niente specchio */
  .side-list li { font-size: 0.85rem; word-break: break-all; padding: 4px 2px; }
  /* comandi in una barra FISSA in basso (zona del pollice): la parte
     nobile dello schermo resta al gioco. In alto solo titolo e data. */
  header { padding: 6px 10px; gap: 4px; }
  .header-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    justify-content: center;
    gap: 5px;
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -2px 8px rgba(34, 34, 42, 0.06);
  }
  .header-right button, .header-right select { padding: 5px 8px; font-size: 0.85rem; }
  /* il contenuto non deve finire sotto la barra */
  main.layout { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
  .btn-label { display: none; }
  #tip-mode { max-width: 36vw; }
  #lang-select { max-width: 32vw; }
  .rank-strip { padding: 4px 8px 2px; }
  #rank-label { min-width: 0; font-size: 0.85rem; }
  #score-label { font-size: 0.85rem; }
  #found-summary { font-size: 0.78rem; text-align: center; }
  /* niente centratura verticale: il fiore sta in alto e le liste sotto;
     scorre main.layout tutto insieme, così "Mostra risposte" resta
     raggiungibile e nessun riquadro interno intercetta i tocchi */
  .panel-center { justify-content: flex-start; overflow: visible; }
  .ring { margin: -2px 0; }
  .controls { gap: 10px; }
  .controls button { width: min(104px, 28vw); height: 44px; font-size: 0.85rem; }
  .current-word { font-size: 1.3rem; }
  h1 { font-size: 1.1rem; }
  #answers-list { columns: 2; }
  /* su schermi stretti il box argomenta non sta nella colonna centrale:
     diventa una scheda fissa sopra il gioco, senza mescolarsi al resto */
  .dispute {
    position: fixed;
    left: 3vw;
    right: 3vw;
    top: 14vh;
    max-width: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  }
  .match-cols { flex-direction: column; }
  .match-chat { width: 88vw; right: 6vw; bottom: calc(100px + env(safe-area-inset-bottom)); }
  #chat-msgs { height: 120px; }
}
