/* Editor chrome. Deliberately its own look — this is the workshop,
   not the site. Dark so the live preview stays the bright thing. */

:root {
  --e-bg:      #0c0f16;
  --e-panel:   #141924;
  --e-line:    #232b3b;
  --e-fg:      #e6ecf8;
  --e-dim:     #8794ac;
  --e-accent:  #22e5c8;
  --e-accent2: #7b5cff;
  --e-warn:    #ffb03a;
  --e-danger:  #ff5c7a;
  --e-mono: "JetBrains Mono", ui-monospace, monospace;
  --e-sans: "Space Grotesk", system-ui, sans-serif;
}

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

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--e-bg);
  color: var(--e-fg);
  font-family: var(--e-sans);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* --- Login ------------------------------------------------------------- */

.login {
  height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(50rem 32rem at 50% 0%, #16233d, var(--e-bg) 70%);
}

.login-card {
  width: min(24rem, 100%);
  background: var(--e-panel);
  border: 1px solid var(--e-line);
  border-radius: 20px;
  padding: 2rem;
  display: grid;
  gap: 0.85rem;
}

.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card p { margin: 0; color: var(--e-dim); font-size: 0.95rem; }

.login-card input {
  font: inherit; padding: 0.85rem 1rem; border-radius: 12px;
  border: 1px solid var(--e-line); background: #0d1119; color: var(--e-fg);
}
.login-card input:focus { outline: 2px solid var(--e-accent); border-color: transparent; }

.login-card button {
  padding: 0.85rem; border: 0; border-radius: 12px; font-weight: 700;
  background: var(--e-accent); color: #04231e;
}

.login-error { color: var(--e-danger) !important; }

/* --- Top bar ----------------------------------------------------------- */

.app { height: 100vh; display: flex; flex-direction: column; }

.bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--e-line);
  background: var(--e-panel);
  flex-shrink: 0;
}

.bar-home { text-decoration: none; font-size: 1.2rem; opacity: 0.7; }
.bar-home:hover { opacity: 1; }

.modes { display: flex; gap: 0.25rem; background: #0d1119; padding: 0.25rem; border-radius: 12px; }

.mode {
  border: 0; background: transparent; color: var(--e-dim);
  padding: 0.5rem 0.9rem; border-radius: 9px; font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.mode:hover { color: var(--e-fg); }
.mode.is-active { background: var(--e-accent); color: #04231e; }

.bar-right { margin-left: auto; display: flex; gap: 0.5rem; align-items: center; }

.ghost {
  border: 1px solid var(--e-line); background: transparent; color: var(--e-fg);
  padding: 0.5rem 0.75rem; border-radius: 10px;
}
.ghost:hover { border-color: var(--e-accent); }

.primary {
  border: 0; background: var(--e-accent); color: #04231e;
  padding: 0.55rem 1.2rem; border-radius: 10px; font-weight: 700;
}
.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.primary.wide { width: 100%; padding: 0.8rem; }

.primary.is-dirty { background: var(--e-warn); color: #241600; }

/* --- Split layout ------------------------------------------------------ */

.split { flex: 1; display: grid; grid-template-columns: minmax(0, 27rem) minmax(0, 1fr); min-height: 0; }

.panel { overflow-y: auto; border-right: 1px solid var(--e-line); padding: 1.25rem; }

.pane { display: none; }
.pane.is-active { display: block; }

.preview { background: #fff; min-height: 0; }
/* White, like a real browser tab. With her stylesheet empty the page has no
   background of its own, so a dark panel here rendered black text on black
   and looked like the preview was broken. */
.preview iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

/* --- Form bits --------------------------------------------------------- */

.pane-title {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--e-accent); margin: 1.75rem 0 0.75rem;
}
.pane-title:first-child { margin-top: 0; }

label { display: block; margin-bottom: 0.7rem; font-size: 0.8rem; color: var(--e-dim); }

input, textarea, select {
  display: block; width: 100%; margin-top: 0.3rem;
  font: inherit; font-size: 0.9rem;
  padding: 0.6rem 0.75rem; border-radius: 10px;
  border: 1px solid var(--e-line); background: #0d1119; color: var(--e-fg);
  resize: vertical;
}
input:focus, textarea:focus { outline: 2px solid var(--e-accent); border-color: transparent; }

.hint { font-size: 0.78rem; color: var(--e-dim); margin: 0.5rem 0 0; }

.add {
  width: 100%; padding: 0.6rem; border-radius: 10px; margin-top: 0.25rem;
  border: 1px dashed var(--e-line); background: transparent; color: var(--e-dim);
}
.add:hover { border-color: var(--e-accent); color: var(--e-accent); }

/* --- Themes ------------------------------------------------------------ */

.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }

.theme-chip {
  border: 2px solid var(--e-line); border-radius: 12px;
  padding: 0.6rem 0.4rem; background: transparent; color: var(--e-fg);
  font-size: 0.75rem; display: grid; gap: 0.4rem; justify-items: center;
}
.theme-chip:hover { border-color: var(--e-dim); }
.theme-chip.is-active { border-color: var(--e-accent); }
.theme-swatch { width: 100%; height: 1.6rem; border-radius: 6px; }

/* --- Repeaters (cards / links) ----------------------------------------- */

.repeater { display: grid; gap: 0.6rem; }

.row {
  border: 1px solid var(--e-line); border-radius: 12px;
  padding: 0.75rem; background: #0f131c;
  display: grid; gap: 0.4rem;
}
.row-head { display: flex; gap: 0.5rem; align-items: center; }
.row-head input.icon { width: 3.2rem; text-align: center; margin: 0; }
.row-head input.title { flex: 1; margin: 0; }

.row-tools { display: flex; gap: 0.25rem; }
.row-tools button {
  border: 1px solid var(--e-line); background: transparent; color: var(--e-dim);
  width: 1.9rem; height: 1.9rem; border-radius: 7px; line-height: 1; padding: 0;
}
.row-tools button:hover { color: var(--e-fg); border-color: var(--e-dim); }
.row-tools .del:hover { color: var(--e-danger); border-color: var(--e-danger); }

/* --- Photos ------------------------------------------------------------ */

.photo-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }

.photo-thumb { position: relative; aspect-ratio: 1; }
.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 9px; border: 1px solid var(--e-line);
}
.photo-thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 1.4rem; height: 1.4rem; border-radius: 50%; padding: 0; line-height: 1;
  border: 0; background: var(--e-danger); color: #fff; font-size: 0.75rem;
}

