:root {
  /* Palette natalizia ad alto contrasto */
  --bg-page: #0c1f15;
  --bg-panel: #132c1f;
  --bg-cartella: #163324;
  --bg-cell: #1d402d;

  --text-main: #f7f3e8;
  --text-muted: #9eb7a7;
  --text-cell-idle: #89a895;

  /* Stato: numeri estratti in precedenza (rosso natalizio) */
  --drawn-bg: #b91c1c;
  --drawn-border: #ef4444;
  --drawn-text: #ffffff;

  /* Stato: ultimo numero estratto (oro natalizio) */
  --last-bg: #f5b700;
  --last-border: #fff3b0;
  --last-text: #111814;

  /* Accenti e bordi */
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, 0.35);
  --border-subtle: rgba(247, 243, 232, 0.12);
  --danger-bg: #991b1b;
  --danger-hover: #b91c1c;
  --success-text: #86efac;
  --error-text: #fca5a5;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at top right, #163826 0%, var(--bg-page) 65%);
  color: var(--text-main);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.35;
}

/* Layout principale: occupa esattamente la viewport evitando lo scrolling */
.app-layout {
  display: grid;
  grid-template-columns: clamp(275px, 24vw, 340px) minmax(0, 1fr);
  gap: clamp(0.6rem, 1.4vw, 1.25rem);
  height: 100dvh;
  padding: clamp(0.6rem, 1.3vh, 1.1rem);
  overflow: hidden;
}

/* =========================================
   SIDEBAR CONTROLLI
   ========================================= */
.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(0.45rem, 1vh, 0.85rem);
  min-height: 0;
  overflow-y: auto;
}

.app-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--gold-soft);
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vh, 1.75rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--last-bg);
}

