:root {
  --bg: #0b0a0f;
  --floor-a: #cfc7b8;
  --floor-b: #c2b9a8;
  --panel: #241f31;
  --edge: #3b3450;
  --ink: #f3eadb;
  --muted: #9a90a8;
  --accent: #ffcc4d;
  --ok: #5bd17a;
  --bad: #ff5a4f;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  color: var(--ink);
  font-family: 'Press Start 2P', ui-monospace, monospace;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1600px;
  height: 900px;
  transform-origin: center;
  background:
    repeating-conic-gradient(var(--floor-a) 0 25%, var(--floor-b) 0 50%) 0 0 / 80px 80px;
  overflow: hidden;
  image-rendering: pixelated;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 22px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 48px;
  font-size: 24px; z-index: 10;
  text-shadow: 3px 3px 0 #000;
}
#best { color: var(--accent); }
#sound { position: absolute; top: 14px; right: 20px; z-index: 40; display: flex; gap: 8px; }
#sound button {
  width: 44px; height: 40px; padding: 0;
  font-size: 18px; line-height: 1;
  background: var(--panel); color: var(--ink);
  border: 3px solid var(--edge); box-shadow: 0 4px 0 #000;
}
#sound button.off { opacity: .45; text-decoration: line-through; }
#hint {
  position: absolute; bottom: 14px; left: 0; right: 0;
  text-align: center; font-size: 12px; color: #4a4155;
}

