:root {
  --bg: #0f1419;
  --bg2: #161d24;
  --bg3: #1e2730;
  --fg: #d8e1ea;
  --fg-dim: #8a99a8;
  --accent: #4da3ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --border: #2a3642;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  outline: none;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #08131f; font-weight: 600; border: none; }
button.danger { background: transparent; color: var(--red); border-color: var(--red); }
button.danger:hover { background: rgba(248, 81, 73, .12); }
button:disabled { opacity: .45; cursor: not-allowed; }

a { color: var(--accent); text-decoration: none; }

/* ---------- centered card (login/admin) ---------- */
.card-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
}
.card h1 { font-size: 20px; margin-bottom: 4px; }
.card .sub { color: var(--fg-dim); margin-bottom: 24px; }
.card label { display: block; margin: 14px 0 6px; color: var(--fg-dim); }
.card input, .card select, .card textarea { width: 100%; }
.card textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.card .row { display: flex; gap: 10px; }
.card .row > * { flex: 1; }
.card .actions { margin-top: 20px; display: flex; gap: 10px; }
.card .actions button { flex: 1; }
.error-box {
  margin-top: 14px;
  color: var(--red);
  background: rgba(248, 81, 73, .1);
  border: 1px solid rgba(248, 81, 73, .4);
  border-radius: 6px;
  padding: 10px;
  display: none;
}

/* ---------- admin panel ---------- */
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 24px; }
.admin-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 22px; border-bottom: 1px solid var(--border); margin-bottom: 24px;
}
.admin-head h1 { font-size: 18px; }
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tabs button { padding: 8px 18px; }
.tabs button.active { border-color: var(--accent); color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }

.section-title { font-size: 15px; font-weight: 600; margin: 26px 0 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--fg-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: rgba(77, 163, 255, .04); }
td .btns { display: flex; gap: 6px; flex-wrap: wrap; }
td .btns button { padding: 4px 10px; font-size: 12px; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge.active { background: rgba(63, 185, 80, .15); color: var(--green); }
.badge.inactive { background: rgba(138, 153, 168, .15); color: var(--fg-dim); }
.badge.expired { background: rgba(248, 81, 73, .15); color: var(--red); }
.badge.pending { background: rgba(210, 153, 34, .15); color: var(--yellow); }
.badge.building { background: rgba(77, 163, 255, .15); color: var(--accent); }
.badge.ready { background: rgba(63, 185, 80, .15); color: var(--green); }
.badge.failed { background: rgba(248, 81, 73, .15); color: var(--red); }
.badge.queued { background: rgba(138, 153, 168, .15); color: var(--fg-dim); }

code.mono { font-family: var(--mono); font-size: 13px; background: var(--bg3); padding: 2px 7px; border-radius: 4px; }
pre.log {
  font-family: var(--mono); font-size: 11px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; max-height: 200px; overflow: auto; white-space: pre-wrap;
  color: var(--fg-dim); margin-top: 8px;
}

/* ---------- editor ---------- */
.editor-shell {
  display: grid;
  grid-template-rows: 52px 1fr;
  height: 100vh;
}
.editor-top {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg2);
}
.editor-top .title { font-weight: 700; }
.editor-top .code-badge {
  font-family: var(--mono); background: var(--bg3);
  border: 1px solid var(--border); border-radius: 6px; padding: 3px 10px; letter-spacing: 1px;
}
.save-state { color: var(--fg-dim); font-size: 12px; }
.save-state.saved { color: var(--green); }
.save-state.dirty { color: var(--yellow); }
.spacer { flex: 1; }
.editor-top select { font-size: 12px; padding: 2px 6px; }

.editor-main {
  display: grid;
  grid-template-columns: 220px 1fr 460px;
  min-height: 0;
}

/* file sidebar */
.filebar {
  border-right: 1px solid var(--border); background: var(--bg2);
  display: flex; flex-direction: column; min-height: 0;
}
.filebar .head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 8px; color: var(--fg-dim); font-size: 12px; text-transform: uppercase;
}
.filebar .head button { padding: 2px 8px; font-size: 11px; }
.file-list { overflow-y: auto; flex: 1; }
.file-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; cursor: pointer; font-family: var(--mono); font-size: 13px;
  border-left: 2px solid transparent;
}
.file-item:hover { background: var(--bg3); }
.file-item.current { border-left-color: var(--accent); color: var(--accent); background: var(--bg3); }
.file-item .del {
  visibility: hidden; background: none; border: none; color: var(--red); padding: 0 4px;
}
.file-item:hover .del { visibility: visible; }

