/* style.css – Werwolf Mobile v3.0 | Blue Glass UI · Dark/Light */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ========== THEME TOKENS ========== */
:root {
  /* Dunkelblau (default) */
  --bg-0: #050b1c;
  --bg-1: #0a1733;
  --bg-2: #0f1f47;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-light: #60a5fa;
  --accent-glow: #38bdf8;
  --accent-glow-soft: #7dd3fc;
  --card-bg: rgba(16, 32, 72, 0.45);
  --card-border: rgba(96, 165, 250, 0.28);
  --text: #eaf1ff;
  --text-dim: rgba(234, 241, 255, 0.72);
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(0, 0, 0, 0.35);
  --shadow: 0 25px 45px -12px rgba(0, 0, 0, 0.6);
  --particle-rgb: 96, 165, 250;
  --line-rgb: 56, 189, 248;
  --meta-color: #0a1733;
  color-scheme: dark;

  /* semantic state colors */
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;

  /* aliases for legacy inline styles in app.js */
  --purple: var(--accent-strong);
  --purple-light: var(--accent-light);
  --purple-glow: var(--accent-glow);
  --bg-dark: var(--bg-0);
  --bg-card: var(--card-bg);
  --border: var(--card-border);
}

:root[data-theme="light"] {
  /* Hellblau */
  --bg-0: #cfe0ff;
  --bg-1: #e8f1ff;
  --bg-2: #ffffff;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-light: #3b82f6;
  --accent-glow: #0ea5e9;
  --accent-glow-soft: #38bdf8;
  --card-bg: rgba(255, 255, 255, 0.72);
  --card-border: rgba(37, 99, 235, 0.18);
  --text: #0c1c3d;
  --text-dim: rgba(12, 28, 61, 0.7);
  --surface: rgba(37, 99, 235, 0.05);
  --surface-2: rgba(37, 99, 235, 0.06);
  --shadow: 0 25px 45px -14px rgba(37, 99, 235, 0.18);
  --particle-rgb: 37, 99, 235;
  --line-rgb: 14, 165, 233;
  --meta-color: #cfe0ff;
  color-scheme: light;
}

/* No-JS fallback: follow device if no manual theme set */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg-0: #cfe0ff; --bg-1: #e8f1ff; --bg-2: #ffffff;
    --accent: #2563eb; --accent-strong: #1d4ed8; --accent-light: #3b82f6;
    --accent-glow: #0ea5e9; --accent-glow-soft: #38bdf8;
    --card-bg: rgba(255, 255, 255, 0.72); --card-border: rgba(37, 99, 235, 0.18);
    --text: #0c1c3d; --text-dim: rgba(12, 28, 61, 0.7);
    --surface: rgba(37, 99, 235, 0.05); --surface-2: rgba(37, 99, 235, 0.06);
    --shadow: 0 25px 45px -14px rgba(37, 99, 235, 0.18);
    --particle-rgb: 37, 99, 235; --line-rgb: 14, 165, 233; --meta-color: #cfe0ff;
    color-scheme: light;
  }
}

body {
  min-height: 100vh;
  min-height: 100dvh; /* avoids content being cut off by mobile browser UI bars */
  background: radial-gradient(circle at 20% 30%, var(--bg-1), var(--bg-0));
  color: var(--text);
  overflow-x: hidden;
  transition: background 0.5s ease, color 0.5s ease;
}

/* ========== PARTICLES ========== */
#particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ========== APP LAYOUT ========== */
.glass-app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.bg-animation {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(40rem 40rem at 18% 22%, rgba(59, 130, 246, 0.20), transparent 60%),
    radial-gradient(36rem 36rem at 82% 78%, rgba(56, 189, 248, 0.16), transparent 60%);
  animation: driftNebula 22s ease-in-out infinite alternate;
}

@keyframes driftNebula {
  0%   { transform: scale(1) translate(0, 0); opacity: 0.55; }
  50%  { opacity: 0.9; }
  100% { transform: scale(1.18) translate(2.5%, 1.8%); opacity: 0.7; }
}

