:root {
  --bg: #1a1440;
  --bg-deep: #2E1065;
  --panel: #241d54;
  --panel2: #2f2866;
  --text: #eef1f8;
  --muted: #a5b4fc;
  --accent: #ffb020;
  --accent-2: #ff6b3d;
  --danger: #ef4444;
  --ok: #22c55e;
  --border: #373073;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }
[hidden] { display: none !important; }

.rotate-hint {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(17, 24, 39, 0.95); color: #fff;
  display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 1.3rem; padding: 2rem;
}
@media (orientation: portrait) { .rotate-hint { display: none !important; } }

/* ---- screens ---- */
.landing, .game {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.landing { align-items: center; justify-content: center; overflow-y: auto; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
  animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-height: 0;
}

@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.title {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: -1px;
  margin: 0;
  background: linear-gradient(90deg, #ffb020, #ff6b3d, #ff4fd8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle { color: var(--muted); margin: 0 0 8px; font-size: 14px; }

.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

input[type='text'] {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 17px;
  outline: none;
}
input[type='text']:focus { border-color: var(--accent); }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #241300; }
.btn-ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn-sm { padding: 9px 12px; font-size: 14px; }
.btn-big { font-size: 1.2rem; padding: 0.85rem 1.7rem; }
.btn-back {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  margin-top: 4px;
}
.btn-back:hover { color: var(--text); border-color: #4a4588; }
.btn:disabled { opacity: 0.4; cursor: default; }

.name-row { display: flex; align-items: center; gap: 8px; }

.avatar-badge {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 24px;
}

.theme-row { display: flex; gap: 10px; justify-content: center; }
.theme-swatch {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 22px;
  transition: transform 0.1s ease;
  color: rgba(0,0,0,0.55);
}
.theme-swatch.selected { border-color: #fff; transform: scale(1.1); }

.code-big {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 8px;
  text-align: center;
  margin: 4px 0;
  color: var(--text);
}

.player-list { display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel2);
  padding: 10px 12px;
  border-radius: 12px;
}
.player-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #3a3470;
  color: var(--muted);
}
.badge.host { background: #5a4308; color: #ffb020; }

.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.hud .back { color: var(--accent); text-decoration: none; font-weight: 700; font-size: 0.9rem; }
.roomcode { color: var(--muted); font-family: monospace; letter-spacing: 0.2em; font-weight: 700; }
.round { color: var(--muted); font-size: 0.9rem; }

.lobby { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }

.play { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.scores { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: center; padding: 0.4rem; }
.score-chip {
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}
.score-chip.you { border-color: var(--accent); color: var(--accent); }
.score-chip.turn { outline: 2px solid var(--accent); }

.turnbanner { text-align: center; padding: 0.3rem; font-weight: 700; color: var(--accent); min-height: 1.4rem; }

.stage { position: relative; flex: 1 1 auto; min-height: 0; touch-action: none; }
canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  border-radius: 14px;
  background: #14103a;
}

.wind {
  position: absolute; top: 0.6rem; right: 0.6rem;
  color: #C7D2FE; font-size: 0.85rem;
  background: rgba(0,0,0,0.35); padding: 0.2rem 0.5rem; border-radius: 8px;
}

.poison { text-align: center; padding: 0.6rem; }
.poison-title { margin: 0 0 0.5rem; font-weight: 700; }
.poison-options { display: flex; gap: 0.8rem; justify-content: center; }
.poison-btn { min-width: 7rem; font-size: 1.1rem; }

.controls { display: flex; gap: 0.7rem; justify-content: center; padding: 0.6rem; }
.reactions { display: flex; gap: 0.6rem; justify-content: center; padding: 0.4rem 0 0.7rem; }
.reaction {
  font-size: 1.4rem;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 3rem; height: 3rem;
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 12, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fade 0.2s ease;
  padding: 16px;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.overlay .card { max-width: 360px; }

.scorelist { list-style: none; padding: 0; margin: 1rem 0; text-align: left; }
.scorelist li { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.podium-actions { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; margin-top: 1rem; }

.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 0; }

.join-error {
  background: rgba(255, 79, 216, 0.12);
  border: 1px solid #ff4fd8;
  color: #ffb3e8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  text-align: center;
}

.row { display: flex; gap: 10px; width: 100%; }
.row > * { flex: 1; }

.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 100;
  animation: fade 0.2s ease;
  max-width: 90vw;
  text-align: center;
}

/* ---- How to Play modal ---- */
.overlay .howto-card { max-width: 430px; gap: 16px; text-align: left; animation: pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1); }
.howto-heading {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, #ffb020, #ff6b3d, #ff4fd8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.howto-list { display: flex; flex-direction: column; gap: 12px; }
.howto-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
}
.howto-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg);
  display: grid;
  place-items: center;
  font-size: 24px;
}
.howto-copy { display: flex; flex-direction: column; gap: 3px; }
.howto-row-title { font-size: 15px; font-weight: 800; }
.howto-desc { font-size: 13px; color: var(--muted); line-height: 1.4; }

@media (min-width: 700px) {
  .card { max-width: 460px; }
  .overlay .howto-card { max-width: 460px; }
}