/* code area */
.codearea {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative;
}
.codearea .guttered { display: flex; flex: 1; min-height: 0; }
.linenos {
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  color: var(--fg-dim); text-align: right; padding: 12px 8px 12px 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  user-select: none; overflow: hidden; min-width: 46px; white-space: pre;
}
.code-layer { position: relative; flex: 1; min-width: 0; min-height: 0; }
#code, #codeHighlight {
  position: absolute; inset: 0; margin: 0; border: none; border-radius: 0;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  padding: 12px 14px; white-space: pre; tab-size: 4; overflow: hidden;
}
#code {
  overflow: auto; resize: none; background: transparent;
  color: transparent; caret-color: var(--fg); z-index: 1;
}
#code:focus { outline: none; }
#code::selection { background: rgba(77, 163, 255, .30); color: transparent; }
#codeHighlight { pointer-events: none; user-select: none; z-index: 0; background: transparent; }

/* syntax color schemes (token themes on the highlight layer) */
#codeHighlight[data-theme="app"] code { color: var(--fg); }
#codeHighlight[data-theme="app"] .token.comment,
#codeHighlight[data-theme="app"] .token.prolog,
#codeHighlight[data-theme="app"] .token.doctype,
#codeHighlight[data-theme="app"] .token.cdata { color: var(--fg-dim); font-style: italic; }
#codeHighlight[data-theme="app"] .token.keyword,
#codeHighlight[data-theme="app"] .token.boolean,
#codeHighlight[data-theme="app"] .token.operator,
#codeHighlight[data-theme="app"] .token.decorator,
#codeHighlight[data-theme="app"] .token.class-name,
#codeHighlight[data-theme="app"] .token.builtin { color: var(--accent); }
#codeHighlight[data-theme="app"] .token.string,
#codeHighlight[data-theme="app"] .token.char,
#codeHighlight[data-theme="app"] .token.triple-quoted-string { color: var(--green); }
#codeHighlight[data-theme="app"] .token.number { color: var(--yellow); }
#codeHighlight[data-theme="app"] .token.function { color: var(--fg); }
#codeHighlight[data-theme="app"] .token.punctuation { color: var(--fg-dim); }

/* Prism Okaidia */
#codeHighlight[data-theme="okaidia"] code { color: #f8f8f2; }
#codeHighlight[data-theme="okaidia"] .token.comment,
#codeHighlight[data-theme="okaidia"] .token.prolog,
#codeHighlight[data-theme="okaidia"] .token.doctype,
#codeHighlight[data-theme="okaidia"] .token.cdata { color: #8292a2; }
#codeHighlight[data-theme="okaidia"] .token.punctuation,
#codeHighlight[data-theme="okaidia"] .token.operator { color: #f8f8f2; }
#codeHighlight[data-theme="okaidia"] .token.keyword { color: #66d9ef; }
#codeHighlight[data-theme="okaidia"] .token.boolean,
#codeHighlight[data-theme="okaidia"] .token.number { color: #ae81ff; }
#codeHighlight[data-theme="okaidia"] .token.string,
#codeHighlight[data-theme="okaidia"] .token.char,
#codeHighlight[data-theme="okaidia"] .token.builtin { color: #a6e22e; }
#codeHighlight[data-theme="okaidia"] .token.function,
#codeHighlight[data-theme="okaidia"] .token.class-name { color: #e6db74; }
#codeHighlight[data-theme="okaidia"] .token.regex,
#codeHighlight[data-theme="okaidia"] .token.important { color: #fd971f; }