/* ---------- Zones ---------- */
.zone {
  position: absolute;
  background: var(--panel);
  border: 6px solid var(--edge);
  box-shadow: 0 8px 0 #000;
  cursor: pointer;
}
.zone.here { border-color: var(--accent); }
.zone.has-art { background: #e8e1d4; }
.zone.has-art .art img { object-fit: cover; }
.zone .art { position: absolute; inset: 0; overflow: hidden; }
.zone .art img {
  width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.zone.warn { animation: pulse .45s infinite alternate; }
@keyframes pulse {
  from { box-shadow: 0 8px 0 #000, 0 0 0 0 rgba(255, 204, 77, 0); }
  to   { box-shadow: 0 8px 0 #000, 0 0 0 16px rgba(255, 204, 77, .6); }
}
.zone.active { border-color: var(--bad); }
.zone.active.here { border-color: var(--ok); }

/* placeholder art for a stage */
.ph {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  text-shadow: 4px 4px 0 #000;
}
.ph .big { font-size: 96px; }
.ph .big.long { font-size: 34px; text-align: center; line-height: 1.4; }
.ph .fire { font-size: 34px; min-height: 40px; }
.ph.s0 { background: #23402f; }
.ph.s1 { background: #3d4024; }
.ph.s2 { background: #563a1c; }
.ph.s3 { background: #6e2814; }
.ph.s4 { background: #3a0d06; animation: flicker .18s infinite alternate; }
@keyframes flicker { from { filter: brightness(1); } to { filter: brightness(1.35) saturate(1.3); } }

/* meeting tag + ring + attendance */
.tag {
  position: absolute; left: 10px; top: 10px;
  padding: 8px 10px; font-size: 13px;
  background: rgba(0, 0, 0, .8);
  display: none; z-index: 3;
}
.badge {
  position: absolute; right: 8px; top: 8px;
  width: 92px; height: 92px; display: none; z-index: 3;
}
.badge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.badge .cnt {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; text-shadow: 3px 3px 0 #000;
}
.att {
  position: absolute; left: 10px; right: 10px; bottom: 10px; height: 18px;
  background: rgba(0, 0, 0, .75); border: 3px solid #000;
  display: none; z-index: 3;
}
.att .fill { height: 100%; width: 0; background: var(--bad); }
.att.good .fill { background: var(--ok); }
.att .mark { position: absolute; left: 50%; top: -6px; bottom: -6px; width: 4px; margin-left: -2px; background: var(--ink); }
.zone.warn .tag, .zone.active .tag,
.zone.warn .badge, .zone.active .badge { display: block; }
.zone.active .att { display: block; }

/* ---------- Hearts ---------- */
.hearts { position: absolute; display: flex; gap: 8px; z-index: 4; }
.heart { position: relative; width: 35px; height: 30px; }
.heart svg { position: absolute; left: 0; top: 0; width: 35px; height: 30px; shape-rendering: crispEdges; }
.heart .full { position: absolute; left: 0; top: 0; height: 30px; overflow: hidden; }

/* ---------- Logo ---------- */
.zone.logo {
  background: #c55832;
  border-color: #8e3a1f;
  overflow: visible;
}
.zone.logo.here { border-color: var(--accent); }
.zone.logo.active { border-color: var(--bad); }
.zone.logo.active.here { border-color: var(--ok); }
.letters {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.slot { position: relative; flex: none; }
.nail {
  position: absolute; width: 6px; height: 6px; margin: -3px 0 0 -3px;
  background: #6b5d55; box-shadow: 1px 1px 0 #3a1408; z-index: 2;
}
.letter {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 64px; color: #fff;
}
.letter img { width: 100%; height: 100%; object-fit: contain; }
.letter.sag { animation: sag 2.2s forwards; }
/* маятник: розгін під дією ваги, проскок за точку рівноваги і загасаючі гойдання */
@keyframes sag {
  0%   { transform: rotate(0deg); animation-timing-function: cubic-bezier(.55, 0, .9, .45); }
  30%  { transform: rotate(calc(var(--hang) + var(--dir) * 32deg)); animation-timing-function: ease-in-out; }
  50%  { transform: rotate(calc(var(--hang) - var(--dir) * 18deg)); animation-timing-function: ease-in-out; }
  66%  { transform: rotate(calc(var(--hang) + var(--dir) * 9deg)); animation-timing-function: ease-in-out; }
  80%  { transform: rotate(calc(var(--hang) - var(--dir) * 4deg)); animation-timing-function: ease-in-out; }
  91%  { transform: rotate(calc(var(--hang) + var(--dir) * 1.5deg)); animation-timing-function: ease-in-out; }
  100% { transform: rotate(var(--hang)); }
}
.letter.fall { animation: fall 1.3s cubic-bezier(.5, 0, 1, .6) forwards; }
@keyframes fall {
  from { transform: rotate(var(--from, 0deg)); opacity: 1; }
  to   { transform: translateY(720px) rotate(var(--to, 200deg)); opacity: 0; }
}
.zone.logo .tag { left: -6px; top: -56px; }
.zone.logo .badge { right: -10px; top: -112px; }
.zone.logo .att { left: -6px; right: 96px; top: -26px; bottom: auto; }

/* ---------- Hero ---------- */
#hero {
  position: absolute; width: 110px; height: 220px; z-index: 6;
  display: flex; align-items: flex-end; justify-content: center;
  font-size: 96px; line-height: 1;
  transition: left .06s linear, top .06s linear;
  pointer-events: none;
  filter: drop-shadow(4px 4px 0 #000);
}
#hero img { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
#hero.flip img { transform: scaleX(-1); }

/* ---------- Popups ---------- */
.pop {
  position: absolute; z-index: 20; pointer-events: none;
  font-size: 22px; white-space: nowrap;
  text-shadow: 3px 3px 0 #000;
  transform: translateX(-50%);
  animation: pop 1.4s forwards;
}
.pop.bad { color: var(--bad); }
.pop.ok { color: var(--ok); }
@keyframes pop {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(.8); }
  15%  { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 30px; text-align: center;
  background: rgba(10, 8, 14, .86);
}
.overlay[hidden], #drunk[hidden] { display: none; }
.overlay.dim { background: rgba(246, 241, 232, .62); }
.title { font-size: 110px; color: var(--accent); text-shadow: 8px 8px 0 #000; }
.rules { font-size: 16px; line-height: 2; max-width: 1100px; }
.rules p + p { margin-top: 14px; }
.muted { color: var(--muted); font-size: 16px; }
h2 { font-size: 56px; }
.gameover {
  font-size: 120px; color: var(--bad);
  text-shadow: 8px 8px 0 #000;
  animation: flicker .25s infinite alternate;
}
#overReason { font-size: 20px; color: #2a2233; }
#overScore { font-size: 24px; color: #9a3412; line-height: 1.8; }
button {
  font: inherit; font-size: 22px;
  color: #000; background: var(--accent);
  border: 0; padding: 18px 30px;
  box-shadow: 0 6px 0 #8a6a12;
  cursor: pointer;
}
button:active { transform: translateY(4px); box-shadow: 0 2px 0 #8a6a12; }
button:disabled { opacity: .5; cursor: default; }

/* ---------- Game over: hero in the corner ---------- */
#drunk {
  position: absolute; right: 30px; bottom: 30px; z-index: 31;
  width: 300px; height: 220px; pointer-events: none;
}
#drunk .who {
  position: absolute; left: 0; bottom: 0; font-size: 110px;
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 2px #fff) drop-shadow(0 0 6px rgba(255, 255, 255, .8));
  animation: sway 2.4s ease-in-out infinite;
}
#drunk .who img { max-height: 220px; image-rendering: pixelated; }
#drunk.anim { width: 260px; height: 400px; right: 20px; bottom: 20px; }
#drunk.anim .who { animation: none; }
#drunk.anim .who img { max-height: 400px; max-width: 260px; }
#drunk .who img.sit { height: 200px; transform: rotate(-8deg); transform-origin: bottom center; }
#drunk .who .beer { position: absolute; left: 70px; bottom: 70px; font-size: 44px; }
#drunk .bottles { position: absolute; left: 120px; bottom: 0; right: 0; height: 100%; }
#drunk .bottles span { position: absolute; font-size: 40px; animation: drop .35s ease-out; }
@keyframes sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes drop { from { transform: translateY(-40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Portrait phones ---------- */
#rotate {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  padding: 24px; text-align: center; font-size: 18px; line-height: 2;
  background: var(--bg);
}
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) {
  #rotate { display: flex; }
}