.upload {
  display: block; text-align: center; margin-top: 0.6rem;
  padding: 0.6rem; border: 1px dashed var(--e-line); border-radius: 10px;
  color: var(--e-dim); cursor: pointer; font-size: 0.85rem;
}
.upload:hover { border-color: var(--e-accent); color: var(--e-accent); }

/* --- Code editor ------------------------------------------------------- */

.code-tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }

.code-tab {
  border: 1px solid var(--e-line); background: transparent; color: var(--e-dim);
  padding: 0.4rem 0.8rem; border-radius: 8px;
  font-family: var(--e-mono); font-size: 0.78rem;
}
.code-tab.is-active { background: var(--e-accent2); border-color: var(--e-accent2); color: #fff; }

/* Plain textarea. An earlier version floated an invisible textarea over a
   syntax-highlighted <pre>; any difference in font metrics made the caret
   drift away from the text, which made it unusable. Boring and correct beats
   colourful and misaligned. */
.code-input {
  display: block;
  width: 100%;
  height: min(62vh, 36rem);
  margin: 0;
  padding: 0.9rem 1rem;
  border: 1px solid var(--e-line);
  border-radius: 12px;
  background: #0a0d14;
  color: #d7e3f4;
  caret-color: var(--e-accent);
  font-family: var(--e-mono);
  font-size: 0.82rem;
  line-height: 1.65;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
  resize: vertical;
}
.code-input:focus { outline: 2px solid var(--e-accent); border-color: transparent; }
.code-input::selection { background: rgba(34, 229, 200, 0.3); }

/* --- AI pane ----------------------------------------------------------- */

.ai-intro h2 { margin: 0 0 0.4rem; font-size: 1.25rem; }
.ai-intro p { margin: 0 0 1rem; color: var(--e-dim); font-size: 0.9rem; }

.ai-examples { display: grid; gap: 0.4rem; margin-bottom: 1rem; }

.ai-example {
  text-align: left; border: 1px solid var(--e-line); background: #0f131c;
  color: var(--e-dim); border-radius: 10px; padding: 0.55rem 0.75rem; font-size: 0.82rem;
}
.ai-example:hover { border-color: var(--e-accent2); color: var(--e-fg); }

#ai-prompt { font-size: 0.95rem; }

.ai-quota { font-size: 0.75rem; color: var(--e-dim); text-align: center; margin: 0.6rem 0 0; }

.ai-result {
  margin-top: 1.25rem; border: 1px solid var(--e-accent2);
  border-radius: 12px; padding: 1rem; background: #150f24;
}
.ai-says { font-size: 0.9rem; line-height: 1.55; margin-bottom: 0.9rem; }
.ai-actions { display: flex; gap: 0.5rem; }
.ai-actions .primary { flex: 1; }

.thinking { display: inline-block; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: 0.4 } }

/* --- Projects ("Stuff") ------------------------------------------------ */

.new-project { display: flex; gap: 0.5rem; }
.new-project input { margin: 0; }
.new-project button { flex-shrink: 0; }

.project-list { display: grid; gap: 0.85rem; margin-top: 1.5rem; }

.project {
  border: 1px solid var(--e-line); border-radius: 14px;
  background: #0f131c; overflow: hidden;
}

