:root {
  --bg: #0b0f18;
  --bg-elevated: #121928;
  --bg-card: #172033;
  --bg-card-hover: #1d2840;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.3);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --red: #e11d48;
  --red-soft: rgba(225, 29, 72, 0.16);
  --blue: #2563eb;
  --blue-soft: rgba(37, 99, 235, 0.16);
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.15);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, #17223a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(14px);
  background: rgba(11, 15, 24, 0.85);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--amber-soft);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: var(--emerald-soft);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.live-pill.offline {
  background: var(--amber-soft);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.35);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.hidden { display: none !important; }

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.panel-header h2, .panel-header h3 { margin: 0; }

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.row { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 650;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  color: #fff;
  background: var(--accent);
}
.btn:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 0.38rem 0.72rem; font-size: 0.8rem; }
.btn-secondary { background: var(--bg-card); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }
.btn-danger { background: var(--red); }
.btn-danger:hover:not(:disabled) { background: #f43f5e; }
.btn-blue { background: var(--blue); }
.btn-blue:hover:not(:disabled) { background: #3b82f6; }
.btn-success { background: var(--emerald); color: #052e16; }
.btn-success:hover:not(:disabled) { background: #34d399; }
.btn-amber { background: var(--amber); color: #271a03; }
.btn-amber:hover:not(:disabled) { background: #fbbf24; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: rgba(255,255,255,0.05); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
}
.badge-red { background: var(--red-soft); color: #fda4af; }
.badge-blue { background: var(--blue-soft); color: #93c5fd; }
.badge-emerald { background: var(--emerald-soft); color: #6ee7b7; }
.badge-amber { background: var(--amber-soft); color: #fcd34d; }

.code-chip {
  font-family: var(--mono);
  font-weight: 800;
  letter-spacing: 0.12em;
  background: rgba(99, 102, 241, 0.18);
  color: #c7d2fe;
  padding: 0.25rem 0.65rem;
  border-radius: 8px;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  background: #0d1320;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.room-list { display: flex; flex-direction: column; gap: 0.55rem; }
.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 0.9rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.room-row:hover { border-color: var(--border-strong); }

.muted { color: var(--text-muted); font-size: 0.88rem; }

.rr-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.9rem 1.15rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

/* Roads & Rails */
.rr-dice-stage {
  display: grid;
  grid-template-columns: auto repeat(4, minmax(100px, 150px));
  justify-content: center;
  align-items: center;
  gap: 1.1rem;
  padding: 1.75rem 1rem;
  background: linear-gradient(145deg, #162033 0%, #0e1523 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
}
@media (max-width: 780px) {
  .rr-dice-stage {
    grid-template-columns: repeat(2, minmax(110px, 150px));
  }
  .rr-round-badge { grid-column: 1 / -1; justify-self: center; }
}

.rr-round-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 112px;
  height: 112px;
  border-radius: 20px;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #1c1002;
  font-weight: 900;
  box-shadow: 0 10px 26px rgba(245, 158, 11, 0.3);
}
.rr-round-num { font-size: 3rem; line-height: 1; }
.rr-round-sub { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }

.rr-die-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.75rem;
  border-radius: 16px;
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.16s ease, border-color 0.16s ease;
}
.rr-die-card:hover { transform: translateY(-3px); }
.rr-die-card.selected { border-color: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.35); }
.rr-die-card.station { background: #fef3c7; }
.rr-die-img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.rr-die-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  color: #334155;
}

.rr-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.rr-board-frame {
  display: grid;
  grid-template-columns: 28px repeat(7, 56px) 28px;
  grid-template-rows: 28px repeat(7, 56px) 28px;
  gap: 3px;
  padding: 12px;
  background: #e2e8f0;
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow-x: auto;
  max-width: 100%;
}
@media (max-width: 560px) {
  .rr-board-frame {
    grid-template-columns: 20px repeat(7, 40px) 20px;
    grid-template-rows: 20px repeat(7, 40px) 20px;
  }
}

.rr-exit-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: #0f172a;
}
.rr-exit-marker.road { color: #b45309; }
.rr-exit-marker.rail { color: #1e293b; }

.rr-cell {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.rr-cell.center-zone {
  background: #fffbeb;
  border-color: #f59e0b;
}
.rr-cell:hover { border-color: #6366f1; box-shadow: inset 0 0 0 2px rgba(99, 102, 241, 0.35); }
.rr-cell img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.rr-cell-round {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 0.58rem;
  font-weight: 800;
  color: #64748b;
  background: rgba(255,255,255,0.8);
  padding: 0 2px;
  border-radius: 3px;
}

/* Rules modal formatting */
.rules-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.95rem;
}
.rules-section h4 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
}
.rules-list {
  margin: 0;
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.rules-list strong { color: var(--text); }

/* Toast & Modal */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 340px;
}
.toast {
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  font-size: 0.86rem;
  font-weight: 600;
  animation: fadeInUp 0.18s ease;
}
.toast.error { border-color: var(--red); background: #3b1220; }
.toast.success { border-color: var(--emerald); background: #0d2b22; }

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

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 8, 15, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-card {
  width: min(580px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 1.35rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

