:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --panel: #ffffff;
  --line: #dcdcd6;
  --text: #1d1e22;
  --dim: #63656d;
  --accent: #2f4fd0;
  --accent-text: #ffffff;
  --soft: #eceef9;
  --good: #1c7a45;
  --warn: #8a5a00;
  --bad: #b3261e;
  --chip: #ededE8;
  --editor: #e2700f;
  --editor-text: #ffffff;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.08);
}

/* Light unless the top bar's button chose dark (theme.js remembers it). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15161a;
  --panel: #1f2126;
  --line: #33363e;
  --text: #e9e9ec;
  --dim: #a0a2aa;
  --accent: #8ba4ff;
  --accent-text: #0c1020;
  --soft: #262b40;
  --good: #5ccb8d;
  --warn: #e0b050;
  --bad: #ff8d85;
  --chip: #2c2e35;
  --editor: #ff9440;
  --editor-text: #1d1006;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

h1 { margin: 0; font-size: 28px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { margin: 0 0 8px; font-size: 18px; font-weight: 650; }
p { margin: 0 0 8px; }

/* The bar across the top: the icon and name, the way back to
   keinomieli.com in the middle. */
.top {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { justify-self: start; display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand img { width: 36px; height: 36px; }
.top .back-home { justify-self: center; border-radius: 999px; padding: 6px 16px; }
.top .end { justify-self: end; display: flex; align-items: center; gap: 4px; min-width: 0; }
.top .who { color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

main { max-width: 1040px; margin: 0 auto; padding: 28px 24px 24px; }

.crumbs { color: var(--dim); font-size: 15px; margin-bottom: 4px; overflow-wrap: anywhere; }
.crumbs a { color: inherit; }

.heading { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.heading .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }

/* Buttons. */
button, .button {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--dim); }
button:disabled { opacity: 0.55; cursor: default; }
button.main, .button.main { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--bad); }
.button.editor { background: var(--editor); border-color: var(--editor); color: var(--editor-text); font-weight: 600; }
.button.editor:hover { filter: brightness(1.08); border-color: var(--editor); }
button.main.danger-main { background: var(--bad); border-color: var(--bad); color: var(--panel); }
button.link { border: 0; background: none; padding: 2px 6px; color: var(--accent); }
button.link.danger { color: var(--bad); }
button:focus-visible, .button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Forms. */
input, select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  max-width: 100%;
}
label.field { display: block; margin-bottom: 12px; font-size: 15px; color: var(--dim); }
label.field input, label.field select { display: block; width: 100%; margin-top: 4px; font-size: 17px; color: var(--text); }

/* Panels and lists. */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card h2 { margin: 0; overflow-wrap: anywhere; }
.card h2 a { color: var(--text); text-decoration: none; }
.card h2 a:hover { text-decoration: underline; }
.card .meta { color: var(--dim); font-size: 15px; }
.card .row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; margin-left: -6px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
.tabs a { padding: 8px 12px; color: var(--dim); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 180px; min-width: 0; }
.toolbar input.grow { width: 100%; }

.chip { display: inline-block; padding: 0 7px; border-radius: 10px; background: var(--chip); color: var(--dim); font-size: 13px; line-height: 22px; white-space: nowrap; }
.chip.good { color: var(--good); }
.chip.busy { color: var(--accent); }
.chip.bad { color: var(--bad); }
dialog p.bad { color: var(--bad); }
.chip.warn { color: var(--warn); }

/* The assets table, which turns into stacked rows on a phone. */
.assets { width: 100%; border-collapse: collapse; }
.assets th { text-align: left; font-size: 13px; font-weight: 600; color: var(--dim); padding: 4px 8px; border-bottom: 1px solid var(--line); }
.assets td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.assets tr:last-child td { border-bottom: 0; }
.assets td.path { width: 100%; min-width: 0; overflow-wrap: anywhere; }
.assets td.path a { color: var(--text); text-decoration: none; font-weight: 500; }
.assets td.path a:hover { text-decoration: underline; }
.assets td.nowrap { white-space: nowrap; }
.assets td.size { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--dim); font-size: 15px; }
.assets td.actions { white-space: nowrap; text-align: right; }

