/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --red: #ff3b3b;
  --red-dark: #c0392b;
  --red-light: #ff6b6b;
  --blue: #3b82f6;
  --blue-dark: #1d4ed8;
  --purple: #8b5cf6;
  --green: #10b981;
  --bg: #0f0f1a;
  --bg2: #16162a;
  --bg3: #1e1e35;
  --card: #1a1a2e;
  --card2: #222240;
  --border: rgba(255,255,255,0.08);
  --text: #f0f0ff;
  --text2: #a0a0c0;
  --text3: #6060a0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --shadow-red: 0 4px 20px rgba(255,59,59,0.3);
}
html { scroll-behavior: smooth; }
body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* ===== GATE ===== */
.gate-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: radial-gradient(ellipse at 50% 30%, #1a0a2e 0%, #0a0a18 100%);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.gate-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 48px 40px 40px;
  width: 100%; max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow), 0 0 60px rgba(255,59,59,0.15);
  position: relative; z-index: 2;
  animation: gateIn 0.6s cubic-bezier(.34,1.56,.64,1);
}
@keyframes gateIn {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to   { opacity: 1; transform: none; }
}
.gate-icon-wrap { margin-bottom: 20px; }
.gate-svg { width: 80px; height: 80px; filter: drop-shadow(0 0 20px rgba(255,59,59,0.5)); }
.gate-title {
  font-family: 'Russo One', sans-serif;
  font-size: 2.2rem; color: var(--text);
  margin-bottom: 8px; letter-spacing: 1px;
}
.gate-sub { color: var(--text2); font-size: 0.95rem; margin-bottom: 28px; }
.gate-input-wrap {
  position: relative; margin-bottom: 16px;
}
.gate-input-wrap .input-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text3); pointer-events: none;
}
.gate-input {
  width: 100%; padding: 14px 16px 14px 44px;
  background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'Nunito', sans-serif; font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-align: center; letter-spacing: 3px;
}
.gate-input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(255,59,59,0.15); }
.gate-btn {
  width: 100%; padding: 14px 24px;
  background: linear-gradient(135deg, var(--red-light), var(--red-dark));
  border: none; border-radius: var(--radius-sm); color: #fff;
  font-family: 'Nunito', sans-serif; font-size: 1rem; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-red);
}
.gate-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(255,59,59,0.4); }
.gate-btn:active { transform: translateY(0); }
.gate-error {
  margin-top: 14px; color: #ff6b6b; font-size: 0.9rem; font-weight: 700;
  min-height: 20px;
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%,100%{transform:translateX(0)}25%{transform:translateX(-6px)}75%{transform:translateX(6px)}
}
/* Floating BG shapes */
.gate-bg-shapes { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.shape {
  position: absolute; font-size: 2.5rem;
  opacity: 0.07; animation: floatShape 8s ease-in-out infinite;
  filter: blur(1px);
}
.s1{top:10%;left:8%;animation-delay:0s;}
.s2{top:20%;right:10%;animation-delay:1.2s;}
.s3{bottom:25%;left:15%;animation-delay:2.4s;}
.s4{bottom:15%;right:8%;animation-delay:0.8s;}
.s5{top:50%;left:50%;animation-delay:1.8s;}
@keyframes floatShape {
  0%,100%{transform:translateY(0) rotate(0deg);}
  50%{transform:translateY(-20px) rotate(10deg);}
}

/* ===== APP SHELL ===== */
.app { min-height: 100vh; display: flex; flex-direction: column; }
/* ===== HEADER ===== */
.header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(20px);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0 24px; height: 64px;
  display: flex; align-items: center; gap: 24px;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-icon-wrap { line-height: 0; }
.logo-text {
  font-family: 'Russo One', sans-serif;
  font-size: 1.4rem; color: var(--text); white-space: nowrap;
}
.logo-accent { color: var(--red-light); }
.nav { display: flex; gap: 4px; flex: 1; justify-content: center; }
.nav-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 18px; border-radius: 999px;
  background: transparent; border: 1.5px solid transparent;
  color: var(--text2); font-family: 'Nunito', sans-serif;
  font-size: 0.9rem; font-weight: 700; cursor: pointer;
  transition: all 0.2s;
}
.nav-btn:hover { color: var(--text); background: var(--bg3); }
.nav-btn.active {
  background: linear-gradient(135deg, rgba(255,59,59,0.15), rgba(255,107,107,0.08));
  border-color: rgba(255,59,59,0.3); color: var(--red-light);
}
.header-user {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; font-weight: 700; color: var(--text2);
  white-space: nowrap;
}
.user-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
}
.user-dot.pulse {
  animation: pulseGreen 2s ease-in-out infinite;
}
@keyframes pulseGreen {
  0%,100%{box-shadow:0 0 0 0 rgba(16,185,129,0.6);}
  50%{box-shadow:0 0 0 5px rgba(16,185,129,0);}
}

