/* ─── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d1117;
  --bg-2:       #161b22;
  --bg-3:       #21262d;
  --border:     #30363d;
  --text:       #e6edf3;
  --text-muted: #8b949e;
  --accent:     #58a6ff;
  --success:    #3fb950;
  --warning:    #d29922;
  --danger:     #f85149;
  --spec-color: #bc8cff;
  --arch-color: #58a6ff;
  --cop-color:  #3fb950;
  --radius:     8px;
  --font-mono:  'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color:       var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size:   14px;
  line-height: 1.5;
}

/* ─── App layout ─────────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  height: 100vh;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
  background:    var(--bg-2);
  border-right:  1px solid var(--border);
  display:       flex;
  flex-direction: column;
  overflow:      hidden;
}

.sidebar-header {
  padding:       16px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}

.logo {
  font-size:   15px;
  font-weight: 600;
  color:       var(--accent);
  letter-spacing: 0.3px;
}

#game-list {
  flex:         1;
  overflow-y:   auto;
  padding:      8px 0;
}

.game-item {
  display:        flex;
  align-items:    center;
  justify-content: space-between;
  padding:        8px 14px;
  cursor:         pointer;
  border-radius:  0;
  gap:            6px;
  transition:     background 0.1s;
}
.game-item:hover { background: var(--bg-3); }
.game-item.active { background: var(--bg-3); border-left: 3px solid var(--accent); }

.game-item-emoji {
  font-size:  15px;
  flex-shrink: 0;
  line-height: 1;
}

.game-item-name {
  flex:         1;
  font-size:    13px;
  overflow:     hidden;
  text-overflow: ellipsis;
  white-space:  nowrap;
}

.game-status-dot {
  width:         8px;
  height:        8px;
  border-radius: 50%;
  flex-shrink:   0;
}
.game-status-dot.deployed  { background: var(--success); }
.game-status-dot.scaffolded { background: var(--warning); }
.game-status-dot.coding    { background: var(--accent); }

.game-item-actions { display: flex; gap: 4px; }
.btn-icon {
  background:    none;
  border:        none;
  color:         var(--text-muted);
  cursor:        pointer;
  padding:       2px 4px;
  font-size:     12px;
  border-radius: 4px;
}
.btn-icon:hover { color: var(--text); background: var(--bg); }

.loading-msg { padding: 16px 14px; color: var(--text-muted); font-size: 12px; }

#btn-new-game {
  margin:     10px 10px 12px;
  flex-shrink: 0;
}

/* ─── Main view ──────────────────────────────────────────────────────────── */
#main-view {
  overflow:   hidden;
  display:    flex;
  flex-direction: column;
  position:   relative;
}

.hidden { display: none !important; }

/* Home screen */
.center-card {
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  height:          100%;
  gap:             12px;
  color:           var(--text-muted);
  text-align:      center;
  padding:         32px;
}
.center-card h1 { font-size: 28px; color: var(--text); }
.center-card p  { max-width: 340px; }

/* Pipeline view */
#pipeline-view {
  flex:        1;
  overflow-y:  auto;
  padding:     24px 32px;
  display:     flex;
  flex-direction: column;
  gap:         24px;
}

.pipeline-step { display: flex; flex-direction: column; gap: 14px; }

.step-header {
  display:     flex;
  align-items: center;
  gap:         12px;
  font-size:   13px;
  color:       var(--text-muted);
}

.step-badge {
  font-size:     10px;
  font-weight:   700;
  letter-spacing: 1.2px;
  padding:       3px 8px;
  border-radius: 4px;
  flex-shrink:   0;
}
.step-badge.spec     { background: rgba(188,140,255,.15); color: var(--spec-color); }
.step-badge.arch     { background: rgba(88,166,255,.15);  color: var(--arch-color); }
.step-badge.copilot  { background: rgba(63,185,80,.15);   color: var(--cop-color);  }
.step-badge.deployed { background: rgba(63,185,80,.25);   color: var(--cop-color);  }

.hint { font-size: 12px; color: var(--text-muted); }

#game-description, #chat-input {
  width:            100%;
  background:       var(--bg-2);
  border:           1px solid var(--border);
  border-radius:    var(--radius);
  color:            var(--text);
  padding:          10px 12px;
  font-size:        13px;
  resize:           vertical;
  font-family:      inherit;
  transition:       border-color 0.15s;
}
#game-description:focus, #chat-input:focus {
  outline:      none;
  border-color: var(--accent);
}

