:root {
  --page-bg: #f8ead5;
  --ink: #2c1d13;
  --panel: rgba(255, 249, 239, 0.88);
  --panel-border: rgba(70, 41, 20, 0.15);
  --shadow: rgba(62, 39, 27, 0.18);
  --accent-red: #d24b2a;
  --accent-green: #506534;
  --accent-blue: #3d7999;
  --accent-gold: #d1a81f;
  --warm-brown: #5a3524;
  --soft-white: #fff7ec;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Avenir Next Condensed", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 32%),
    radial-gradient(circle at bottom right, rgba(255, 203, 132, 0.55), transparent 30%),
    linear-gradient(160deg, #f8f0df 0%, #efd8b5 48%, #d2b48d 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(rgba(92, 63, 44, 0.05) 1px, transparent 1px),
    radial-gradient(rgba(92, 63, 44, 0.035) 1px, transparent 1px);
  background-position: 0 0, 14px 14px;
  background-size: 28px 28px;
  opacity: 0.6;
}

.page-shell {
  position: relative;
  padding: 28px;
}

.hero {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.hero-copy,
.hero-art,
.panel,
.game-panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: 0 16px 35px var(--shadow);
  backdrop-filter: blur(10px);
}

.hero-copy,
.hero-art,
.panel {
  border-radius: 28px;
}

.hero-copy {
  padding: 28px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent-red);
}

h1,
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  font-size: clamp(2.4rem, 5vw, 4.8rem);
  line-height: 0.94;
}

.subtitle {
  max-width: 42rem;
  font-size: 1.12rem;
  line-height: 1.5;
}

.language-switch {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.lang-btn,
#start-button,
#submit-button,
#refresh-button,
.audio-toggle {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  transition: transform 120ms ease, filter 120ms ease;
}

.lang-btn {
  padding: 10px 15px;
  background: rgba(90, 53, 36, 0.09);
  color: var(--ink);
}

.lang-btn.active {
  background: var(--warm-brown);
  color: var(--soft-white);
}

.lang-btn:hover,
#start-button:hover,
#submit-button:hover,
#refresh-button:hover,
.audio-toggle:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.hero-art {
  position: relative;
  min-height: 260px;
  padding: 22px;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(61, 121, 153, 0.2), transparent 30%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(235, 218, 197, 0.8));
}

.hero-art::before,
.hero-art::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(210, 75, 42, 0.12);
}

.hero-art::before {
  width: 180px;
  height: 180px;
  right: -50px;
  top: -40px;
}

.hero-art::after {
  width: 140px;
  height: 140px;
  left: -40px;
  bottom: -50px;
}

.buddy-card {
  position: absolute;
  border-radius: 22px;
  background: rgba(255, 251, 244, 0.94);
  border: 1px solid rgba(44, 29, 19, 0.09);
  box-shadow: 0 18px 28px rgba(48, 32, 21, 0.14);
}

.buddy-card-left {
  inset: 22px 34% 22px 22px;
  transform: rotate(-5deg);
}

.buddy-card-right {
  width: 44%;
  right: 22px;
  top: 42px;
  bottom: 42px;
  padding: 24px;
  display: flex;
  align-items: end;
  justify-content: start;
  transform: rotate(7deg);
  background:
    linear-gradient(180deg, rgba(255, 241, 226, 0.95), rgba(240, 221, 198, 0.94));
}

.card-note {
  max-width: 10rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  line-height: 1.05;
}

/* ============================================
   BUDDY PORTRAIT — Buddy the Sable (référence photo réelle)
   Traits clés : grandes oreilles triangulaires écartées,
   tête triangulaire, museau court arrondi, corps brun-gris foncé
   ============================================ */

.buddy-portrait {
  position: absolute;
  inset: 4% 6% 8%;
}

.ear,
.body,
.paw,
.face,
.muzzle,
.mouth,
.tongue,
.tail,
.collar,
.eye,
.nose {
  position: absolute;
}

.buddy-portrait::before,
.buddy-portrait::after,
.paw::before,
.paw::after,
.face::before,
.face::after,
.ear::before {
  content: "";
  position: absolute;
}

/* Ombre portée sous Buddy */
.buddy-portrait::before {
  left: 20%;
  right: 20%;
  bottom: 0%;
  height: 10%;
  background: radial-gradient(circle at center, rgba(20, 12, 8, 0.25), transparent 70%);
  filter: blur(8px);
}

.buddy-portrait::after {
  display: none;
}

