:root {
  --ink: #3b2a1a;
  --ink-soft: #7a6352;
  --bg1: #fff1b8;
  --bg2: #ffc8a8;
  --card: #fffdf7;
  --go1: #49c46b;
  --go2: #2fa152;
  --wood1: #c98a4b;
  --wood2: #9c6232;
  --cloth1: #ff6f6f;
  --cloth2: #fff7ee;
  --danger: #e2463f;
  --radius: 26px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI", system-ui, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 18%, #ffffff88 0 6px, transparent 7px) 0 0 / 90px 90px,
    radial-gradient(circle at 70% 60%, #ffffff66 0 4px, transparent 5px) 0 0 / 70px 70px,
    linear-gradient(160deg, var(--bg1), var(--bg2));
  background-color: var(--bg2);
  min-height: 100dvh;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

[hidden] { display: none !important; }

body { display: flex; flex-direction: column; }
.credit { text-align: center; padding: 6px 16px max(14px, env(safe-area-inset-bottom)); font-weight: 700; font-size: .95rem; color: var(--ink-soft); }
.credit a { color: #e2582c; font-weight: 800; text-decoration: none; padding: 8px 2px; }
.credit a:hover, .credit a:focus-visible { text-decoration: underline; }
body.playing .credit { display: none; }

.screen {
  flex: 1 0 auto;
  min-height: calc(100dvh - 48px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.card {
  width: 100%;
  max-width: 470px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 22px 22px;
  box-shadow: 0 10px 0 #e9a77c, 0 20px 40px #a0502a33;
  text-align: center;
}

h1, h2 { margin: 6px 0 8px; line-height: 1.1; letter-spacing: -0.5px; }
h1 { font-size: clamp(2rem, 8vw, 2.6rem); color: #e2582c; }
h2 { font-size: clamp(1.6rem, 6vw, 2rem); }
.lead { font-size: 1.15rem; color: var(--ink-soft); margin: 0 0 18px; }
.kicker { margin: 0; text-transform: uppercase; letter-spacing: 2px; font-weight: 800; font-size: .8rem; color: #e2582c; }
.hint { color: var(--ink-soft); font-size: .95rem; margin: 6px 0 14px; }
.err { color: var(--danger); font-weight: 700; min-height: 1.3em; margin: 10px 0 0; }
.link { display: inline-block; margin-top: 14px; color: #e2582c; font-weight: 700; padding: 10px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 3px; color: #e2582c; }

.spr { display: inline-block; aspect-ratio: 1; background-image: url(food.webp); background-repeat: no-repeat; vertical-align: middle; }
.logo-row { display: flex; justify-content: center; gap: 4px; }
.logo-row span { width: 52px; animation: bob 2.4s ease-in-out infinite; }
.logo-row span:nth-child(2) { animation-delay: .2s; }
.logo-row span:nth-child(3) { animation-delay: .4s; }
.logo-row span:nth-child(4) { animation-delay: .6s; }
.logo-row span:nth-child(5) { animation-delay: .8s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }

.lbl { display: block; text-align: left; font-weight: 800; margin: 6px 4px; }
.nick-row { display: flex; gap: 10px; }
.inp {
  flex: 1;
  min-width: 0;
  font: 700 1.3rem var(--font);
  padding: 14px 16px;
  min-height: 60px;
  border-radius: 18px;
  border: 3px solid #f1c9a6;
  background: #fff;
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
}
.inp:focus { outline: none; border-color: #ff9a52; box-shadow: 0 0 0 4px #ffcf9e88; }
.inp.small { font-size: .95rem; min-height: 52px; }

.btn {
  font: 800 1.1rem var(--font);
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  min-height: 56px;
  min-width: 56px;
  cursor: pointer;
  color: var(--ink);
  background: #ffe3c4;
  box-shadow: 0 5px 0 #e9b386;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #e9b386; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.icon { font-family: var(--emoji); font-size: 1.6rem; padding: 0; width: 60px; min-height: 60px; }
.btn.big { width: 100%; font-size: 1.45rem; min-height: 72px; margin-top: 10px; }
.btn.go { color: #fff; background: linear-gradient(180deg, var(--go1), var(--go2)); box-shadow: 0 6px 0 #1f7a3b; text-shadow: 0 2px 0 #0003; }
.btn.go:active { box-shadow: 0 2px 0 #1f7a3b; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink-soft); margin-top: 12px; text-decoration: underline; }

.code-box { margin-top: 22px; padding-top: 18px; border-top: 3px dashed #f1d6bd; }
.code-inp { text-transform: uppercase; letter-spacing: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; text-align: center; }
.code-inp::placeholder { letter-spacing: 6px; color: #d9c3ad; }
.btn.go-sm { color: #fff; background: linear-gradient(180deg, var(--go1), var(--go2)); box-shadow: 0 5px 0 #1f7a3b; min-height: 60px; padding: 0 24px; text-shadow: 0 2px 0 #0003; }
.captcha { display: flex; justify-content: center; margin: 4px 0 6px; min-height: 0; }

.rules { margin-top: 18px; text-align: left; background: #fff4e4; border-radius: 18px; padding: 12px 16px; }
.rules summary { font-weight: 800; cursor: pointer; padding: 6px 0; font-size: 1.1rem; }
.rules ul { padding-left: 4px; list-style: none; margin: 8px 0 4px; }
.rules li { margin: 10px 0; font-size: 1.02rem; display: flex; align-items: center; gap: 10px; line-height: 1.3; }
.rules .em { display: inline-flex; gap: 2px; flex: 0 0 62px; justify-content: center; }
.rules .em .spr { width: 30px; }
.rules .em.txt { font-family: var(--emoji); font-size: 1.3rem; width: 62px; justify-content: center; }

.sound-btn {
  position: fixed; z-index: 50;
  top: max(10px, env(safe-area-inset-top)); right: 10px;
  width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: #fffdf7; box-shadow: 0 4px 0 #e9a77c;
  font-family: var(--emoji); font-size: 1.5rem; cursor: pointer;
}
.net-pill {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: max(14px, env(safe-area-inset-top));
  background: #3b2a1a; color: #fff; padding: 8px 16px; border-radius: 999px; font-weight: 700;
}

/* Lobby */
.share { display: flex; gap: 8px; margin: 14px 0 4px; }
.players { list-style: none; padding: 0; margin: 10px 0 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.players li {
  display: flex; align-items: center; gap: 10px;
  background: #fff4e4; border-radius: 16px; padding: 10px 12px;
  font-weight: 800; text-align: left; min-height: 56px; overflow: hidden;
  animation: popin .35s ease-out;
}
.players li.me { outline: 3px solid #ffb37a; }
.players li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.players li.off { opacity: .45; }
.dot { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: .95rem; font-weight: 800; box-shadow: inset 0 -3px 0 #0002; }
.crown { font-family: var(--emoji); }
.wait { font-weight: 800; color: var(--ink-soft); font-size: 1.15rem; margin: 18px 0 4px; }
.dots::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
@keyframes popin { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Game */
@media (max-width: 520px) { .screen:not(.game) { padding-top: max(76px, env(safe-area-inset-top)); align-items: flex-start; } }
.screen.game { flex-direction: column; justify-content: flex-start; padding-top: max(10px, env(safe-area-inset-top)); gap: 10px; }
.hud { width: 100%; max-width: 560px; display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 8px; padding-right: 58px; }
.hud-box { background: var(--card); border-radius: 18px; padding: 6px 8px; box-shadow: 0 4px 0 #e9a77c; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 58px; }
.hud-lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 800; color: var(--ink-soft); }
.hud-val { font-size: 1.7rem; font-weight: 800; line-height: 1; }
.hud-val.low { color: var(--danger); animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.15); } }
.rainbow { display: flex; gap: 5px; margin-top: 4px; }
.rainbow i { width: 20px; height: 20px; border-radius: 50%; border: 3px dashed #d9c3ad; transition: transform .2s; }
.rainbow i.on { border: 3px solid #0000002a; transform: scale(1.12); }

.arena { --w: min(calc(100vw - 20px), calc((100dvh - 190px) * 0.8), 620px); width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; flex: 1; }
.table {
  width: var(--w);
  aspect-ratio: 4 / 5;
  position: relative;
  border-radius: 34px;
  padding: 16px;
  background:
    repeating-linear-gradient(92deg, #0000 0 18px, #0000000d 18px 20px),
    linear-gradient(160deg, var(--wood1), var(--wood2));
  box-shadow: inset 0 0 0 4px #ffffff33, 0 12px 0 #7a4a24, 0 26px 40px #5a2d1066;
  container-type: inline-size;
  touch-action: none;
}
.cloth {
  position: absolute; inset: 16px; border-radius: 22px;
  background:
    repeating-linear-gradient(0deg, #ff6f6f88 0 22px, transparent 22px 44px),
    repeating-linear-gradient(90deg, #ff6f6f88 0 22px, transparent 22px 44px),
    var(--cloth2);
  box-shadow: inset 0 0 30px #b4541f44;
}
.food {
  position: absolute;
  width: 21%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%) scale(0);
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: radial-gradient(circle at 50% 45%, #fff 0 58%, #eee 59% 64%, #fff 65%);
  box-shadow: 0 6px 0 #0000001f, 0 0 0 4px #ffffffaa;
  display: grid;
  place-items: center;
  font-family: var(--emoji);
  font-size: 12.5cqw;
  line-height: 1;
  transition: transform .22s cubic-bezier(.3, 1.6, .5, 1), opacity .25s;
  z-index: 2;
}
.food.in { transform: translate(-50%, -50%) scale(1); }
.food.leaving { transform: translate(-50%, -50%) scale(.55); opacity: .25; transition-duration: .6s; }
.food.grab { transform: translate(-50%, -50%) scale(1.3); opacity: 0; transition-duration: .18s; pointer-events: none; }
.food .spr { width: 80%; pointer-events: none; filter: drop-shadow(0 3px 1px #0003); }
.food .ring { position: absolute; inset: -6px; border-radius: 50%; border: 5px solid; pointer-events: none; }

.pop {
  position: absolute; z-index: 5; pointer-events: none;
  transform: translate(-50%, -50%);
  font-weight: 800; font-size: 7cqw; white-space: nowrap;
  text-shadow: 0 3px 0 #fff, 0 -2px 0 #fff, 2px 0 0 #fff, -2px 0 0 #fff;
  animation: floatup 1.1s ease-out forwards;
}
.pop.good { color: #1f9d4a; }
.pop.bad { color: var(--danger); }
.pop.bonus { color: #8a3bd6; font-size: 9cqw; }
.pop.other { font-size: 4.6cqw; opacity: .9; }
@keyframes floatup { from { margin-top: 0; opacity: 1; } to { margin-top: -14cqw; opacity: 0; } }

.countdown {
  position: absolute; inset: 0; z-index: 10; display: grid; place-items: center;
  font-size: 40cqw; font-weight: 800; color: #fff; text-shadow: 0 8px 0 #e2582c, 0 0 40px #0004;
  background: #0002; border-radius: 34px;
}
.countdown.small { font-size: 16cqw; }

.board { list-style: none; margin: 0; padding: 0; width: var(--w, 100%); max-width: 620px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.board li { display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 999px; padding: 4px 12px 4px 4px; font-weight: 800; box-shadow: 0 3px 0 #e9a77c; transition: order .3s; }
.board li .dot { width: 26px; height: 26px; flex-basis: 26px; font-size: .8rem; }
.board li .nm { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li.me { background: #fff1c2; }
.board li .sc { min-width: 2ch; text-align: right; }

/* Results */
.results { list-style: none; padding: 0; margin: 14px 0; text-align: left; }
.results li { display: grid; grid-template-columns: 44px 34px 1fr auto; align-items: center; gap: 10px; background: #fff4e4; border-radius: 18px; padding: 10px 12px; margin: 8px 0; animation: popin .4s ease-out backwards; }
.results li.me { outline: 3px solid #ffb37a; }
.results .medal { font-family: var(--emoji); font-size: 1.9rem; text-align: center; font-weight: 800; }
.results .nm { font-weight: 800; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .sub .spr { width: 20px; margin-right: 2px; }
.results .sub { display: block; white-space: normal; font-size: .85rem; color: var(--ink-soft); font-weight: 700; }
.results .sc { font-size: 1.6rem; font-weight: 800; }

@media (orientation: landscape) and (min-width: 820px) {
  .arena { --w: min(calc((100dvh - 120px) * 0.8), 620px); flex-direction: row; justify-content: center; align-items: flex-start; }
  .board { flex-direction: column; width: 220px; flex-wrap: nowrap; }
  .board li { border-radius: 16px; padding: 6px 12px 6px 6px; }
  .board li .nm { max-width: none; flex: 1; }
  .hud { max-width: 860px; }
}

@media (max-width: 440px) {
  .players { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01s !important; }
}
