:root {
  --bg: #0d0f1a;
  --bg2: #141828;
  --bg3: #1e2438;
  --accent: #7c6aff;
  --accent2: #a78bfa;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --border: #2d3555;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#controller-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.3s;
}

#controller-badge.ai-mode {
  border-color: var(--accent);
  background: rgba(124, 106, 255, 0.15);
  color: var(--accent2);
}

/* ── Main layout ── */
main {
  display: flex;
  gap: 16px;
  flex: 1;
  overflow: hidden;
  padding: 16px 0;
}

/* ── Canvas ── */
#game-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#gameCanvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #0a0b12;
  cursor: crosshair;
  display: block;
}

#controls-overlay {
  display: flex;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
}

#controls-overlay span::before {
  content: '';
}

/* ── Sidebar ── */
#sidebar {
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

section h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ── Status panel ── */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--text-dim); }
.stat-row span:last-child { font-family: var(--mono); font-size: 12px; color: var(--accent2); }

/* ── Webhook panel ── */
.help-text {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 10px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 10px;
}

input[type="url"],
input[type="number"],
select {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  transition: border-color 0.2s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

select option { background: var(--bg3); }

#webhook-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-primary, .btn-danger, .btn-secondary, .btn-ghost {
  padding: 7px 14px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: white;
  flex: 1;
}
.btn-primary:hover:not(:disabled) { background: var(--accent2); }

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.3);
  flex: 1;
}
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.25); }

.btn-secondary {
  width: 100%;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent2); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  padding: 2px 6px;
}
.btn-ghost:hover { color: var(--text); }

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Log ── */
#webhook-log {
  margin-top: 12px;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

#log-entries {
  max-height: 120px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 11px;
}

#log-entries::-webkit-scrollbar { width: 3px; }
#log-entries::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.log-entry {
  padding: 2px 0;
  line-height: 1.4;
  color: var(--text-dim);
  border-bottom: 1px solid rgba(45, 53, 85, 0.5);
  display: flex;
  gap: 6px;
}

.log-entry:last-child { border-bottom: none; }
.log-entry .log-time { color: #4a5568; min-width: 52px; }
.log-entry.success .log-action { color: var(--green); }
.log-entry.error .log-action { color: var(--red); }
.log-entry.info .log-action { color: var(--accent2); }

#demo-section hr { border: none; border-top: 1px solid var(--border); margin-bottom: 12px; }

/* ── Actions reference ── */
#actions-reference table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}

#actions-reference td {
  padding: 4px 6px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

#actions-reference td:first-child { font-family: var(--mono); color: var(--yellow); }
#actions-reference td:last-child { color: var(--text-dim); }
#actions-reference tr:last-child td { border-bottom: none; }

code {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--yellow);
}

/* ── n8n panel ── */
.setup-steps {
  padding-left: 18px;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.9;
}

.setup-steps strong { color: var(--text); }

.btn-download {
  display: block;
  text-align: center;
  padding: 8px 14px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: white;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.2s;
}

.btn-download:hover { opacity: 0.85; }

/* ── System prompt box ── */
#system-prompt-section {
  margin-top: 14px;
}

.prompt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

#system-prompt-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
}

#system-prompt-box::-webkit-scrollbar { width: 3px; }
#system-prompt-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Responsive ── */
@media (max-width: 900px) {
  main { flex-direction: column; overflow: auto; }
  #sidebar { width: 100%; }
}