.project-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--e-line);
}
.project-head a {
  font-weight: 700; color: var(--e-accent); text-decoration: none;
  font-family: var(--e-mono); font-size: 0.9rem;
}
.project-head a:hover { text-decoration: underline; }
.project-head .count { color: var(--e-dim); font-size: 0.78rem; margin-left: auto; }
.project-head .del {
  border: 1px solid var(--e-line); background: transparent; color: var(--e-dim);
  width: 1.9rem; height: 1.9rem; border-radius: 7px; padding: 0; line-height: 1;
}
.project-head .del:hover { color: var(--e-danger); border-color: var(--e-danger); }

.drop {
  margin: 0.75rem 0.9rem;
  border: 1px dashed var(--e-line); border-radius: 10px;
  padding: 1.1rem 0.75rem; text-align: center;
  color: var(--e-dim); font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
}
.drop.is-over { border-color: var(--e-accent); background: rgba(34,229,200,.07); color: var(--e-accent); }
.drop button {
  border: 1px solid var(--e-line); background: transparent; color: var(--e-fg);
  padding: 0.35rem 0.75rem; border-radius: 8px; font-size: 0.8rem; margin: 0 0.15rem;
}
.drop button:hover { border-color: var(--e-accent); }

/* Folder tree. A flat list of 150+ paths was unreadable, and there was no way
   to delete a whole directory. */
.file-tree {
  margin: 0 0.9rem 0.9rem;
  font-family: var(--e-mono); font-size: 0.76rem;
  max-height: 22rem; overflow-y: auto;
}

/* Each nesting level indents, with a guide line back to its parent. */
.tree-level .tree-level {
  margin-left: 0.55rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--e-line);
}

.tree-dir > summary,
.tree-file {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.28rem 0.45rem; border-radius: 6px;
  color: var(--e-dim);
}
.tree-dir > summary { cursor: pointer; list-style: none; }
.tree-dir > summary::-webkit-details-marker { display: none; }

/* Disclosure triangle we control, so it lines up with the file rows. */
.tree-dir > summary::before {
  content: "▸";
  display: inline-block; width: 0.8rem;
  color: var(--e-accent); transition: transform 0.12s;
}
.tree-dir[open] > summary::before { transform: rotate(90deg); }

.tree-file { padding-left: 1.25rem; }

.tree-dir > summary:hover,
.tree-file:hover { background: #0b0e15; }

.tree-name { color: var(--e-fg); flex: 1; word-break: break-all; }
.tree-dir > summary .tree-name { font-weight: 700; }
.tree-name.index { color: var(--e-accent); }

.tree-meta { color: #5b6780; font-size: 0.7rem; white-space: nowrap; }

.tree-del {
  border: 0; background: transparent; color: #46506b;
  padding: 0 0.25rem; font-size: 0.85rem; line-height: 1; flex-shrink: 0;
}
.tree-del:hover { color: var(--e-danger); }

.project-empty { padding: 0 0.9rem 0.9rem; color: var(--e-warn); font-size: 0.78rem; }

/* --- History drawer ---------------------------------------------------- */

.drawer {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 6, 11, 0.72);
  display: grid; place-items: center; padding: 1.5rem;
}

.drawer-card {
  width: min(28rem, 100%); max-height: 80vh; overflow-y: auto;
  background: var(--e-panel); border: 1px solid var(--e-line);
  border-radius: 18px; padding: 1.5rem;
}
.drawer-card h2 { margin: 0 0 0.3rem; font-size: 1.2rem; }
.drawer-card ul { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 0.4rem; }

.drawer-card li {
  display: flex; align-items: center; gap: 0.75rem;
  border: 1px solid var(--e-line); border-radius: 10px; padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
}
.drawer-card li span { color: var(--e-dim); flex: 1; }
.drawer-card li button {
  border: 1px solid var(--e-accent); background: transparent;
  color: var(--e-accent); padding: 0.3rem 0.7rem; border-radius: 8px; font-size: 0.8rem;
}

/* --- Toast ------------------------------------------------------------- */

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  z-index: 100; padding: 0.7rem 1.25rem; border-radius: 999px;
  background: var(--e-accent); color: #04231e; font-weight: 600; font-size: 0.9rem;
  box-shadow: 0 10px 30px -8px rgba(0,0,0,.6);
}
.toast.is-error { background: var(--e-danger); color: #fff; }

/* --- Mobile ------------------------------------------------------------ */

@media (max-width: 52rem) {
  .split { grid-template-columns: 1fr; }
  .panel { border-right: 0; }
  /* One at a time on a phone; the 👁️ button swaps them. */
  .preview { display: none; }
  body.show-preview .panel { display: none; }
  body.show-preview .preview { display: block; }
  .mode span { display: none; }
  .themes { grid-template-columns: repeat(3, 1fr); }
}
