:root {
  --bg: #141a2e;
  --bg2: #0b1020;
  --ink: #f4f6ff;
  --muted: #9aa3c7;
  --card: #1e2642;
  --line: #2f3a62;
  --accent: #ffcf3f;
  --flash: transparent;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink);
  font-family: 'Polin', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--flash);
  opacity: .28;
  transition: background .5s ease;
  pointer-events: none;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
  z-index: 1;
}

/* ---------- hint ---------- */
.hint {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  pointer-events: none;
  z-index: 2;
  transition: opacity .3s ease;
}
.hint.gone { opacity: 0; }
.hint h1 {
  margin: 28px 0 8px;
  font-weight: 900;
  font-size: clamp(1.8rem, 7vw, 2.8rem);
}
.hint p {
  margin: 0;
  max-width: 22em;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}
.hint-hand {
  position: relative;
  width: 150px;
  height: 90px;
}
.hint-hand span {
  position: absolute;
  top: 15px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 5px solid currentColor;
  animation: pop 2.4s ease-in-out infinite;
}
.hint-hand span:nth-child(1) { right: 0;   color: #ff5d73; }
.hint-hand span:nth-child(2) { right: 45px; color: #3fd0ff; animation-delay: .25s; }
.hint-hand span:nth-child(3) { right: 90px; color: #ffcf3f; animation-delay: .5s; }
@keyframes pop {
  0%, 100% { transform: scale(.85); opacity: .6; }
  40%      { transform: scale(1.05); opacity: 1; }
}

/* ---------- top bar ---------- */
.bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  z-index: 5;
  transition: opacity .3s ease;
}
.playing .bar { opacity: 0; pointer-events: none; }

.round-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(30, 38, 66, .85);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.round-btn svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.round-btn circle { fill: var(--card); }
#sound-btn .mute { display: none; }
#sound-btn[aria-pressed="false"] .wave { display: none; }
#sound-btn[aria-pressed="false"] .mute { display: inline; }

.chip {
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(30, 38, 66, .85);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* ---------- fingers ---------- */
.finger {
  --size: 118px;
  --c: #fff;
  --p: 0;
  position: absolute;
  left: 0; top: 0;
  width: var(--size);
  height: var(--size);
  margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
  border-radius: 50%;
  pointer-events: none;
  will-change: transform;
}
.finger .ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 7px solid var(--c);
  box-shadow: 0 0 24px var(--c), inset 0 0 18px color-mix(in srgb, var(--c) 60%, transparent);
  animation: breathe 1s ease-in-out infinite;
  transition: transform .45s cubic-bezier(.2, 1.6, .4, 1), opacity .35s ease, border-width .3s ease;
}
.finger .dot {
  position: absolute;
  inset: 26%;
  border-radius: 50%;
  background: var(--c);
  opacity: .9;
  transition: transform .45s cubic-bezier(.2, 1.6, .4, 1), opacity .35s ease;
}
/* countdown arc around each finger */
.finger .arc {
  position: absolute;
  inset: -16px;
  border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent calc(50% - 5px), #000 calc(50% - 4px));
  mask: radial-gradient(circle, transparent calc(50% - 5px), #000 calc(50% - 4px));
  opacity: .75;
  transition: opacity .2s ease;
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.finger.out .ring,
.finger.out .dot { transform: scale(0); opacity: 0; }
.finger.out .arc,
.finger.picked .arc,
.finger.team .arc { opacity: 0; }

.finger.picked .ring {
  border-width: 10px;
  animation: winner .8s ease-in-out infinite;
}
.finger.picked .dot { transform: scale(1.15); }
@keyframes winner {
  0%, 100% { transform: scale(1.35); }
  50%      { transform: scale(1.6); }
}

.finger.team .ring { animation: none; transform: scale(1.2); }
.finger .num {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 2.2rem;
  color: #0b1020;
  opacity: 0;
  transform: scale(.4);
  transition: opacity .3s ease, transform .4s cubic-bezier(.2, 1.6, .4, 1);
}
.finger.team .num { opacity: 1; transform: scale(1); }

/* the message above a chosen finger */
.tag {
  position: absolute;
  left: 0; top: 0;
  padding: 10px 18px;
  border-radius: 16px;
  background: var(--c);
  color: #0b1020;
  font-weight: 900;
  font-size: clamp(1.25rem, 5.5vw, 1.7rem);
  white-space: nowrap;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.3);
  animation: tag-in .55s cubic-bezier(.2, 1.6, .4, 1) forwards;
}
.tag::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 18px; height: 18px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
  border-radius: 3px;
}
.tag.below::after { bottom: auto; top: -9px; }
@keyframes tag-in {
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- banner ---------- */
.banner {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 26px);
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--muted);
  pointer-events: none;
  z-index: 3;
  padding: 0 20px;
  min-height: 1.5em;
}
.banner.big {
  color: var(--ink);
  font-weight: 900;
  font-size: clamp(1.4rem, 6vw, 2rem);
}

/* ---------- settings panel ---------- */
.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(5, 8, 18, .6);
  -webkit-user-select: text;
  user-select: text;
}
.panel[hidden] { display: none; }
.panel-card {
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .25s ease-out;
}
@media (min-width: 560px) {
  .panel { align-items: center; }
  .panel-card { border-radius: 24px; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.panel h2 { margin: 0 0 14px; font-size: 1.5rem; font-weight: 900; }
.field { margin-bottom: 18px; }
.field[hidden] { display: none; }
.label { display: block; margin-bottom: 8px; color: var(--muted); font-weight: 700; }

.seg {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 14px;
  background: var(--bg2);
}
.seg button {
  flex: 1;
  padding: 11px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.seg button[aria-checked="true"] { background: var(--accent); color: #0b1020; }

.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button {
  width: 48px; height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  font: inherit;
  font-size: 1.6rem;
  cursor: pointer;
}
.stepper button:disabled { opacity: .35; cursor: default; }
.stepper output { min-width: 2ch; text-align: center; font-size: 1.8rem; font-weight: 900; }

#msg-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
}
#msg-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.quick button {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}

.primary {
  width: 100%;
  margin-top: 4px;
  padding: 15px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #0b1020;
  font: inherit;
  font-weight: 900;
  font-size: 1.15rem;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .finger .ring, .hint-hand span, .finger.picked .ring { animation: none; }
}
