/* Stile comune dei mini-giochi (orso-pizza.html, coccinella-mele.html) */
:root {
  --bg-top: #f5ebe0;
  --bg-mid: #e8d5c4;
  --bg-bottom: #ddc9b8;
  --surface: rgba(255, 250, 245, 0.98);
  --text: #4a3f35;
  --heading: #5c4a3a;
  --muted: #6b5b4f;
  --btn-from: #9c7a50;
  --btn-to: #84643f;
  --shadow: rgba(139, 119, 101, 0.3);
  --focus: #6b4e2a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-top: #221c17;
    --bg-mid: #2a221c;
    --bg-bottom: #1d1814;
    --surface: rgba(48, 40, 34, 0.96);
    --text: #efe3d6;
    --heading: #f6eadc;
    --muted: #cdbcab;
    --btn-from: #a8845a;
    --btn-to: #8c6b44;
    --shadow: rgba(0, 0, 0, 0.4);
    --focus: #f0d2a8;
    color-scheme: dark;
  }
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-mid) 40%, var(--bg-bottom) 100%);
  background-color: var(--bg-mid);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.game-shell {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: 0 14px 32px var(--shadow);
  padding: 14px 16px 20px;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}

.game-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--heading);
}

.score {
  font-size: 0.9rem;
  color: var(--muted);
}

.stage {
  position: relative;
}

canvas {
  display: block;
  margin: 0 auto;
  border-radius: 16px;
  background: #1f2124;
  width: 100%;
  max-width: 420px;
  height: auto;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  border-radius: 16px;
  background: rgba(20, 16, 12, 0.72);
  color: #fff;
  text-align: center;
}

.overlay[hidden] {
  display: none;
}

.overlay p {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
}

.overlay-btn {
  min-height: 48px;
  padding: 0.7rem 1.6rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--btn-from) 0%, var(--btn-to) 100%);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.instructions {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.controls {
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  gap: 8px;
  justify-content: center;
}

.btn-dir {
  border-radius: 14px;
  border: none;
  background: linear-gradient(180deg, var(--btn-from) 0%, var(--btn-to) 100%);
  color: #fff;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-dir:active {
  transform: translateY(2px);
}

.btn-dir[data-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}

.btn-dir[data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.btn-dir[data-dir="down"] {
  grid-column: 2;
  grid-row: 2;
}

.btn-dir[data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

/* su desktop usiamo la tastiera */
@media (hover: hover) and (pointer: fine) {
  .controls {
    display: none;
  }
}
