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

:root {
  --primary: #4a90d9;
  --primary-dark: #3570b0;
  --secondary: #6c757d;
  --bg: #0a0e17;
  --panel: #141b2d;
  --panel-border: #1e2a45;
  --text: #e0e6f0;
  --text-dim: #7a8baa;
  --accent-red: #e74c5e;
  --accent-blue: #4a90d9;
  --accent-gold: #f0c040;
  --success: #28a745;
}

html, body {
  width: 100%; height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.screen { display: none; width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
.screen.active { display: flex; }

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 24px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 16px; font-weight: 600; transition: all 0.2s;
  font-family: inherit;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: #555; }
.btn-small { padding: 6px 16px; font-size: 14px; }

/* ===== NAME SCREEN ===== */
#screen-name {
  justify-content: center; align-items: center;
  background: radial-gradient(ellipse at 50% 30%, #1a2a4a, var(--bg));
}
.name-container { text-align: center; padding: 20px; }
.title-area { margin-bottom: 30px; }
#title-canvas { display: block; margin: 0 auto 10px; }
.title-area h1 {
  font-size: 48px; font-weight: 800;
  background: linear-gradient(135deg, var(--accent-gold), #ff8040);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
}
.subtitle { color: var(--text-dim); font-size: 18px; margin-top: 4px; }
.name-form { display: flex; flex-direction: column; gap: 12px; max-width: 320px; margin: 0 auto; }
.name-form input {
  padding: 14px 18px; border-radius: 10px; border: 2px solid var(--panel-border);
  background: var(--panel); color: var(--text); font-size: 18px; text-align: center;
  outline: none; font-family: inherit;
}
.name-form input:focus { border-color: var(--primary); }

/* ===== LOBBY ===== */
#screen-lobby {
  flex-direction: column;
  background: var(--bg);
}
.lobby-container { display: flex; flex-direction: column; height: 100%; width: 100%; }
.lobby-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--panel-border);
}
.lobby-header h2 { font-size: 20px; }
.header-info { display: flex; gap: 16px; align-items: center; }
#player-name-display {
  background: var(--primary); color: #fff; padding: 4px 12px;
  border-radius: 12px; font-size: 14px; font-weight: 600;
}
#online-count { color: var(--text-dim); font-size: 14px; }

.lobby-body {
  display: flex; flex: 1; overflow: hidden;
}
.rooms-panel {
  flex: 1; display: flex; flex-direction: column;
  border-right: 1px solid var(--panel-border);
  min-width: 0;
}
.chat-panel {
  width: 350px; display: flex; flex-direction: column;
  min-width: 0;
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
}
.panel-header h3, .chat-panel h3 { font-size: 16px; color: var(--text-dim); }
.chat-panel h3 { padding: 12px 16px 8px; }

.rooms-list {
  flex: 1; overflow-y: auto; padding: 8px 16px;
}
.empty-msg { color: var(--text-dim); text-align: center; padding: 40px 20px; font-style: italic; }

.room-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; margin-bottom: 8px;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 10px; transition: border-color 0.2s;
}
.room-item:hover { border-color: var(--primary); }
.room-info h4 { font-size: 15px; margin-bottom: 2px; }
.room-info span { font-size: 13px; color: var(--text-dim); }
.btn-join {
  padding: 6px 20px; background: var(--success); color: #fff;
  border: none; border-radius: 6px; cursor: pointer; font-weight: 600;
  font-family: inherit;
}
.btn-join:hover { background: #219a3a; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 8px 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.chat-msg { font-size: 14px; line-height: 1.4; word-break: break-word; }
.chat-msg.system { color: var(--text-dim); font-style: italic; font-size: 13px; }
.chat-msg.game-result { color: var(--accent-gold); font-weight: 600; }
.chat-msg .sender { font-weight: 600; color: var(--accent-blue); }

.chat-input-area {
  display: flex; gap: 8px; padding: 10px 16px;
  border-top: 1px solid var(--panel-border);
}
.chat-input-area input {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--panel-border); background: var(--panel);
  color: var(--text); outline: none; font-family: inherit; font-size: 14px;
}
.chat-input-area input:focus { border-color: var(--primary); }

