:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273549;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --success: #22c55e;
  --danger: #ef4444;
  --warn: #f59e0b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  height: 54px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: linear-gradient(135deg, #facc15, #ef4444, #3b82f6);
  color: #0f172a;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 1px;
  font-size: 0.95rem;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.9rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-pill {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.status-pill.online {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.status-pill.offline {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.nickname-box {
  display: flex;
  gap: 6px;
}

input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #334155;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.35);
}

/* Lobby */
.lobby-container {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.lobby-header h1 {
  font-size: 1.5rem;
  margin-bottom: 6px;
}

.lobby-header p {
  color: var(--muted);
  margin-bottom: 22px;
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.room-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.room-status-tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.room-status-tag.playing {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
}

.slot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.slot-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.slot-side {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.slot-player {
  font-size: 0.9rem;
}

.tick-badge {
  font-size: 0.78rem;
  color: var(--success);
  font-weight: 700;
}

/* Room Game Layout */
.room-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 330px;
  min-height: 0;
}

.stage-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: radial-gradient(circle at center, #1e293b 0%, #0b1120 100%);
}

.stage-hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.85);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.side-badge {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 700;
}

.timer-badge {
  font-family: ui-monospace, monospace;
  background: var(--surface-2);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}

.stage-actions {
  display: flex;
  gap: 8px;
}

.canvas-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

.camera-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(15, 23, 42, 0.9);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.btn-cam {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-cam:hover {
  background: #334155;
}

.btn-cam-primary {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.cam-hint {
  margin-left: auto;
  font-size: 0.76rem;
  color: var(--muted);
}

/* Waiting Overlay */
.waiting-overlay {
  position: absolute;
  inset: 48px 0 0 0;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.waiting-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}

.waiting-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wait-slot {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.85rem;
}

.ready-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--surface-2);
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.ready-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--success);
}

/* Sphere Controls */
.sphere-host {
  position: absolute;
  right: 18px;
  bottom: 58px;
  z-index: 15;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.sphere-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

.sphere-svg {
  width: 176px;
  height: 176px;
  user-select: none;
}

.sphere-btn {
  cursor: pointer;
  transition: transform 0.1s;
}

.sphere-btn:hover circle,
.sphere-btn:hover path.btn-bg {
  fill: #38bdf8;
}

.sphere-btn:hover text,
.sphere-btn:hover path.arrow-icon {
  fill: #0f172a;
  stroke: #0f172a;
}

.sphere-actions {
  display: flex;
  gap: 6px;
  width: 100%;
}

.sphere-actions .btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.78rem;
}

/* Sidebar: Card + Chat */
.sidebar-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-box {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.panel-header h3 {
  font-size: 0.95rem;
}

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

.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--bg);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.card-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.6);
}

.card-cell.empty {
  border-style: dashed;
  border-color: rgba(148, 163, 184, 0.25);
}

.card-note {
  margin-top: 8px;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.35;
}

/* Chat */
.chat-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  margin-bottom: 10px;
}

.chat-msg {
  background: var(--bg);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.84rem;
  line-height: 1.35;
  border-left: 3px solid var(--accent);
}

.chat-msg.side-B {
  border-left-color: #f59e0b;
}

.chat-msg-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.chat-form {
  display: flex;
  gap: 6px;
}

.chat-form input {
  flex: 1;
  min-width: 0;
}

/* Victory Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.victory-icon {
  font-size: 2.8rem;
}

.win-time {
  font-size: 1.05rem;
  color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  z-index: 100;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

/* Auth & Online Players */
input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
}

input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-user-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-nick {
  font-weight: 700;
  font-size: 0.92rem;
}

.reg-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.guest-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.lobby-content {
  display: grid;
  grid-template-columns: 1fr 290px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 900px) {
  .lobby-content {
    grid-template-columns: 1fr;
  }
}

.online-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.online-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.online-panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
}

.online-count-badge {
  background: var(--surface-2);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}

.online-players-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
}

.online-player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.online-player-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.online-player-name {
  font-size: 0.88rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-player-loc {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
}

.auth-modal-card {
  width: min(380px, 92vw);
  text-align: left;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 16px;
}

.auth-tab {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-error {
  color: #f87171;
  font-size: 0.84rem;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  padding: 8px 10px;
  border-radius: 6px;
}
