:root {
  --bg: #0f1218;
  --bg-elev-1: #171c25;
  --bg-elev-2: #1d2430;
  --bg-elev-3: #232d3c;
  --border: #304057;
  --text: #e7edf7;
  --text-muted: #9fb0c9;
  --accent: #61b9ff;
  --accent-soft: #21456d;
  --ok: #79d48e;
  --error: #ff8a8a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans", "Helvetica Neue", sans-serif;
}

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

a:hover {
  text-decoration: underline;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(180deg, #17202d 0%, #131a24 100%);
  border-bottom: 1px solid var(--border);
}

.site-header-left {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  min-width: 0;
}

.site-brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #d7ecff;
}

.site-header-title {
  color: var(--text-muted);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-shrink: 0;
}

.site-nav a {
  color: #c4d9f2;
  font-size: 0.92rem;
}

.site-user {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding-left: 0.3rem;
  border-left: 1px solid var(--border);
}

.logout-form {
  margin: 0;
}

.logout-form button {
  background: none;
  border: none;
  color: #c4d9f2;
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  padding: 0;
}

.logout-form button:hover {
  text-decoration: underline;
}

/* ---------- log in ---------- */

.auth-card {
  max-width: 22rem;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem 1.5rem;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.auth-card label {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.auth-card input[type="text"],
.auth-card input[type="password"] {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font: inherit;
  width: 100%;
}

.auth-submit {
  margin-top: 1rem;
  align-self: flex-start;
}

.auth-error {
  color: var(--error);
  font-size: 0.88rem;
  margin: 0 0 0.4rem;
}

/* Separates the Keycloak button from the local username/password form. The
   rules either side are drawn with a flex row so the label sits in the gap. */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: 1.1rem 0 0.2rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border);
}

.page-main {
  padding: 1.25rem;
}

.content-shell {
  max-width: 1100px;
}

.page-title {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
}

.meta {
  color: var(--text-muted);
  margin: 0 0 1.25rem;
}

.table {
  border-collapse: collapse;
  width: 100%;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}

.table th {
  background: var(--bg-elev-2);
}

.table tr:last-child td {
  border-bottom: none;
}

.link-row {
  margin: 0 0 1rem;
}

/* ---------- shared page furniture (games list, game overview) ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-head .meta {
  margin-bottom: 0;
}

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  text-decoration: none;
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent-soft);
  border-color: #33628f;
  color: #dcefff;
}

.btn-primary:hover {
  background: #2a5686;
}

.btn-secondary {
  background: var(--bg-elev-2);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--bg-elev-3);
}

.is-empty {
  color: var(--text-muted);
  font-style: italic;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-elev-1);
}

/* ---------- games list ---------- */

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.game-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.game-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.game-card-banner {
  display: block;
  aspect-ratio: 16 / 9;
  background: var(--bg-elev-2);
  overflow: hidden;
}

.game-card-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Stands in for a missing banner: the title's first letter on a wash of the
   accent colour, so a card without artwork still reads as a distinct tile. */
.banner-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #24344c 0%, #1a2433 100%);
  color: #4f7ba8;
  font-size: 2.6rem;
  font-weight: 700;
  user-select: none;
}

.game-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.85rem 1rem 1rem;
  flex: 1 1 auto;
}

.game-card-title {
  margin: 0;
  font-size: 1.05rem;
}

.game-card-title a {
  color: var(--text);
}

.game-card-title a:hover {
  color: var(--accent);
  text-decoration: none;
}

.game-card-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
  flex: 1 1 auto;
}