.counter {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.counter strong {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.panel {
  background-color: var(--bg-panel);
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius-md);
  padding: clamp(0.6rem, 1.2vh, 0.9rem);
}

.panel-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

/* Ultimo numero estratto */
.last-drawn-panel {
  text-align: center;
}

.last-number {
  display: grid;
  place-items: center;
  width: clamp(4.2rem, 10vh, 6rem);
  height: clamp(4.2rem, 10vh, 6rem);
  margin: 0.25rem auto 0.5rem;
  border-radius: 50%;
  background-color: var(--bg-cell);
  border: 3px solid var(--gold-soft);
  color: var(--text-muted);
  font-size: clamp(2rem, 4.8vh, 3rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: background-color 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.last-number.is-active {
  background-color: var(--last-bg);
  border-color: var(--last-border);
  color: var(--last-text);
  box-shadow: 0 0 20px rgba(245, 183, 0, 0.45);
}

.recent-wrapper {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-list {
  color: var(--text-main);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Pulsanti e icone */
.icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

.icon--light {
  filter: brightness(0) invert(1);
}

.icon--dark {
  filter: brightness(0);
}

.icon--gold {
  filter: brightness(0) saturate(100%) invert(76%) sepia(74%) saturate(751%) hue-rotate(356deg) brightness(101%) contrast(103%);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn:focus-visible,
input:focus-visible {
  outline: 2px solid var(--last-bg);
  outline-offset: 2px;
}

.btn-primary {
  background-color: var(--last-bg);
  color: var(--last-text);
}

.btn-primary:hover:not(:disabled) {
  background-color: #ffca28;
}

.btn-secondary {
  background-color: var(--drawn-bg);
  color: var(--drawn-text);
  border-color: var(--drawn-border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #d12323;
}

.btn-danger {
  background-color: var(--danger-bg);
  color: #ffffff;
  border-color: var(--drawn-border);
}

.btn-danger:hover:not(:disabled) {
  background-color: var(--danger-hover);
}

.btn-menu {
  background-color: var(--bg-cell);
  color: var(--text-main);
  border-color: var(--border-subtle);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 0.6rem;
}

.btn-menu:hover:not(:disabled) {
  background-color: #25523a;
  border-color: var(--gold-soft);
}

.btn-danger-outline:hover:not(:disabled) {
  background-color: rgba(185, 28, 28, 0.35);
  border-color: var(--drawn-border);
}

/* Estrazione digitale + manuale */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn-draw {
  width: 100%;
  padding: clamp(0.65rem, 1.3vh, 0.9rem);
  font-size: 1rem;
}

.manual-form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
}

.manual-input-group {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
}

.manual-input-group input {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius-sm);
  background-color: var(--bg-page);
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.feedback {
  min-height: 1.15em;
  margin: 0;
  font-size: 0.8rem;
}

.feedback.is-error {
  color: var(--error-text);
}

.feedback.is-success {
  color: var(--success-text);
}

/* Menu partita */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

/* Footer sidebar: legenda sopra, crediti sotto */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.legend {
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  width: 100%;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.swatch--last {
  background-color: var(--last-bg);
  border: 1px solid var(--last-border);
}

.swatch--drawn {
  background-color: var(--drawn-bg);
  border: 1px solid var(--drawn-border);
}

.credits {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  color: var(--text-muted);
  text-align: center;
}

.credits-logo {
  display: block;
  height: 22px;
  width: auto;
  max-width: 150px;
  object-fit: contain;
}

.credits-link {
  color: var(--text-main);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.15s ease;
}

.credits-link:hover {
  color: var(--last-bg);
}

.credits-logo-link {
  display: inline-block;
  line-height: 0;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.credits-logo-link:hover {
  opacity: 0.85;
  transform: scale(1.03);
}

.credits-link:focus-visible,
.credits-logo-link:focus-visible {
  outline: 2px solid var(--last-bg);
  outline-offset: 2px;
}

/* =========================================
   TABELLONE 6 CARTELLE (90 NUMERI)
   ========================================= */
.board-container {
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(0.45rem, 1.3vh, 0.95rem);
  height: 100%;
  min-height: 0;
}

.cartella {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: clamp(0.25rem, 0.7vh, 0.5rem);
  padding: clamp(0.35rem, 0.9vh, 0.65rem);
  background-color: var(--bg-cartella);
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius-md);
  min-width: 0;
  min-height: 0;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-sm);
  background-color: var(--bg-cell);
  border: 1px solid var(--border-subtle);
  color: var(--text-cell-idle);
  font-size: clamp(1rem, min(2.4vw, 3.6vh), 2.15rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

/* Numeri estratti in precedenza */
.cell.is-drawn {
  background-color: var(--drawn-bg);
  border-color: var(--drawn-border);
  color: var(--drawn-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Ultimo numero estratto */
.cell.is-last {
  background-color: var(--last-bg);
  border-color: var(--last-border);
  color: var(--last-text);
  font-weight: 900;
  box-shadow: 0 0 0 2px var(--last-border), 0 0 16px rgba(245, 183, 0, 0.55);
  transform: scale(1.03);
  z-index: 1;
}

/* =========================================
   MODALE NATIVO DI DOPPIA VERIFICA
   ========================================= */
.confirm-dialog {
  width: min(460px, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--gold);
  border-radius: var(--radius-lg);
  background-color: var(--bg-panel);
  color: var(--text-main);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.confirm-dialog::backdrop {
  background-color: rgba(6, 15, 10, 0.78);
  backdrop-filter: blur(2px);
}

.dialog-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--last-bg);
}

.dialog-body {
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dialog-description {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-main);
}

.dialog-warning {
  margin: 0;
  padding: 0.65rem 0.8rem;
  border-left: 3px solid var(--last-bg);
  border-radius: var(--radius-sm);
  background-color: rgba(245, 183, 0, 0.1);
  color: #fde68a;
  font-size: 0.86rem;
}

.dialog-import-box {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.35rem;
}

.dialog-import-box[hidden] {
  display: none;
}

.file-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.dialog-import-box input[type="file"] {
  padding: 0.45rem;
  border: 1px dashed var(--gold-soft);
  border-radius: var(--radius-sm);
  background-color: var(--bg-page);
  color: var(--text-main);
  font-size: 0.85rem;
}

.import-status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.84rem;
}

.import-status.is-valid {
  color: var(--success-text);
}

.import-status.is-error {
  color: var(--error-text);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
}

/* Adattamento per schermi stretti / orientamento verticale */
@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar {
    overflow: visible;
  }

  .board {
    min-height: 62vh;
  }

  .cell {
    font-size: clamp(0.95rem, 3.2vw, 1.4rem);
    min-height: 2.3rem;
  }
}