@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Nunito:wght@500;700;800&display=swap');

:root {
  --sky: #FDECC8;
  --sea: #1B7A73;
  --sea-light: #2A9D8F;
  --sand: #E8C994;
  --wood: #6B4226;
  --accent: #C1440E;
  --gold: #E3B23C;
  --ink: #2B2118;
  --paper: #F4E9CE;
  --found: #4C9A5A;
  --font-display: 'Baloo 2', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: radial-gradient(circle at 50% 0%, #cdeee6, #6fae a1 70%);
  background: radial-gradient(circle at 50% 0%, #cdeee6, #6fae9f 70%);
  overflow-x: hidden;
}

button {
  font-family: var(--font-display);
  cursor: pointer;
}

/* ---------- Écrans génériques ---------- */
.screen {
  display: none;
  min-height: 100vh;
  width: 100%;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 24px 16px;
}

.screen.active { display: flex; }

/* ---------- Écran de chargement ---------- */
.loading-box {
  text-align: center;
}

.loading-compass {
  width: 90px;
  height: 90px;
  margin: 0 auto 18px;
  animation: spin 2.4s linear infinite;
}

.loading-compass svg { width: 100%; height: 100%; }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.loading-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--wood);
  margin-bottom: 14px;
}

.loading-bar {
  width: 220px;
  height: 14px;
  background: #ffffff80;
  border: 2px solid var(--wood);
  border-radius: 999px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  transition: width 0.25s ease;
}

/* ---------- Accueil ---------- */
.home-box {
  background: var(--paper);
  border: 4px solid var(--wood);
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 0 rgba(0,0,0,0.18);
}

.home-title-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 8px;
}

.home-title-img[data-broken="true"] { display: none; }

.home-title-fallback {
  display: none;
  font-family: var(--font-display);
  font-size: 2.2rem;
  line-height: 1.1;
  color: var(--accent);
  margin: 0 0 18px;
  text-shadow: 2px 2px 0 var(--gold);
}

.home-title-fallback.show { display: block; }

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 0 #8a3009;
}
.btn-primary:active { transform: translateY(3px); box-shadow: none; }

.btn-secondary {
  background: var(--sea-light);
  color: white;
  box-shadow: 0 4px 0 #145e58;
}
.btn-secondary:active { transform: translateY(3px); box-shadow: none; }

.home-footer-text {
  font-size: 0.9rem;
  color: var(--wood);
  margin: 10px 0 0;
  font-weight: 600;
}

/* ---------- Modale règles ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,40,35,0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-overlay.show { display: flex; }

.modal-card {
  background: var(--paper);
  border: 4px solid var(--gold);
  border-radius: 20px;
  padding: 26px 26px 20px;
  max-width: 420px;
  text-align: center;
}

.modal-card h2 {
  font-family: var(--font-display);
  color: var(--accent);
  margin-top: 0;
}

.modal-card p {
  font-weight: 600;
  line-height: 1.7;
  margin-bottom: 18px;
}

/* ---------- Écran de jeu ---------- */
#screen-game { padding: 12px; align-items: stretch; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--paper);
  border: 3px solid var(--wood);
  border-radius: 16px;
  padding: 10px 16px;
  margin: 0 auto 12px;
  max-width: 1080px;
  width: 100%;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 8px;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  background: #ffffff80;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scene-title {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--accent);
  font-size: 1.1rem;
}

.scene-progress {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--wood);
  background: #ffffffaa;
  border-radius: 999px;
  padding: 4px 12px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(210px, 1fr);
  gap: 14px;
  max-width: 1080px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 760px) {
  .game-layout { grid-template-columns: 1fr; }
}

.scene-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 3px solid var(--wood);
  box-shadow: 0 6px 0 rgba(0,0,0,0.18);
  background: #cfe9e3;
  line-height: 0;
}

.scene-image {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
}

.hitzones-layer {
  position: absolute;
  inset: 0;
}

.hitzone {
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.001);
  cursor: pointer;
}

.hitzone.debug-visible {
  background: rgba(255, 216, 77, 0.28);
  border: 2px dashed #ffb703;
}

.found-ring {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.4);
  border-radius: 50%;
  border: 4px solid #FFD84D;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 0 14px rgba(255, 216, 77, 0.9);
}

.found-ring.active {
  animation: pop-ring 0.6s ease-out forwards;
}

@keyframes pop-ring {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  55% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.miss-mark {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  pointer-events: none;
  opacity: 0.9;
}

.miss-mark.play {
  animation: ripple 0.5s ease-out forwards;
}

@keyframes ripple {
  0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
}

.debug-panel {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0,0,0,0.75);
  color: #FFD84D;
  font-family: monospace;
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 8px;
  max-width: 90%;
  z-index: 5;
}

.sidebar {
  background: var(--paper);
  border: 3px solid var(--wood);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18);
  align-self: start;
}

.sidebar h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0 0 10px;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff8ea;
  border: 2px solid #e2cb98;
  border-radius: 12px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 0.95rem;
  transition: all 0.25s ease;
}

.item-list .item-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.item-list .item-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.item-list li.found {
  background: #e4f4e6;
  border-color: var(--found);
  color: var(--found);
  text-decoration: line-through;
  opacity: 0.9;
}

.item-list li .check {
  margin-left: auto;
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s ease;
}

.item-list li.found .check {
  opacity: 1;
  transform: scale(1);
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: white;
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 35, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}

.overlay.show { display: flex; }

.overlay-card {
  background: var(--paper);
  border: 4px solid var(--gold);
  border-radius: 20px;
  padding: 26px 30px;
  text-align: center;
  max-width: 340px;
}

.overlay-card h3 {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 1.4rem;
  margin: 6px 0;
}

.overlay-card .btn { margin-top: 10px; }