.thumb { width: 36px; height: 36px; border-radius: 4px; background: var(--chip); display: grid; place-items: center; overflow: hidden; color: var(--dim); font-size: 10px; text-transform: uppercase; }
.thumb img { width: 100%; height: 100%; object-fit: contain; }

@media (max-width: 720px) {
  .top { display: flex; padding: 8px 12px; min-height: 52px; }
  .top .back-home { margin: 0 auto; }
  .top .end { flex: none; }
  .top .theme .word { display: none; }
  .brand { font-size: 0; }
  .top .back-home { padding: 4px 10px; font-size: 14px; }
  .top .who { display: none; }
  main { padding: 20px 16px 16px; }
  .assets thead { display: none; }
  .assets, .assets tbody { display: block; }
  .assets tr { display: grid; grid-template-columns: 44px 1fr auto; gap: 2px 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .assets tr:last-child { border-bottom: 0; }
  .assets td { padding: 0; border: 0; display: block; }
  .assets td.thumbcell { grid-row: span 2; }
  .assets td.path { grid-column: 2 / -1; width: auto; }
  .assets td.actions { grid-column: 1 / -1; text-align: left; margin-left: -6px; }
  .assets td.actions button { padding: 4px 6px; }
}

.empty { padding: 32px 16px; text-align: center; color: var(--dim); }
.empty p:last-child { margin-bottom: 0; }

.dropping { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 8px; }

.notice { padding: 10px 12px; margin-bottom: 12px; border-radius: 6px; background: var(--soft); overflow-wrap: anywhere; }
.notice.bad { background: transparent; border: 1px solid var(--bad); color: var(--bad); }

/* The project page's three parts. */
.parts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 16px; }
.parts .panel { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.parts .panel p { color: var(--dim); margin: 0; flex: 1; }

.plain { list-style: none; margin: 0; padding: 0; width: 100%; }
.plain li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; min-width: 0; }
.plain li:last-child { border-bottom: 0; }
.plain .end { margin-left: auto; color: var(--dim); font-size: 15px; }
.parts .panel .buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { color: var(--dim); margin: 0; }

