:root {
  --bg: #0a0a0a;
  --panel: #1a1a2e;
  --panel-hover: #16213e;
  --border: #2a2a4a;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --accent: #47c2ff;
  --accent-glow: rgba(71, 194, 255, 0.3);
  --success: #7be67e;
  --warning: #ffd93d;
  --danger: #ff6b6b;
  --host-color: #4ecdc4;
  --join-color: #a78bfa;
}

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

body {
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft YaHei", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(71, 194, 255, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(167, 139, 250, 0.06) 0%, transparent 50%);
  color: var(--text);
  line-height: 1.6;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ===== Header ===== */
header {
  text-align: center;
  margin-bottom: 24px;
  padding: 20px 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700;
  background: linear-gradient(135deg, #47c2ff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ===== Controls ===== */
.controls {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  transition: border-color 0.3s ease;
}

.panel:hover {
  border-color: rgba(71, 194, 255, 0.3);
}

.panel h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--accent);
}

/* ===== Form Elements ===== */
label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--text-muted);
}

input[type="number"],
input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  outline: none;
}

input[type="number"]:focus,
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ===== AI Toggle ===== */
.ai-option {
  margin: 12px 0;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
}

.toggle-label:hover {
  background: rgba(71, 194, 255, 0.1);
  border-color: var(--accent);
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-text {
  font-size: 0.95rem;
  color: var(--text);
}

/* ===== Buttons ===== */
button {
  border: none;
  border-radius: 12px;
  cursor: pointer;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:active {
  transform: scale(0.97);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #2e7cff, #1875ff);
  color: white;
  box-shadow: 0 4px 15px rgba(46, 124, 255, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(46, 124, 255, 0.5);
  transform: translateY(-1px);
}

.btn-host {
  flex: 1;
  background: linear-gradient(135deg, #4ecdc4, #44b8b0);
  color: white;
  box-shadow: 0 4px 15px rgba(78, 205, 196, 0.3);
}

.btn-host:hover {
  box-shadow: 0 6px 20px rgba(78, 205, 196, 0.5);
  transform: translateY(-1px);
}

.btn-join {
  flex: 1;
  background: linear-gradient(135deg, #a78bfa, #8b5cf6);
  color: white;
  box-shadow: 0 4px 15px rgba(167, 139, 250, 0.3);
}

.btn-join:hover {
  box-shadow: 0 6px 20px rgba(167, 139, 250, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--accent);
}

/* ===== Layout Helpers ===== */
.row {
  display: flex;
  gap: 10px;
}

.mt-10 {
  margin-top: 10px;
}

/* ===== Status Panel ===== */
.status-panel {
  display: flex;
  flex-direction: column;
}

.status-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.status-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

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

.status-value.accent {
  color: var(--accent);
}

.peer-id {
  font-family: monospace;
  font-size: 0.8rem;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Timer ===== */
.timer {
  color: var(--success);
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.timer.warning {
  color: var(--danger);
  animation: pulse 1s infinite;
}

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

/* ===== Board ===== */
.board-section {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

canvas {
  width: min(100%, 720px);
  max-width: 100%;
  border: 3px solid var(--border);
  border-radius: 16px;
  background: #d7b16f;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.4),
    0 0 40px rgba(215, 177, 111, 0.1);
  cursor: pointer;
  touch-action: none;
}

canvas:hover {
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 50px rgba(215, 177, 111, 0.15);
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Responsive ===== */
@media (max-width: 980px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .app-shell {
    padding: 12px;
  }

  header {
    margin-bottom: 16px;
    padding: 12px 0;
  }

  h1 {
    font-size: 1.8rem;
  }
}

@media (max-width: 480px) {
  .row {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .status-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