.ui-container {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 1300px;
  margin: 0 auto;
}

/* ========== GLASS CARD ========== */
.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 2rem;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow), 0 0 0 1px rgba(96, 165, 250, 0.12);
  padding: 1.8rem;
  color: var(--text);
  animation: cardEnter 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.1) forwards;
  transition: background 0.5s ease, border-color 0.5s ease, color 0.5s ease;
}

@keyframes cardEnter {
  0% { transform: scale(0.92) translateY(20px); opacity: 0; filter: blur(4px); }
  100% { transform: scale(1) translateY(0); opacity: 1; filter: blur(0); }
}

/* ========== TYPOGRAPHY ========== */
/* Gradient text only where clip-to-text is supported — otherwise color:transparent
   would render the headings invisible. */
h1, h2, h3 {
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
}
@supports (-webkit-background-clip: text) or (background-clip: text) {
  h1, h2, h3 {
    background: linear-gradient(135deg, var(--text) 0%, var(--accent-glow) 110%);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
  }
}

h1 { font-size: 2rem; font-weight: 800; }

p, label, span, div { color: var(--text); }

/* ========== BUTTONS ========== */
.glass-button {
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  border: none;
  border-radius: 2rem;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.4, 1.1), box-shadow 0.25s ease;
  backdrop-filter: blur(4px);
  font-size: 1rem;
  box-shadow: 0 8px 22px -8px rgba(37, 99, 235, 0.55);
  position: relative;
  overflow: hidden;
}

.glass-button::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.4s, height 0.4s;
}

.glass-button:active::after { width: 220px; height: 220px; }

.glass-button:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 16px 34px -8px rgba(56, 189, 248, 0.55);
}

.glass-button:active { transform: translateY(0) scale(0.98); }

.glass-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.glass-button-small { padding: 0.4rem 1rem; font-size: 0.85rem; color: #fff; }

.btn-success { background: linear-gradient(135deg, #16a34a, #22c55e); box-shadow: 0 8px 20px -8px rgba(34, 197, 94, 0.5); }
.btn-danger  { background: linear-gradient(135deg, #dc2626, #ef4444); box-shadow: 0 8px 20px -8px rgba(239, 68, 68, 0.5); }
.btn-warning { background: linear-gradient(135deg, #d97706, #f59e0b); box-shadow: 0 8px 20px -8px rgba(245, 158, 11, 0.5); }

/* ========== INPUTS ========== */
input, select {
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 2rem;
  padding: 0.75rem 1.2rem;
  color: var(--text);
  font-size: 1rem;
  width: 100%;
  outline: none;
  transition: all 0.3s ease;
}

input:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25), 0 0 20px rgba(56, 189, 248, 0.2);
  background: var(--surface-2);
}

input::placeholder { color: var(--text-dim); opacity: 0.7; }

/* ========== PLAYER TAGS ========== */
.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin: 1.2rem 0;
}

.player-tag {
  background: var(--surface-2);
  backdrop-filter: blur(8px);
  border-radius: 2rem;
  padding: 0.5rem 1rem;
  border-left: 3px solid var(--accent-light);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  animation: tagSlideIn 0.3s ease forwards;
  transition: all 0.2s;
}

.player-tag:hover {
  background: rgba(59, 130, 246, 0.16);
  transform: translateX(4px);
}

.player-tag.dead {
  opacity: 0.5;
  text-decoration: line-through;
  border-left-color: var(--danger);
}

@keyframes tagSlideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ========== NARRATOR SCRIPT ========== */
.narrator-script {
  background: var(--surface-2);
  border-radius: 1.5rem;
  padding: 1.2rem;
  border: 1px solid var(--accent-glow);
  animation: scriptPulse 3s infinite alternate;
  margin: 1rem 0;
  position: relative;
  overflow: hidden;
}

.narrator-script::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(56, 189, 248, 0.07), transparent);
  animation: scriptShimmer 4s infinite;
}

@keyframes scriptPulse {
  0% { border-color: rgba(56, 189, 248, 0.3); box-shadow: 0 0 8px rgba(56, 189, 248, 0.15); }
  100% { border-color: rgba(56, 189, 248, 0.8); box-shadow: 0 0 25px rgba(56, 189, 248, 0.35); }
}

@keyframes scriptShimmer {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ========== VOTE GRID ========== */
.vote-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.8rem;
  margin: 1.2rem 0;
}

.vote-card {
  background: var(--surface);
  border-radius: 1.2rem;
  padding: 0.8rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1);
  border: 1px solid var(--card-border);
  position: relative;
  overflow: hidden;
}

.vote-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.32), rgba(56, 189, 248, 0.12));
  opacity: 0;
  transition: opacity 0.3s;
  border-radius: 1.2rem;
}

