/* Phone controller (index.html). Shared tokens and components are in common.css. */

/* ------------------------------------------------------------ no browser gestures, no scrolling */

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation; /* no double-tap zoom */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  position: fixed;
  inset: 0;
  background: #0b3a22 radial-gradient(130% 90% at 50% -10%, #2b8c54 0%, #13552f 45%, #072617 100%);
  color: var(--snow);
  font-family: var(--font-body);
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea { user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
img, svg { -webkit-user-drag: none; }
h1, h2, h3 { font-family: var(--font-title); font-weight: 400; margin: 0; line-height: 1.08; }
p { margin: 0; }

/* Falling snow: two tiled layers moved by transform only (cheap). Each loops after 300px,
   which every tile height divides, so there is no jump. */
.snowfall { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.snowfall i {
  position: absolute;
  left: 0;
  right: 0;
  top: -300px;
  height: calc(100% + 300px);
  background-image: radial-gradient(circle, #fff 0 1.7px, transparent 2.4px), radial-gradient(circle, #fff 0 1.1px, transparent 1.7px);
  background-size: 150px 150px, 100px 100px;
  background-position: 20px 30px, 70px 60px;
  opacity: 0.5;
  animation: snowfall 16s linear infinite;
  will-change: transform;
}
.snowfall i + i {
  background-size: 300px 300px, 60px 60px;
  background-position: 120px 40px, 10px 10px;
  opacity: 0.28;
  animation-duration: 27s;
}
@keyframes snowfall { from { transform: translateY(0); } to { transform: translateY(300px); } }
body.ctl-on .snowfall { opacity: 0.6; }

/* ------------------------------------------------------------ screens */

#app {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
.screen { display: none; flex: 1; min-height: 0; position: relative; }
body[data-screen='connecting'] #scr-connecting,
body[data-screen='pick'] #scr-pick,
body[data-screen='new'] #scr-new,
body[data-screen='kicked'] #scr-kicked { display: flex; }
body[data-screen='main'] #scr-main { display: grid; }

.screen.center { flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }

.logo {
  font-family: var(--font-title);
  font-size: clamp(2.6rem, 13vw, 4rem);
  line-height: 0.9;
  color: var(--gold);
  text-shadow: 0 4px 0 var(--red-dk), 0 10px 22px rgba(0, 0, 0, 0.35);
  transform: rotate(-3deg);
}
.logo span { display: block; }
.logo span + span { color: #fff; text-shadow: 0 4px 0 var(--red), 0 10px 22px rgba(0, 0, 0, 0.35); transform: translateX(0.4em); }
.logo.small { font-size: 1.05rem; transform: none; text-shadow: 0 2px 0 var(--red-dk); }
.logo.small span { display: inline; transform: none; text-shadow: 0 2px 0 var(--red); }

.lead { font-family: var(--font-title); font-size: 1.3rem; }
.help { max-width: 22em; opacity: 0.85; line-height: 1.35; }
.sub { font-size: 1rem; line-height: 1.35; opacity: 0.9; }
.msg { min-height: 1.3em; font-size: 0.95rem; color: var(--red); }
.msg.good { color: var(--green); }

.hop { height: 150px; display: grid; place-items: end center; }
.hop .figure { width: 92px; animation: hop 1.1s cubic-bezier(0.3, 0, 0.3, 1) infinite; transform-origin: 50% 100%; }
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1.06, 0.94); }
  15% { transform: translateY(0) scale(0.96, 1.05); }
  50% { transform: translateY(-34px) scale(1, 1); }
  85% { transform: translateY(0) scale(1, 1); }
}

.card { background: var(--snow); color: var(--ink); border-radius: var(--radius); box-shadow: 0 6px 0 var(--snow-dk), var(--shadow); padding: 20px; }
.form-card { width: min(100%, 380px); display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
.form-card h1 { font-size: 1.9rem; color: var(--red); }
.form-card .sub { color: var(--ink-soft); }

.text-in {
  width: 100%;
  min-width: 0;
  font-family: var(--font-title);
  font-size: 1.5rem; /* >= 16px so iOS doesn't zoom in on focus */
  padding: 0.5em 0.75em;
  border-radius: 16px;
  border: 3px solid var(--snow-dk);
  background: #fff;
  color: var(--ink);
  text-align: center;
  outline: none;
}
.text-in:focus { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(247, 195, 64, 0.35); }

.round-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.round-btn svg { width: 24px; height: 24px; }
.round-btn:active { background: rgba(255, 255, 255, 0.32); }

/* ------------------------------------------------------------ who are you? */

#scr-pick { flex-direction: column; }
.pick-head { position: relative; padding: 14px 60px 10px; text-align: center; }
.pick-head h1 { margin-top: 4px; font-size: 2.1rem; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.pick-head .round-btn { position: absolute; right: 12px; top: 18px; }
.pick-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(106px, 1fr));
  gap: 14px;
  padding: 8px 14px 28px;
  align-content: start;
}
.pick-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 16px 6px 12px;
  border: 0;
  border-radius: 22px;
  background: var(--snow);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--snow-dk), var(--shadow-sm);
  font-family: var(--font-title);
  font-size: 1.08rem;
  cursor: pointer;
  touch-action: manipulation;
}
.pick-tile .avatar { --s: 66px; }
.pick-tile:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--snow-dk); }
.pick-tile:disabled { opacity: 0.5; cursor: default; }
.pick-tile.busy { opacity: 1; animation: pulse 0.6s ease-in-out infinite alternate; }
.pick-tile.new { background: var(--gold); box-shadow: 0 5px 0 var(--gold-dk), var(--shadow-sm); }
.pick-tile .plus { width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.55); }
.pick-tile .plus svg { width: 34px; height: 34px; }
.pick-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-tag { margin-top: -6px; font-family: var(--font-body); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--red); }
.pick-empty { grid-column: 1 / -1; text-align: center; padding: 30px 10px; }
@keyframes pulse { to { transform: scale(0.95); } }

