:root {
  --brand-green: #0F5C3F;
  --brand-gold: #D4A94E;
  --brand-bordeaux: #5C1A2B;
  --text-cream: #FBF3E1;
  --bg: #121212;
  --bg-panel: #1c1c1c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* L'attributo hidden deve vincere sempre: altrimenti una regola come
   ".clock-bar { display: flex }" lo annulla (la barra dell'orologio vuota
   compariva anche nelle partite senza tempo). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-cream);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
}

#app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--brand-gold);
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}

.big-button {
  display: block;
  width: 100%;
  padding: 0.9rem 1rem;
  margin: 0.5rem 0;
  background: var(--brand-bordeaux);
  color: var(--text-cream);
  border: 2px solid var(--brand-gold);
  border-radius: 10px;
  font-size: 1.1rem;
}

.big-button:hover, .big-button:focus-visible {
  background: var(--brand-green);
}

.hero-image {
  display: block;
  width: 60%;
  max-width: 260px;
  margin: 1rem auto;
  border-radius: 16px;
}

/* Scacchiera */
.board-container {
  display: inline-block;
  border: 3px solid var(--brand-gold);
  margin: 1rem auto;
}

.board-row {
  display: flex;
}

/* Lato casella: riempie la larghezza disponibile (fino a 76 px, ad es. su
   iPad) senza superare il 9% dell'altezza, così campo comandi e pulsanti
   restano sullo schermo. Prima era bloccato a 56 px anche sugli schermi
   grandi. Le immagini dei set raster sono a 168 px: nitide fino a 84 px. */
.square {
  --sq: max(34px, min(calc((min(100vw, 640px) - 2rem - 6px) / 8), 9vh, 76px));
  width: var(--sq);
  height: var(--sq);
  border: none;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Focus da tastiera ben visibile su qualunque colore casella. */
.square:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: -5px;
  box-shadow: inset 0 0 0 5px #000000;
}

.square.selected {
  outline: 3px solid var(--brand-gold);
  outline-offset: -3px;
}

.square.legal-target::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: rgba(212, 169, 78, 0.85);
}

.piece-svg {
  width: 90%;
  height: 90%;
  pointer-events: none;
}
.piece-svg, .piece-svg * {
  stroke-width: 2;
}

.clock-bar {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  padding: 0.25rem 0.5rem;
  background: var(--bg-panel);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.move-form {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.move-form input[type="text"] {
  flex: 1;
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--brand-gold);
  background: #fff;
  color: #111;
}
.move-form button {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 2px solid var(--brand-gold);
  background: var(--brand-green);
  color: var(--text-cream);
}

.function-box {
  display: flex;
  gap: 0.5rem;
}
.function-box button {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 2px solid var(--brand-bordeaux);
  background: transparent;
  color: var(--text-cream);
}

.post-game-panel {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg-panel);
  border-radius: 10px;
  text-align: center;
}
.post-game-panel button {
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: 2px solid var(--brand-gold);
  background: var(--brand-bordeaux);
  color: var(--text-cream);
}

form .field {
  margin-bottom: 1rem;
}
form label {
  display: block;
  margin-bottom: 0.25rem;
}
select, input[type="number"], input[type="text"], textarea {
  font-size: 1rem;
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--brand-gold);
  background: #fff;
  color: #111;
}

fieldset {
  border: 1px solid var(--brand-gold);
  border-radius: 8px;
  margin-bottom: 1rem;
}
legend {
  color: var(--brand-gold);
  padding: 0 0.4rem;
}

.preview-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.preview-row button {
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 2px solid var(--brand-gold);
  background: var(--brand-green);
  color: var(--text-cream);
}
.preview-row button[aria-pressed="true"] {
  background: var(--brand-bordeaux);
}

.color-swatch-preview {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}
.color-swatch-preview .swatch {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid #000;
}
.contrast-warning {
  color: #ffb3b3;
  font-weight: bold;
}
.contrast-ok {
  color: #b7f7c0;
}

.app-dialog {
  border-radius: 12px;
  border: 2px solid var(--brand-gold);
  background: var(--bg-panel);
  color: var(--text-cream);
  padding: 1.2rem;
  max-width: 90vw;
}
.app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}
.dialog-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
.dialog-buttons button {
  flex: 1;
  min-width: 100px;
  padding: 0.6rem;
  border-radius: 8px;
  border: 2px solid var(--brand-gold);
  background: transparent;
  color: var(--text-cream);
}
.dialog-buttons button.primary {
  background: var(--brand-green);
}

.saved-game-item {
  border: 1px solid var(--brand-gold);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}
.saved-game-item textarea {
  width: 100%;
  height: 8rem;
  margin-top: 0.5rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--brand-gold);
  background: none;
  border: none;
  text-decoration: underline;
  padding: 0.4rem 0;
}

.info-section a {
  color: var(--brand-gold);
}

.home-footer {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(212, 169, 78, 0.35);
  font-size: 0.95rem;
}

.home-footer p {
  margin: 0.4rem 0;
}

.home-footer a {
  color: var(--brand-gold);
}

.field-error {
  color: #ffb3b3;
  font-weight: bold;
  margin: 0.5rem 0 0;
}

.field-hint {
  font-size: 0.9rem;
  opacity: 0.85;
  margin: 0.25rem 0 0.75rem;
}

.volume-value {
  display: inline-block;
  min-width: 3.5em;
  margin-left: 0.5rem;
  font-variant-numeric: tabular-nums;
}

.status-message {
  margin: 0.5rem 0;
}

.import-section textarea {
  width: 100%;
  min-height: 6rem;
}
.import-section button,
.saved-game-item button {
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 2px solid var(--brand-gold);
  background: var(--brand-green);
  color: var(--text-cream);
  margin-top: 0.5rem;
}
.saved-game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Titoli che ricevono il focus a ogni cambio schermata: nessun riquadro di
   focus visibile al clic, ma il titolo resta il punto di partenza per lo
   screen reader. */
h1[tabindex="-1"]:focus,
h2[tabindex="-1"]:focus {
  outline: none;
}

.nested-fieldset {
  border: none;
  padding: 0;
  margin: 0 0 1rem;
}
.nested-fieldset legend {
  padding: 0;
  color: var(--text-cream);
}

.saved-games-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.saved-game-item h4 {
  margin: 0;
  font-size: 1rem;
}

/* Voce e musica durante la partita */
.live-settings {
  margin-top: 1rem;
}
.live-settings .field {
  margin-bottom: 0.6rem;
}
.live-settings label {
  display: block;
}
.live-settings input[type="range"] {
  vertical-align: middle;
}

/* Pulsante "Ripristina colori predefiniti" in Impostazioni */
fieldset > button {
  margin-top: 0.6rem;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 2px solid var(--brand-gold);
  background: var(--brand-green);
  color: var(--text-cream);
}
/* Su telefono le opzioni lunghe (es. "Espanso, più semplice ...") non
   devono far uscire il menu dallo schermo. */
.live-settings {
  min-width: 0;
}
.live-settings select {
  max-width: 100%;
}