.vote-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-light);
  box-shadow: 0 8px 20px -4px rgba(37, 99, 235, 0.4);
}

.vote-card:hover::before { opacity: 1; }

.vote-card.selected {
  border-color: var(--accent-glow);
  background: rgba(56, 189, 248, 0.32);
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.45), 0 8px 25px -4px rgba(37, 99, 235, 0.45);
}

.vote-card.selected::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.75rem;
  color: var(--accent-glow);
  font-weight: 700;
}

/* ========== FADE TRANSITION ========== */
.fade-transition { animation: cinematicFade 0.5s cubic-bezier(0.23, 1, 0.32, 1); }

@keyframes cinematicFade {
  0% { opacity: 0; transform: translateY(12px); filter: blur(3px); }
  100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}

/* ========== LOADER ========== */
.loader {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(96, 165, 250, 0.18);
  border-top: 3px solid var(--accent-glow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 1rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== ICON BUTTONS (Main Menu) ========== */
.icon-grid {
  display: flex;
  justify-content: space-around;
  gap: 1rem;
  margin: 2rem 0;
  flex-wrap: wrap;
}

.icon-button {
  flex: 1;
  min-width: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  background: var(--surface);
  border-radius: 1.5rem;
  padding: 1.4rem 1rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1);
  border: 1px solid var(--card-border);
  position: relative;
  overflow: hidden;
}

.icon-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(56, 189, 248, 0.18), transparent 70%);
  opacity: 0;
  transition: opacity 0.3s;
}

.icon-button:hover {
  background: rgba(59, 130, 246, 0.15);
  transform: translateY(-6px);
  border-color: var(--accent-light);
  box-shadow: 0 16px 32px -8px rgba(37, 99, 235, 0.35);
}

.icon-button:hover::before { opacity: 1; }
.icon-button:active { transform: translateY(-2px) scale(0.97); }

.icon-button i {
  font-size: 2.4rem;
  color: var(--accent-glow);
  transition: transform 0.3s;
}

.icon-button:hover i { transform: scale(1.15); }

.icon-button span { font-weight: 600; font-size: 0.9rem; text-align: center; }

/* ========== SWITCH ========== */
.switch-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border-radius: 3rem;
  padding: 0.6rem 1.2rem;
  margin: 1rem 0;
}

.switch-label { font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }

.switch { position: relative; display: inline-block; width: 52px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--danger);
  transition: 0.3s;
  border-radius: 28px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(24px); }

/* ========== BADGES ========== */
.public-badge {
  display: inline-block;
  padding: 0.2rem 0.8rem;
  border-radius: 2rem;
  font-size: 0.7rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.public-badge.public { background: var(--success); color: white; }
.public-badge.private { background: var(--danger); color: white; }

/* ========== ROLE CARDS ========== */
.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0;
}

.role-card {
  background: var(--surface);
  border-radius: 1.2rem;
  padding: 0.8rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.2, 0.9, 0.4, 1.1);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  user-select: none;
}

.role-card:hover { transform: translateY(-2px); border-color: var(--accent-light); }

.role-card.selected {
  background: rgba(56, 189, 248, 0.3);
  border-color: var(--accent-glow);
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

.role-card.locked {
  cursor: not-allowed;
  position: relative;
  background: rgba(37, 99, 235, 0.25);
  border-color: var(--accent-strong);
  opacity: 0.85;
}
.role-card.locked::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    135deg,
    transparent,
    transparent 8px,
    rgba(96, 165, 250, 0.1) 8px,
    rgba(96, 165, 250, 0.1) 16px
  );
  pointer-events: none;
}
.role-card.locked:hover { transform: none; }