/* Prism Tomorrow Night */
#codeHighlight[data-theme="tomorrow"] code { color: #ccc; }
#codeHighlight[data-theme="tomorrow"] .token.comment,
#codeHighlight[data-theme="tomorrow"] .token.prolog,
#codeHighlight[data-theme="tomorrow"] .token.doctype,
#codeHighlight[data-theme="tomorrow"] .token.cdata { color: #999; }
#codeHighlight[data-theme="tomorrow"] .token.punctuation { color: #ccc; }
#codeHighlight[data-theme="tomorrow"] .token.keyword,
#codeHighlight[data-theme="tomorrow"] .token.builtin { color: #cc99cd; }
#codeHighlight[data-theme="tomorrow"] .token.function,
#codeHighlight[data-theme="tomorrow"] .token.boolean,
#codeHighlight[data-theme="tomorrow"] .token.number { color: #f08d49; }
#codeHighlight[data-theme="tomorrow"] .token.class-name,
#codeHighlight[data-theme="tomorrow"] .token.constant { color: #f8c555; }
#codeHighlight[data-theme="tomorrow"] .token.string,
#codeHighlight[data-theme="tomorrow"] .token.char,
#codeHighlight[data-theme="tomorrow"] .token.regex { color: #7ec699; }
#codeHighlight[data-theme="tomorrow"] .token.operator,
#codeHighlight[data-theme="tomorrow"] .token.url { color: #67cdcc; }

/* Prism Twilight */
#codeHighlight[data-theme="twilight"] code { color: #fff; }
#codeHighlight[data-theme="twilight"] .token.comment,
#codeHighlight[data-theme="twilight"] .token.prolog,
#codeHighlight[data-theme="twilight"] .token.doctype,
#codeHighlight[data-theme="twilight"] .token.cdata { color: #777; }
#codeHighlight[data-theme="twilight"] .token.punctuation { opacity: .7; }
#codeHighlight[data-theme="twilight"] .token.keyword,
#codeHighlight[data-theme="twilight"] .token.builtin,
#codeHighlight[data-theme="twilight"] .token.constant { color: #f9ed99; }
#codeHighlight[data-theme="twilight"] .token.boolean,
#codeHighlight[data-theme="twilight"] .token.number { color: #ce6849; }
#codeHighlight[data-theme="twilight"] .token.string,
#codeHighlight[data-theme="twilight"] .token.char,
#codeHighlight[data-theme="twilight"] .token.operator { color: #909e6a; }
#codeHighlight[data-theme="twilight"] .token.atrule { color: #7385a5; }
#codeHighlight[data-theme="twilight"] .token.regex,
#codeHighlight[data-theme="twilight"] .token.important { color: #e8c062; }

/* output area */
.outarea {
  border-left: 1px solid var(--border); background: var(--bg2);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.run-tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px 0; overflow-x: auto; min-height: 40px;
}
.run-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px 6px 0 0;
  cursor: pointer; font-size: 12px; white-space: nowrap; background: var(--bg);
}
.run-tab.active { border-bottom-color: var(--bg); color: var(--accent); }
.run-tab .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.run-tab.finished .dot { background: var(--fg-dim); }
.run-tab.error .dot { background: var(--red); }
.run-tab .x { color: var(--fg-dim); padding: 0 2px; }
.run-tab .x:hover { color: var(--red); }

.term-out {
  flex: 1; min-height: 80px; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 0 0 6px 6px;
  margin: 0 10px; padding: 10px 12px;
  font-family: var(--mono); font-size: 12px; line-height: 1.55; white-space: pre-wrap;
  word-break: break-all;
}
.term-out .err { color: var(--red); }
.term-out .sys { color: var(--fg-dim); font-style: italic; }
.term-empty { color: var(--fg-dim); font-style: italic; }

.term-input {
  display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border);
}
.term-input input { flex: 1; font-family: var(--mono); font-size: 12px; }
.term-input button { font-size: 12px; }

/* gui */
.gui-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px 6px; color: var(--fg-dim); font-size: 12px; text-transform: uppercase;
}
.gui-head button { font-size: 12px; padding: 2px 10px; }
.gui-wrap {
  padding: 0 10px 12px; display: flex; justify-content: center;
}
.gui-wrap.fs {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: #0b1016; padding: 0;
}
#guicanvas {
  background: #10161d; border: 1px solid var(--border); border-radius: 6px;
  max-width: 100%; cursor: default; outline: none; display: none;
}
.gui-wrap.fs #guicanvas { border: none; border-radius: 0; }
#guicanvas:focus { border-color: var(--accent); }
#fsExitBtn { display: none; }
.gui-wrap.fs #fsExitBtn { display: block; position: absolute; top: 12px; right: 12px; }
.gui-hint { font-size: 11px; color: var(--fg-dim); padding: 0 14px 8px; display: none; }

/* login page logo */
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #08131f; font-weight: 800; font-family: var(--mono);
}
.notice { font-size: 12px; color: var(--fg-dim); margin-top: 16px; text-align: center; }