/* stegui layout.
 *
 * Deliberately unstyled. This file positions things and nothing else: no
 * palette, no button skins, no rounded corners, no shadows. Controls are
 * whatever the browser draws by default. The only rules that set a colour are
 * the syntax highlighting block at the bottom, plus the hairlines that mark
 * where one pane stops and the next begins, and the system keywords (Canvas,
 * CanvasText, Highlight) that let popups sit opaquely over the text under them.
 */

:root {
  --sidebar-width: 260px;
  --terminal-height: 260px;
  --code-font: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --code-size: 13px;
  --code-line: 20px;
  --code-pad: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--code-font);
  font-size: 13px;
}

/* ----------------------------------------------------------- lock screen */

#lock {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lock-form { width: 320px; }
#lock h1 { margin: 0 0 8px; font-size: 16px; }
#lock p { margin: 8px 0; }
#lock input { width: 100%; }

/* ------------------------------------------------------------ app frame */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) 4px 1fr;
  grid-template-rows: 1fr auto;
}

#app[hidden], #lock[hidden] { display: none; }

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

#sidebar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#sidebar-head { flex: 0 0 auto; padding: 4px; }
#root-form { display: flex; gap: 2px; margin-bottom: 4px; }
#root-path { flex: 1; min-width: 0; font-family: var(--code-font); }
#tree-actions { display: flex; flex-wrap: wrap; gap: 2px; }

#tree {
  flex: 1;
  overflow: auto;
  padding: 2px 4px 12px;
  white-space: nowrap;
}

#tree .node {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 1px 2px;
  cursor: default;
  user-select: none;
}

#tree .node .twisty { width: 1em; flex: 0 0 auto; }
#tree .node .name { overflow: hidden; text-overflow: ellipsis; }
#tree .node[data-selected="1"] { background: Highlight; color: HighlightText; }
#tree .children { padding-left: 12px; }
#tree .empty, #tree .error { padding-left: 16px; }

/* ------------------------------------------------------------- splitters */

#split-x {
  grid-column: 2;
  grid-row: 1;
  cursor: col-resize;
  border-left: 1px solid;
  border-right: 1px solid;
}

#split-y {
  height: 4px;
  cursor: row-resize;
  border-top: 1px solid;
  border-bottom: 1px solid;
}

/* ------------------------------------------------------------- main pane */

#main {
  grid-column: 3;
  grid-row: 1;
  display: grid;
  grid-template-rows: auto 1fr auto var(--terminal-height);
  overflow: hidden;
}

/* ------------------------------------------------------------------ tabs */

#tabbar {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  border-bottom: 1px solid;
  min-height: 1.9em;
}

#tabbar .tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-right: 1px solid;
  cursor: default;
  user-select: none;
  flex: 0 0 auto;
}

#tabbar .tab[data-active="1"] { text-decoration: underline; }
#tabbar .tab .close { font-family: var(--code-font); line-height: 1; }

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

#editor-area { position: relative; overflow: hidden; }
#editor-empty { padding: 12px; }
#editor { position: absolute; inset: 0; display: flex; }
#editor[hidden] { display: none; }

#gutter {
  flex: 0 0 auto;
  overflow: hidden;
  border-right: 1px solid;
  text-align: right;
}

/* The gutter, the highlight layer and the textarea must lay text out
 * identically or the caret drifts away from the characters under it. */
#gutter-inner, #highlight, #input {
  font-family: var(--code-font);
  font-size: var(--code-size);
  line-height: var(--code-line);
  tab-size: 4;
  white-space: pre;
  padding: var(--code-pad) 0;
  margin: 0;
  border: 0;
}

#gutter-inner { padding-left: 8px; padding-right: 6px; }

#code { position: relative; flex: 1; overflow: hidden; }

#highlight {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  padding-left: var(--code-pad);
  padding-right: var(--code-pad);
}

#highlight-inner { font: inherit; white-space: pre; display: block; }

#input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  resize: none;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: CanvasText;
  padding-left: var(--code-pad);
  padding-right: var(--code-pad);
  outline: none;
}

/* The textarea paints on top of the coloured copy of the same text, so an
 * opaque selection would hide the very characters you just selected. The tint
 * is the system highlight colour, only see-through. */
#input::selection { background: Highlight; color: transparent; }
#input::selection { background: color-mix(in srgb, Highlight 35%, transparent); }

/* -------------------------------------------------------- autocomplete */

#autocomplete {
  position: absolute;
  z-index: 5;
  max-height: 180px;
  min-width: 140px;
  overflow-y: auto;
  background: Canvas;
  color: CanvasText;
  border: 1px solid;
}

#autocomplete[hidden] { display: none; }
#autocomplete .item { padding: 1px 4px; cursor: default; white-space: pre; }
#autocomplete .item[data-active="1"] { background: Highlight; color: HighlightText; }
#autocomplete .item .kind { float: right; padding-left: 12px; }

/* -------------------------------------------------------------- terminal */

#terminal-panel { display: flex; flex-direction: column; overflow: hidden; }

#terminal-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  padding: 2px;
  overflow-x: auto;
  white-space: nowrap;
}

#terminal-tabs .tterm { margin-right: 2px; }
#terminal-tabs .tterm[data-active="1"] { text-decoration: underline; }

#terminal-host { flex: 1; overflow: hidden; position: relative; }
#terminal-host .term-instance { position: absolute; inset: 0; }
#terminal-host .term-instance[hidden] { display: none; }

/* ---------------------------------------------------------------- status */

#status {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 6px;
  border-top: 1px solid;
  overflow: hidden;
  white-space: nowrap;
}

#status-msg { flex: 1; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------- context menu */

#context-menu {
  position: fixed;
  z-index: 10;
  display: flex;
  flex-direction: column;
  background: Canvas;
  color: CanvasText;
  border: 1px solid;
}

#context-menu[hidden] { display: none; }
#context-menu button { text-align: left; }

/* ---------------------------------------------------------------------- *
 * Syntax highlighting. The one place colour is used on purpose, because
 * telling a string from a keyword is the whole point of highlighting.
 * ---------------------------------------------------------------------- */

.tok-comment  { color: #6a737d; font-style: italic; }
.tok-string   { color: #032f62; }
.tok-number   { color: #005cc5; }
.tok-keyword  { color: #d73a49; }
.tok-builtin  { color: #6f42c1; }
.tok-function { color: #6f42c1; }
.tok-type     { color: #22863a; }
.tok-tag      { color: #22863a; }
.tok-attr     { color: #6f42c1; }
.tok-meta     { color: #e36209; }
.tok-heading  { font-weight: bold; }

@media (prefers-color-scheme: dark) {
  .tok-comment  { color: #8b949e; }
  .tok-string   { color: #a5d6ff; }
  .tok-number   { color: #79c0ff; }
  .tok-keyword  { color: #ff7b72; }
  .tok-builtin  { color: #d2a8ff; }
  .tok-function { color: #d2a8ff; }
  .tok-type     { color: #7ee787; }
  .tok-tag      { color: #7ee787; }
  .tok-attr     { color: #d2a8ff; }
  .tok-meta     { color: #ffa657; }
}
