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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a26;
  --border: #2a2a3a;
  --text: #e0e0e8;
  --text-dim: #8888a0;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --green: #00d4aa;
  --red: #ff6b6b;
  --yellow: #ffd93d;
}

body {
  font-family: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ==================== Header ==================== */

header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid var(--border);
}

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

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 0.65rem;
  background: var(--accent);
  color: white;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  vertical-align: middle;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background 0.3s;
}

.dot.connected { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.disconnected { background: var(--red); }
.dot.connecting { background: var(--yellow); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.stats-bar {
  display: flex;
  gap: 2rem;
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.stats-bar strong {
  color: var(--text);
}

/* ==================== Tabs ==================== */

.tabs {
  display: flex;
  padding: 0 2rem;
  gap: 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ==================== Demo Panels ==================== */

main {
  padding: 1.5rem 2rem;
}

.demo-panel {
  display: none;
}

.demo-panel.active {
  display: block;
}

.demo-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.demo-header h2 {
  font-size: 1.2rem;
  margin-bottom: 0.25rem;
}

.demo-desc {
  color: var(--text-dim);
  font-size: 0.8rem;
  max-width: 600px;
  line-height: 1.5;
}

.demo-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.7rem;
  padding: 0.2rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--green);
  white-space: nowrap;
}

/* ==================== Canvas / Drawing ==================== */

.drawing-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover { color: var(--text); border-color: var(--text-dim); }
.tool-btn.active { color: var(--accent); border-color: var(--accent); background: rgba(108, 92, 231, 0.1); }

.tool-btn svg { flex-shrink: 0; }

.clear-btn { color: var(--red); }
.clear-btn:hover { border-color: var(--red); background: rgba(255, 107, 107, 0.1); }

.color-picker {
  gap: 0.3rem;
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  flex-shrink: 0;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text); box-shadow: 0 0 6px rgba(224, 224, 232, 0.3); }

.size-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.size-btn:hover { border-color: var(--text-dim); }
.size-btn.active { border-color: var(--accent); background: rgba(108, 92, 231, 0.1); }

.size-dot {
  display: block;
  background: var(--text);
  border-radius: 50%;
}

.canvas-container {
  position: relative;
  width: 100%;
  height: 500px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  cursor: crosshair;
}

.draw-layer,
.cursor-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.draw-layer {
  z-index: 1;
}

.cursor-layer {
  z-index: 2;
  pointer-events: none;
}

.canvas-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 0.9rem;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 3;
}

/* ==================== Game ==================== */

.game-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-canvas-wrap {
  position: relative;
  max-width: 100%;
}

#gameScreen {
  background: #0d0d15;
  border-radius: 6px;
  border: 1px solid var(--border);
  max-width: 100%;
  display: block;
}

.game-hint {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 0.75rem;
  text-align: center;
}

.scoreboard {
  margin-top: 0.75rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
}

.score-entry {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.score-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ==================== Chat ==================== */

.chat-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  height: 500px;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  font-size: 0.85rem;
}

.msg-name {
  font-weight: 600;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.msg-text {
  color: var(--text);
  word-break: break-word;
}

.msg-latency {
  font-size: 0.65rem;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-left: auto;
  padding: 0.1rem 0.4rem;
  background: var(--surface-2);
  border-radius: 3px;
}

.system-msg {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
  padding: 0.5rem;
}

.chat-input {
  display: flex;
  border-top: 1px solid var(--border);
}

.chat-input input {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.chat-input input::placeholder { color: var(--text-dim); }

.chat-input button {
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: white;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-input button:hover { background: #7c6cf7; }
.chat-input button:disabled { background: var(--surface-2); color: var(--text-dim); cursor: not-allowed; }

/* ==================== Transfer / Speed Test ==================== */

.transfer-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.transfer-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.action-btn {
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover { background: #7c6cf7; }
.action-btn:disabled { background: var(--surface-2); color: var(--text-dim); cursor: not-allowed; }
.action-btn.secondary { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.action-btn.secondary:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.secondary:disabled { border-color: var(--border); color: var(--text-dim); }

.transfer-streams {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stream-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stream-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  width: 70px;
  flex-shrink: 0;
}

.progress-track {
  flex: 1;
  height: 24px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 3px;
  transition: width 0.15s ease;
}

.progress-fill.complete {
  background: var(--green);
}

.stream-speed {
  font-size: 0.75rem;
  color: var(--text-dim);
  width: 100px;
  text-align: right;
  flex-shrink: 0;
}

.transfer-summary {
  display: flex;
  gap: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.summary-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.summary-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

/* ==================== Ping / Latency ==================== */

.ping-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.ping-stats {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.ping-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 100px;
}

.ping-stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ping-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.ping-stat-value.rtt-green { color: var(--green); }
.ping-stat-value.rtt-yellow { color: var(--yellow); }
.ping-stat-value.rtt-red { color: var(--red); }

.ping-chart-wrap {
  margin-bottom: 1rem;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

#pingChart {
  display: block;
  width: 100%;
  height: 200px;
}

.ping-server-stats {
  display: flex;
  gap: 2rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.ping-server-stats strong {
  color: var(--text);
}

/* ==================== Footer ==================== */

footer {
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

footer p {
  font-size: 0.75rem;
  color: var(--text-dim);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer-note {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: var(--green);
}

/* ==================== Scrollbar ==================== */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ==================== Responsive ==================== */

@media (max-width: 768px) {
  header { padding: 1rem; }
  main { padding: 1rem; }
  .stats-bar { gap: 0.75rem; font-size: 0.7rem; }
  .tabs { padding: 0 1rem; }
  .tab { padding: 0.6rem 0.8rem; font-size: 0.8rem; }
  .canvas-container { height: 350px; }
  #gameScreen { width: 100%; height: auto; }
  .drawing-toolbar { gap: 0.5rem; }
  .color-swatch { width: 18px; height: 18px; }
  .ping-stats { gap: 1rem; }
  .ping-stat { min-width: 70px; }
  .ping-stat-value { font-size: 1.2rem; }
  .transfer-summary { gap: 1rem; }
  .stream-bar { flex-wrap: wrap; }
  .stream-speed { width: auto; text-align: left; }
}

@media (max-width: 480px) {
  .stats-bar { gap: 0.5rem; font-size: 0.65rem; }
  .demo-header { flex-direction: column; }
  .demo-meta { margin-top: 0.5rem; }
  .transfer-controls { flex-direction: column; }
  .action-btn { width: 100%; text-align: center; }
}