/* ===== SECTIONS ===== */
.section { display: none; flex: 1; }
.section.active { display: block; }
.section-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 40px 24px 60px;
}
/* ===== HERO ===== */
.hero-block { text-align: center; margin-bottom: 40px; }
.hero-icon-row {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  margin-bottom: 16px;
}
.hero-dice-icon {
  font-size: 3.5rem;
  animation: diceSpin 6s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(255,59,59,0.4));
}
@keyframes diceSpin {
  0%,100%{transform:rotate(-5deg) scale(1);}
  50%{transform:rotate(5deg) scale(1.05);}
}
.hero-emoji { font-size: 2rem; }
.bounce1 { animation: bounceY 2.5s ease-in-out infinite; }
.bounce2 { animation: bounceY 2.5s ease-in-out infinite 0.5s; }
@keyframes bounceY {
  0%,100%{transform:translateY(0);}50%{transform:translateY(-8px);}
}
.hero-title {
  font-family: 'Russo One', sans-serif;
  font-size: 2rem; margin-bottom: 10px;
  background: linear-gradient(135deg, #fff 30%, var(--red-light));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.hero-sub { color: var(--text2); font-size: 1rem; }
/* ===== CARDS ===== */
.cards-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px;
}
@media(max-width:700px){.cards-row{grid-template-columns:1fr;}}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.card-header h3 { font-size: 1rem; font-weight: 800; color: var(--text); flex: 1; }
.card-icon {
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-blue  { background: rgba(59,130,246,0.15); color: var(--blue); }
.icon-red   { background: rgba(255,59,59,0.15);  color: var(--red-light); }
.icon-purple{ background: rgba(139,92,246,0.15); color: var(--purple); }
.icon-green { background: rgba(16,185,129,0.15); color: var(--green); }
.badge {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 10px;
  font-size: 0.78rem; font-weight: 800; color: var(--text2);
}
.badge.ml-auto { margin-left: auto; }

/* ===== INPUTS & BUTTONS ===== */
.text-input {
  width: 100%; padding: 11px 14px;
  background: var(--bg3); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: 'Nunito', sans-serif; font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.text-input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(255,59,59,0.12); }
.text-input::placeholder { color: var(--text3); }
.input-row { display: flex; gap: 8px; margin-bottom: 14px; }
.input-row .text-input { flex: 1; }
.add-btn {
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  border: none; color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 12px rgba(59,130,246,0.3);
}
.add-btn:hover { transform: scale(1.08); }
.rand-btn {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, var(--red-light), var(--red-dark));
  border: none; border-radius: var(--radius-sm); color: #fff;
  font-family: 'Nunito', sans-serif; font-size: 1.05rem; font-weight: 900;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: var(--shadow-red); transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 20px; letter-spacing: 0.5px;
}
.rand-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(255,59,59,0.45); }
.rand-btn:active { transform: translateY(0); }
.clear-btn {
  background: transparent; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text3);
  font-family: 'Nunito', sans-serif; font-size: 0.8rem; font-weight: 700;
  padding: 6px 12px; cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; gap: 5px;
}
.clear-btn:hover { border-color: var(--red); color: var(--red-light); }
.clear-btn.full-w { width: 100%; justify-content: center; margin-top: 12px; }
.ml-auto { margin-left: auto; }
.geo-btn {
  width: 100%; padding: 11px;
  background: linear-gradient(135deg, var(--green), #059669);
  border: none; border-radius: var(--radius-sm); color: #fff;
  font-family: 'Nunito', sans-serif; font-size: 0.9rem; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 2px 12px rgba(16,185,129,0.3); transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 10px;
}
.geo-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(16,185,129,0.4); }
.send-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--red-light), var(--red-dark));
  border: none; color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: transform 0.15s;
}
.send-btn:hover { transform: scale(1.08); }

