/* pgbench — a workbench in Postgres blue, lit by an amber prompt. */

:root {
  --bg: #0d141f;
  --panel: #131d2b;
  --panel-2: #182436;
  --line: #223046;
  --text: #dce6f2;
  --muted: #8195ad;
  --accent: #e9a13b;
  --accent-ink: #1a1206;
  --blue: #6fb3e0;
  --pass: #46c08a;
  --fail: #e25c6d;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------ topbar: the psql prompt */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.prompt-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prompt-db { color: var(--blue); font-weight: 600; }
.prompt-hash { color: var(--accent); font-weight: 600; margin-right: 0.6ch; }
.prompt-cmd { color: var(--muted); }

.pg-status { margin-left: 1ch; color: var(--muted); }
.pg-status.ok { color: var(--pass); }
.pg-status.ok::before { content: '\2022  '; }
.pg-status.bad { color: var(--fail); }

.total-progress { color: var(--muted); font-family: var(--mono); }

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

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem 0.75rem 2rem;
  overflow-y: auto;
}

.main {
  padding: 1.5rem 2rem 3rem;
  overflow-y: auto;
  max-width: 980px;
}

/* ------------------------------------------------ sidebar nav */

.nav-cat { margin-bottom: 1.1rem; }

.nav-cat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 0.5rem 0.35rem;
}

.nav-cat-name {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.nav-cat-count {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.nav-list { list-style: none; margin: 0; padding: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.88rem;
  cursor: pointer;
}

.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--accent); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.tick {
  width: 1.1em;
  flex: none;
  font-family: var(--mono);
  color: transparent;
}
.tick.done { color: var(--pass); }

.nav-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.diff {
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  flex: none;
}
.diff-easy   { color: var(--pass); border-color: rgba(70, 192, 138, 0.4); }
.diff-medium { color: var(--accent); border-color: rgba(233, 161, 59, 0.4); }
.diff-hard   { color: var(--fail); border-color: rgba(226, 92, 109, 0.4); }

/* ------------------------------------------------ exercise head */

.ex-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6rem 0.9rem; }

.ex-eyebrow {
  width: 100%;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--blue);
  text-transform: lowercase;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.solved-banner {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--pass);
}

.ex-prompt { margin: 0.9rem 0 1rem; max-width: 68ch; }

/* ------------------------------------------------ folds */

.fold {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  margin: 0 0 0.8rem;
}

.fold summary {
  cursor: pointer;
  padding: 0.55rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  user-select: none;
}
.fold summary:hover { color: var(--text); }
.fold summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.fold[open] summary { border-bottom: 1px solid var(--line); color: var(--text); }

.fold-body { padding: 0.8rem 0.9rem; margin: 0; }

.fold-solution summary { color: var(--accent); }

.solution-sql {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre-wrap;
  overflow-x: auto;
}

.schema-table { margin-bottom: 1rem; }
.schema-table:last-of-type { margin-bottom: 0.25rem; }
.schema-table-name {
  margin: 0 0 0.35rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--blue);
}

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

.editor-block { margin: 1.1rem 0 1rem; }

.editor-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
}
.editor-frame:focus-within { border-color: var(--accent); }

