@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap');

:root {
  --color-bg: #fdfbf7;
  --color-bg-alt: #f6efe2;
  --color-champagne: #e8d5b7;
  --color-champagne-dark: #b99a63;
  --color-text: #3a332c;
  --color-text-light: #7a6f5f;
  --color-white: #ffffff;
  --font-sans: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--color-champagne);
}
.game-topbar__back { color: var(--color-text-light); text-decoration: none; font-size: 0.9rem; }
.game-topbar__title { font-family: var(--font-sans); font-weight: 600; font-size: 1.1rem; margin: 0; }

.game-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem;
  gap: 1rem;
}
@media (min-height: 560px) {
  .game-wrap { justify-content: center; }
}

.game-stage {
  position: relative;
  width: 100%;
  max-width: 960px;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(58, 51, 44, 0.12);
  border: 1px solid var(--color-champagne);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--color-bg);
  touch-action: none;
}

.hud {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  right: 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  pointer-events: none;
}
.hud__lives { display: flex; gap: 0.3rem; }
.hud__lives span {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--color-champagne-dark);
  box-shadow: 0 0 0 2px var(--color-white);
}
.hud__lives span.lost { background: transparent; box-shadow: inset 0 0 0 2px var(--color-champagne-dark); }
.hud__progress { flex: 1; height: 8px; background: rgba(255,255,255,0.6); border-radius: 999px; overflow: hidden; }
.hud__progress-bar {
  height: 100%; width: 100%; background: var(--color-champagne-dark);
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.15s linear;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(253, 251, 247, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem;
  gap: 0.75rem;
}
.overlay--hidden { display: none; }
#winOverlay { background: rgba(253, 251, 247, 0.55); }
#winOverlay h2, #winOverlay p { text-shadow: 0 1px 6px rgba(253, 251, 247, 0.9); }
.overlay h2 { font-family: var(--font-sans); font-weight: 600; font-size: 1.6rem; margin: 0; }
.overlay p { color: var(--color-text-light); margin: 0; max-width: 420px; font-size: 0.92rem; }
.overlay__controls { font-size: 0.85rem; }
.kbd-hint {
  display: inline-block; background: var(--color-white); border: 1px solid var(--color-champagne-dark);
  border-radius: 4px; padding: 0.05rem 0.4rem; font-size: 0.8rem;
}
.touch-hint { display: block; margin-top: 0.4rem; font-size: 0.78rem; }
.overlay button {
  margin-top: 0.5rem;
  font: inherit; cursor: pointer; border: none; border-radius: 999px;
  padding: 0.7rem 2rem; background: var(--color-champagne-dark); color: var(--color-white); font-size: 1rem;
}
.overlay button:hover { opacity: 0.9; }
.overlay__link { margin-top: 0.5rem; font-size: 0.85rem; color: var(--color-champagne-dark); text-decoration: underline; }

.touch-controls {
  width: 100%;
  max-width: 960px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem;
}
.touch-controls__move { display: flex; gap: 0.6rem; }
.touch-controls button {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--color-champagne-dark);
  background: var(--color-white); color: var(--color-text);
  border-radius: 12px; width: 3.2rem; height: 3.2rem; font-size: 1.2rem;
  user-select: none; -webkit-user-select: none;
  /* none, non manipulation: durante la pressione il telefono non deve
     interpretare il movimento del dito come uno scorrimento della pagina */
  touch-action: none;
  -webkit-touch-callout: none;
}
.touch-controls #btnJump { width: 6rem; letter-spacing: 0.05em; font-size: 0.85rem; }
.touch-controls button:active { background: var(--color-champagne); }

@media (hover: hover) and (pointer: fine) {
  .touch-controls { display: none; }
}

/* Telefono in orizzontale: lo schermo è basso, i comandi non ci starebbero
   sotto al campo — vanno sopra, appoggiati ai bordi. */
@media (max-height: 520px) and (pointer: coarse) {
  .game-topbar { padding: 0.35rem 0.8rem; }
  .game-topbar__title { font-size: 0.95rem; }
  .game-wrap { padding: 0.4rem; gap: 0.4rem; }
  .touch-controls {
    position: fixed;
    left: 0; right: 0; bottom: 0.7rem;
    max-width: none;
    padding: 0 1.2rem;
    pointer-events: none;
  }
  .touch-controls button {
    pointer-events: auto;
    opacity: 0.85;
    box-shadow: 0 2px 8px rgba(58, 51, 44, 0.25);
  }
}