.role-card i { font-size: 1.2rem; }

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 20, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(12px); }
}

.modal-content {
  max-width: 450px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-content.large { max-width: 750px; }

/* ========== CODE INPUT ========== */
.code-input-container {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  margin: 1.5rem 0;
}

.code-box {
  width: 3.2rem;
  height: 4rem;
  font-size: 1.8rem;
  text-align: center;
  text-transform: uppercase;
  border-radius: 1rem;
  background: var(--surface);
  border: 1.5px solid var(--card-border);
  color: var(--text);
  transition: all 0.25s ease;
  padding: 0;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
  font-weight: 700;
}

.code-box:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.4), inset 0 2px 4px rgba(0, 0, 0, 0.1);
  background: var(--surface-2);
  transform: translateY(-3px) scale(1.05);
  outline: none;
}

/* ========== JOIN SPLIT ========== */
.join-split { display: flex; gap: 2rem; text-align: left; }

.join-split-left {
  flex: 1;
  border-right: 1px solid var(--card-border);
  padding-right: 1.5rem;
  display: flex;
  flex-direction: column;
}

.join-split-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.public-lobby-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  padding: 0.8rem 1rem;
  border-radius: 1rem;
  margin-bottom: 0.6rem;
  border: 1px solid var(--card-border);
  transition: all 0.25s ease;
}

.public-lobby-item:hover {
  background: rgba(59, 130, 246, 0.12);
  border-color: var(--accent-light);
  transform: translateX(4px);
}

.public-lobby-info { display: flex; flex-direction: column; }
.public-lobby-code { font-weight: bold; font-size: 1.1rem; color: var(--accent-glow); }
.public-lobby-players { font-size: 0.85rem; opacity: 0.7; }

/* ========== VOTE DETAILS ========== */
.vote-detail-list {
  background: var(--surface-2);
  border-radius: 1rem;
  padding: 0.8rem;
  margin: 0.8rem 0;
}

.vote-detail-item {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--card-border);
}

.vote-detail-item:last-child { border-bottom: none; }

/* ========== ROLE DISPLAY (Reveal) ========== */
.role-display {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 20, 0.92);
  backdrop-filter: blur(25px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: roleRevealBg 0.5s ease;
}

@keyframes roleRevealBg { from { opacity: 0; } to { opacity: 1; } }

.role-display-content { text-align: center; max-width: 380px; width: 90%; padding: 2.5rem; }

.role-reveal-card { animation: roleCardReveal 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.1); }

@keyframes roleCardReveal {
  0% { transform: scale(0.3) rotateY(180deg); opacity: 0; }
  50% { transform: scale(1.05) rotateY(0deg); opacity: 1; }
  100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}

.role-reveal-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  animation: roleIconPulse 2s infinite;
}

@keyframes roleIconPulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.45)); }
  50% { transform: scale(1.1); filter: drop-shadow(0 0 20px rgba(56, 189, 248, 0.75)); }
}

.role-timer { font-size: 2rem; font-weight: 700; margin-top: 0.5rem; color: var(--accent-glow); }

.role-timer-bar {
  width: 100%;
  height: 4px;
  background: rgba(96, 165, 250, 0.15);
  border-radius: 4px;
  margin-top: 1rem;
  overflow: hidden;
}

.role-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent-glow));
  border-radius: 4px;
  transition: width 1s linear;
  width: 100%;
}

/* ========== TOAST NOTIFICATIONS ========== */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  border-radius: 1rem;
  padding: 0.8rem 1.5rem;
  color: var(--text);
  font-weight: 500;
  font-size: 0.9rem;
  border: 1px solid var(--card-border);
  box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.1) forwards;
  pointer-events: auto;
  max-width: 400px;
  text-align: center;
}

