:root {
  --bg: #101114;
  --panel: #181a1f;
  --panel-2: #20232b;
  --border: #30343d;
  --text: #f2f4f8;
  --muted: #a6adbb;
  --accent: #7aa2ff;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, .button, input, textarea, select {
  font: inherit;
}
button, .button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.65rem 0.8rem;
  border-radius: 0.65rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 0.35rem;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
.icon-button {
  min-width: 52px;
  padding: .55rem .6rem;
  align-self: flex-start;
}
.project-badge {
  min-width: 1.2rem;
  padding: 0 .2rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.4;
}
.brand,
.project-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}
.brand {
  margin-bottom: 1rem;
}
.brand-copy {
  min-width: 0;
}
.project-popover-wrap {
  position: relative;
  align-self: flex-start;
}
.memory-popover-wrap {
  position: relative;
  align-self: flex-start;
}
.memory-count {
  min-width: 1.2rem;
  padding: 0 .2rem;
  border-radius: 999px;
  background: var(--accent);
  color: #08111f;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.4;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 390px;
  min-height: 100vh;
}
.sidebar, .assistant-panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow: auto;
}
.assistant-panel {
  border-right: 0;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.assistant-heading,
.memory-panel-head,
.memory-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}
.assistant-heading {
  align-items: flex-start;
}
.brand h1, .assistant-panel h2 { margin: 0; font-size: 1.05rem; }
.assistant-panel h3 { margin: 0; font-size: .95rem; }
.brand p, .assistant-panel p, .hint, #saveState {
  color: var(--muted);
  font-size: .85rem;
  margin: .35rem 0 0;
}
.stack { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 1rem 0; }
.stack .button { grid-column: span 2; }
.project-panel {
  display: grid;
  gap: .85rem;
  padding: .9rem;
  border: 1px solid var(--border);
  border-radius: .9rem;
  background: rgba(13, 14, 17, 0.98);
  position: fixed;
  width: min(360px, calc(100vw - 2rem));
  max-height: min(70vh, 520px);
  overflow: auto;
  z-index: 21;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.project-panel[hidden] {
  display: none;
}
.platform-credit {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: .8rem;
}
.platform-credit a {
  color: var(--text);
  text-decoration: none;
}
.platform-credit a:hover {
  color: var(--accent);
}
.file-tree { display: grid; gap: .18rem; }
.tree-item {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: .38rem .5rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: .45rem;
}
.tree-item.file { color: var(--text); }
.tree-item.active { background: var(--panel-2); color: var(--accent); }
.tree-children { margin-left: .9rem; padding-left: .5rem; border-left: 1px solid var(--border); }
.workspace { min-width: 0; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  min-height: 72px;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}
.topbar strong { display: block; }
.topbar-actions { display: flex; gap: .5rem; }
#btnDelete { color: var(--danger); }
.editor-panel { min-height: 0; }
.CodeMirror {
  height: calc(100vh - 72px);
  font-size: 14px;
  line-height: 1.5;
}
.field { display: grid; gap: .4rem; }
.field span { color: var(--muted); font-size: .85rem; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  background: #0d0e11;
  color: var(--text);
  border-radius: .65rem;
  padding: .7rem;
  outline: none;
}
textarea { min-height: 120px; resize: vertical; }
.grow textarea { min-height: 150px; }
.memory-panel {
  display: grid;
  gap: .85rem;
  padding: .9rem;
  border: 1px solid var(--border);
  border-radius: .9rem;
  background: rgba(13, 14, 17, 0.98);
  position: fixed;
  width: min(420px, calc(100vw - 2rem));
  max-height: min(70vh, 640px);
  overflow: auto;
  z-index: 20;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.memory-panel[hidden] {
  display: none;
}
.memory-form,
.memory-list {
  display: grid;
  gap: .75rem;
}
.memory-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}
.memory-form textarea {
  min-height: 96px;
}
.memory-empty {
  border: 1px dashed var(--border);
  border-radius: .8rem;
  padding: .9rem;
  color: var(--muted);
  font-size: .9rem;
}
.memory-card {
  border: 1px solid var(--border);
  border-radius: .8rem;
  padding: .8rem;
  background: #0d0e11;
}
.memory-card-actions {
  display: flex;
  gap: .4rem;
}
.memory-card-actions button {
  padding: .35rem .55rem;
}
.memory-card-body {
  margin: .6rem 0 0;
  color: var(--text);
  font-size: .92rem;
  white-space: pre-wrap;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--text);
  white-space: nowrap;
}
.toggle input {
  width: auto;
  margin: 0;
}
.assistant-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
#btnAskGemini { grid-column: span 2; border-color: var(--accent); }
.suggestion-box {
  min-height: 0;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: .8rem;
  overflow: hidden;
  background: #0d0e11;
}
.suggestion-box h3 {
  margin: 0;
  padding: .75rem;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.suggestion-box pre {
  margin: 0;
  padding: .85rem;
  white-space: pre-wrap;
  overflow: auto;
  max-height: 45vh;
  color: var(--text);
}
dialog {
  border: 1px solid var(--border);
  border-radius: .9rem;
  background: var(--panel);
  color: var(--text);
  width: min(520px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(0,0,0,.65); }
menu { display: flex; justify-content: flex-end; gap: .5rem; padding: 0; margin: 1rem 0 0; }
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 280px 1fr; }
  .assistant-panel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .CodeMirror { height: 60vh; }
  .brand,
  .assistant-heading,
  .project-panel-head,
  .memory-panel-head,
  .memory-card-head {
    flex-direction: column;
  }
  .project-panel,
  .memory-panel {
    position: fixed;
    top: 1rem;
    right: 1rem;
    left: 1rem;
    width: auto;
    max-height: calc(100vh - 2rem);
  }
}