/* ------------------------------------------------------------ main screen layout */

#scr-main {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) 46%;
  grid-template-areas: 'top' 'panel' 'ctl';
}
body:not(.ctl-on) #scr-main { grid-template-rows: auto minmax(0, 1fr) 0; }

#topbar { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 8px 10px 6px; min-width: 0; }
.me { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; border: 0; background: none; padding: 4px; color: inherit; text-align: left; cursor: pointer; }
#me-avatar .avatar { --s: 46px; }
.me-text { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.me-name { max-width: 100%; font-family: var(--font-title); font-size: 1.3rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.chip { font-size: 0.82rem; padding: 2px 9px; border-radius: 999px; background: var(--gold); color: var(--ink); box-shadow: 0 2px 0 var(--gold-dk); white-space: nowrap; }
.net-dot { width: 14px; height: 14px; flex: none; margin: 0 6px; border-radius: 50%; background: #9aa5b1; box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18); transition: background 0.3s; }
.net-dot.good { background: #3ddc84; }
.net-dot.ok { background: #ffd23f; }
.net-dot.bad { background: #ff8c1a; }
.net-dot.off { background: #ff4d5e; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }

#panel {
  grid-area: panel;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 16px 8px;
  overflow: hidden;
  text-align: center;
}
#panel > * { max-width: 100%; max-height: 100%; }

#controller { grid-area: ctl; position: relative; display: none; touch-action: none; transition: opacity 0.3s, filter 0.3s; }
body.ctl-on #controller { display: block; }
body.offline #controller { opacity: 0.45; filter: grayscale(0.7); }
/* Out of the round (knocked out, home, watching): the controls do nothing, so they say so. */
#ctl-note { display: none; }
body.ctl-done #controller > :not(#ctl-note) { opacity: 0.28; filter: grayscale(0.8); pointer-events: none; }
body.ctl-done #ctl-note { display: flex; position: absolute; inset: 0; z-index: 3; align-items: center; justify-content: center; text-align: center; padding: 0 24px; font-family: var(--font-title); font-size: 1.35rem; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45); pointer-events: none; }

/* ------------------------------------------------------------ phase panels */

.big-title { font-size: 1.75rem; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.lobby, .intro, .cd-panel, .playing, .result, .final { display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 0; }
.lobby .figure { width: 78px; animation: hop 1.6s cubic-bezier(0.3, 0, 0.3, 1) infinite; transform-origin: 50% 100%; margin-top: 14px; }
.lobby-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 4px; }
.lobby-btns .btn { font-size: 1rem; min-height: 44px; padding: 0.45em 1em; }
.emotes { display: flex; gap: 10px; justify-content: center; }
.emote { width: 48px; height: 48px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.15); font-size: 1.55rem; line-height: 1; cursor: pointer; touch-action: manipulation; transition: transform 0.1s; }
.emote:active, .emote.sent { transform: scale(1.25); background: rgba(247, 195, 64, 0.45); }
.emote:disabled { opacity: 0.45; }

.kind-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 13px 4px 10px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-family: var(--font-title);
  font-size: 1rem;
  box-shadow: 0 3px 0 var(--red-dk);
}
.kind-badge svg { width: 18px; height: 18px; }
.kind-badge.survival { background: #3a6ff7; box-shadow: 0 3px 0 #2347b3; }
.kind-badge.final { background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--gold-dk); }

.round-tag { font-family: var(--font-title); color: var(--gold); font-size: 1.15rem; letter-spacing: 0.02em; }
.map-name { font-size: clamp(2.1rem, 10vw, 3.2rem); text-shadow: 0 4px 0 rgba(0, 0, 0, 0.28); }
.desc { font-size: 1.08rem; line-height: 1.4; max-width: 28em; opacity: 0.93; }
.get-ready { font-family: var(--font-title); font-size: 2rem; color: var(--gold); text-shadow: 0 3px 0 var(--red-dk); animation: throb 0.7s ease-in-out infinite alternate; }
@keyframes throb { from { transform: scale(0.94); } to { transform: scale(1.06); } }

.cd-map { font-family: var(--font-title); font-size: 1.5rem; }
.cd-hint { font-family: var(--font-title); color: var(--gold); font-size: 1.2rem; }

.playing .play-row { display: flex; align-items: center; gap: 12px; }
.timer { font-family: var(--font-title); font-size: 2.6rem; font-variant-numeric: tabular-nums; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); }
.timer:empty { display: none; }
.status-text { font-family: var(--font-title); font-size: 1.45rem; line-height: 1.15; max-width: 18em; }
.kind-badge.kart { background: #8b5cf6; box-shadow: 0 3px 0 #5b33b8; }
.place-chip { font-family: var(--font-title); font-size: 1.35rem; padding: 2px 14px; border-radius: 999px; background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--gold-dk); white-space: nowrap; }
.race-strip { position: relative; width: min(230px, 58vw); height: 10px; margin: 12px 26px 4px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.3); }
.race-strip .mk { position: absolute; top: 50%; width: 12px; height: 12px; margin-left: -6px; transform: translateY(-50%); border-radius: 50%; border: 2px solid #fff; transition: left 0.45s linear; }
.race-strip .mk.back { background: #9aa6b2; }
.race-strip .mk.lead { background: #2a9d55; }
.race-strip .mk.you { width: 20px; height: 20px; margin-left: -10px; z-index: 1; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35); }
.race-strip .flag { position: absolute; right: -24px; top: 50%; transform: translateY(-50%); font-size: 1.1rem; line-height: 1; }
.kart-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin-top: 6px; }
.lap-chip { font-family: var(--font-title); font-size: 1.3rem; padding: 2px 12px; border-radius: 999px; background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--gold-dk); }
.item-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 1rem; padding: 3px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.92); color: var(--ink); }
.item-chip.empty { background: rgba(255, 255, 255, 0.25); color: inherit; font-weight: 600; }
.item-emoji { font-size: 1.4rem; line-height: 1; }
#btn-dive.has-item { animation: item-glow 0.9s ease-in-out infinite alternate; }
@keyframes item-glow { from { filter: brightness(1); } to { filter: brightness(1.35) drop-shadow(0 0 10px #ffd166); } }
.status-text.finished, .status-text.survived { color: var(--gold); }
.status-text.eliminated { color: #ffc2c8; }
.status-text.spectating { font-size: 1.15rem; opacity: 0.9; }

.result-icon { width: 110px; height: 110px; animation: pop-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.result-icon svg { width: 100%; height: 100%; overflow: visible; }
.result-msg { font-size: clamp(1.8rem, 8vw, 2.6rem); text-shadow: 0 4px 0 rgba(0, 0, 0, 0.28); }
.result.finished .result-msg, .result.survived .result-msg { color: var(--gold); }
@keyframes pop-in { from { transform: scale(0.3) rotate(-20deg); opacity: 0; } }

/* leaderboard */
.board-card { width: min(100%, 520px); min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px 10px 10px; }
.board-card h2 { font-size: 1.45rem; color: var(--red); }
.board {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 2px 4px 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.board .row {
  display: grid;
  grid-template-columns: 34px auto minmax(0, 1fr) auto 46px;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 2px 0 var(--snow-dk);
  text-align: left;
}
.board .row.me { background: var(--gold-lt); box-shadow: 0 0 0 3px var(--gold), 0 3px 0 var(--gold-dk); position: sticky; bottom: 3px; top: 3px; z-index: 1; }
.board .avatar { --s: 38px; }
.board .rank { font-family: var(--font-title); font-size: 1.2rem; text-align: center; color: var(--ink-soft); }
.board .rank.r1, .board .rank.r2, .board .rank.r3 { width: 32px; height: 32px; line-height: 32px; border-radius: 50%; color: #fff; font-size: 1.05rem; }
.board .rank.r1 { background: #e7a90d; box-shadow: 0 2px 0 #a8770a; }
.board .rank.r2 { background: #9aa5b1; box-shadow: 0 2px 0 #6c7680; }
.board .rank.r3 { background: #c47a3d; box-shadow: 0 2px 0 #8a5328; }
.board .name { font-family: var(--font-title); font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-family: var(--font-title); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.board .delta { font-size: 0.9rem; color: var(--green); text-align: right; font-variant-numeric: tabular-nums; }

/* final */
.final { width: 100%; height: 100%; justify-content: flex-start; padding-top: 6px; }
.winner { position: relative; display: flex; gap: 12px; justify-content: center; padding-top: 30px; }
.winner .crown { position: absolute; top: 0; left: 50%; width: 76px; transform: translateX(-50%) rotate(-6deg); filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.25)); z-index: 2; }
.winner .crown svg { width: 100%; display: block; }
.avatar.huge { --s: 116px; animation: pop-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.winner .avatar.huge + .avatar.huge { --s: 92px; } /* shared win: smaller faces */
.final-title { font-size: clamp(2rem, 9vw, 2.8rem); color: var(--gold); text-shadow: 0 4px 0 var(--red-dk); }
.my-place { font-family: var(--font-title); font-size: 1.15rem; }
.final .board-card { flex: 0 1 auto; }

/* ------------------------------------------------------------ controller */

#stick-zone { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; touch-action: none; }
#btn-zone { position: absolute; right: 0; top: 0; bottom: 0; width: 50%; touch-action: none; }
#stick {
  position: absolute;
  left: 50%;
  top: 52%;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.06) 40%, rgba(255, 255, 255, 0.17));
  border: 3px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.25), 0 6px 18px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}
#stick.idle { opacity: 0.33; transition: opacity 0.25s; }
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 70px;
  margin: -35px 0 0 -35px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff 0 8%, var(--gold-lt) 22%, var(--gold) 55%, var(--gold-dk));
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.22), 0 9px 18px rgba(0, 0, 0, 0.35);
}
.zone-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.85rem;
  letter-spacing: 0.25em;
  opacity: 0.32;
  pointer-events: none;
}

.pad-btn {
  --jump: clamp(100px, 30vmin, 138px);
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  font-family: var(--font-title);
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.05s;
}
.pad-btn::before { content: ''; position: absolute; inset: -10px; border-radius: 50%; } /* bigger hit area */
.pad-btn svg { width: 36%; height: 36%; pointer-events: none; }
.pad-btn span { font-size: calc(var(--d) * 0.16); letter-spacing: 0.05em; pointer-events: none; }
#btn-jump {
  --d: var(--jump);
  width: var(--d);
  height: var(--d);
  right: 22px;
  bottom: 22px;
  background: radial-gradient(circle at 35% 28%, #ff8c96, var(--red) 58%, var(--red-dk));
  box-shadow: 0 7px 0 var(--red-dk), 0 12px 22px rgba(0, 0, 0, 0.35), inset 0 0 0 5px rgba(255, 255, 255, 0.22);
}
#btn-dive {
  --d: calc(var(--jump) * 0.7);
  width: var(--d);
  height: var(--d);
  right: calc(22px + var(--jump) * 0.86);
  bottom: calc(22px + var(--jump) * 0.88);
  background: radial-gradient(circle at 35% 28%, #8de8ae, var(--green-lt) 55%, var(--green-dk));
  box-shadow: 0 6px 0 var(--green-dk), 0 10px 18px rgba(0, 0, 0, 0.32), inset 0 0 0 4px rgba(255, 255, 255, 0.22);
}
#btn-jump.down { transform: translateY(5px) scale(0.96); box-shadow: 0 2px 0 var(--red-dk), 0 4px 10px rgba(0, 0, 0, 0.3), inset 0 0 0 5px rgba(255, 255, 255, 0.35); }
#btn-dive.down { transform: translateY(4px) scale(0.96); box-shadow: 0 2px 0 var(--green-dk), 0 4px 10px rgba(0, 0, 0, 0.3), inset 0 0 0 4px rgba(255, 255, 255, 0.35); }

/* ------------------------------------------------------------ overlays */

body[data-phase='countdown'] #panel { justify-content: flex-start; padding-top: 14px; }
#countdown {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  top: 27%;
  bottom: 46%;
  display: grid;
  place-items: center;
  pointer-events: none;
}
#countdown .num {
  font-family: var(--font-title);
  font-size: min(38vw, 30vh);
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 5px var(--red-dk);
  paint-order: stroke fill;
  text-shadow: 0 10px 0 var(--red-dk), 0 18px 34px rgba(0, 0, 0, 0.4);
  animation: count-pop 0.95s ease-out both;
}
#countdown .num.go { color: var(--gold); font-size: min(30vw, 26vh); }
@keyframes count-pop {
  0% { transform: scale(0.35); opacity: 0; }
  22% { transform: scale(1.14); opacity: 1; }
  55% { transform: scale(1); }
  100% { transform: scale(0.92); opacity: 0.85; }
}