.agent-output {
  background:    var(--bg-2);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       14px 16px;
  font-size:     13px;
  line-height:   1.7;
  white-space:   pre-wrap;
  max-height:    55vh;
  overflow-y:    auto;
  font-family:   var(--font-mono);
  color:         var(--text);
  min-height:    120px;
}

.action-bar { display: flex; gap: 10px; flex-wrap: wrap; }

.copilot-card {
  background:    var(--bg-2);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       20px 22px;
  display:       flex;
  flex-direction: column;
  gap:           12px;
}

.file-path, .inline-code {
  display:       inline-block;
  background:    var(--bg-3);
  border:        1px solid var(--border);
  border-radius: 4px;
  padding:       3px 8px;
  font-family:   var(--font-mono);
  font-size:     12px;
  color:         var(--accent);
  word-break:    break-all;
}

.code-block {
  background:    var(--bg);
  border:        1px solid var(--border);
  border-radius: var(--radius);
  padding:       12px 16px;
  font-family:   var(--font-mono);
  font-size:     12px;
  color:         var(--success);
  overflow-x:    auto;
  white-space:   pre;
}

/* Game frame */
#game-frame-wrap {
  flex:        1;
  display:     flex;
  flex-direction: column;
  overflow:    hidden;
}

.game-topbar {
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  padding:       8px 16px;
  background:    var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}

#game-title-bar { font-weight: 600; font-size: 14px; }

#game-frame {
  flex:         1;
  border:       none;
  background:   var(--bg);
  width:        100%;
}

/* ─── Chat panel ─────────────────────────────────────────────────────────── */
#chat-panel {
  background:     var(--bg-2);
  border-left:    1px solid var(--border);
  display:        flex;
  flex-direction: column;
  overflow:       hidden;
}

.chat-header {
  padding:       14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink:   0;
}
.chat-title { font-weight: 600; font-size: 14px; display: block; }
.chat-sub   { font-size: 11px; color: var(--text-muted); }

#chat-messages {
  flex:      1;
  overflow-y: auto;
  padding:   12px;
  display:   flex;
  flex-direction: column;
  gap:       10px;
}

.msg {
  padding:       8px 12px;
  border-radius: var(--radius);
  font-size:     13px;
  line-height:   1.6;
  max-width:     100%;
  word-break:    break-word;
  white-space:   pre-wrap;
}
.msg.user      { background: var(--bg-3); align-self: flex-end; color: var(--text); }
.msg.assistant { background: transparent; border: 1px solid var(--border); color: var(--text); }
.msg.error     { background: rgba(248,81,73,.1); border: 1px solid var(--danger); color: var(--danger); }
.msg.changelog-saved { background: rgba(63,185,80,.1); border: 1px solid var(--success); color: var(--success); font-size: 11px; padding: 4px 10px; }
.msg.streaming { opacity: 0.85; }

#chat-input-wrap {
  padding:       10px 12px 12px;
  border-top:    1px solid var(--border);
  display:       flex;
  flex-direction: column;
  gap:           8px;
  flex-shrink:   0;
}

.chat-send-row {
  display:        flex;
  gap:            8px;
  align-items:    center;
}

.btn-mic {
  display:     flex;
  align-items: center;
  gap:         4px;
  flex-shrink: 0;
}

.btn-mic.recording {
  background:  rgba(248, 81, 73, 0.2);
  border-color: var(--danger);
  color:       var(--danger);
}

.btn-mic.recording .mic-icon {
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1);    opacity: 1; }
  50%       { transform: scale(1.3); opacity: 0.6; }
}

/* recording status dot in chat header */
.chat-header .rec-dot {
  display:       inline-block;
  width:         8px;
  height:        8px;
  border-radius: 50%;
  background:    var(--danger);
  margin-left:   6px;
  animation:     mic-pulse 1s ease-in-out infinite;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display:       inline-flex;
  align-items:   center;
  justify-content: center;
  border:        none;
  border-radius: var(--radius);
  padding:       9px 18px;
  font-size:     13px;
  font-weight:   500;
  cursor:        pointer;
  transition:    opacity 0.15s, background 0.15s;
  white-space:   nowrap;
}
.btn:hover  { opacity: 0.85; }
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent);   color: #0d1117; }
.btn-success { background: var(--success);  color: #0d1117; }
.btn-ghost   { background: var(--bg-3);     color: var(--text); border: 1px solid var(--border); }
.btn-sm      { padding: 6px 12px; font-size: 12px; }

/* ─── Spinner ────────────────────────────────────────────────────────────── */
.spinner {
  width:  14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Scrollbars ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