/* ===== PLAYER LIST ===== */
.player-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 240px; overflow-y: auto;
  margin-bottom: 8px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.player-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; background: var(--bg3);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  animation: slideIn 0.2s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: none; }
}
.player-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 900; flex-shrink: 0;
}
.player-name { flex: 1; font-size: 0.9rem; font-weight: 700; }
.player-remove {
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(255,59,59,0.1); color: var(--red-light);
  cursor: pointer; font-size: 0.75rem; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.player-remove:hover { background: rgba(255,59,59,0.25); }

/* ===== RESULT ===== */
.result-area {
  min-height: 160px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); background: var(--bg3);
  border: 1.5px dashed var(--border); padding: 20px;
}
.result-placeholder { text-align: center; color: var(--text3); }
.placeholder-emoji { font-size: 2.5rem; margin-bottom: 10px; }
.result-placeholder p { font-size: 0.9rem; line-height: 1.5; }
.result-content { width: 100%; }
.result-role {
  display: flex; align-items: center; gap: 16px;
  padding: 16px; border-radius: var(--radius-sm);
  margin-bottom: 12px; border: 1px solid var(--border);
}
.result-role:last-child { margin-bottom: 0; }
.role-catcher { background: linear-gradient(135deg, rgba(255,59,59,0.12), rgba(255,59,59,0.05)); border-color: rgba(255,59,59,0.25); }
.role-runner  { background: linear-gradient(135deg, rgba(59,130,246,0.12), rgba(59,130,246,0.05)); border-color: rgba(59,130,246,0.25); }
.role-icon { font-size: 2rem; }
.role-info { flex: 1; }
.role-label { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 3px; }
.role-catcher .role-label { color: var(--red-light); }
.role-runner  .role-label { color: var(--blue); }
.role-name { font-size: 1.2rem; font-weight: 900; color: var(--text); }

/* ===== HISTORY ===== */
.history-card { margin-top: 0; }
.history-list {
  max-height: 260px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.history-empty { color: var(--text3); font-size: 0.9rem; text-align: center; padding: 20px 0; }
.history-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-bottom: 8px;
  background: var(--bg3); animation: slideIn 0.2s ease;
}
.history-num {
  font-size: 0.75rem; font-weight: 900; color: var(--text3);
  min-width: 28px; text-align: center;
}
.history-roles { flex: 1; }
.history-role-line { font-size: 0.85rem; margin-bottom: 2px; }
.history-time { font-size: 0.75rem; color: var(--text3); white-space: nowrap; }

/* ===== MAP LAYOUT ===== */
.map-layout {
  display: flex; height: calc(100vh - 64px); overflow: hidden;
}
.map-sidebar {
  width: 300px; flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.sidebar-section {
  padding: 20px 16px; border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; flex: 1; }
.sidebar-title {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.8rem; font-weight: 900; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text2); margin-bottom: 14px;
}
.geo-status {
  font-size: 0.8rem; margin-top: 8px; min-height: 18px;
  color: var(--green); font-weight: 700;
}
.online-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 200px; overflow-y: auto;
}
.online-empty { color: var(--text3); font-size: 0.85rem; text-align: center; padding: 10px 0; }
.online-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--bg3); border: 1px solid var(--border);
  cursor: pointer; transition: background 0.2s, border-color 0.2s;
}
.online-item:hover { background: var(--card2); border-color: rgba(255,59,59,0.3); }
.online-item.self { border-color: rgba(59,130,246,0.3); }
.online-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.online-dot.red { background: var(--red-light); box-shadow: 0 0 6px var(--red-light); }
.online-dot.blue { background: var(--blue); box-shadow: 0 0 6px var(--blue); }
.online-name { flex: 1; font-size: 0.85rem; font-weight: 700; }
.online-dm {
  font-size: 0.7rem; color: var(--text3); background: var(--border);
  border-radius: 4px; padding: 2px 6px; font-weight: 700;
}