.toast-success { border-color: var(--success); box-shadow: 0 12px 30px -8px rgba(34, 197, 94, 0.35); }
.toast-error { border-color: var(--danger); box-shadow: 0 12px 30px -8px rgba(239, 68, 68, 0.35); }
.toast-warning { border-color: var(--warning); box-shadow: 0 12px 30px -8px rgba(245, 158, 11, 0.35); }
.toast-info { border-color: var(--info); box-shadow: 0 12px 30px -8px rgba(59, 130, 246, 0.35); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast-exit { animation: toastOut 0.35s ease forwards; }

@keyframes toastOut { to { opacity: 0; transform: translateY(-10px) scale(0.9); } }

/* ========== PHASE OVERLAY ========== */
.phase-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.phase-overlay.active { opacity: 1; animation: phaseFlash 2s ease forwards; }

.phase-overlay.phase-night { background: radial-gradient(circle, rgba(10, 23, 51, 0.95), rgba(5, 11, 28, 0.98)); }
.phase-overlay.phase-day { background: radial-gradient(circle, rgba(56, 189, 248, 0.18), rgba(96, 165, 250, 0.06)); }
.phase-overlay.phase-vote { background: radial-gradient(circle, rgba(37, 99, 235, 0.2), rgba(0, 0, 0, 0.8)); }

@keyframes phaseFlash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

.phase-overlay-icon {
  font-size: 5rem;
  animation: phaseIconBounce 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.1) 0.2s both;
}

@keyframes phaseIconBounce {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.phase-overlay-text {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 1rem;
  color: #fff;
  animation: phaseTextSlide 0.5s ease 0.3s both;
}
@supports (-webkit-background-clip: text) or (background-clip: text) {
  .phase-overlay-text {
    background: linear-gradient(135deg, #fff, var(--accent-glow));
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
  }
}

@keyframes phaseTextSlide {
  from { transform: translateY(15px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ========== FLOATING ICON BUTTONS (Guide + Theme) ========== */
.guide-btn, .theme-toggle {
  position: fixed;
  top: 1rem;
  top: calc(1rem + env(safe-area-inset-top)); /* clear the notch/status bar with viewport-fit=cover */
  z-index: 800;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--accent-glow);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.guide-btn { right: 1rem; }
.theme-toggle { right: 4.2rem; }

/* ========== LANGUAGE PICKER ========== */
.lang-select {
  position: fixed;
  top: 1rem;
  top: calc(1rem + env(safe-area-inset-top));
  right: 7.4rem;
  z-index: 800;
  height: 44px;
  width: auto;
  max-width: 9rem;
  padding: 0 0.7rem;
  border-radius: 1.4rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: all 0.25s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

.lang-select:hover {
  background: rgba(59, 130, 246, 0.3);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.35);
}

.lang-select:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.lang-select option {
  background: var(--bg-1);
  color: var(--text);
}

@media (max-width: 760px) {
  .lang-select { max-width: 3.6rem; font-size: 0.8rem; padding: 0 0.4rem; }
  .install-bar-text span { display: none; }
  .install-bar { gap: 0.6rem; padding-left: 0.8rem; padding-right: 0.8rem; }
}

.guide-btn:hover, .theme-toggle:hover {
  transform: scale(1.1) rotate(8deg);
  background: rgba(59, 130, 246, 0.3);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.35);
}

.theme-toggle i { transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.1); }

/* ========== GUIDE MODAL ========== */
.guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 20, 0.85);
  backdrop-filter: blur(20px);
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

.guide-container {
  max-width: 600px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(96, 165, 250, 0.4) transparent;
}

.guide-header { text-align: center; margin-bottom: 2rem; }
.guide-header h2 { font-size: 1.8rem; }

.guide-section {
  margin-bottom: 1.5rem;
  padding: 1.2rem;
  background: var(--surface);
  border-radius: 1.2rem;
  border: 1px solid var(--card-border);
  animation: guideCardIn 0.4s ease both;
}

.guide-section:nth-child(2) { animation-delay: 0.05s; }
.guide-section:nth-child(3) { animation-delay: 0.1s; }
.guide-section:nth-child(4) { animation-delay: 0.15s; }
.guide-section:nth-child(5) { animation-delay: 0.2s; }

@keyframes guideCardIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.guide-section h3 { font-size: 1.1rem; margin-bottom: 0.6rem; }

.guide-role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.8rem;
}

.guide-role-item {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
  padding: 0.7rem;
  border-radius: 0.8rem;
  background: var(--surface-2);
  transition: all 0.2s;
}

.guide-role-item:hover { background: rgba(59, 130, 246, 0.1); transform: translateX(4px); }

.guide-role-icon { font-size: 1.5rem; flex-shrink: 0; width: 2.5rem; text-align: center; }
.guide-role-info { flex: 1; }
.guide-role-info strong { color: var(--accent-glow); }
.guide-role-info p { font-size: 0.82rem; opacity: 0.8; margin-top: 0.2rem; line-height: 1.4; }

.guide-phase-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.8rem 0;
}

