:root {
  --bg: #1b2330;
  --bg-dots: #243044;
  --panel: #151b24;
  --panel-2: #202938;
  --border: #2d3748;
  --text: #e6e1cf;
  --muted: #8a94a6;
  --accent: #f29718;
  --danger: #e05561;
  /* Must match DEFAULT_FG / DEFAULT_BG in src/term.rs */
  --term-fg: #e6e1cf;
  --term-bg: #0f1419;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 600; }
/* A link styled as the main button ("Sign in with Microsoft"). */
a.button {
  display: block;
  padding: 10px;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  color: #1a1a1a;
  background: var(--accent);
  border-radius: 6px;
}

.muted { color: var(--muted); }
kbd {
  font: 12px ui-monospace, monospace;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
}

/* ---------- Desktop + taskbar ---------- */

#desktop {
  position: absolute;
  inset: 0 0 48px 0;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dots) 1px, transparent 1px);
  background-size: 22px 22px;
}

#empty-hint {
  position: absolute;
  top: 45%;
  width: 100%;
  padding: 0 16px;
  text-align: center;
}

#taskbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
#taskbar form { margin: 0; }
#user { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

#tasks {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  min-width: 0;
}
.task { white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.task.active { border-color: var(--accent); }
.task.minimized { opacity: 0.55; font-style: italic; }

/* ---------- Floating windows ---------- */

.win {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 240px;
  min-height: 140px;
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  resize: both;            /* the browser draws the resize grip; no JavaScript needed */
}
.win.focused { border-color: var(--accent); box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6); }
.win.maximized { border-radius: 0; resize: none; }
.win.bell { border-color: var(--text); }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 4px 0 12px;
  background: var(--panel-2);
  cursor: move;
  user-select: none;
  touch-action: none;
}
.title { flex: 1; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rec { font-size: 11px; font-weight: 600; color: var(--danger); letter-spacing: 0.04em; white-space: nowrap; }
.controls { display: flex; gap: 2px; }
.ctl {
  width: 28px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}
.ctl:hover { background: var(--border); color: var(--text); }
.ctl.close:hover { background: var(--danger); color: #fff; }

/* ---------- Panes and splits inside a window ---------- */

.panes { flex: 1; display: flex; min-height: 0; min-width: 0; }
.panes > * { flex: 1 1 0; }
.split { display: flex; min-width: 0; min-height: 0; }
.split.row { flex-direction: row; }
.split.col { flex-direction: column; }
/* The line between two panes; drag it to resize them. */
.divider { flex: 0 0 4px; background: var(--border); touch-action: none; }
.split.row > .divider { cursor: col-resize; }
.split.col > .divider { cursor: row-resize; }
.divider:hover { background: var(--muted); }
.pane { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
/* With more than one pane, the one that takes typing is outlined. */
.split .pane.active { box-shadow: inset 0 0 0 1px var(--accent); }
.pane .scrollpos {
  position: absolute;
  top: 4px; right: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--panel-2);
  font-size: 12px;
  color: var(--muted);
}

/* The terminal screen: one <div> per row, rendered to HTML by the server. */
.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 4px 6px;
  overflow: hidden;
  font: 14px/18px ui-monospace, "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  color: var(--term-fg);
  white-space: pre;
  cursor: text;
}
.screen > div { height: 18px; }
.screen .b { font-weight: bold; }
.screen .d { opacity: 0.6; }
.screen .i { font-style: italic; }
.screen .u { text-decoration: underline; }
.screen .w { display: inline-block; width: 2ch; }
.screen.mouse { cursor: default; } /* a program is reading the mouse */
.win:not(.focused) .screen .cur,
.split .pane:not(.active) .screen .cur {
  color: inherit !important;
  background: transparent !important;
  outline: 1px solid var(--muted);
  outline-offset: -1px;
}
.screen .info { color: var(--danger); white-space: normal; }
/* "This terminal will close in 60 seconds …" over the bottom of the pane. */
.pane .notice {
  position: absolute;
  left: 6px; right: 6px; bottom: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--accent);
  color: #1a1a1a;
  font: 600 12px system-ui, sans-serif;
}
.pane.ended .screen::after {
  content: attr(data-ended);
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 4px 8px;
  background: var(--panel-2);
  color: var(--muted);
  font: 12px system-ui, sans-serif;
  white-space: normal;
}

/* Keyboard focus target. Kept off-screen rather than hidden so it still receives keys and pastes. */
.input {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

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

.login-page {
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}
.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card input {
  font: inherit;
  padding: 10px 12px;
  color: var(--text);
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin: 0; }
.login-card button { padding: 10px; }
.error { color: var(--danger); }

/* ---------- Command palette ---------- */

#palette {
  position: fixed;
  inset: 0;
  z-index: 1000000; /* above every window, however often they were raised */
  background: rgba(0, 0, 0, 0.35);
}
.palette-box {
  width: min(560px, calc(100% - 32px));
  margin: 12vh auto 0;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6);
}
.palette-box input {
  width: 100%;
  font: inherit;
  padding: 8px 10px;
  color: var(--text);
  background: var(--term-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.palette-box input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.palette-box ul {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}
.palette-box li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.palette-box li[aria-selected="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.palette-box li.empty { color: var(--muted); cursor: default; }
.palette-box kbd { white-space: nowrap; color: var(--muted); }

@media (max-width: 600px) {
  #tile, #user { display: none; }
  .task { max-width: 110px; }
}