/* ===== CHAT ===== */
.chat-section { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-messages {
  flex: 1; overflow-y: auto; max-height: 220px;
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 12px; padding-right: 4px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.chat-msg {
  padding: 8px 12px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  font-size: 0.85rem; animation: slideIn 0.2s ease;
  word-break: break-word;
}
.chat-msg.own { background: rgba(255,59,59,0.1); border-color: rgba(255,59,59,0.2); }
.chat-msg.dm-msg { background: rgba(139,92,246,0.1); border-color: rgba(139,92,246,0.25); }
.msg-author { font-weight: 900; font-size: 0.78rem; margin-bottom: 2px; }
.msg-text { color: var(--text2); line-height: 1.4; }
.msg-time { font-size: 0.7rem; color: var(--text3); margin-top: 3px; }
.chat-input-row { display: flex; gap: 6px; }
.chat-input-row .text-input { flex: 1; }

/* ===== MAP ===== */
.map-container {
  flex: 1; position: relative; min-width: 0;
}
#map { width: 100%; height: 100%; }
.map-legend-overlay {
  position: absolute; bottom: 24px; left: 16px; z-index: 500;
  background: rgba(15,15,26,0.85); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 6px;
  backdrop-filter: blur(8px);
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text2); font-weight: 700; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.red { background: var(--red-light); box-shadow: 0 0 6px var(--red-light); }
.legend-dot.blue { background: var(--blue); box-shadow: 0 0 6px var(--blue); }
.map-hint {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  z-index: 500; background: rgba(15,15,26,0.9); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 20px;
  font-size: 0.9rem; color: var(--text2); font-weight: 700;
  text-align: center; pointer-events: none;
  transition: opacity 0.3s; backdrop-filter: blur(8px);
}

/* ===== DM POPUP ===== */
.dm-popup {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  width: 320px; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 30px rgba(0,0,0,0.3);
  overflow: hidden; animation: popupIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popupIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: none; }
}
.popup-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--bg3); border-bottom: 1px solid var(--border);
}
.popup-title-row { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 0.9rem; }
.popup-close {
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-size: 1rem; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; transition: background 0.2s;
}
.popup-close:hover { background: var(--border); color: var(--text); }
.popup-messages {
  max-height: 200px; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.popup-input-row { display: flex; gap: 6px; padding: 12px; border-top: 1px solid var(--border); }
.popup-input-row .text-input { flex: 1; }

/* ===== TOAST ===== */
.toast {
  position: fixed; top: 80px; right: 24px; z-index: 9998;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 18px;
  font-size: 0.9rem; font-weight: 700; color: var(--text);
  box-shadow: var(--shadow); animation: toastIn 0.3s ease;
  max-width: 300px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: none; }
}

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container { background: #0d0d1a !important; }
.leaflet-tile { filter: brightness(0.7) saturate(0.5) hue-rotate(200deg); }
.custom-player-marker { cursor: pointer; }
.marker-label {
  background: rgba(15,15,26,0.9); border: 2px solid var(--red-light);
  border-radius: 8px; padding: 3px 8px;
  font-family: 'Nunito', sans-serif; font-size: 11px; font-weight: 800;
  color: var(--text); white-space: nowrap; box-shadow: 0 0 10px rgba(255,59,59,0.3);
}
.marker-label.self { border-color: var(--blue); box-shadow: 0 0 10px rgba(59,130,246,0.3); }

/* ===== RESPONSIVE ===== */
@media(max-width:900px) {
  .map-layout { flex-direction: column; }
  .map-sidebar { width: 100%; height: auto; max-height: 40vh; flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .sidebar-section { min-width: 200px; flex: 1; border-right: 1px solid var(--border); border-bottom: none; }
  .map-container { flex: 1; min-height: 300px; }
}
@media(max-width:600px) {
  .header-inner { padding: 0 14px; gap: 12px; }
  .logo-text { font-size: 1.1rem; }
  .nav-btn span { display: none; }
  .section-inner { padding: 24px 14px 40px; }
  .hero-title { font-size: 1.5rem; }
  .dm-popup { width: calc(100vw - 32px); right: 16px; }
}