.guide-phase-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border-radius: 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.guide-phase-step span:first-child { font-size: 1.3rem; }
.guide-phase-arrow { color: var(--accent-glow); font-size: 1.2rem; }

/* ========== CHAT WIDGET ========== */
.chat-container {
  position: fixed;
  bottom: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom)); /* clear the home indicator */
  right: 1rem;
  width: 340px;
  max-height: 420px;
  display: flex;
  flex-direction: column;
  z-index: 900;
  border-radius: 1.5rem;
  overflow: hidden;
  background: var(--card-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--card-border);
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.6);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.1), box-shadow 0.4s ease;
  will-change: transform;
}

.chat-container.collapsed {
  transform: translateY(calc(100% - 46px));
  box-shadow: 0 10px 20px -5px rgba(0, 0, 0, 0.4);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.55), rgba(56, 189, 248, 0.5));
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 0.95rem;
  color: #fff;
}

.chat-toggle-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.chat-toggle-btn:hover { background: rgba(255, 255, 255, 0.15); }

.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  transition: opacity 0.3s ease 0.1s, visibility 0.3s 0.1s;
}

.chat-container.collapsed .chat-body {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 280px;
  min-height: 120px;
  scrollbar-width: thin;
  scrollbar-color: rgba(96, 165, 250, 0.4) transparent;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(96, 165, 250, 0.4); border-radius: 2px; }

.chat-msg {
  padding: 0.4rem 0.7rem;
  border-radius: 1rem;
  background: var(--surface);
  max-width: 85%;
  word-break: break-word;
  animation: msgFadeIn 0.25s ease;
  align-self: flex-start;
}

.chat-msg-own {
  background: rgba(37, 99, 235, 0.28);
  border: 1px solid var(--card-border);
  align-self: flex-end;
}

.chat-msg-wolf {
  background: rgba(220, 38, 38, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.chat-msg-dead {
  background: rgba(100, 116, 139, 0.2);
  border: 1px solid rgba(148, 163, 184, 0.25);
  font-style: italic;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-msg-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-glow);
  display: block;
  margin-bottom: 0.1rem;
}

.chat-msg-own .chat-msg-name { color: var(--accent-light); }
.chat-msg-wolf .chat-msg-name { color: #fca5a5; }
.chat-msg-dead .chat-msg-name { color: #94a3b8; }
.chat-msg-text { font-size: 0.85rem; line-height: 1.35; }

.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--card-border);
  background: var(--surface-2);
}

.chat-input-area input {
  flex: 1;
  border-radius: 1.5rem;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  border: 1px solid var(--card-border);
  background: var(--surface);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent-glow));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-send-btn:hover { transform: scale(1.1); box-shadow: 0 4px 12px rgba(56, 189, 248, 0.5); }

.chat-empty { text-align: center; padding: 2rem 1rem; color: var(--text-dim); font-size: 0.85rem; }

/* ========== INPUT ERROR ========== */
.error-flash {
  border-color: var(--danger) !important;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.5) !important;
  animation: shake 0.4s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* ========== INSTALL BAR (top, iOS + Android) ========== */