/* The deploy page: a new build, and the builds so far. */
.deploy-new { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.deploy-new h2, .deploy-list h2 { margin: 0 0 4px; }
.deploy-new p.bad { color: var(--bad); margin: 0; }
.deploy-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 4px 0; }
.deploy-fields label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 15px; }
.deploy-fields label.grow { flex: 1 1 240px; }
.deploy-fields label.grow input { width: 100%; }
#deploy-version { width: 9em; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.deploys td.version { min-width: 7em; overflow-wrap: anywhere; }
.deploys .note { color: var(--dim); font-size: 14px; }
.deploys td.when { white-space: nowrap; font-size: 15px; }
.deploys td.actions > * + * { margin-left: 6px; }
.deploys tr:has(+ tr.deploy-more) td { border-bottom: 0; }
.deploys tr.deploy-more td { padding-top: 0; overflow-wrap: anywhere; }
.deploys tr.deploy-more p { margin: 0 0 6px; }
.deploys tr.deploy-more p.bad { color: var(--bad); }
.deploy-log { margin: 0 0 6px; max-height: 280px; overflow: auto; padding: 10px 12px; background: #141418; color: #d8d8e0; border-radius: 6px; font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

/* The tuning page. */
main.wide { max-width: 1680px; }
/* The game in the middle, its settings to the left, images and models to the right. */
.tune-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr); grid-template-areas: "settings play assets"; gap: 16px; align-items: start; }
.tune-play { grid-area: play; position: sticky; top: 12px; }
.tune-settings { grid-area: settings; min-width: 0; }
.tune-assets { grid-area: assets; min-width: 0; }
.tune-play .savebar { position: static; margin: 12px 0 0; }
/* Beside the game a setting is two lines: its name and Reset, then the control the column's width. */
.tune-settings .tune-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label reset" "control control"; gap: 6px 12px; }
.tune-settings .tune-row > .tune-label { grid-area: label; }
.tune-settings .tune-row > .tune-reset { grid-area: reset; }
.tune-settings .tune-row > :nth-child(2) { grid-area: control; }
.player { display: flex; flex-direction: column; gap: 10px; }
.player-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.player-bar h2 { margin: 0; flex: 1 1 auto; }
.player-bar .grow { flex: 1 1 160px; }
.player-bar .bad { color: var(--bad); }
.player-bar label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.player-box { width: 100%; margin: 0 auto; background: #141418; border-radius: 6px; overflow: hidden; }
.player-frame { display: block; width: 100%; height: 100%; border: 0; }
.player-missing { padding: 24px; color: #cfcfd6; }
.player-missing .hint { color: #9a9aa6; }
/* Narrower: the images and models under the settings; then all in one column. */
@media (max-width: 1280px) {
  .tune-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); grid-template-areas: "settings play" "assets play"; }
}
@media (max-width: 900px) {
  .tune-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "play" "settings" "assets"; }
  .tune-play { position: static; }
}
.danger-zone { margin-top: 16px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.danger-zone p { margin: 0; color: var(--dim); }
.tune-panel { margin-bottom: 12px; }
.tune-panel h2 { overflow-wrap: anywhere; }
.tune-panel .chip { font-weight: 400; vertical-align: 1px; }
.tune-scene { margin: 20px 0 8px; font-size: 20px; }
.tune-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 56px; gap: 4px 16px; align-items: center; padding: 10px 8px; margin: 0 -8px; border-top: 1px solid var(--line); border-radius: 4px; }
.tune-row label { font-weight: 500; }
.tune-row.changed, .plain li.changed { background: var(--soft); }
/* A row an agent just changed over MCP lights up once. */
.tune-row.touched { animation: tune-touched 1.4s ease-out; }
@keyframes tune-touched { from { background: color-mix(in srgb, var(--accent) 30%, transparent); } }
@media (prefers-reduced-motion: reduce) { .tune-row.touched { animation: none; } }
.tune-reset { text-align: right; }
.tune-reset button { padding: 2px 0; }
.tune-reset button[hidden] { display: none; }
.tune-control { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tune-slider { flex: 1 1 auto; min-width: 0; padding: 0; accent-color: var(--accent); }
.tune-number { flex: 0 0 84px; width: 84px; font-variant-numeric: tabular-nums; }
.tune-text { width: 100%; }
.tune-asset { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tune-asset .path, .tune-swap .path { overflow-wrap: anywhere; min-width: 0; }
.tune-asset button { margin-left: auto; }
.tune-panel .plain li { flex-wrap: nowrap; padding: 8px; margin: 0 -8px; width: calc(100% + 16px); border-radius: 4px; }
.tune-swap { min-width: 0; }
.tune-panel .plain .end { display: flex; flex: none; gap: 4px; align-items: center; }
.tune-row input[type="color"] { width: 56px; height: 34px; padding: 2px; cursor: pointer; }
.tune-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); justify-self: start; }
.savebar { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px -8px -8px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.savebar .grow { flex: 1 1 120px; color: var(--dim); }
.savebar.dirty .grow { color: var(--text); font-weight: 600; }
.choices { max-height: min(50vh, 420px); overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.choices h3 { margin: 8px 0 4px; font-size: 15px; font-weight: 600; color: var(--dim); }
.choices .plain li { padding: 0; border: 0; }
.choice { display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 4px; padding: 6px 8px; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.choice.on { border-color: var(--accent); background: var(--soft); }

@media (max-width: 720px) {
  .tune-row { grid-template-columns: minmax(0, 1fr) auto; }
  .tune-label { grid-column: 1 / -1; }
  .tune-panel .plain li { flex-wrap: wrap; }
  .tune-panel .plain .end { margin-left: 44px; }
}

code.secret { display: block; padding: 8px; margin: 8px 0; border-radius: 6px; background: var(--chip); font-size: 15px; overflow-wrap: anywhere; }

/* The login. */
.center { min-height: calc(100vh - 61px); display: grid; place-items: center; padding: 48px 16px 16px; }
.login { width: min(380px, 100%); }
.login img { width: 96px; height: 96px; display: block; margin: -64px auto 4px; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3)); }
.login h1, .login > .hint:first-of-type { text-align: center; }
.login h1 { margin: 8px 0 4px; }
.login form button { width: 100%; }
.login a.button { display: block; text-align: center; text-decoration: none; margin-bottom: 8px; box-sizing: border-box; }
.login form { margin-top: 12px; }
.login form .hint { margin: 8px 0 0; }
.hint { color: var(--dim); font-size: 15px; }

dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { font-size: 19px; }
dialog p { color: var(--dim); overflow-wrap: anywhere; }
dialog .row { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 8px 14px; border-radius: 6px; background: var(--text); color: var(--bg); z-index: 10; overflow-wrap: anywhere; }
.toast.bad { background: var(--bad); color: #fff; }

/* The console, on a project's pages: bottom left, a third of the width, dark
   in both themes as the editor's is. */
.console {
  position: fixed; left: 0; bottom: 0; z-index: 5;
  display: flex; flex-direction: column;
  width: max(33.4vw, 360px); max-width: 100vw; height: 280px;
  background: #17181c; color: #e8e8ea;
  border-top: 1px solid #33363e; border-right: 1px solid #33363e; border-top-right-radius: 8px;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.18);
  font: 13px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.console.closed { height: auto; }
.console.closed .console-out, .console.closed .console-in { display: none; }
.console-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 10px; border-bottom: 1px solid #2c2e35; }
.console.closed .console-head { border-bottom: 0; }
.console-head button { font: inherit; font-size: 13px; padding: 2px 10px; border-radius: 999px; }
.console-toggle { margin-right: auto; border: 0; background: none; color: #a2a4ab; padding-left: 0; }
.console-toggle::after { content: " \25BE"; }
.console.closed .console-toggle::after { content: " \25B4"; }
.console-toggle:hover { color: #e8e8ea; }
.console .mcp { border: 1px solid; font-weight: 600; }
.console .mcp::before { content: "\25CF  "; }
.console .mcp.off { color: #ff8080; border-color: #8a3b3b; background: #2a1719; }
.console .mcp.on { color: #6fe39a; border-color: #2f7a4c; background: #142a1d; }
.console-out { flex: 1; overflow-y: auto; padding: 6px 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.console-out .line.in { color: #a2a4ab; }
.console-out .line.ok { color: #e8e8ea; }
.console-out .line.bad { color: #ff8d85; }
.console-out .line.agent { color: #c3a6ff; margin-top: 4px; }
.console-out .line.note { color: #8fb4ff; }
.console-in { border-top: 1px solid #2c2e35; }
.console-line { width: 100%; border: 0; border-radius: 0; background: #111215; color: #e8e8ea; font: inherit; padding: 7px 10px; }
.console-line:focus-visible { outline: 1px solid #6d8dff; outline-offset: -1px; }
/* Room under the page for it, so nothing hides behind it. */
body.console-shown main { padding-bottom: 300px; }
@media (max-width: 720px) {
  .console { width: 100vw; height: 45vh; border-right: 0; border-top-right-radius: 0; }
  body.console-shown main { padding-bottom: calc(45vh + 20px); }
}