/* The card's main action: playing. Sized to be the obvious thing to click. */
.btn-play {
  align-self: stretch;
  text-align: center;
  margin-top: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.game-card-links {
  display: flex;
  gap: 0.9rem;
  margin: 0.2rem 0 0;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

/* ---------- game overview ---------- */

.game-hero {
  position: relative;
  border: 1px solid var(--border);
  /* Square bottom: the Play button below butts straight up against it, so the
     two read as one block rather than two stacked cards. */
  border-radius: 12px 12px 0 0;
  overflow: hidden;
  background: var(--bg-elev-1);
  min-height: 150px;
  display: flex;
  align-items: flex-end;
}

/* The game's main action, the full width of the banner and directly under it. */
.btn-play-hero {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.8rem 1rem;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 0 0 12px 12px;
  /* Overlap the hero's 1px border so there is no seam between them. */
  margin: -1px 0 1.25rem;
}

.game-hero-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.game-hero-body {
  position: relative;
  width: 100%;
  padding: 2.5rem 1.25rem 1.1rem;
  /* Keeps the title readable over whatever the banner happens to be. */
  background: linear-gradient(180deg, rgba(15, 18, 24, 0) 0%, rgba(15, 18, 24, 0.88) 65%, rgba(15, 18, 24, 0.96) 100%);
}

.game-hero.no-banner {
  min-height: 0;
}

.game-hero.no-banner .game-hero-body {
  padding-top: 1.1rem;
  background: none;
}

.game-hero-title {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: 0.01em;
}

.game-hero-desc {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  max-width: 62ch;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
}

.chip {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.panel-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.panel-row-spacer {
  flex: 1 1 auto;
}

.panel {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem 1.15rem;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.panel .table {
  background: transparent;
  border: none;
}

.panel .table th {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.panel-grid .panel {
  margin-bottom: 1rem;
}

.prose {
  color: var(--text);
  line-height: 1.6;
  max-width: 70ch;
}

.prose p {
  margin: 0 0 0.8rem;
}

.prose p:last-child {
  margin-bottom: 0;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.tag {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font-size: 0.85rem;
}

/* ---------- messages, tags, contributors, engine ---------- */

.messages {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  max-width: 1100px;
}

.message {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 6px;
  background: var(--bg-elev-1);
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.message.success { border-left-color: var(--ok); }
.message.error { border-left-color: var(--error); }
.message.info { border-left-color: var(--accent); }

/* Tag chips are links, so they need the interactive states plain chips lack. */
.chip-tag,
.tag-filter .chip {
  cursor: pointer;
  color: var(--text-muted);
}

.chip-tag:hover,
.tag-filter .chip:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
}

.tag-filter .chip-on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #dcefff;
}

.tag-filter {
  margin-bottom: 1rem;
}

.chip-small {
  font-size: 0.72rem;
  padding: 0.1rem 0.5rem;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0;
}

.engine-problem {
  color: var(--error);
  margin: 0 0 0.4rem;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.inline-form label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.inline-form input {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font: inherit;
}

/* ---------- action kinds ---------- */

.kind-group + .kind-group {
  margin-top: 0.9rem;
}

.kind-heading {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kind-heading.kind-clash {
  color: var(--error);
}

.tag-clash {
  border-color: var(--error);
}

.tag-note {
  margin-left: 0.4rem;
  font-size: 0.72rem;
  color: var(--error);
}

/* Group headings inside the action editor's palette column. */
.palette-group {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8ea3bf;
  margin: 0.75rem 0 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid #2a3a52;
}

.palette-group:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

/* ---------- library ---------- */

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.library-card {
  display: flex;
  gap: 0.75rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
}

/* Sheets are large and any aspect ratio; a fixed contained box keeps the rows
   even without cropping away the part that identifies the artifact. */
.library-thumb {
  flex: 0 0 64px;
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #0b0e13;
  border: 1px solid var(--border);
  border-radius: 6px;
  image-rendering: pixelated;
}

/* Stand-in for the thumbnail when a resource is a sound rather than a
   picture — a rendered tracker song, most likely. */
.library-thumb-audio {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: var(--accent);
}

.library-audio {
  width: 100%;
  max-width: 20rem;
  height: 2rem;
  margin: 0.35rem 0;
}

/* Destructive action inside a row of links, so it reads as a link rather than
   competing with the primary buttons around it. */
.btn-link-danger {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--error);
  cursor: pointer;
}

.btn-link-danger:hover {
  text-decoration: underline;
}

.library-card-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.library-card-body h3 {
  margin: 0;
  font-size: 0.95rem;
}

.library-desc {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.library-card-body .meta {
  margin: 0;
  font-size: 0.75rem;
}

.library-card-body .btn {
  align-self: flex-start;
  margin-top: 0.2rem;
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
}

.library-inline {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.library-inline input {
  width: 4em;
  background: var(--bg-elev-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
  font: inherit;
}

/* Library pane inside the dudes editor */
.library-heading {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #8ea3bf;
  margin: 1rem 0 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

#library-dudes {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
}

#library-dudes li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.5rem;
  margin-bottom: 0.3rem;
  border: 1px solid #344865;
  border-radius: 6px;
  background: #1a2334;
  font-size: 0.85rem;
}

#library-dudes li.is-empty {
  border-style: dashed;
  background: none;
  justify-content: center;
}

.library-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-add {
  flex: 0 0 auto;
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid #33628f;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0.1rem 0.45rem;
}

.library-add:hover {
  background: #2a5686;
}

/* ---------- play page ---------- */

/* The engine sizes its canvas from the frame's viewport the moment it boots,
   so the frame has to reach its final height before then — and stay put after.
   calc(100vh - 58px) guessed the header's height, which is wrong as soon as
   the header wraps; letting the column do the arithmetic is exact. */
.play-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.play-main {
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.play-bar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.5rem 1rem;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.play-hint {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.play-bar .btn-link {
  background: var(--bg-elev-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.play-bar .btn-link:hover {
  background: var(--bg-elev-3);
  text-decoration: none;
}

/* The engine sizes its own canvas; this just gives it the rest of the page. */
.play-frame {
  flex: 1 1 auto;
  width: 100%;
  border: none;
  display: block;
  background: #000;
}

.code-block {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.85rem;
}

.col-actions {
  white-space: nowrap;
}

.col-actions a + a {
  margin-left: 0.75rem;
}

.editor-main {
  padding: 0;
  height: calc(100vh - 58px);
}

.editor-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.65rem 1rem;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.editor-toolbar .toolbar-title {
  font-weight: 600;
  margin-right: 0.3rem;
}

.editor-toolbar label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.editor-toolbar select,
.editor-toolbar input,
.editor-toolbar button,
.editor-toolbar .btn-link {
  background: var(--bg-elev-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
  font: inherit;
}

.editor-toolbar input[type="number"] {
  width: 4.2em;
}

.editor-toolbar button,
.editor-toolbar .btn-link {
  cursor: pointer;
}

.editor-toolbar .btn-link {
  text-decoration: none;
}

.editor-toolbar .btn-link:hover {
  background: var(--bg-elev-3);
  text-decoration: none;
}

.toolbar-spacer {
  flex: 1 1 auto;
}

#status {
  min-width: 12rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#status.ok {
  color: var(--ok);
}

#status.error {
  color: var(--error);
}

.editor-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

#palette-pane {
  flex: 0 0 auto;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: #111723;
}

#palette-pane.collision-mode {
  outline: 2px solid #ff4040;
  outline-offset: -2px;
}

#map-pane {
  flex: 1 1 auto;
  overflow: auto;
  background: #1a2330;
}

#palette-canvas,
#map-canvas {
  display: block;
  image-rendering: pixelated;
}

#palette-canvas,
#map-canvas,
.port .dot {
  cursor: crosshair;
}

#map-canvas {
  margin: 1rem;
}

#palette {
  flex: 0 0 220px;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: #111723;
  color: #dbe7f7;
  padding: 0.5rem;
}

#palette h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #8ea3bf;
  margin: 0.2rem 0 0.6rem;
}

.palette-item {
  background: #1e2940;
  border: 1px solid #344865;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.palette-item:hover {
  border-color: #5f8bbb;
}

.palette-item .pname {
  font-weight: 700;
  font-size: 0.85rem;
}

/* One line only: the full text is the hover tooltip, so a long description
   cannot push the palette into a scroll of paragraphs. */
.palette-item .pdesc {
  font-size: 0.72rem;
  color: #a6b6cc;
  margin-top: 0.2rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#workspace-pane {
  flex: 1 1 auto;
  overflow: auto;
  background: #151d2a;
  position: relative;
}

#workspace {
  position: relative;
  width: 3000px;
  height: 2000px;
  background-image: radial-gradient(#29384f 1px, transparent 1px);
  background-size: 24px 24px;
}

#wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#wires path {
  stroke: #88d4a2;
  stroke-width: 2.5;
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
}

#wires path:hover {
  stroke: #ff9090;
}

#wires path.temp {
  stroke: #d6cc7b;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

.node {
  position: absolute;
  width: 250px;
  background: #202f48;
  color: var(--text);
  border: 1px solid #3d5579;
  border-radius: 8px;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.node.unknown {
  border-color: #a65e5e;
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #2c4264;
  padding: 0.3rem 0.5rem;
  border-radius: 8px 8px 0 0;
  cursor: grab;
  font-weight: 700;
}

.node-header button {
  background: none;
  border: none;
  color: #c4d1e2;
  cursor: pointer;
  font-size: 1rem;
}

.node-header button:hover {
  color: #ff9090;
}

.node-ports {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
}

.ports-in,
.ports-out {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.port {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: #c0cbdb;
}

.ports-out .port {
  flex-direction: row-reverse;
}

.port .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #88d4a2;
  border: 2px solid #1a2330;
  flex: 0 0 auto;
}

.port.in .dot {
  background: #74add1;
  margin-left: -7px;
}

.port.out .dot {
  margin-right: -7px;
}

.node-args {
  padding: 0.3rem 0.5rem 0.5rem;
}

.node-args label {
  display: block;
  color: #9fb0c9;
  margin-top: 0.3rem;
}

.node-args input,
.node-args select {
  width: 100%;
  background: #172236;
  color: var(--text);
  border: 1px solid #3d5579;
  border-radius: 4px;
  padding: 0.15rem 0.3rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.75rem;
}

.node-args input.bad {
  border-color: var(--error);
}

.pair-row {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.25rem;
  align-items: center;
}

.pair-row input,
.pair-row select {
  flex: 1 1 50%;
  min-width: 0;
  width: auto;
}

.pair-row button {
  background: none;
  border: none;
  color: #7f93b1;
  cursor: pointer;
  flex: 0 0 auto;
}

.pair-row button:hover {
  color: var(--error);
}

.add-row {
  margin-top: 0.3rem;
  font-size: 0.7rem;
  background: #2c4264;
  color: var(--text);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0.15rem 0.6rem;
}

.add-row:hover {
  background: #35517a;
}

#dude-list-pane {
  flex: 0 0 220px;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: #111723;
  padding: 0.5rem;
}

#dude-list-pane h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: #8ea3bf;
  margin: 0.2rem 0 0.6rem;
}

