:root {
  --bg: #f5f5f7;
  --tile: #ffffff;
  --text: #111111;
  --muted: #6b7280;
  --accent: #6e56cf;
  --accent-ink: #ffffff;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #f5a524;
  --hero: linear-gradient(135deg, #6e56cf 0%, #e5484d 100%);
  --border: transparent;
  --hairline: rgba(17, 17, 17, 0.08);
  --inset: #f5f5f7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 24px;
  --radius-inner: 12px;
  --gap: 14px;
  --pad: 22px;
  --font: "Geist", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b0b0f;
  --tile: #1c1c22;
  --text: #f5f5f7;
  --muted: #9ca3af;
  --border: rgba(255, 255, 255, 0.08);
  --hairline: rgba(255, 255, 255, 0.08);
  --inset: #131318;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  height: 64px; padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand img { width: 30px; height: 30px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.menubar { display: flex; gap: 2px; }
.menu { position: relative; }
.menu > button {
  background: none; border: 0; padding: 6px 10px; border-radius: 10px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.menu > button:hover, .menu.open > button { background: var(--tile); box-shadow: var(--shadow); }

.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; z-index: 30;
  background: var(--tile); border: 1px solid var(--hairline); border-radius: 16px; box-shadow: var(--shadow);
  padding: 6px; display: grid; gap: 2px;
}
.dropdown.right { left: auto; right: 0; }
.dropdown button, .dropdown a {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  width: 100%; padding: 8px 10px; border: 0; border-radius: 10px; background: none;
  text-align: left; text-decoration: none; font-size: 14px; cursor: pointer;
}
.dropdown button:hover, .dropdown a:hover { background: var(--inset); }
.dropdown hr { border: 0; border-top: 1px solid var(--hairline); margin: 4px 6px; }
.dropdown kbd { font: 12px var(--mono); color: var(--muted); }
.dropdown-meta { padding: 8px 10px 6px; font-size: 12px; font-weight: 500; color: var(--muted); }

.user-btn {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px;
  background: var(--tile); border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow); cursor: pointer;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user-btn .name { font-weight: 500; font-size: 14px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.session-chip {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--tile); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13px; font-weight: 500;
}
.session-chip .pin { font-family: var(--mono); letter-spacing: 0.12em; color: var(--accent); font-weight: 700; }

/* Buttons and inputs -------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-inner); border: 1px solid var(--hairline);
  background: var(--tile); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: transform 200ms ease-out, background 200ms ease-out;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-light { background: #fff; color: #111; border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--border); background: var(--tile); box-shadow: var(--shadow); font-size: 16px;
}

.field { display: grid; gap: 6px; }
.field label, .caption { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.input, select.input {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-inner); border: 1px solid var(--hairline);
  background: var(--inset); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.pin-input { font: 700 34px var(--mono); letter-spacing: 0.35em; text-align: center; padding: 14px 10px; }
.error { color: var(--danger); font-size: 13px; font-weight: 500; min-height: 20px; }

/* Bento landing ----------------------------------------------------------------- */

.bento {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-rows: minmax(140px, auto);
  grid-auto-flow: dense;
  gap: var(--gap);
  max-width: 1240px;
  margin: 12px auto 48px;
  padding: 0 20px;
}
.tile {
  background: var(--tile); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: var(--pad); min-width: 0;
  animation: rise 300ms ease-out both; animation-delay: calc(var(--i, 0) * 40ms);
}
.bento > .tile { transition: transform 200ms ease-out; }
.bento > .tile:hover { transform: scale(1.02); }
.bento > .tile.static:hover { transform: none; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .tile { animation: none; } .bento > .tile:hover { transform: none; } }

.span-1 { grid-column: span 1; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.rows-2 { grid-row: span 2; }

.tile h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.tile .big { font-size: 48px; font-weight: 700; line-height: 1.05; letter-spacing: -0.03em; }
.tile.metric { display: flex; flex-direction: column; justify-content: space-between; }

.hero { background: var(--hero); color: #fff; border: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 20px; }
.hero h1 { margin: 0; font-size: clamp(32px, 5vw, 56px); line-height: 1; letter-spacing: -0.04em; overflow-wrap: anywhere; }
.hero p { margin: 10px 0 0; font-size: 18px; opacity: 0.9; max-width: 34ch; }
.hero .caption { color: rgba(255, 255, 255, 0.8); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }

.pin-result { display: grid; gap: 8px; padding: 14px; border-radius: var(--radius-inner); background: var(--inset); }
.pin-result .pin { font: 700 44px var(--mono); letter-spacing: 0.2em; color: var(--accent); }

.portal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.portal-head .input { max-width: 280px; }
.candidates { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.candidate { border-radius: 20px; background: var(--inset); padding: 16px; display: grid; gap: 10px; align-content: start; }
.candidate h3 { margin: 0; font-size: 17px; display: flex; justify-content: space-between; align-items: baseline; }
.session-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; border-radius: var(--radius-inner); background: var(--tile); }
.session-row .meta { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.chip.ended { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 18px; text-align: center; border: 1px dashed var(--hairline); border-radius: 16px; }
.steps { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }

/* IDE -------------------------------------------------------------------------- */

.ide {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) minmax(320px, 38%);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "toolbar toolbar toolbar" "explorer editor side";
  gap: 12px; padding: 0 12px 12px;
  height: calc(100vh - 64px);
}
.ide.no-explorer { grid-template-columns: 0 minmax(0, 1fr) minmax(320px, 38%); }
.ide.no-side { grid-template-columns: 236px minmax(0, 1fr) 0; }
.ide.no-explorer.no-side { grid-template-columns: 0 minmax(0, 1fr) 0; }
.ide .tile { padding: 0; border-radius: 22px; display: flex; flex-direction: column; overflow: hidden; }
.ide-toolbar { grid-area: toolbar; flex-direction: row !important; align-items: center; gap: 12px; padding: 10px 12px !important; }
.pane-explorer { grid-area: explorer; }
.pane-editor { grid-area: editor; }
.pane-side { grid-area: side; display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; min-height: 0; }
.pane-side.only-preview { grid-template-rows: minmax(0, 1fr) 0; }
.pane-side.only-console { grid-template-rows: 0 minmax(0, 1fr); }
.no-explorer .pane-explorer, .no-side .pane-side { display: none; }

.pane-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--hairline); }
.pane-head .actions { margin-left: auto; display: flex; gap: 4px; }
.pane-head .icon-btn { width: 28px; height: 28px; border-radius: 9px; font-size: 14px; box-shadow: none; }
.pane-body { flex: 1; min-height: 0; overflow: auto; }

.tree { list-style: none; margin: 0; padding: 6px; font-size: 14px; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree-item {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 10px; cursor: pointer; user-select: none;
}
.tree-item:hover { background: var(--inset); }
.tree-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); font-weight: 600; }
.tree-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .ops { display: none; gap: 2px; }
.tree-item:hover .ops, .tree-item:focus-within .ops { display: flex; }
.tree-item .ops button { border: 0; background: none; cursor: pointer; padding: 0 4px; color: var(--muted); border-radius: 6px; }
.tree-item .ops button:hover { color: var(--text); background: var(--tile); }
.tree-icon { width: 16px; text-align: center; color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; padding: 8px 8px 0; overflow-x: auto; border-bottom: 1px solid var(--hairline); min-height: 45px; }
.tab {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px 7px 12px; border-radius: 12px 12px 0 0;
  font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.tab.active { background: var(--inset); color: var(--text); }
.tab button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 2px; border-radius: 6px; line-height: 1; }
.tab button:hover { color: var(--text); background: var(--tile); }
.editor-host { flex: 1; min-height: 0; background: var(--inset); }
.editor-host .cm-editor { height: 100%; font-size: 14px; }
.editor-host .cm-scroller { font-family: var(--mono); }
.editor-empty { display: grid; place-items: center; height: 100%; color: var(--muted); }

.run-btn { background: var(--accent); color: #fff; border: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 500; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 36px; height: 22px; border-radius: 999px; background: var(--hairline); position: relative; cursor: pointer; transition: background 200ms ease-out; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform 200ms ease-out; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.dot.saving { background: var(--warn); }
.dot.offline { background: var(--danger); }
.toolbar-title { font-weight: 700; font-size: 15px; }
.toolbar-sep { width: 1px; height: 24px; background: var(--hairline); }

.preview-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.output { margin: 0; padding: 14px; font: 13px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }
.console { padding: 10px 14px; font: 12.5px/1.55 var(--mono); }
.console .entry { padding: 8px 0; border-bottom: 1px dashed var(--hairline); }
.console .cmd { color: var(--accent); font-weight: 600; white-space: pre-wrap; word-break: break-all; }
.console .out { white-space: pre-wrap; word-break: break-word; margin: 4px 0; }
.console .err { white-space: pre-wrap; word-break: break-word; color: var(--danger); margin: 4px 0; }
.console .note { color: var(--muted); }
.console .meta { color: var(--muted); font-size: 11.5px; }
.console .log { color: var(--text); }

.banner { grid-column: 1 / -1; padding: 10px 14px; border-radius: 14px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 600; font-size: 14px; }

/* Toast and dialog ----------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 10px 16px; border-radius: 14px; background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow); animation: rise 200ms ease-out both;
}
dialog {
  border: 1px solid var(--hairline); border-radius: var(--radius); padding: var(--pad); width: min(420px, 92vw);
  background: var(--tile); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(11, 11, 15, 0.45); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 12px; }
dialog .row { justify-content: flex-end; margin-top: 16px; }
.shortcuts { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; font-size: 14px; }
.shortcuts kbd { font: 12.5px var(--mono); padding: 2px 6px; border-radius: 6px; background: var(--inset); }

/* Responsive ------------------------------------------------------------------- */

@media (max-width: 960px) {
  .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3, .span-4, .span-6 { grid-column: span 2; }
  .menubar { display: none; }
  .btn { white-space: nowrap; }
  .session-chip { display: none; }
  .ide, .ide.no-explorer, .ide.no-side, .ide.no-explorer.no-side {
    grid-template-columns: 1fr; grid-template-rows: auto 220px 60vh 70vh;
    grid-template-areas: "toolbar" "explorer" "editor" "side"; height: auto;
  }
  .ide-toolbar { flex-wrap: wrap; }
  .user-btn .name { display: none; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 14px; gap: 10px; }
  .bento { padding: 0 14px; }
  #signin-btn { display: none; }
  .tile .big { font-size: 40px; }
}
