@font-face {
  font-family: "DepartureMono";
  src: url("/fonts/DepartureMono-Regular.woff2") format("woff2");
  font-display: swap;
}

/* ── skins: switched by data-skin, colours only through variables ── */
:root, [data-skin="space"] {
  --bg: #050505; --panel: #0b0b0b; --fg: #ececec; --mid: #9a9a9a; --dim: #3a3a3a;
  --line: #262626; --accent: #ff3d7f; --ok: #ececec; --warn: #ffb020; --paper: 0;
}
[data-skin="paper"] {
  --bg: #d8d1c4; --panel: #cfc7b8; --fg: #141414; --mid: #4c4a45; --dim: #a59e90;
  --line: #b3ab9c; --accent: #d1301f; --paper: 1;
}
[data-skin="cyclone"] {
  --bg: #1b0d0e; --panel: #241112; --fg: #f0dcd6; --mid: #b49089; --dim: #5a3a38;
  --line: #3e2526; --accent: #ff6a4d;
}
[data-skin="phosphor"] {
  --bg: #020a05; --panel: #04110a; --fg: #9dffbf; --mid: #4fa873; --dim: #1d4a2e;
  --line: #12301e; --accent: #e8ff5a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
.note { margin-top: 12px; line-height: 1.6; }
.meter.muted { color: var(--mid); letter-spacing: 0; }
html, body { height: 100%; background: var(--bg); color: var(--fg); }
body {
  font: 13px/1.45 DepartureMono, ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  text-transform: none;
}
[data-density="compact"] body { font-size: 12px; line-height: 1.35; }
button, input, textarea { font: inherit; color: inherit; background: none; border: 0; outline: 0; }
button { cursor: pointer; }
::selection { background: var(--accent); color: var(--bg); }

/* graph-paper grid and scanlines are env flags */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 12px 12px; opacity: 0;
}
[data-grid="true"] body::before { opacity: 0.35; }
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.18) 2px 3px);
  opacity: 0;
}
[data-scanlines="true"] body::after { opacity: 1; }
[data-skin="paper"][data-scanlines="true"] body::after { opacity: .35; }

.app {
  position: relative; z-index: 1; height: 100%;
  display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr);
  max-width: 560px; margin: 0 auto;
  padding: env(safe-area-inset-top) 0 0;
}