#dude-list {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
}

#dude-list li {
  padding: 0.35rem 0.6rem;
  margin-bottom: 0.3rem;
  border: 1px solid #344865;
  border-radius: 6px;
  background: #1e2940;
  cursor: pointer;
  user-select: none;
}

#dude-list li:hover {
  border-color: #5f8bbb;
}

#dude-list li.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

#dude-form-pane {
  flex: 0 0 340px;
  overflow: auto;
  padding: 1rem;
  border-right: 1px solid var(--border);
}

#dude-form-pane.collapsed {
  flex-basis: 2.8rem;
  padding: 0.5rem 0.4rem;
  overflow: hidden;
}

#dude-form-pane.collapsed #dude-form {
  display: none;
}

.collapse-btn {
  display: block;
  margin-bottom: 0.6rem;
  background: var(--bg-elev-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.collapse-btn:hover {
  background: var(--bg-elev-3);
  color: var(--text);
}

#dude-form {
  max-width: 620px;
}

#level-map-pane {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.level-map-toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.level-map-toolbar label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.level-map-toolbar select {
  background: var(--bg-elev-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  font: inherit;
  margin-left: 0.3rem;
}

.place-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.level-dudes-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev-1);
  font-size: 0.82rem;
}

.level-dudes-label {
  color: var(--text-muted);
  flex: 0 0 auto;
}