/* ===== WAITING ===== */
#screen-waiting {
  justify-content: center; align-items: center;
  background: radial-gradient(ellipse at 50% 40%, #1a2a4a, var(--bg));
}
.waiting-container { text-align: center; padding: 20px; }
.waiting-container h2 { margin-bottom: 20px; font-size: 24px; }
.waiting-container p { color: var(--text-dim); margin: 16px 0; }
.waiting-animation {
  width: 120px; height: 120px; margin: 20px auto; position: relative;
}
.blob-waiting {
  width: 60px; height: 60px; background: var(--accent-red);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  position: absolute; bottom: 10px; left: 10px;
  animation: blobBounce 1.5s ease-in-out infinite;
}
.ball-waiting {
  width: 30px; height: 30px; background: #fff;
  border-radius: 50%; position: absolute; top: 5px; right: 15px;
  animation: ballFloat 2s ease-in-out infinite;
}
@keyframes blobBounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-15px)} }
@keyframes ballFloat { 0%,100%{transform:translate(0,0)} 50%{transform:translate(-10px,-10px)} }

/* ===== GAME ===== */
#screen-game {
  justify-content: center; align-items: center;
  background: #000; position: relative;
}
#game-canvas {
  display: block;
  image-rendering: auto;
}
#game-ui-overlay {
  position: absolute; top: 0; left: 0; right: 0;
  pointer-events: none; z-index: 10;
}
#score-display {
  display: flex; justify-content: center; align-items: center; gap: 8px;
  padding: 8px; font-size: 28px; font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.score-left { color: var(--accent-red); }
.score-right { color: var(--accent-blue); }
.score-divider { color: #fff; font-size: 20px; }

.btn-quit {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px; padding: 0;
  background: rgba(0,0,0,0.5); color: #fff;
  border: none; border-radius: 50%; cursor: pointer;
  font-size: 18px; z-index: 20; display: flex;
  align-items: center; justify-content: center;
}
.btn-quit:hover { background: var(--accent-red); }

/* ===== TOUCH CONTROLS ===== */
.touch-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: none; justify-content: space-between; align-items: flex-end;
  padding: 15px 10px; z-index: 15; pointer-events: none;
}
.touch-controls-top {
  bottom: auto; top: 0; align-items: flex-start;
}
.touch-left-area, .touch-right-area { display: flex; gap: 8px; }
.touch-btn {
  pointer-events: auto;
  width: 64px; height: 64px;
  background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.8);
  border: 2px solid rgba(255,255,255,0.25); border-radius: 50%;
  font-size: 20px; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.touch-btn:active, .touch-btn.active {
  background: rgba(255,255,255,0.35);
  border-color: rgba(255,255,255,0.5);
}
.touch-jump { width: 80px; height: 80px; font-size: 14px; font-weight: 800; }

@media (pointer: coarse) {
  .touch-controls { display: flex; }
}

/* ===== OVERLAYS / MODALS ===== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75); z-index: 100;
  display: flex; justify-content: center; align-items: center;
}
.overlay-content, .modal-content {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 16px; padding: 32px 40px; text-align: center;
  max-width: 400px; width: 90%;
}
.overlay-content h2 { font-size: 28px; margin-bottom: 12px; color: var(--accent-gold); }
.overlay-content p { margin: 8px 0; }
.returning-msg { color: var(--text-dim); font-style: italic; margin-top: 16px; }

.modal-content h3 { margin-bottom: 16px; }
.modal-content input {
  width: 100%; padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--panel-border); background: var(--bg);
  color: var(--text); font-size: 16px; margin-bottom: 16px;
  outline: none; font-family: inherit;
}
.modal-content input:focus { border-color: var(--primary); }
.modal-buttons { display: flex; gap: 10px; justify-content: center; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .lobby-body { flex-direction: column; }
  .rooms-panel { border-right: none; border-bottom: 1px solid var(--panel-border); flex: 1; }
  .chat-panel { width: 100%; flex: 1; }
  .title-area h1 { font-size: 32px; }
  #title-canvas { width: 250px; height: 125px; }
  #score-display { font-size: 22px; }
}
