:root {
  --bg: #14122b;
  --bg2: #241d4d;
  --card: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f3f1ff;
  --dim: #a9a3d4;
  --accent: #ffb84d;
  --win: #4ade80;
  --lose: #f87171;
  --me: #7c9cff;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden], .hidden { display: none !important; }

html, body { margin: 0; min-height: 100%; }
html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom, no 300ms delay */
  overscroll-behavior: none;
}
body {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg2), var(--bg)) fixed;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}
input, select { -webkit-user-select: text; user-select: text; font-size: 16px; /* <16px makes iOS zoom on focus */ }
.record { margin: -8px 0 16px; color: var(--accent); font-weight: 700; font-size: 14px; }

.screen { max-width: 560px; margin: 0 auto; padding: 16px 0 20px; min-height: 100dvh; }
#room { display: flex; flex-direction: column; }
#lobby { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
#lobby .card { width: 100%; }

h1, h2 { margin: 0; }
.logo { font-size: 56px; letter-spacing: 6px; display: flex; gap: 8px; }
.logo span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo span:nth-child(2) { animation-delay: .3s; }
.logo span:nth-child(3) { animation-delay: .6s; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(-6deg); } }
h2 { font-size: 28px; margin-top: 8px; }
.sub { color: var(--dim); margin: 6px 0 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(8px);
  display: flex; flex-direction: column; gap: 14px; text-align: left;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--dim); }
input, select {
  font: inherit; color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
#code { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 700; min-width: 0; flex: 1; }
.row { display: flex; gap: 10px; }
.or { text-align: center; color: var(--dim); font-size: 13px; }

button {
  font: inherit; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; transition: transform .1s, background .15s, opacity .15s;
}
@media (hover: hover) { button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.13); } }
button:active:not(:disabled) { transform: scale(.96); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: linear-gradient(135deg, #ffb84d, #ff7a59); color: #2a1500; border: 0; }
@media (hover: hover) { button.primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, #ffb84d, #ff7a59); } }

/* Room */
.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.grow { flex: 1; }
.chip { padding: 8px 12px; font-size: 14px; border-radius: 999px; }
.chip.subtle { border: 0; background: none; color: var(--dim); font-weight: 400; padding: 0 4px; }
#room-code { letter-spacing: 3px; }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.vs { color: var(--dim); font-weight: 800; font-size: 13px; letter-spacing: 2px; }
.player {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-align: center; min-height: 92px;
  transition: border-color .2s, box-shadow .2s;
}
.player.me { border-color: var(--me); }
.player.winning { box-shadow: 0 0 0 2px var(--win), 0 0 24px rgba(74, 222, 128, .35); }
.player .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .name i { font-style: normal; font-size: 12px; color: var(--dim); font-weight: 400; }
.player .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--win); margin-right: 6px; }
.player .dot.off { background: #666; }
.player .state { font-size: 13px; color: var(--dim); min-height: 18px; margin-top: 2px; }
.player .state.ready { color: var(--accent); }
.pips { display: flex; justify-content: center; gap: 6px; margin-top: 8px; }
.pip { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); transition: all .3s; }
.pip.on { background: var(--accent); border-color: var(--accent); transform: scale(1.15); }
.empty { color: var(--dim); }

.arena {
  position: relative; margin: 12px 0 8px; flex: 1; min-height: 140px;
  display: grid; grid-template-columns: 1fr 1fr; align-items: center; justify-items: center;
}
.hand { font-size: clamp(70px, 24vw, 112px); line-height: 1; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .4)); transition: transform .25s, opacity .25s; }
.hand.right { transform: scaleX(-1); }
.hand.dim { opacity: .45; filter: grayscale(.6); }
.hand.shake.left { animation: shakeL .4s ease-in-out 3; }
.hand.shake.right { animation: shakeR .4s ease-in-out 3; }
@keyframes shakeL { 50% { transform: translateY(-34px) rotate(12deg); } }
@keyframes shakeR { 0%, 100% { transform: scaleX(-1); } 50% { transform: scaleX(-1) translateY(-34px) rotate(12deg); } }
.hand.pop.left { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
.hand.pop.right { animation: popR .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.4); } to { transform: scale(1); } }
@keyframes popR { from { transform: scaleX(-.4) scaleY(.4); } to { transform: scaleX(-1); } }
.hand.win { transform: scale(1.18); }
.hand.win.right { transform: scaleX(-1.18) scaleY(1.18); }
.banner {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; font-size: 34px; font-weight: 900; letter-spacing: 1px;
  text-shadow: 0 4px 18px rgba(0, 0, 0, .6);
}
.banner.show { animation: banner 1.1s ease-out both; }
@keyframes banner { 0% { transform: scale(.3); opacity: 0; } 30% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.banner.win { color: var(--win); } .banner.lose { color: var(--lose); } .banner.draw { color: var(--accent); }

.status { text-align: center; min-height: 26px; font-weight: 600; margin-bottom: 10px; }

.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.picker .random { grid-column: 1 / -1; padding: 10px; font-size: 15px; flex-direction: row; justify-content: center; }
.picker button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative;
  padding: 14px 6px; font-size: 14px; border-radius: var(--radius);
}
.picker button span { font-size: 44px; line-height: 1.1; }
.picker button kbd { position: absolute; top: 6px; right: 8px; font-size: 11px; color: var(--dim); font-family: inherit; }
.picker button.chosen { border-color: var(--accent); background: rgba(255, 184, 77, .18); transform: translateY(-4px); }
@media (hover: none) { .picker button kbd { display: none; } }

.meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; min-height: 40px; }
.streak { display: flex; gap: 5px; flex-wrap: wrap; }
.streak i { width: 12px; height: 12px; border-radius: 3px; background: var(--line); }
.streak i.w { background: var(--win); } .streak i.l { background: var(--lose); } .streak i.d { background: var(--dim); }
.matchbar { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 14px; font-weight: 700; color: var(--dim); font-size: 14px; letter-spacing: .5px; text-transform: uppercase; }
.matchbar b { color: var(--accent); }
.seg { display: inline-flex; background: rgba(0,0,0,.28); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px 16px; border-radius: 999px; font-size: 15px; min-width: 44px; }
.seg button.on { background: linear-gradient(135deg, #ffb84d, #ff7a59); color: #2a1500; }
.seg button:disabled { opacity: .5; }
.badge { display: inline-block; align-self: center; padding: 6px 14px; border-radius: 999px; font-weight: 800; font-size: 14px; background: rgba(255,184,77,.16); color: var(--accent); border: 1px solid rgba(255,184,77,.4); }
.badge:empty { display: none; }
.recap { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.recap span { font-size: 18px; padding: 4px 8px; border-radius: 10px; background: rgba(255,255,255,.06); border: 1px solid var(--line); }
.recap span.w { border-color: var(--win); background: rgba(74,222,128,.12); }
.recap span.l { border-color: var(--lose); background: rgba(248,113,113,.12); }
.nextlen { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--dim); font-size: 14px; flex-wrap: wrap; }
.overlay .card { max-height: 100dvh; overflow-y: auto; }

.reactions { display: flex; justify-content: center; gap: 6px; margin-top: 14px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.reactions::-webkit-scrollbar { display: none; }
.reactions button { padding: 8px 12px; font-size: 24px; border-radius: 999px; flex: none; }

.float-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.float {
  position: absolute; bottom: 12%; font-size: 52px; animation: floatUp 2.2s ease-out forwards;
  text-align: center; text-shadow: 0 4px 12px rgba(0, 0, 0, .4);
}
.float small { display: block; font-size: 12px; color: var(--text); font-weight: 600; }
@keyframes floatUp { to { transform: translateY(-55vh) scale(1.3); opacity: 0; } }

.overlay {
  position: fixed; inset: 0; background: rgba(10, 8, 26, .75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5;
}
.overlay .card { width: min(380px, 100%); text-align: center; align-items: stretch; animation: pop .45s cubic-bezier(.2, 1.4, .4, 1); }
.overlay .sub { margin: 0; }
.trophy { font-size: 72px; line-height: 1; animation: trophy 1.6s ease-in-out infinite; }
@keyframes trophy { 50% { transform: translateY(-8px) rotate(-5deg) scale(1.06); } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: #000c; border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; font-size: 14px;
}

@media (max-width: 480px) {
  .screen { padding-top: 8px; }
  .picker button { min-height: 104px; justify-content: center; }
  .picker button span { font-size: 46px; }
  .picker .random { min-height: 48px; }
  .chip { padding: 10px 14px; }
  .player { padding: 10px 8px; min-height: 84px; }
  .status { font-size: 15px; }
  .banner { font-size: 30px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .scoreboard { gap: 6px; } .player { min-height: 60px; padding: 6px; }
  .picker button { min-height: 60px; } .picker button span { font-size: 28px; }
  .hand { font-size: 56px; } .reactions, .meta { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