#level-dudes {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin: 0;
  padding: 0;
}

#level-dudes li.empty {
  color: var(--text-muted);
}

#level-map-scroll {
  flex: 1 1 auto;
  overflow: auto;
  background: #1a2330;
}

#level-map-canvas {
  display: block;
  image-rendering: pixelated;
  margin: 1rem;
}

#level-map-canvas.placing {
  cursor: crosshair;
}

#level-map-canvas.deleting {
  cursor: not-allowed;
}

#dude-dialog {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  min-width: 260px;
}

#dude-dialog::backdrop {
  background: rgba(5, 8, 12, 0.65);
}

#dude-dialog h3 {
  margin: 0 0 0.6rem;
  font-size: 1rem;
}

#dude-dialog label {
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.55rem;
}

#dude-dialog input,
#dude-dialog select {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  background: var(--bg-elev-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
  font: inherit;
}

#dude-dialog .dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

#dude-dialog .dialog-buttons button {
  background: var(--bg-elev-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

#dude-dialog .dialog-buttons button[value="ok"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

#dude-form fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev-1);
  margin: 0 0 1rem;
  padding: 0.75rem 1rem 1rem;
}

#dude-form legend {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  padding: 0 0.4rem;
}

#dude-form label {
  display: block;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.6rem;
}

#dude-form input,
#dude-form select {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
  font: inherit;
  margin-top: 0.2rem;
}

#dude-form .vec2 input {
  width: 5.5em;
}

#dude-form label.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.preview-row {
  margin-top: 0.6rem;
}

#dude-preview {
  max-width: 100%;
  max-height: 200px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0b0e13;
}

#dude-action-lists {
  list-style: none;
  margin: 0.4rem 0 0.6rem;
  padding: 0;
}

#dude-action-lists li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
}

#dude-action-lists button {
  background: none;
  border: none;
  color: #7f93b1;
  cursor: pointer;
}

#dude-action-lists button:hover {
  color: var(--error);
}

.action-add-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.action-add-row input {
  flex: 0 1 12rem;
}

#dude-animations .pair-row input:first-child {
  flex: 0 1 8rem;
}

#dude-animations .pair-row input[type="number"] {
  flex: 0 1 5.5rem;
}

@media (max-width: 820px) {
  .game-grid {
    grid-template-columns: 1fr;
  }

  .game-hero-title {
    font-size: 1.4rem;
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-nav {
    width: 100%;
  }

  .editor-main {
    height: auto;
    min-height: calc(100vh - 58px);
  }

  .editor-body {
    flex-direction: column;
  }

  #palette {
    flex-basis: 180px;
    max-height: 220px;
  }
}