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

html, body { overscroll-behavior: none; }

body {
  font-family: Georgia, 'Times New Roman', serif;
  background: radial-gradient(ellipse at center, #3a2e22 0%, #241b12 70%, #171008 100%);
  color: #e8dcc4;
  min-height: 100vh;
}

a { color: #e9c46a; text-decoration: none; }
a:hover { text-decoration: underline; }

.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.center { text-align: center; }

.header { text-align: center; margin-bottom: 18px; }
.header h1 {
  font-size: clamp(24px, 4vw, 36px);
  letter-spacing: 2px;
  color: #e9c46a;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}
.sub { font-size: 15px; color: #b8a888; font-style: italic; margin-top: 4px; }

/* galleria */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.maze-card {
  background: rgba(20, 14, 8, 0.75);
  border: 2px solid #4a3826;
  border-radius: 10px;
  padding: 14px;
  color: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform 0.15s, border-color 0.15s;
}
.maze-card:hover { transform: translateY(-3px); border-color: #c9973f; text-decoration: none; }
.maze-card canvas { border-radius: 4px; image-rendering: pixelated; background: #241c13; }
.maze-info { text-align: center; }
.maze-info h3 { color: #e9c46a; font-size: 17px; }
.maze-info .author { color: #b8a888; font-size: 13px; font-style: italic; }
.maze-info .meta { color: #d8c9a3; font-size: 13px; margin-top: 4px; }
.foot { text-align: center; margin-top: 30px; }
.teacher-link { font-size: 13px; color: #8a7550; }

/* gioco */
.layout { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; justify-content: center; }
.game-col { flex: 1 1 560px; min-width: 300px; display: flex; justify-content: center; }
.hud { display: flex; gap: 16px; align-items: center; margin-bottom: 10px; font-size: 15px; color: #d8c9a3; flex-wrap: wrap; justify-content: center; }
.hud b { color: #e9c46a; }
.maze-canvas {
  display: block; border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.75), 0 0 0 6px #4a3826, 0 0 0 8px #2a1f14;
  max-width: 94vw; max-height: 70vh; touch-action: none;
}
.dpad { display: none; margin-top: 14px; grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 60px); gap: 6px; }
.dpad button { font-size: 22px; padding: 0; border-radius: 12px; touch-action: none; }
@media (pointer: coarse) { .dpad { display: grid; } }

.board-col { flex: 0 1 340px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }

/* card */
.save-card {
  background: linear-gradient(160deg, #f5e9c8, #e0c98f);
  color: #4a3517;
  padding: 18px 20px; border-radius: 10px;
  border: 3px solid #a07f3f;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.save-card h2 { font-size: 20px; margin-bottom: 6px; }
.save-card p { font-size: 14px; margin-bottom: 10px; }
.save-card.ok { border-color: #5d8a3c; }
.save-card.hint { border-color: #7a6a4a; }
.save-row { display: flex; gap: 8px; }
.save-row input, .panel input[type="text"], .panel input[type="password"] {
  flex: 1; font-family: inherit; font-size: 15px; padding: 8px 10px;
  border-radius: 8px; border: 2px solid #a07f3f; background: #fffaf0; color: #4a3517;
}

button {
  font-family: inherit; font-size: 15px; cursor: pointer;
  background: linear-gradient(180deg, #c9973f, #9c6f24);
  color: #fff8e7; border: 2px solid #6e4c15; border-radius: 8px; padding: 8px 16px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
button:disabled { opacity: 0.5; cursor: default; }
button.ghost { background: none; border: 1px solid #8a7550; color: #c9b78d; padding: 5px 12px; font-size: 13px; border-radius: 6px; text-shadow: none; }
button.ghost.dark { border-color: #a07f3f; color: #6e4c15; }
button.ghost.danger { border-color: #a03232; color: #a03232; }
button.active { background: linear-gradient(180deg, #5d8a3c, #456b2a); border-color: #33501f; }

.error { color: #ff9a8a; font-size: 13px; margin-top: 6px; }
.save-card .error { color: #a03232; }
.muted { color: #8a7550; font-size: 14px; }

/* classifica */
.leaderboard {
  background: rgba(20, 14, 8, 0.75);
  border: 2px solid #4a3826; border-radius: 10px;
  padding: 16px 18px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.leaderboard h2 { color: #e9c46a; font-size: 20px; margin-bottom: 10px; }
.leaderboard table, .admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.leaderboard th, .admin-table th {
  text-align: left; color: #b8a888; font-size: 12px; text-transform: uppercase;
  letter-spacing: 1px; padding: 4px 6px; border-bottom: 1px solid #4a3826;
}
.leaderboard td, .admin-table td { padding: 7px 6px; border-bottom: 1px solid rgba(74, 56, 38, 0.5); }
.leaderboard td.name { font-weight: bold; color: #f0e6cc; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.medal-1 td:first-child { color: #ffd700; font-weight: bold; }
.medal-2 td:first-child { color: #c0c0c0; font-weight: bold; }
.medal-3 td:first-child { color: #cd7f32; font-weight: bold; }

/* area docente */
.panel {
  background: rgba(20, 14, 8, 0.75);
  border: 2px solid #4a3826; border-radius: 10px;
  padding: 20px 22px; margin: 0 auto 18px; max-width: 980px;
}
.panel.narrow { max-width: 440px; }
.panel h2 { color: #e9c46a; font-size: 20px; margin-bottom: 8px; }
.panel p { margin-bottom: 12px; }
.panel input[type="number"] {
  width: 70px; font-family: inherit; font-size: 14px; padding: 5px 8px;
  border-radius: 6px; border: 2px solid #a07f3f; background: #fffaf0; color: #4a3517;
}
.panel input[type="file"] { color: #d8c9a3; font-size: 14px; }
.field { display: block; margin-bottom: 12px; font-size: 14px; color: #d8c9a3; }
.field input { display: block; width: 100%; margin-top: 4px; }

.detect-controls { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; font-size: 14px; color: #d8c9a3; }
.detect-controls label { display: flex; gap: 6px; align-items: center; }
.photo-canvas { max-width: 100%; border-radius: 6px; cursor: crosshair; display: block; margin-bottom: 16px; }
.edit-scroll { overflow: auto; max-width: 100%; margin-bottom: 12px; }
.edit-canvas { cursor: pointer; image-rendering: pixelated; }
.actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.hidden { display: none !important; }

/* pannello vittoria */
.win-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 7, 4, 0.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.win-modal { max-width: 420px; width: 100%; text-align: center; animation: pop 0.25s ease-out; }
.win-result { font-size: 17px; }
.win-modal .save-row { margin-top: 4px; }
.win-modal .skip { margin-top: 10px; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* miniatura segreta: il labirinto non si mostra in anteprima */
.thumb.mystery {
  width: 160px; height: 110px;
  display: flex; align-items: center; justify-content: center;
  font-size: 52px; font-weight: bold; color: rgba(255,248,231,0.92);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  background: radial-gradient(circle at center, #3a2e22, #171008);
  border: 2px dashed #6e5a3a;
  border-radius: 4px; opacity: 0.95;
}

/* selettore colore tessera */
.color-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 6px; }
.color-dot {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  padding: 0; cursor: pointer;
  background-clip: padding-box;
}
.color-dot.auto {
  background: radial-gradient(circle at 35% 30%, #8a7550, #241c13);
  font-size: 14px; line-height: 1;
}
.color-dot.selected { border-color: #fff8e7; box-shadow: 0 0 0 3px rgba(233,196,106,0.6); }
.color-dot.taken { opacity: 0.35; }
