/* POLLO KOMBAT — acquerello Ghibli al tramonto */

:root {
  --cream: #FBF3E4;
  --paper: #F6EBD3;
  --ink: #4A3B2E;
  --ink-soft: #7A6A56;
  --red: #C0392B;
  --red-deep: #8F2B20;
  --teal: #4E7E7B;
  --gold: #D9A441;
  --sky-hi: #8FC7E8;
  --sky-lo: #FFE3B8;
  --shadow: rgba(74, 59, 46, 0.35);
  --font-title: "Cormorant Garamond", Georgia, serif;
  --font-ui: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", sans-serif;
  --font-hand: "Caveat", cursive;
}

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

html, body {
  height: 100%;
  background: #241C15;
  font-family: var(--font-ui);
  color: var(--ink);
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(120% 90% at 50% 10%, #3A2E22 0%, #241C15 70%);
}

canvas#game {
  display: block;
  width: min(100vw, calc(100vh * (960 / 540)));
  height: min(100vh, calc(100vw * (540 / 960)));
  image-rendering: auto;
  box-shadow: 0 0 90px rgba(0, 0, 0, 0.55);
  cursor: crosshair;
}

/* vignetta + grana sopra il canvas, sotto gli overlay */
#vignette, #grain {
  position: absolute;
  width: min(100vw, calc(100vh * (960 / 540)));
  height: min(100vh, calc(100vw * (540 / 960)));
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
#vignette {
  background: radial-gradient(ellipse 75% 65% at 50% 45%, transparent 55%, rgba(58, 36, 18, 0.28) 100%);
  z-index: 3;
}
#grain {
  z-index: 4;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-shift 0.9s steps(3) infinite;
}
@keyframes grain-shift {
  0% { background-position: 0 0; }
  33% { background-position: 37px -19px; }
  66% { background-position: -23px 41px; }
}

/* ==================== OVERLAY ==================== */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}
.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
/* classifica e biglietto sempre sopra gli altri overlay */
#board { z-index: 30; }
#note { z-index: 40; }