.CodeMirror {
  height: auto;
  min-height: 9rem;
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.6;
  padding: 0.4rem 0;
}
.CodeMirror-gutters { background: var(--panel-2); border-right: 1px solid var(--line); }
.CodeMirror-linenumber { color: #46587290; font-size: 0.78rem; }
.cm-s-bench .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.cm-s-bench .CodeMirror-selected { background: #24354d; }
.cm-s-bench.CodeMirror-focused .CodeMirror-selected { background: #2b405c; }

.cm-s-bench .cm-keyword  { color: var(--blue); font-weight: 500; }
.cm-s-bench .cm-builtin  { color: #9d8ce8; }
.cm-s-bench .cm-string   { color: #8fc98f; }
.cm-s-bench .cm-string-2 { color: #8fc98f; }
.cm-s-bench .cm-number   { color: var(--accent); }
.cm-s-bench .cm-atom     { color: var(--accent); }
.cm-s-bench .cm-comment  { color: #5c6f88; font-style: italic; }
.cm-s-bench .cm-operator { color: #c7d5e6; }
.cm-s-bench .cm-variable-2 { color: #7fd0d8; }
.cm-s-bench .cm-bracket  { color: var(--muted); }

.editor-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.btn {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 7px;
  padding: 0.5rem 1.05rem;
  cursor: pointer;
  border: 1px solid var(--line);
}
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover:not(:disabled) { background: #f2b258; }

.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); }

.keys { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }

/* ------------------------------------------------ output & tests */

.output { margin-bottom: 0.9rem; }

.output-head {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0.5rem 0 0.5rem;
}

.table-scroll { overflow-x: auto; }

.result-table {
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.82rem;
  min-width: 240px;
}
.result-table th, .result-table td {
  border: 1px solid var(--line);
  padding: 0.3rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}
.result-table th { background: var(--panel); color: var(--blue); font-weight: 600; }
.result-table td { background: #101a28; }
.null-cell { color: var(--muted); font-style: italic; }

.table-note { font-size: 0.78rem; color: var(--muted); margin: 0.45rem 0 0; }
.error-text { color: var(--fail); font-family: var(--mono); font-size: 0.85rem; white-space: pre-wrap; }
.pass-text { color: var(--pass); font-family: var(--mono); font-size: 0.9rem; font-weight: 600; }

.test-list { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 0.8rem; }

.test-item {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  padding: 0.5rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  animation: rise 220ms ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .test-item { animation: none; }
}

.test-chip {
  font-weight: 600;
  min-width: 3.2em;
  letter-spacing: 0.05em;
}
.test-item.pass .test-chip { color: var(--pass); }
.test-item.fail .test-chip { color: var(--fail); }
.test-item.running .test-chip { color: var(--muted); }

.test-name { color: var(--text); font-weight: 500; flex: none; }
.test-note { color: var(--muted); }

.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 0.4rem;
}
.compare-head {
  margin: 0 0 0.4rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.empty-state { color: var(--muted); font-family: var(--mono); }

/* ------------------------------------------------ footer */

.foot {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.7rem 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
  font-family: var(--mono);
  background: var(--panel);
}

/* ------------------------------------------------ account & auth */

.topbar-right { display: flex; align-items: center; gap: 0.9rem; }

.account-area { display: flex; align-items: center; gap: 0.55rem; }

.account-chip {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--pass);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 32ch;
}

.sync-note { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }

.btn-small { padding: 0.28rem 0.7rem; font-size: 0.75rem; }

.auth-dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 26rem;
  width: calc(100vw - 2.5rem);
}
.auth-dialog::backdrop { background: rgba(5, 9, 15, 0.65); }

.auth-form { padding: 1.4rem 1.5rem 1.5rem; }

.auth-title {
  margin: 0 0 0.5rem;
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 600;
}

.auth-blurb { margin: 0 0 1.1rem; color: var(--muted); font-size: 0.88rem; }

.auth-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.auth-input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  margin-bottom: 1rem;
}
.auth-input:focus { outline: none; border-color: var(--accent); }

.auth-code { letter-spacing: 0.35em; font-size: 1.1rem; max-width: 12rem; }

.auth-sent { margin: -0.2rem 0 0.9rem; color: var(--pass); font-size: 0.85rem; font-family: var(--mono); }

.auth-actions { display: flex; justify-content: flex-end; gap: 0.6rem; }

.auth-error { margin: 0.9rem 0 0; }

/* ------------------------------------------------ small screens */

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 40vh;
  }
  .main { padding: 1.1rem 1rem 2.5rem; }
  .compare-grid { grid-template-columns: 1fr; }
}