#confetti { position: fixed; inset: 0; z-index: 25; pointer-events: none; overflow: hidden; }
#confetti i { position: absolute; top: -24px; display: block; animation: confetti-fall linear infinite; will-change: transform; }
@keyframes confetti-fall { to { transform: translate3d(var(--dx, 0), calc(100vh + 60px), 0) rotate(var(--r, 360deg)); } }

#offline {
  position: fixed;
  z-index: 70;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-family: var(--font-title);
  font-size: 1rem;
  box-shadow: var(--shadow);
}
#offline .spinner { width: 20px; height: 20px; border-width: 3px; border-top-color: #fff; }

/* ------------------------------------------------------------ edit sheet */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(4, 18, 11, 0.55); }
.sheet-card {
  position: relative;
  width: min(100%, 520px);
  max-height: calc(100% - env(safe-area-inset-top, 0px) - 12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
  border-radius: 28px 28px 0 0;
  background: var(--snow);
  color: var(--ink);
  box-shadow: var(--shadow);
  animation: sheet-up 0.24s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.sheet-card h2 { font-size: 1.6rem; color: var(--red); padding-right: 50px; }
.sheet-x { position: absolute; right: 14px; top: 12px; background: var(--snow-dk); color: var(--ink); }
.sheet-x:active { background: #ddd2be; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; display: flex; flex-direction: column; gap: 18px; padding: 4px 2px 6px; }
.edit-photo { display: flex; align-items: center; gap: 18px; }
#edit-figure { padding-top: 22px; }
#edit-figure .figure { width: 92px; }
.photo-btns { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.photo-btns .btn { font-size: 1.02rem; padding: 0.5em 0.9em; }
.photo-note { margin: 0; font-size: 0.82rem; color: var(--ink-soft); }
.name-form label, .hat-title { display: block; margin-bottom: 6px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }
.name-row { display: flex; gap: 10px; }
.name-row .text-in { font-size: 1.3rem; text-align: left; padding: 0.4em 0.65em; }
.name-form .msg { margin-top: 6px; }
.view-note { margin: 0 0 10px; font-size: 0.95rem; color: var(--ink-soft); }
.view-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.hat-picker { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.hat-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 6px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 0 var(--snow-dk);
  font-size: 0.78rem;
  cursor: pointer;
  touch-action: manipulation;
}
.hat-opt .hat-icon { width: 44px; height: 44px; }
.hat-opt.on { border-color: var(--gold); background: var(--gold-lt); }

/* ------------------------------------------------------------ landscape: the controller fills the
   screen under the top bar and the phase panel floats in the middle without stealing touches */

@media (orientation: landscape) {
  #scr-main { grid-template-rows: auto minmax(0, 1fr); grid-template-areas: 'top' 'panel'; }
  body:not(.ctl-on) #scr-main { grid-template-rows: auto minmax(0, 1fr); }
  #topbar { padding: 4px 10px 2px; }
  #me-avatar .avatar { --s: 40px; }
  #controller { grid-area: panel; }
  body.ctl-on #panel {
    z-index: 2;
    align-self: start;
    justify-self: center;
    width: min(46%, 440px);
    padding-top: 0;
    pointer-events: none;
  }
  body.ctl-on #panel :is(button, label, a, .scroll) { pointer-events: auto; }
  body.ctl-on .lobby .figure { display: none; }
  body.ctl-on .big-title { font-size: 1.35rem; }
  body.ctl-on .lobby .sub { font-size: 0.9rem; }
  body.ctl-on .timer { font-size: 2rem; }
  body.ctl-on .status-text { font-size: 1.15rem; }
  #countdown { top: 34%; bottom: 0; }
  body[data-phase='countdown'] #panel { padding-top: 0; }
  #stick { top: 56%; }
  .pad-btn { --jump: clamp(100px, 31vmin, 132px); }
  #btn-jump { right: 26px; bottom: 20px; }

  .final { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); grid-template-rows: auto auto 1fr; column-gap: 20px; align-items: center; }
  .final .winner { grid-column: 1; grid-row: 1; }
  .final .final-title { grid-column: 1; grid-row: 2; }
  .final .my-place { grid-column: 1; grid-row: 3; align-self: start; }
  .final .board-card { grid-column: 2; grid-row: 1 / 4; height: 100%; }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 26px; max-height: calc(100% - 16px); padding-bottom: 18px; }
}

/* short screens (small phones, landscape) */
@media (max-height: 640px) {
  .lobby .figure { width: 60px; margin-top: 8px; }
  .big-title { font-size: 1.45rem; }
  .result-icon { width: 80px; height: 80px; }
  .avatar.huge { --s: 92px; }
  .desc { font-size: 0.98rem; }
}

@media (prefers-reduced-motion: reduce) {
  .snowfall i, .hop .figure, .lobby .figure, .get-ready, .pick-tile.busy { animation: none; }
}