.install-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 960; /* above floating buttons (800), below modals (1000) */
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 1rem;
  padding-top: calc(0.6rem + env(safe-area-inset-top));
  background: rgba(10, 23, 51, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--card-border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  transform: translateY(-130%);
  transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.1);
  pointer-events: none;
}
.install-bar.show {
  transform: translateY(0);
  pointer-events: auto;
}
.install-bar-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  flex-shrink: 0;
}
.install-bar-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  min-width: 0;
  flex: 1;
}
.install-bar-text strong { font-size: 0.92rem; }
.install-bar-text span {
  font-size: 0.78rem;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.install-bar-btn {
  flex-shrink: 0;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}
.install-bar-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text);
  opacity: 0.6;
  font-size: 1.6rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  cursor: pointer;
  border-radius: 50%;
  transition: opacity 0.2s ease, background 0.2s ease;
}
.install-bar-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.1); }

/* While the bar is open, push the floating top controls below it so they don't overlap. */
html.install-bar-open .guide-btn,
html.install-bar-open .theme-toggle,
html.install-bar-open .lang-select {
  top: calc(1rem + env(safe-area-inset-top) + 60px);
}

/* iOS install instruction steps */
.ios-install-steps {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  margin: 1.2rem 0;
  text-align: left;
}
.ios-install-step {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0.9rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--card-border);
  border-radius: 0.7rem;
  font-size: 0.9rem;
}
.ios-install-step i { color: var(--accent-glow); font-size: 1.2rem; width: 1.4rem; text-align: center; }

/* ========== CONSENT / OFFLINE ICONS ========== */
.consent-icon-wrap,
.offline-icon-wrap {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-size: 2rem;
}

.consent-icon-wrap {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.3), rgba(56, 189, 248, 0.15));
  color: var(--accent-glow);
  animation: roleIconPulse 3s infinite;
}

.offline-icon-wrap {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.3), rgba(220, 38, 38, 0.15));
  color: var(--danger);
}

/* ========== LEGAL LINKS ========== */
.legal-link { color: var(--accent-glow); text-decoration: none; transition: opacity 0.2s; }
.legal-link:hover { opacity: 0.7; }

/* ========== CHOICE MODAL ========== */
.choice-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 20, 0.8);
  backdrop-filter: blur(15px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: modalFadeIn 0.3s ease;
}

/* ========== WIN SCREEN CONFETTI ========== */
@keyframes confettiFall {
  0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confettiFall 3s linear forwards;
  z-index: 2001;
  pointer-events: none;
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
  /* Disable animations entirely instead of fast-forwarding them: a 0.001s run of a
     looping/forwards animation leaves elements stuck in their final keyframe
     (invisible confetti, mid-transition cards). The loader keeps spinning since
     it's the only progress indicator. */
  *, *::before, *::after {
    animation: none !important;
    transition-duration: 0.001s !important;
  }
  .loader { animation: spin 0.8s linear infinite !important; }
  .confetti-piece { display: none; }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 760px) {
  .glass-card { padding: 1.2rem; border-radius: 1.5rem; }
  .glass-button { padding: 0.6rem 1.2rem; }
  h1 { font-size: 1.6rem; }
  .icon-button { min-width: 100px; padding: 1rem 0.6rem; }
  .icon-button i { font-size: 1.8rem; }
  .icon-button span { font-size: 0.8rem; }
  .roles-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .chat-container { left: 0.5rem; right: 0.5rem; width: auto; bottom: 0.5rem; }
  .join-split { flex-direction: column-reverse; gap: 1.5rem; }
  .join-split-left { border-right: none; border-top: 1px solid var(--card-border); padding-right: 0; padding-top: 1.5rem; }
  .code-input-container { gap: 0.3rem; }
  .code-box { width: 2.5rem; height: 3.5rem; font-size: 1.4rem; }
  .guide-role-grid { grid-template-columns: 1fr; }
  .toast { max-width: 90vw; font-size: 0.82rem; }
  .toast-container { bottom: 4.5rem; }
  .vote-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}