/* ==================== MENU ==================== */
#menu { background: transparent; }
.menu-inner {
  text-align: center;
  padding-bottom: 4vh;
  animation: menu-rise 1.2s cubic-bezier(0.19, 1, 0.22, 1) both;
}
@keyframes menu-rise {
  from { opacity: 0; transform: translateY(26px); }
  to { opacity: 1; transform: none; }
}
.kicker {
  font-family: var(--font-hand);
  font-size: clamp(16px, 2.4vh, 24px);
  color: #FFF6E0;
  text-shadow: 0 1px 12px rgba(60, 30, 10, 0.6);
  letter-spacing: 0.04em;
  margin-bottom: 0.4em;
}
.title {
  font-family: var(--font-title);
  font-weight: 600;
  font-style: italic;
  font-size: clamp(48px, 13vh, 112px);
  line-height: 0.95;
  color: var(--cream);
  text-shadow:
    0 2px 0 rgba(143, 43, 32, 0.35),
    0 6px 28px rgba(60, 25, 8, 0.65);
  letter-spacing: 0.01em;
}
.title .t-kombat { color: #FFD9A0; }
.subtitle {
  font-family: var(--font-title);
  font-size: clamp(15px, 2.8vh, 26px);
  font-weight: 600;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: #FFE9C4;
  text-shadow: 0 1px 10px rgba(60, 30, 10, 0.7);
  margin-top: 0.7em;
}
.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 4.5vh;
}
.menu-buttons.row { flex-direction: row; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.menu-foot {
  margin-top: 3.2vh;
  font-family: var(--font-hand);
  font-size: clamp(15px, 2.2vh, 21px);
  color: rgba(255, 240, 214, 0.85);
  text-shadow: 0 1px 8px rgba(60, 30, 10, 0.6);
}
.menu-foot em { color: #FFC49A; font-style: normal; }

/* ==================== BOTTONI ==================== */
.btn {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  padding: 11px 30px;
  border-radius: 999px;
  border: 2px solid rgba(74, 59, 46, 0.28);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow), 0 8px 22px rgba(30, 15, 5, 0.35);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s;
  min-width: 210px;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 var(--shadow), 0 12px 26px rgba(30, 15, 5, 0.4); }
.btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--shadow); }
.btn-primary {
  background: linear-gradient(180deg, #D8564A, var(--red));
  border-color: var(--red-deep);
  color: #FFF4E4;
  text-shadow: 0 1px 2px rgba(90, 20, 10, 0.5);
}
.btn-primary:hover { background: linear-gradient(180deg, #E2645A, #C74436); }
.btn-close { margin-top: 18px; min-width: 150px; }

/* ==================== PANNELLI ==================== */
.panel {
  background: var(--cream);
  border-radius: 18px;
  padding: 34px 44px;
  max-width: 620px;
  width: min(92vw, 620px);
  max-height: 88vh;
  overflow: auto;
  text-align: center;
  box-shadow: 0 24px 70px rgba(15, 8, 3, 0.6), inset 0 0 0 1px rgba(74, 59, 46, 0.12);
  animation: panel-pop 0.4s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
.overlay:not(.visible) .panel { animation: none; }
@keyframes panel-pop {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.panel.wide { max-width: 780px; width: min(94vw, 780px); }
.panel.narrow { max-width: 440px; }
.panel.paper {
  background:
    radial-gradient(140% 100% at 20% 0%, rgba(217, 164, 65, 0.10), transparent 55%),
    var(--paper);
}
.panel-title {
  font-family: var(--font-title);
  font-style: italic;
  font-weight: 600;
  font-size: 38px;
  color: var(--ink);
  margin-bottom: 8px;
}
#help .panel-title, #pause .panel-title { margin-bottom: 20px; }
.death-title { color: var(--red-deep); font-size: 42px; }
.death-sub { color: var(--ink-soft); font-family: var(--font-hand); font-size: 21px; margin-bottom: 14px; }
.pause-quote { font-family: var(--font-hand); font-size: 21px; color: var(--ink-soft); margin-bottom: 22px; }

/* comandi */
.help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px 18px;
  text-align: left;
  align-items: center;
  margin: 0 auto;
  max-width: 420px;
}
.key {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  background: #EADDC2;
  border: 1px solid rgba(74, 59, 46, 0.25);
  border-bottom-width: 3px;
  border-radius: 8px;
  padding: 4px 10px;
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
}
.help-note { margin-top: 18px; font-family: var(--font-hand); font-size: 19px; color: var(--ink-soft); }

/* ==================== CLASSIFICA ==================== */
.board-sub { color: var(--ink-soft); margin-bottom: 16px; font-size: 15px; }
.board-scroll { max-height: 52vh; overflow: auto; border-radius: 12px; border: 1px solid rgba(74, 59, 46, 0.15); }
#board-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
#board-table th {
  position: sticky; top: 0;
  background: #EADDC2;
  font-family: var(--font-title);
  font-style: italic;
  font-weight: 700;
  font-size: 15px;
  padding: 9px 12px;
  text-align: left;
  color: var(--ink);
  z-index: 1;
}
#board-table th.num, #board-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#board-table td { padding: 8px 12px; border-top: 1px solid rgba(74, 59, 46, 0.1); text-align: left; }
#board-table tbody tr:nth-child(odd) { background: rgba(217, 164, 65, 0.06); }
#board-table tr.me { background: rgba(192, 57, 43, 0.13) !important; font-weight: 700; }
#board-table tr.done td:first-child { color: var(--gold); font-weight: 800; }
.w-icon { margin-right: 6px; }
.badge-top {
  display: inline-block;
  background: var(--gold);
  color: #4A3505;
  font-size: 11px;
  font-weight: 800;
  border-radius: 99px;
  padding: 2px 8px;
  letter-spacing: 0.05em;
}
.board-empty { padding: 40px 10px; color: var(--ink-soft); font-family: var(--font-hand); font-size: 22px; }

/* ==================== MORTE / STATS ==================== */
.stats-row {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 18px 0;
}
.stat {
  background: rgba(74, 59, 46, 0.07);
  border: 1px solid rgba(74, 59, 46, 0.14);
  border-radius: 14px;
  padding: 10px 18px;
  min-width: 118px;
}
.stat b {
  display: block;
  font-size: 24px;
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
}
.stat span { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.06em; text-transform: uppercase; }
#score-form label { display: block; font-family: var(--font-hand); font-size: 20px; color: var(--ink-soft); margin-bottom: 8px; }
.form-row { display: flex; gap: 10px; justify-content: center; }
#player-name {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 999px;
  border: 2px solid rgba(74, 59, 46, 0.3);
  background: #FFFDF6;
  color: var(--ink);
  width: 240px;
  outline: none;
}
#player-name:focus { border-color: var(--red); }
#btn-submit-score { min-width: 0; }
.submit-msg { min-height: 22px; margin-top: 10px; font-family: var(--font-hand); font-size: 19px; color: var(--teal); }

/* ==================== IL BIGLIETTO ==================== */
#note { background: rgba(30, 18, 8, 0.55); backdrop-filter: blur(3px); }
.note-paper {
  background:
    linear-gradient(174deg, #FDF6E3 0%, #F3E6C8 100%);
  width: min(92vw, 470px);
  padding: 40px 44px 32px;
  border-radius: 4px 22px 6px 18px;
  transform: rotate(-1.6deg);
  box-shadow: 0 30px 80px rgba(10, 5, 0, 0.7), inset 0 0 60px rgba(180, 140, 60, 0.12);
  text-align: center;
  animation: note-drop 0.7s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}
@keyframes note-drop {
  from { opacity: 0; transform: rotate(4deg) translateY(-60px) scale(0.9); }
  to { opacity: 1; transform: rotate(-1.6deg); }
}
.note-head {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 20px;
}
.note-body {
  font-family: var(--font-hand);
  font-size: 22px;
  line-height: 1.35;
  color: #3E3225;
}
.note-body strong { color: var(--red-deep); }
.note-sign {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink-soft);
  margin: 22px 0 26px;
}
#btn-note-ok { min-width: 0; }

/* ==================== TITOLI DI CODA ==================== */
#credits {
  background: linear-gradient(180deg, #A8D4EA 0%, #CDE7EE 40%, #FBE7C3 100%);
  flex-direction: column;
}
.credits-sky { position: absolute; inset: 0; overflow: hidden; }
.c-cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  filter: blur(2px);
  animation: cloud-drift linear infinite;
}
.c-cloud.c1 { width: 340px; height: 90px; top: 16%; animation-duration: 68s; }
.c-cloud.c2 { width: 220px; height: 60px; top: 42%; animation-duration: 92s; animation-delay: -30s; }
.c-cloud.c3 { width: 420px; height: 110px; top: 66%; animation-duration: 118s; animation-delay: -70s; opacity: 0.7; }
@keyframes cloud-drift {
  from { transform: translateX(-480px); }
  to { transform: translateX(calc(100vw + 480px)); }
}
.credits-scroll {
  position: absolute;
  left: 0; right: 0;
  text-align: center;
  color: #4A3B2E;
  animation: credits-up 30s linear both;
  padding: 0 20px;
}
#credits.visible .credits-scroll { animation-play-state: running; }
@keyframes credits-up {
  from { top: 100%; }
  to { top: -160%; }
}
.cr-kicker { font-family: var(--font-ui); font-weight: 800; letter-spacing: 0.3em; font-size: 15px; color: var(--red-deep); margin-bottom: 30px; }
.cr-title { font-family: var(--font-title); font-style: italic; font-weight: 600; font-size: 96px; margin-bottom: 40px; }
.cr-text { font-family: var(--font-hand); font-size: 26px; line-height: 1.5; margin-bottom: 60px; }
.cr-text.small { font-family: var(--font-ui); font-size: 15px; font-weight: 500; line-height: 1.8; color: var(--ink-soft); }
.cr-thanks { font-family: var(--font-title); font-style: italic; font-size: 40px; margin-bottom: 120px; }
#credits .stats-row { margin-bottom: 60px; }
#credits .stat { background: rgba(255, 253, 246, 0.6); }
.btn-credits {
  position: absolute;
  bottom: 5vh;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  animation: fade-in 1s ease 24s both;
}
@keyframes fade-in { to { opacity: 1; } }

/* ==================== MOBILE ==================== */
#rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #241C15;
  color: var(--cream);
  font-family: var(--font-hand);
  font-size: 26px;
  text-align: center;
  align-items: center;
  justify-content: center;
  padding: 30px;
  line-height: 1.5;
}
@media (pointer: coarse) and (max-width: 900px) {
  #rotate-hint { display: flex; }
}