/* ── header ── */
.bar {
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 16px 8px; text-transform: uppercase;
  border-bottom: 1px dashed var(--line);
}
.bar .call { font-size: 15px; letter-spacing: .08em; }
.bar .sep { color: var(--mid); }
.bar .kp { margin-left: auto; color: var(--accent); }
.ticker {
  min-width: 0; overflow: hidden; white-space: nowrap; color: var(--mid);
  padding: 4px 16px; font-size: 10px; text-transform: uppercase;
  border-bottom: 1px dotted var(--line);
}
.ticker span { display: inline-block; animation: tick 40s linear infinite; }
@keyframes tick { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ── screens ── */
main { overflow-y: auto; -webkit-overflow-scrolling: touch; position: relative; }
.screen { display: none; padding: 12px 16px 24px; }
.screen.on { display: block; animation: blink-in .18s steps(3); }
@keyframes blink-in { 0% { opacity: 0; } 50% { opacity: .5; } 100% { opacity: 1; } }

.label { color: var(--mid); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.hr { border: 0; border-top: 1px dashed var(--line); margin: 12px 0; }
.dots { border: 0; height: 1px; margin: 12px 0;
  background-image: radial-gradient(var(--mid) 0.8px, transparent 0.9px); background-size: 6px 2px; }

.hero { position: relative; height: 300px; margin: 4px -4px 8px; }
.hero canvas { width: 100%; height: 100%; display: block; }
.hero .cap { position: absolute; left: 10px; bottom: 8px; font-size: 9px; color: var(--mid); text-transform: uppercase; line-height: 1.3; }
.hero .cap.r { left: auto; right: 10px; text-align: right; }

.counter { display: flex; justify-content: center; gap: 12px; font-size: 22px; letter-spacing: .06em; margin: 6px 0 4px; }
.counter .bar-sep { color: var(--mid); }
canvas.dotchart { width: 100%; height: 72px; display: block; margin: 8px 0; }

/* topic "codes" table */
.codes { list-style: none; }
.codes li {
  display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 7px 0; border-bottom: 1px dotted var(--line); cursor: pointer;
}
.codes li:active { background: var(--panel); }
.codes .id { letter-spacing: .08em; text-transform: uppercase; }
.codes .id b { font-weight: normal; color: var(--accent); }
.codes .st { color: var(--mid); font-size: 11px; grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.codes .age { color: var(--mid); font-size: 11px; }
.codes li.sleep .id { color: var(--mid); }

/* meters like TEMP [||||||||] */
.meters { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; text-transform: uppercase; }
.meter { letter-spacing: -.05em; white-space: nowrap; overflow: hidden; color: var(--fg); }
.meter i { font-style: normal; color: var(--dim); }
.meters .v { text-align: right; min-width: 4ch; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; font-size: 11px; text-transform: uppercase; }
.kv dt { color: var(--mid); }
.kv dd { text-align: right; }
.kv dd::before { content: ""; }

/* modules */
.mods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mod {
  border: 1px solid var(--line); padding: 10px; min-height: 120px; position: relative;
  display: flex; flex-direction: column; justify-content: space-between; text-align: left;
}
.mod pre { font: inherit; font-size: 9px; line-height: 1; color: var(--fg); white-space: pre; }
.mod .nm { text-transform: uppercase; letter-spacing: .1em; }
.mod .ds { color: var(--mid); font-size: 10px; }
.mod.off { opacity: .45; }
.mod.new { border-style: dashed; color: var(--mid); align-items: center; justify-content: center; }
.mod::after { content: ""; position: absolute; top: 6px; right: 6px; width: 5px; height: 5px; background: var(--accent); }
.mod.off::after, .mod.new::after { display: none; }

/* environment */
.opts { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px; }
.opt { border: 1px solid var(--line); padding: 6px 10px; text-transform: uppercase; font-size: 11px; }
.opt.on { border-color: var(--fg); background: var(--fg); color: var(--bg); }
.swatch { width: 26px; height: 26px; border: 1px solid var(--line); }
.swatch.on { outline: 1px solid var(--fg); outline-offset: 2px; }

/* ── chat terminal ── */
.chat { display: flex; flex-direction: column; min-height: 100%; }
.chat .head { display: flex; gap: 8px; align-items: baseline; text-transform: uppercase; }
.chat .head .back { color: var(--mid); }
.chat .primer { color: var(--mid); font-size: 11px; margin: 6px 0 10px; border-left: 2px solid var(--dim); padding-left: 8px; }
.log { flex: 1; }
.msg { margin: 0 0 14px; white-space: pre-wrap; word-break: break-word; }
.msg .meta { font-size: 10px; color: var(--mid); text-transform: uppercase; margin-bottom: 2px; }
.msg.user .meta::before { content: "> "; color: var(--accent); }
.msg.user .body { color: var(--fg); }
.msg.agent .body { padding-left: 10px; border-left: 1px solid var(--fg); }
.msg.system .body { color: var(--mid); font-size: 11px; border: 1px dashed var(--dim); padding: 6px 8px; }
.thinking { display: none; height: 230px; margin: 4px -4px 10px; }
.thinking.on { display: block; }
.thinking canvas { width: 100%; height: 100%; }
.thinking { position: relative; }
.thinking .cap { position: absolute; left: 10px; bottom: 8px; font-size: 9px; color: var(--mid); text-transform: uppercase; }
.msg .meta .ch { border: 1px solid var(--dim); padding: 0 3px; margin: 0 2px; color: var(--fg); }
.msg .meta .ch.pwa { border-color: var(--accent); color: var(--accent); }
.msg.unsent .body { color: var(--mid); }
.msg .meta .st { color: var(--accent); }
.msg .retry { margin-top: 6px; padding: 4px 8px; font-size: 10px; }
.msg.system.warn .body { border-color: var(--accent); color: var(--fg); }
.xcard { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: stretch; }
.xcard .opt { display: flex; align-items: center; padding: 4px 8px; font-size: 10px; }
button.fcard { width: 100%; text-align: left; }
.prompt .stop { color: var(--accent); border: 1px solid var(--accent); padding: 0 6px; }
.viewer { position: fixed; inset: 0; z-index: 55; background: var(--bg); display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.viewer .vhead { display: flex; gap: 10px; align-items: baseline; padding: 12px 16px 8px; border-bottom: 1px dashed var(--line); text-transform: uppercase; }
.viewer .vhead span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer .vhead button { color: var(--accent); }
.viewer pre { flex: 1; overflow: auto; padding: 12px 16px 24px; font: inherit; font-size: 12px; white-space: pre-wrap; word-break: break-word; }
.empty { color: var(--mid); text-align: center; padding: 30px 0; font-size: 11px; text-transform: uppercase; }

.prompt {
  display: flex; gap: 8px; align-items: flex-end;
  border-top: 1px solid var(--line); padding: 10px 16px; background: var(--bg);
}
.prompt .ps { color: var(--accent); padding-bottom: 2px; }
.prompt textarea { flex: 1; resize: none; min-height: 20px; max-height: 140px; caret-color: var(--accent); }
.prompt textarea::placeholder { color: var(--dim); text-transform: uppercase; }
.prompt button { text-transform: uppercase; color: var(--mid); }
.prompt button:not(:disabled) { color: var(--fg); }

/* ── attachments: composer, tray, cards ── */
.prompt .attach { color: var(--accent); font-size: 18px; line-height: 1; padding: 0 2px 1px 0; }
.tray { border-top: 1px dashed var(--line); padding: 8px 16px 2px; background: var(--bg); max-height: 38vh; overflow-y: auto; }
.tray-head { margin-bottom: 6px; }
.up { padding: 6px 0 8px; border-bottom: 1px dotted var(--line); }
.up:last-child { border-bottom: 0; }
.up-top { display: flex; gap: 8px; align-items: baseline; }
.up-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-size, .up-st { color: var(--mid); font-size: 11px; }
.up-bar { letter-spacing: -.05em; white-space: pre; overflow: hidden; color: var(--fg); margin: 2px 0; }
.up[data-state="done"] .up-bar { color: var(--accent); }
.up[data-state="paused"] .up-bar, .up[data-state="queued"] .up-bar { color: var(--mid); }
.up-st.warn { color: var(--warn, var(--accent)); }
.up-st.bad { color: var(--accent); }
.up-acts { display: flex; gap: 6px; margin-top: 4px; }
.up-acts .opt, .f-acts .opt { padding: 4px 8px; font-size: 10px; }
.opt.danger { border-color: var(--accent); color: var(--accent); }
a.opt { color: inherit; text-decoration: none; display: inline-block; }

.msg .files { display: grid; gap: 6px; margin-top: 6px; white-space: normal; }
.fcard { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); padding: 6px; color: inherit; text-decoration: none; min-width: 0; }
.fcard .thumb { width: 56px; height: 56px; object-fit: cover; display: block; flex: none; image-rendering: pixelated; }
.glyph { flex: none; min-width: 56px; text-align: center; color: var(--accent); font-size: 11px; }
.finfo { display: flex; flex-direction: column; min-width: 0; }
.fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmeta { color: var(--mid); font-size: 10px; text-transform: uppercase; }
.fcard.deleted { border-style: dashed; color: var(--mid); }
.fcard.deleted .glyph { color: var(--mid); }

.flist { list-style: none; }
.flist > li { padding: 10px 0; border-bottom: 1px dotted var(--line); }
.flist .f-top { display: flex; gap: 10px; align-items: center; }
.flist .thumb { width: 64px; height: 64px; object-fit: cover; flex: none; border: 1px solid var(--line); }
.flist .glyph { min-width: 64px; }
.flist .f-info { min-width: 0; flex: 1; }
.flist .f-view { margin-top: 8px; }
.flist .f-view img, .flist .f-view video { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: var(--panel); }
.flist .f-view audio { width: 100%; }
.f-acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.flist .empty { border: 0; }

.drop { position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center;
  background: var(--bg); opacity: .92; border: 2px dashed var(--accent); color: var(--accent); text-transform: uppercase; pointer-events: none; }
.hint { color: var(--accent); }

/* ── bottom tabs ── */
nav.tabs {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  padding: 0 0 env(safe-area-inset-bottom); background: var(--bg);
}
nav.tabs button { padding: 10px 0 12px; text-transform: uppercase; font-size: 11px; color: var(--mid); letter-spacing: .06em; white-space: nowrap; }
nav.tabs button.on { color: var(--fg); }
nav.tabs button.on::before { content: "■ "; color: var(--accent); }
.app.in-chat nav.tabs { display: none; }

/* ── boot ── */
.boot {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; flex-direction: column; justify-content: center; padding: 24px;
}
.boot.gone { opacity: 0; pointer-events: none; transition: opacity .4s steps(4); }
.boot pre { font: inherit; font-size: 10px; line-height: 1.35; white-space: pre-wrap; color: var(--fg);
  background: var(--panel); border: 1px solid var(--line); padding: 10px; max-width: 520px; margin: 0 auto; width: 100%; }
.boot .eye { text-align: center; white-space: pre; font-size: 9px; line-height: 1; color: var(--fg); margin-bottom: 16px; }
.boot .prog { margin: 14px auto 0; max-width: 520px; width: 100%; letter-spacing: -.05em; color: var(--mid); }
.cursor { display: inline-block; width: .6em; background: var(--fg); animation: cur 1s steps(1) infinite; }
@keyframes cur { 50% { opacity: 0; } }

/* login */
.login { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 28px; max-width: 420px; margin: 0 auto; position: relative; z-index: 1; }
.login h1 { font-weight: normal; font-size: 18px; letter-spacing: .1em; margin-bottom: 18px; }
.login input { border-bottom: 1px solid var(--fg); width: 100%; padding: 8px 0; }
.login button { width: 100%; margin-top: 18px; border: 1px solid var(--fg); padding: 10px; text-transform: uppercase; }
.login .err { color: var(--accent); min-height: 1.4em; margin-top: 10px; font-size: 11px; }

@media (prefers-reduced-motion: reduce) {
  .ticker span, .cursor { animation: none; }
}