/* OREILLES — GRANDES, triangulaires, très écartées, signature de Buddy
   Beige/brun clair à l'intérieur */
.ear {
  width: 20%;
  height: 28%;
  /* Ancrées au sommet de la tête (face débute à ~20%) */
  top: 12%;
  background: #2a1c14;
  clip-path: polygon(10% 100%, 0% 30%, 50% 0%, 100% 30%, 90% 100%);
  /* Derrière la tête pour que la base soit cachée par la face */
  z-index: 4;
}

.ear-left {
  left: 18%;
  transform: rotate(-8deg);
}

.ear-right {
  right: 18%;
  transform: rotate(8deg);
}

/* Intérieur oreille — beige/brun clair comme sur la photo */
.ear::before {
  inset: 12% 18% 8% 18%;
  background: linear-gradient(180deg, #c8956a 0%, #a06840 60%, #7a4a28 100%);
  clip-path: polygon(15% 100%, 5% 32%, 50% 4%, 95% 32%, 85% 100%);
  opacity: 0.88;
}

/* CORPS — trapézoïdal, épaules larges, se rétrécit vers le bas */
.body {
  left: 18%;
  right: 18%;
  top: 52%;
  bottom: 4%;
  background: linear-gradient(180deg, #2a1e16 0%, #1a130e 100%);
  border-radius: 35% 35% 30% 30%;
  z-index: 2;
}

/* TETE — triangulaire, large en haut (oreilles), pointue vers le bas (museau) */
.face {
  left: 14%;
  right: 14%;
  top: 20%;
  bottom: 30%;
  background: radial-gradient(circle at 50% 55%, #2e2018 0%, #1a130e 55%, #0e0a07 100%);
  /* Triangle arrondi — large en haut, étroit en bas */
  border-radius: 45% 45% 55% 55% / 35% 35% 65% 65%;
  clip-path: polygon(8% 15%, 50% 0%, 92% 15%, 98% 55%, 80% 90%, 50% 100%, 20% 90%, 2% 55%);
  z-index: 5;
}

/* Joues légèrement plus claires */
.face::before {
  left: 8%;
  top: 50%;
  width: 22%;
  height: 20%;
  background: radial-gradient(circle, rgba(80, 55, 38, 0.25), transparent 70%);
  border-radius: 50%;
}

.face::after {
  right: 8%;
  top: 50%;
  width: 22%;
  height: 20%;
  background: radial-gradient(circle, rgba(80, 55, 38, 0.22), transparent 70%);
  border-radius: 50%;
}

/* MUSEAU — court, arrondi, centré bas de la tête */
.muzzle {
  left: 36%;
  right: 36%;
  top: 64%;
  bottom: 22%;
  background: radial-gradient(circle at 50% 35%, #3a2a1e 0%, #1e1510 80%);
  border-radius: 50%;
  z-index: 6;
}

/* QUEUE — petite, visible derrière */
.tail {
  width: 16%;
  height: 18%;
  right: 6%;
  top: 62%;
  background: linear-gradient(180deg, #1e1610, #0c0908);
  border-radius: 50% 40% 60% 55%;
  transform: rotate(20deg);
  z-index: 1;
}

/* COLLIER BLEU — signature Buddy */
.collar {
  left: 30%;
  right: 30%;
  top: 74%;
  height: 4.5%;
  background: #3d7999;
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(61, 121, 153, 0.2);
  z-index: 8;
}

/* YEUX — petits, noirs, rapprochés (comme sur la photo) */
.eye {
  width: 9%;
  height: 10%;
  top: 40%;
  background: radial-gradient(circle at 34% 30%, #1e1a18 0%, #060404 60%, #020202 100%);
  border-radius: 50%;
  z-index: 9;
}

.eye::after {
  width: 32%;
  height: 32%;
  left: 12%;
  top: 10%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
}

.eye-left {
  left: 32%;
}

.eye-right {
  right: 32%;
}

/* NEZ — petit, arrondi, couleur sombre */
.nose {
  width: 9%;
  height: 6.5%;
  left: 45.5%;
  top: 63%;
  background: #0c0908;
  border-radius: 42% 42% 54% 54%;
  z-index: 8;
}

/* BOUCHE — fermée, discrète */
.mouth {
  left: 44%;
  right: 44%;
  top: 71%;
  bottom: 20%;
  background: #090706;
  border-radius: 30% 30% 50% 50%;
  z-index: 7;
}

.mouth::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 20%;
  width: 1px;
  height: 40%;
  background: rgba(255, 200, 160, 0.1);
  transform: translateX(-50%);
}

/* LANGUE — cachée */
.tongue {
  display: none;
}

/* PATTES — petites, arrondies */
.paw {
  width: 18%;
  height: 18%;
  bottom: 4%;
  background: linear-gradient(180deg, #1c1510 0%, #0a0807 100%);
  border-radius: 36% 36% 28% 28%;
  z-index: 4;
}

.paw-left {
  left: 20%;
}

.paw-right {
  right: 20%;
}

/* Petites griffes blanches */
.paw::before {
  bottom: 6%;
  width: 8%;
  height: 16%;
  background: #ede8e2;
  border-radius: 45% 45% 70% 70%;
  left: 22%;
  box-shadow: 13px 0 0 #ede8e2, 26px 0 0 #ede8e2;
}

.paw::after {
  display: none;
}
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(290px, 0.8fr);
  gap: 24px;
  align-items: start;
}

.game-stack {
  display: grid;
  gap: 24px;
  min-width: 0;
}

.game-panel {
  position: relative;
  padding: 14px;
  border-radius: 32px;
}

.howto-panel {
  padding: 30px 34px;
}

.howto-panel h2 {
  margin-bottom: 16px;
  font-size: clamp(2rem, 3.4vw, 3rem);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 22px;
  background: #fffaf3;
}

.canvas-banner {
  position: absolute;
  left: 50%;
  top: 42px;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: rgba(44, 29, 19, 0.85);
  color: #fff8f1;
  border-radius: 999px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
}

.hidden {
  display: none;
}

.sidebar {
  display: grid;
  gap: 18px;
  align-content: start;
}

.panel {
  padding: 20px;
}

.panel h2 {
  margin-bottom: 12px;
  font-size: 1.6rem;
}

.field-label,
.status-text {
  display: block;
  font-size: 0.94rem;
}

.field-label {
  margin-bottom: 8px;
}

#player-name {
  width: 100%;
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(44, 29, 19, 0.18);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  font: inherit;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

#start-button,
#submit-button,
#refresh-button,
.audio-toggle {
  padding: 11px 16px;
}

#start-button {
  background: linear-gradient(180deg, #d85d35, #b9411e);
  color: var(--soft-white);
}

#submit-button {
  background: linear-gradient(180deg, #568148, #39592f);
  color: var(--soft-white);
}

#submit-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

#refresh-button {
  background: rgba(61, 121, 153, 0.14);
  color: var(--ink);
}

.status-text {
  min-height: 2.8em;
  margin-top: 14px;
  line-height: 1.45;
}

.audio-controls {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(44, 29, 19, 0.08);
  display: grid;
  gap: 10px;
}

.audio-title {
  font-size: 1.1rem;
  margin: 0;
}

.audio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.audio-label {
  font-size: 0.96rem;
}

.audio-toggle {
  min-width: 86px;
  background: rgba(61, 121, 153, 0.12);
  color: var(--ink);
}

.audio-toggle.active {
  background: linear-gradient(180deg, #5a3524, #341d12);
  color: var(--soft-white);
}

.panel-section + .panel-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(44, 29, 19, 0.08);
}

.panel-section-title {
  margin: 0 0 8px;
  font-size: 0.96rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(44, 29, 19, 0.82);
}

.panel-help-text {
  margin: 0;
  line-height: 1.55;
}

.mini-list {
  margin: 0;
  padding-left: 18px;
  line-height: 1.65;
}

.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.leaderboard-list {
  margin: 14px 0 0;
  padding-left: 24px;
  display: grid;
  gap: 10px;
}

.leaderboard-list li {
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.96rem;
}

.leaderboard-list .meta {
  opacity: 0.72;
}

@keyframes drift {
  0%,
  100% {
    transform: translateY(0) rotate(-5deg);
  }
  50% {
    transform: translateY(-6px) rotate(-3deg);
  }
}

.buddy-card-left {
  animation: drift 4.8s ease-in-out infinite;
}

@media (max-width: 1100px) {
  .hero,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .hero-art {
    min-height: 220px;
  }
}

@media (max-width: 760px) {
  .page-shell {
    padding: 16px;
  }

  .hero-copy,
  .hero-art,
  .panel,
  .game-panel {
    border-radius: 22px;
  }

  .button-row {
    flex-direction: column;
  }

  #start-button,
  #submit-button,
  .audio-toggle {
    width: 100%;
  }

  .audio-row {
    align-items: start;
    flex-direction: column;
  }
}
