:root {
  color-scheme: dark;
  --app: #0e1115;
  --panel: #13171c;
  --head: #181d23;
  --field: #0b0e11;
  --hover: #222831;
  --line: #262d35;
  --text: #eef2f5;
  --muted: #a7b1bc;
  --dim: #7f8a96;
  --accent: #38e1f0;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--app);
  color: var(--text);
  font:
    12px -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  height: 100dvh;
  min-width: 900px;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr) 27px;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button,
select {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--head);
  padding: 6px 9px;
  cursor: pointer;
}
button:hover {
  background: var(--hover);
  border-color: #3c4652;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button.active,
button[aria-pressed="true"] {
  color: var(--accent);
  background: #133038;
  border-color: #23616a;
}
.primary {
  color: #071316;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 650;
}
.primary:hover {
  background: #83f1f8;
  color: #071316;
}
.primary.playing {
  background: #e8b931;
  border-color: #e8b931;
}
input,
textarea {
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  min-width: 0;
  outline: none;
}
input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}
header {
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
.brand strong {
  letter-spacing: 1.5px;
  font-size: 12px;
}
.mark {
  color: var(--accent);
  border: 1px solid #2d6570;
  border-radius: 6px;
  font-size: 20px;
  font-weight: 800;
  width: 29px;
  height: 30px;
  text-align: center;
  line-height: 28px;
}
.chip {
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 4px 6px;
  border-radius: 4px;
}
.project-actions {
  display: flex;
  gap: 5px;
}
#save-state {
  margin-left: auto;
  white-space: nowrap;
  font-size: 10px;
  color: var(--dim);
}
.workspace {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 274px;
  min-height: 0;
}
.left,
.right {
  background: var(--panel);
  min-height: 0;
  overflow: auto;
}
.left {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}
.right {
  border-left: 1px solid var(--line);
}
.panel-title {
  min-height: 37px;
  background: var(--head);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 1px;
  font-weight: 650;
  gap: 6px;
}
.panel-title button {
  font-size: 10px;
  padding: 3px 5px;
  letter-spacing: 0;
}
.panel-title select {
  max-width: 135px;
  padding: 3px;
  font-size: 11px;
  letter-spacing: 0;
}
.search-row {
  display: flex;
  padding: 10px;
  gap: 5px;
}
.search-row input {
  width: 100%;
}
#tree {
  overflow: auto;
  flex: 1;
  min-height: 125px;
  padding: 0 6px 10px;
}
.group {
  padding: 12px 7px 5px;
  color: var(--dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
}
.tree-row {
  width: 100%;
  display: flex;
  text-align: left;
  align-items: center;
  gap: 7px;
  background: none;
  border-color: transparent;
  padding: 6px 9px;
}
.tree-icon {
  color: var(--dim);
  width: 13px;
}
#assets {
  height: 135px;
  overflow: auto;
  padding: 5px 10px;
}
.file-row {
  border: 0;
  background: none;
  display: block;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  font-size: 11px;
  color: var(--muted);
  padding: 5px;
}
.left-note {
  padding: 12px;
  color: var(--dim);
  font-size: 10px;
  line-height: 1.7;
  border-top: 1px solid var(--line);
}
.key-option {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px;
  font-size: 10px;
  color: var(--muted);
}
main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 43px minmax(0, 1fr) 205px;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.tools {
  display: flex;
  gap: 3px;
}
.tools button {
  font-size: 16px;
  padding: 3px 7px;
  white-space: nowrap;
}
.tools span {
  font-size: 11px;
}
.toolbar label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--dim);
  font-size: 10px;
}
.toolbar input {
  width: 40px;
  padding: 4px;
}
.history {
  display: flex;
  margin-left: auto;
  gap: 3px;
}
.history button {
  padding: 4px 8px;
}
#play {
  white-space: nowrap;
}
#viewport {
  position: relative;
  overflow: hidden;
  background: #08090b;
  outline: none;
  touch-action: none;
}
#game {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}
#ui,
#gizmo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#view-chip {
  position: absolute;
  top: 12px;
  left: 12px;
  background: #0e1115dc;
  border: 1px solid #3c4652;
  border-radius: 5px;
  padding: 6px 9px;
  font-size: 10px;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  margin-right: 4px;
}
#hint {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  text-align: center;
  font-size: 10px;
  color: #d4dbe2;
  background: #0b0e11b0;
  border-radius: 4px;
  padding: 5px;
  pointer-events: none;
}
#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0e1115e8;
  color: var(--accent);
}
#loading[hidden] {
  display: none;
}
.bottom {
  border-top: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
}
.tabs {
  display: flex;
  align-items: center;
  height: 35px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
  gap: 3px;
}
.tabs button {
  border: 0;
  background: none;
  border-radius: 0;
  font-size: 11px;
  padding: 10px;
}
.tabs button.active {
  box-shadow: inset 0 -2px var(--accent);
  color: var(--accent);
}
#fps {
  margin-left: auto;
  font:
    10px ui-monospace,
    monospace;
  color: var(--dim);
  white-space: nowrap;
}
.tab-content {
  height: calc(100% - 35px);
  overflow: auto;
}
.palette-top,
.code-top {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  color: var(--dim);
  font-size: 10px;
}
.palette-top select {
  min-width: 120px;
}
.palette-top span {
  line-height: 1.4;
}
#palette {
  display: flex;
  gap: 8px;
  padding: 3px 10px;
  overflow-x: auto;
}
.tile {
  width: 66px;
  flex-shrink: 0;
  padding: 5px;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.tile canvas {
  width: 45px;
  height: 45px;
  border-radius: 3px;
  background: #08090b;
  image-rendering: pixelated;
}
.code-top {
  height: 36px;
  padding: 4px 10px;
}
.code-top button {
  padding: 4px 7px;
}
.code-top select {
  max-width: 240px;
  padding: 4px;
}
textarea {
  resize: none;
  display: block;
  border-radius: 0;
  width: 100%;
  height: calc(100% - 36px);
  font:
    11px/1.6 ui-monospace,
    SFMono-Regular,
    monospace;
  tab-size: 2;
  padding: 10px 13px;
}
#console-panel {
  margin: 0;
  padding: 10px;
  white-space: pre-wrap;
  font:
    11px/1.6 ui-monospace,
    monospace;
  color: var(--muted);
}
#inspector {
  padding: 12px;
}
#inspector h2 {
  font-size: 15px;
  margin: 2px 0 12px;
}
.entity-actions {
  display: flex;
  gap: 5px;
  margin-bottom: 15px;
}
.entity-actions button {
  font-size: 10px;
}
.component {
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 10px;
  overflow: hidden;
}
.component summary {
  font-size: 11px;
  cursor: pointer;
  background: var(--head);
  padding: 9px;
  font-weight: 600;
}
.component .fields {
  padding: 8px;
}
.field {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  margin-bottom: 7px;
  min-height: 27px;
}
.field > span {
  color: var(--muted);
  font-size: 10px;
  overflow-wrap: anywhere;
}
.field input {
  width: 100%;
  font:
    10px ui-monospace,
    monospace;
  padding: 6px;
}
.field input[type="checkbox"] {
  width: auto;
  justify-self: start;
}
.vector {
  display: flex;
  gap: 3px;
}
.vector input {
  width: 33%;
  padding: 5px 3px;
}
.field.wide {
  grid-template-columns: 1fr;
}
.field.wide input {
  font-size: 10px;
}
.field-error {
  border-color: #e5484d;
}
#entity-id {
  color: var(--dim);
  font-size: 10px;
}
.add-component {
  width: 100%;
  font-size: 11px;
}
footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  font-size: 10px;
  color: var(--dim);
  border-top: 1px solid var(--line);
  background: var(--panel);
}
#status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
footer.error #status {
  color: #ff8286;
}
dialog {
  width: 460px;
  border: 1px solid #3c4652;
  border-radius: 12px;
  padding: 30px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 90px #0008;
}
dialog::backdrop {
  background: #050709b8;
  backdrop-filter: blur(6px);
}
.eyebrow {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--accent);
}
dialog h1 {
  font-size: 27px;
  letter-spacing: -0.7px;
  margin: 12px 0;
}
dialog p {
  color: var(--muted);
  line-height: 1.7;
}
dialog label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 22px 0;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
body.playing #gizmo,
body.playing #hint {
  display: none;
}
body.playing #view-chip .dot {
  background: #e8b931;
}
[hidden] {
  display: none !important;
}
@media (max-width: 1150px) {
  header {
    gap: 10px;
    padding: 0 10px;
  }
  .brand .chip {
    display: none;
  }
  .project-actions button {
    font-size: 10px;
    padding: 6px;
  }
  .workspace {
    grid-template-columns: 180px minmax(0, 1fr) 240px;
  }
  .tools span {
    display: none;
  }
  .toolbar {
    gap: 5px;
  }
  .toolbar label {
    display: none;
  }
  .palette-top span {
    font-size: 9px;
  }
  .field {
    grid-template-columns: 68px minmax(0, 1fr);
  }
  main {
    grid-template-rows: 43px minmax(0, 1fr) 190px;
  }
  #save-state {
    font-size: 9px;
  }
}
@media (max-height: 700px) {
  main {
    grid-template-rows: 43px minmax(0, 1fr) 160px;
  }
  .left-note {
    display: none;
  }
}

#play-hud {
  display: none;
  position: absolute;
  left: 12px;
  right: 12px;
  top: 45px;
  gap: 5px;
  flex-wrap: wrap;
  pointer-events: none;
}
body.playing #play-hud {
  display: flex;
}
#play-hud span {
  border: 1px solid #ffffff24;
  border-radius: 4px;
  padding: 5px 7px;
  background: #0b0e11c9;
  font-size: 10px;
}

.full-app {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  font-weight: 650;
  font-size: 11px;
}
header {
  gap: 10px;
  padding: 0 10px;
  flex-wrap: wrap;
  align-content: center;
}
body {
  grid-template-rows: 86px minmax(0, 1fr) 27px;
}
#save-state {
  margin-left: auto;
}
#guide {
  position: absolute;
  right: 16px;
  bottom: 45px;
  width: min(350px, calc(100% - 32px));
  padding: 20px;
  background: #101a22f2;
  border: 1px solid #38e1f070;
  border-radius: 12px;
  box-shadow: 0 16px 60px #0009;
  z-index: 8;
}
#guide[hidden] {
  display: none;
}
#guide h2 {
  font-size: 20px;
  letter-spacing: -0.4px;
  margin: 16px 0 8px;
}
#guide p {
  color: var(--muted);
  line-height: 1.6;
  margin: 0 0 16px;
}
#guide-close {
  position: absolute;
  top: 7px;
  right: 7px;
  border: 0;
  background: transparent;
  color: var(--muted);
}
.guide-steps {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  font-size: 10px;
  color: var(--dim);
}
.guide-steps .active {
  color: var(--accent);
}
.gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.sample-card {
  display: flex;
  position: relative;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  overflow: hidden;
  background: var(--field);
}
.sample-card:has(input:checked) {
  border-color: var(--accent);
}
.sample-card img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
}
.sample-card input {
  position: absolute;
  right: 15px;
  top: 15px;
  accent-color: var(--accent);
}
.sample-card span {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}
.sample-card.pending {
  justify-content: center;
  opacity: 0.6;
}
#new-dialog {
  width: min(720px, 90vw);
  max-width: 720px;
}
#share-dialog {
  max-width: 520px;
  line-height: 1.7;
}
#share-link {
  color: var(--accent);
  overflow-wrap: anywhere;
}
@media (max-width: 1100px) {
  header .full-app {
    font-size: 10px;
  }
  header {
    gap: 7px;
  }
  .brand strong {
    font-size: 11px;
  }
  #guide {
    width: 300px;
    padding: 16px;
  }
}

#ai-panel {
  height: calc(100% - 35px);
  display: grid;
  grid-template-rows: 32px minmax(0, 1fr) 36px;
}
.ai-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px;
  font-size: 10px;
  color: var(--muted);
}
.ai-top label {
  white-space: nowrap;
}
.ai-top button {
  padding: 3px 6px;
  font-size: 10px;
}
#ai-balance {
  margin-right: auto;
}
#ai-thread {
  overflow: auto;
  padding: 6px 12px;
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
}
#ai-thread p {
  margin: 0 0 7px;
}
#ai-thread .user {
  color: var(--accent);
}
#ai-thread .receipt {
  color: var(--dim);
  font:
    10px ui-monospace,
    monospace;
}
#ai-form {
  display: flex;
  gap: 6px;
  padding: 3px 8px;
}
#ai-message {
  flex: 1;
  min-width: 0;
}
#ai-settings,
#ai-connect {
  max-height: 90vh;
  overflow: auto;
  width: 560px;
}
#ai-settings label,
#ai-connect label {
  margin: 12px 0;
}
#relay-code {
  font:
    700 28px ui-monospace,
    monospace;
  color: var(--accent);
  letter-spacing: 3px;
}
#relay-log {
  font:
    10px ui-monospace,
    monospace;
  max-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
}
@media (max-width: 1100px) {
  .tabs button {
    padding: 10px 6px;
    font-size: 10px;
  }
  .ai-top {
    gap: 4px;
  }
  #ai-balance {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Create | Games */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  margin-right: 8px;
}
.segmented button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
}
.segmented button + button {
  border-left: 1px solid var(--line);
}
.segmented button[aria-pressed="true"] {
  background: var(--hover);
  color: var(--text);
  border-color: var(--line);
}
.workspace {
  position: relative;
}
#games-page {
  position: absolute;
  inset: 0;
  z-index: 20;
  overflow: auto;
  background: var(--app);
  padding: 24px 24px 40px;
}
#games-page[hidden] {
  display: none;
}
.games-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}
#games-page h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
}
#games-page h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 28px 0 12px;
}
#games-count,
.games-note {
  color: var(--muted);
  margin: 0;
}
.games-note {
  margin-top: 20px;
  max-width: 720px;
}
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.game-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.game-cover {
  aspect-ratio: 16 / 9;
  background: #08090b;
  color: var(--dim);
  display: grid;
  place-items: center;
}
.game-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.game-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.game-body h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}
.game-genre {
  color: var(--dim);
  font-size: 11px;
}
.game-body p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  flex: 1;
}
.game-shows {
  color: var(--dim);
  font-size: 11px;
}
.game-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

/* Arcwright AI chat column (desktop Pro chat: your message in a tinted bubble on the right, replies as plain text) */
.workspace {
  grid-template-columns: 210px minmax(0, 1fr) 274px 320px;
}
body.chat-closed .workspace {
  grid-template-columns: 210px minmax(0, 1fr) 274px;
}
body.chat-closed .chat {
  display: none;
}
.chat {
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat #ai-balance {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chat #ai-panel {
  flex: 1;
  min-height: 0;
  height: auto;
  display: flex;
  flex-direction: column;
}
.chat .ai-top {
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.chat #ai-thread {
  flex: 1;
  min-height: 0;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
}
.chat #ai-thread p {
  margin: 0 0 10px;
}
.chat #ai-thread .user {
  color: var(--text);
  background: var(--hover);
  border-radius: 12px;
  padding: 7px 11px;
  margin-left: auto;
  width: fit-content;
  max-width: 88%;
}
.chat #ai-thread .about {
  color: var(--dim);
  font-size: 11px;
  text-align: right;
  margin-bottom: 4px;
}
.chat #ai-thread .receipt {
  color: var(--dim);
  font:
    11px ui-monospace,
    monospace;
  margin-bottom: 4px;
}
.ai-hello strong {
  font-size: 15px;
  font-weight: 600;
}
.ai-hello p {
  color: var(--muted);
  margin: 6px 0 12px !important;
}
.ai-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-suggestions button {
  text-align: left;
  font-size: 12px;
}
#ai-selection {
  margin: 0 12px 6px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  width: fit-content;
}
#ai-selection[hidden] {
  display: none;
}
.chat #ai-form {
  padding: 0 12px;
  align-items: flex-end;
}
.chat #ai-message {
  resize: none;
  font-size: 13px;
  min-height: 40px;
  max-height: 160px;
}
.ai-hint {
  color: var(--dim);
  font-size: 11px;
  padding: 6px 12px 10px;
}
.ai-hint a {
  color: var(--muted);
}
#sparks-pill,
#chat-toggle {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#chat-toggle[aria-pressed="true"] {
  color: var(--text);
  background: var(--hover);
}
#sparks-dialog {
  width: 560px;
}
.sparks-packs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin: 14px 0;
}
.sparks-pack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 12px;
  text-align: left;
}
.sparks-pack strong {
  font-size: 13px;
}
.sparks-pack span {
  color: var(--muted);
}
.sparks-pack em {
  color: var(--accent);
  font-style: normal;
  font-size: 11px;
  min-height: 14px;
}
.sparks-pack.popular {
  border-color: #23616a;
}
.sparks-note,
#sparks-account {
  color: var(--muted);
}
@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 190px minmax(0, 1fr) 250px 290px;
  }
}

/* Publish */
#publish-dialog {
  width: 640px;
  max-height: 92vh;
  overflow: auto;
}
#publish-dialog h3 {
  font-size: 12px;
  font-weight: 600;
  margin: 16px 0 6px;
}
.publish-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.publish-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  color: var(--muted);
}
.publish-grid .wide {
  grid-column: 1 / -1;
}
#publish-checks {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  font-size: 12px;
}
#publish-checks li {
  padding: 3px 0;
  color: var(--muted);
}
#publish-checks li.fail {
  color: #f08488;
}
#publish-status.error {
  color: #f08488;
}
#publish-creator {
  color: var(--muted);
}
.paint-modes {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.paint-modes button {
  border: 0;
  border-radius: 0;
  padding: 4px 9px;
}
.paint-modes button + button {
  border-left: 1px solid var(--line);
}

/* Sprites, History, Playtest */
#sprites-panel,
#history-panel,
#playtest-panel {
  height: calc(100% - 35px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#sprites-filter {
  width: 200px;
}
#sprites-grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  padding: 8px 12px 12px;
}
.sprite-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  align-items: stretch;
  min-width: 0;
}
.sprite-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #08090b;
  border-radius: 4px;
  image-rendering: auto;
}
.sprite-tile span {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#history-list {
  flex: 1;
  overflow: auto;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
}
.history-row {
  display: flex;
  justify-content: space-between;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
  padding: 4px 8px;
}
.history-row:hover {
  background: var(--hover);
}
.history-row time {
  color: var(--dim);
  font:
    11px ui-monospace,
    monospace;
}
.history-row.undone {
  color: var(--dim);
}
.history-now {
  color: var(--accent);
  padding: 4px 8px;
  font-size: 11px;
}
#playtest-result {
  flex: 1;
  overflow: auto;
  padding: 8px 14px;
  font-size: 12px;
}
#playtest-result p {
  margin: 0 0 5px;
}
#playtest-result p.fail {
  color: #f08488;
}
#playtest-result pre {
  color: var(--dim);
  font-size: 11px;
  white-space: pre-wrap;
}
.search-row {
  position: relative;
}
.add-menu {
  position: absolute;
  top: 100%;
  left: 8px;
  right: 8px;
  z-index: 30;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px #0008;
}
.add-menu[hidden] {
  display: none;
}
.add-menu button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
}
.add-menu button:hover {
  background: var(--hover);
}
.game-link {
  align-self: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  margin-left: auto;
}
.game-link:hover {
  color: var(--text);
}
/* Phones: the Games page first (see body.mobile below for the editor). */
.phone-note {
  display: none;
}
@media (max-width: 900px) {
  .phone-note {
    display: block;
    color: var(--muted);
    margin: 8px 0 0;
  }
  .games-head .full-app,
  .game-link {
    display: none;
  }
}

/* Arcwright AI chat column (desktop Pro chat: your message in a tinted bubble on the right, replies as plain text) */
.workspace {
  grid-template-columns: 210px minmax(0, 1fr) 274px 320px;
}
body.chat-closed .workspace {
  grid-template-columns: 210px minmax(0, 1fr) 274px;
}
body.chat-closed .chat {
  display: none;
}
.chat {
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat #ai-balance {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chat #ai-panel {
  flex: 1;
  min-height: 0;
  height: auto;
  display: flex;
  flex-direction: column;
}
.chat .ai-top {
  flex-wrap: wrap;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.chat #ai-thread {
  flex: 1;
  min-height: 0;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
}
.chat #ai-thread p {
  margin: 0 0 10px;
}
.chat #ai-thread .user {
  color: var(--text);
  background: var(--hover);
  border-radius: 12px;
  padding: 7px 11px;
  margin-left: auto;
  width: fit-content;
  max-width: 88%;
}
.chat #ai-thread .about {
  color: var(--dim);
  font-size: 11px;
  text-align: right;
  margin-bottom: 4px;
}
.chat #ai-thread .receipt {
  color: var(--dim);
  font:
    11px ui-monospace,
    monospace;
  margin-bottom: 4px;
}
.ai-hello strong {
  font-size: 15px;
  font-weight: 600;
}
.ai-hello p {
  color: var(--muted);
  margin: 6px 0 12px !important;
}
.ai-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-suggestions button {
  text-align: left;
  font-size: 12px;
}
#ai-selection {
  margin: 0 12px 6px;
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  width: fit-content;
}
#ai-selection[hidden] {
  display: none;
}
.chat #ai-form {
  padding: 0 12px;
  align-items: flex-end;
}
.chat #ai-message {
  resize: none;
  font-size: 13px;
  min-height: 40px;
  max-height: 160px;
}
.ai-hint {
  color: var(--dim);
  font-size: 11px;
  padding: 6px 12px 10px;
}
.ai-hint a {
  color: var(--muted);
}
#sparks-pill,
#chat-toggle {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#chat-toggle[aria-pressed="true"] {
  color: var(--text);
  background: var(--hover);
}
#sparks-dialog {
  width: 560px;
}
.sparks-packs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
  margin: 14px 0;
}
.sparks-pack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 10px 12px;
  text-align: left;
}
.sparks-pack strong {
  font-size: 13px;
}
.sparks-pack span {
  color: var(--muted);
}
.sparks-pack em {
  color: var(--accent);
  font-style: normal;
  font-size: 11px;
  min-height: 14px;
}
.sparks-pack.popular {
  border-color: #23616a;
}
.sparks-note,
#sparks-account {
  color: var(--muted);
}
@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 190px minmax(0, 1fr) 250px 290px;
  }
}

/* Publish */
#publish-dialog {
  width: 640px;
  max-height: 92vh;
  overflow: auto;
}
#publish-dialog h3 {
  font-size: 12px;
  font-weight: 600;
  margin: 16px 0 6px;
}
.publish-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}
.publish-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  color: var(--muted);
}
.publish-grid .wide {
  grid-column: 1 / -1;
}
#publish-checks {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  font-size: 12px;
}
#publish-checks li {
  padding: 3px 0;
  color: var(--muted);
}
#publish-checks li.fail {
  color: #f08488;
}
#publish-status.error {
  color: #f08488;
}
#publish-creator {
  color: var(--muted);
}
.paint-modes {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.paint-modes button {
  border: 0;
  border-radius: 0;
  padding: 4px 9px;
}
.paint-modes button + button {
  border-left: 1px solid var(--line);
}

/* Sprites, History, Playtest */
#sprites-panel,
#history-panel,
#playtest-panel {
  height: calc(100% - 35px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#sprites-filter {
  width: 200px;
}
#sprites-grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  padding: 8px 12px 12px;
}
.sprite-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  align-items: stretch;
  min-width: 0;
}
.sprite-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #08090b;
  border-radius: 4px;
  image-rendering: auto;
}
.sprite-tile span {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#history-list {
  flex: 1;
  overflow: auto;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
}
.history-row {
  display: flex;
  justify-content: space-between;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
  padding: 4px 8px;
}
.history-row:hover {
  background: var(--hover);
}
.history-row time {
  color: var(--dim);
  font:
    11px ui-monospace,
    monospace;
}
.history-row.undone {
  color: var(--dim);
}
.history-now {
  color: var(--accent);
  padding: 4px 8px;
  font-size: 11px;
}
#playtest-result {
  flex: 1;
  overflow: auto;
  padding: 8px 14px;
  font-size: 12px;
}
#playtest-result p {
  margin: 0 0 5px;
}
#playtest-result p.fail {
  color: #f08488;
}
#playtest-result pre {
  color: var(--dim);
  font-size: 11px;
  white-space: pre-wrap;
}
.search-row {
  position: relative;
}
.add-menu {
  position: absolute;
  top: 100%;
  left: 8px;
  right: 8px;
  z-index: 30;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px #0008;
}
.add-menu[hidden] {
  display: none;
}
.add-menu button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
}
.add-menu button:hover {
  background: var(--hover);
}
.game-link {
  align-self: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
  margin-left: auto;
}
.game-link:hover {
  color: var(--text);
}
.inspector-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 10px 0;
  border-bottom: 1px solid var(--line);
}
.inspector-tabs button {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 2px solid transparent;
}
.inspector-tabs button[aria-pressed="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}
#inspector-text {
  padding: 10px;
}
#inspector-text[hidden] {
  display: none;
}
#entity-text {
  width: 100%;
  min-height: 360px;
  font:
    11px ui-monospace,
    monospace;
  resize: vertical;
}
#animation-panel {
  height: calc(100% - 35px);
  overflow: auto;
}
.panel-empty {
  color: var(--muted);
  padding: 12px 14px;
  margin: 0;
}
#anim-info {
  color: var(--dim);
  font-size: 11px;
}
.anim-main {
  display: flex;
  gap: 12px;
  padding: 8px 12px 12px;
  min-height: 0;
}
.anim-stage {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--dim);
  font:
    11px ui-monospace,
    monospace;
}
#anim-preview {
  background:
    repeating-conic-gradient(#15191e 0% 25%, #1b2026 0% 50%) 0 0 / 16px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.anim-side {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#anim-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 4px;
}
#anim-strip canvas {
  flex: none;
  background: #08090b;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
#anim-strip canvas.active {
  border-color: var(--accent);
}
.anim-new {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.anim-new input[type="number"] {
  width: 56px;
}
.anim-new #anim-name {
  width: 90px;
}

/* Sizing (10-27): the canvas's pixel buffer (CSS size × devicePixelRatio) must never size its own column, or each
   resize grows it past the inspector. The viewport takes its size from the grid; the canvases fill it. */
main {
  grid-template-columns: minmax(0, 1fr);
}
#viewport {
  min-width: 0;
  min-height: 0;
}
#game {
  position: absolute;
  inset: 0;
}
.tabs {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tabs button {
  white-space: nowrap;
  flex: none;
}
.toolbar,
.palette-top,
.code-top {
  min-width: 0;
  overflow: hidden;
}
.palette-top > span,
.code-top > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
/* Narrower windows: the chat floats over the inspector (✦ Chat opens it) so the game view keeps its room. */
@media (max-width: 1399px) {
  .workspace,
  body.chat-closed .workspace {
    grid-template-columns: 200px minmax(0, 1fr) 260px;
  }
  .chat {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 330px;
    z-index: 25;
    box-shadow: -12px 0 32px #0009;
  }
}
#sparks-welcome {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 12px 0;
}
#sparks-welcome[hidden],
.welcome-row[hidden] {
  display: none;
}
#sparks-welcome h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
}
#welcome-copy,
#welcome-status {
  color: var(--muted);
  margin: 4px 0 8px;
}
.welcome-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
#welcome-email {
  flex: 1;
  min-width: 200px;
}
#welcome-code {
  width: 140px;
  letter-spacing: 3px;
}
#import-dialog {
  width: 700px;
}
#import-preview {
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: repeating-conic-gradient(#15191e 0% 25%, #1b2026 0% 50%) 0 0 / 16px 16px;
}
#import-found,
#import-bg-found,
#import-count {
  color: var(--muted);
}
#import-dialog a,
.ai-hint a {
  color: var(--accent);
}
.chat #ai-form {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.ai-buttons {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.ai-buttons button {
  min-width: 34px;
}
#ai-mic.listening {
  background: #5a1f24;
  border-color: #f08488;
}
#ai-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 6px;
}
#ai-attachments[hidden] {
  display: none;
}
.ai-chip {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #08090b;
}
.ai-chip img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.ai-chip button {
  position: absolute;
  top: 2px;
  right: 2px;
  padding: 0 5px;
  font-size: 11px;
  line-height: 16px;
}
.chat.dropping {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}
.ai-pictures {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin: 0 0 6px;
}
.ai-pic {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 96px;
}
.ai-pic img {
  width: 96px;
  height: 72px;
  object-fit: contain;
  background: #08090b;
  border-radius: 6px;
  border: 1px solid var(--line);
}
.ai-pic button {
  font-size: 11px;
  padding: 2px 4px;
}
#packs-panel {
  height: calc(100% - 35px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#packs-list {
  display: flex;
  gap: 6px;
  padding: 8px 12px 0;
  overflow-x: auto;
  flex: none;
}
.pack-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  white-space: nowrap;
  flex: none;
}
.pack-chip img {
  width: 40px;
  height: 26px;
  object-fit: cover;
  border-radius: 4px;
}
.pack-chip.active {
  border-color: var(--accent);
}
#packs-filter {
  width: 140px;
}
#packs-grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  padding: 8px 12px 12px;
}

/* Guide */
#guide-page {
  position: absolute;
  inset: 0;
  z-index: 21;
  overflow: auto;
  background: var(--app);
  padding: 24px;
}
#guide-page[hidden] {
  display: none;
}
.guide-wrap {
  max-width: 980px;
  margin: 0 auto;
  line-height: 1.55;
  font-size: 13px;
}
.guide-wrap h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
}
.guide-wrap h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 28px 0 8px;
}
.guide-wrap h3 {
  font-size: 13px;
  font-weight: 600;
  margin: 18px 0 6px;
}
.guide-wrap p,
.guide-wrap li {
  color: var(--muted);
}
.guide-wrap b {
  color: var(--text);
}
.guide-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}
.guide-toc a {
  color: var(--muted);
  text-decoration: none;
}
.guide-toc a:hover {
  color: var(--text);
}
.guide-steps-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 12px 0;
}
.guide-steps-row.two {
  grid-template-columns: repeat(2, 1fr);
}
.guide-steps-row figure {
  margin: 0;
}
.guide-steps-row img {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--line);
  display: block;
}
.guide-steps-row figcaption {
  color: var(--dim);
  font-size: 11px;
  margin-top: 4px;
}
.guide-rules {
  padding-left: 18px;
}
.guide-rules li {
  margin: 4px 0;
}
.guide-prompt {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 8px 0;
}
.guide-prompt b {
  display: inline-block;
  margin-right: 8px;
}
.guide-prompt button {
  font-size: 11px;
  padding: 2px 8px;
}
.guide-prompt p {
  margin: 6px 0 0;
  font-size: 12px;
}
.guide-wrap code {
  background: var(--field);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--text);
}
.file-menu {
  position: relative;
}
#file-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  background: var(--head);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
  box-shadow: 0 8px 24px #0008;
}
#file-menu[hidden] {
  display: none;
}
#file-menu button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 10px;
}
#file-menu button:hover {
  background: var(--hover);
}
header {
  flex-wrap: nowrap;
}
body {
  grid-template-rows: 54px minmax(0, 1fr) 27px;
}
@media (max-width: 1180px) {
  .brand .chip,
  #save-state {
    display: none;
  }
}

/* ---- Phones and tablets (mobile.js sets body.mobile at <= 900 px, body.touch on touch screens) ---- */
#mtabs,
.mobile-only,
#touch-controls {
  display: none;
}
body.mobile {
  min-width: 0;
  height: calc(100dvh - var(--keyboard, 0px));
  grid-template-rows: auto minmax(0, 1fr) auto;
}
body.mobile footer {
  display: none;
}
body.mobile header {
  padding: 6px 10px;
  gap: 8px;
  min-height: 48px;
}
body.mobile header > :not(.brand):not(.file-menu):not(#sparks-pill) {
  display: none;
}
body.mobile .brand strong,
body.mobile .brand .chip {
  display: none;
}
body.mobile .file-menu {
  margin-left: auto;
}
body.mobile #file-menu-btn {
  font-size: 0;
}
body.mobile #file-menu-btn::after {
  content: "☰  Menu";
  font-size: 14px;
}
body.mobile #file-menu {
  left: auto;
  right: 0;
  min-width: 230px;
}
body.mobile #file-menu .mobile-only {
  display: block;
}
body.mobile #file-menu hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 0;
  width: 100%;
}
body.mobile #file-menu a.full-app {
  padding: 8px 10px;
}
body.mobile #mtabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 2px 4px calc(2px + env(safe-area-inset-bottom));
}
body.mobile #mtabs button {
  flex: 1;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 0;
  font-size: 11px;
  color: var(--muted);
  min-height: 50px;
}
body.mobile #mtabs button span {
  font-size: 17px;
  line-height: 20px;
}
body.mobile #mtabs button.active {
  color: var(--accent);
}
body.mobile.games-open #mtabs,
body.mobile.guide-open #mtabs,
body.mobile.keyboard #mtabs,
body.mobile.playing #mtabs {
  display: none;
}
body.mobile .workspace,
body.mobile.chat-closed .workspace {
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: auto minmax(0, 1fr) 46%;
}
body.mobile[data-sheet="none"] .workspace,
body.mobile.playing .workspace {
  grid-template-rows: auto minmax(0, 1fr) 0;
}
body.mobile.keyboard .workspace {
  grid-template-rows: 0 0 minmax(0, 1fr);
}
body.mobile main {
  display: contents;
}
body.mobile .toolbar {
  grid-row: 1;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 6px;
  padding: 4px 8px;
}
body.mobile .toolbar .tools span,
body.mobile .toolbar label {
  display: none;
}
body.mobile #viewport {
  grid-row: 2;
}
body.mobile .left,
body.mobile .right,
body.mobile .chat,
body.mobile .bottom {
  grid-row: 3;
  grid-column: 1;
  display: none;
  border: 0;
  border-top: 1px solid var(--line);
  min-height: 0;
  overflow: auto;
}
body.mobile[data-sheet="scene"] .left {
  display: flex;
}
body.mobile[data-sheet="inspect"] .right {
  display: block;
}
body.mobile[data-sheet="ai"] .chat {
  display: flex !important;
  position: static;
  width: auto;
  box-shadow: none;
}
body.mobile[data-sheet="tiles"] .bottom,
body.mobile[data-sheet="packs"] .bottom,
body.mobile[data-sheet="more"] .bottom {
  display: block;
}
body.mobile[data-sheet="tiles"] .bottom .tabs,
body.mobile[data-sheet="packs"] .bottom .tabs {
  display: none;
}
body.mobile[data-sheet="tiles"] .tab-content,
body.mobile[data-sheet="packs"] .tab-content {
  height: 100% !important;
}
body.mobile .left-note,
body.mobile #hint {
  display: none;
}
body.mobile #games-page,
body.mobile #guide-page {
  z-index: 30;
}
body.mobile .workspace > #games-page,
body.mobile .workspace > #guide-page {
  grid-row: 1 / -1;
  position: absolute;
  inset: 0;
}
body.mobile #guide {
  left: 8px;
  right: 8px;
  bottom: 8px;
  width: auto;
}
body.mobile .guide-steps-row,
body.mobile .guide-steps-row.two {
  grid-template-columns: 1fr;
}
body.mobile .publish-grid {
  grid-template-columns: 1fr;
}
body.mobile dialog {
  width: calc(100vw - 16px) !important;
  max-width: none;
  max-height: calc(100dvh - 16px - var(--keyboard, 0px));
  overflow: auto;
}
body.mobile input,
body.mobile textarea,
body.mobile select {
  font-size: 16px;
}
/* Fingers: bigger targets everywhere on touch screens. */
body.touch button,
body.touch select {
  min-height: 38px;
  touch-action: manipulation;
}
body.touch .field input {
  min-height: 34px;
}
body.touch .tile,
body.touch .sprite-tile {
  min-width: 76px;
}
body.touch .tree-row {
  min-height: 40px;
}
body.touch .history-row {
  min-height: 40px;
}
/* On-screen play controls (touch screens, while playing). */
body.touch.playing #touch-controls,
body.mobile.playing #touch-controls {
  display: flex;
}
#touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px max(12px, env(safe-area-inset-left)) calc(12px + env(safe-area-inset-bottom));
  pointer-events: none;
  z-index: 9;
}
#touch-controls button {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: #0b0e11a8;
  border: 1px solid #ffffff40;
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}
#touch-controls button.down {
  background: #38e1f0a0;
  color: #05191c;
}
.tc-pad {
  display: grid;
  grid-template-columns: 58px 58px 58px;
  grid-template-rows: 58px 58px;
  gap: 4px;
}
.tc-pad [data-key^="LEFT"] {
  grid-area: 2 / 1;
}
.tc-pad [data-key^="UP"] {
  grid-area: 1 / 2;
}
.tc-pad [data-key^="DOWN"] {
  grid-area: 2 / 2;
}
.tc-pad [data-key^="RIGHT"] {
  grid-area: 2 / 3;
}
.tc-actions {
  display: grid;
  grid-template-columns: 58px 72px;
  grid-template-rows: 58px 72px;
  gap: 6px;
  align-items: center;
  justify-items: center;
}
.tc-actions [data-key="J"] {
  grid-area: 1 / 1;
}
.tc-actions [data-key="K"] {
  grid-area: 1 / 2;
}
.tc-actions [data-key="E"] {
  grid-area: 2 / 1;
}
.tc-actions .tc-jump {
  grid-area: 2 / 2;
  width: 72px;
  height: 72px;
  font-size: 12px;
}
@media (max-width: 380px) {
  #touch-controls button {
    width: 50px;
    height: 50px;
  }
  .tc-pad {
    grid-template-columns: 50px 50px 50px;
    grid-template-rows: 50px 50px;
  }
  .tc-actions {
    grid-template-columns: 50px 64px;
    grid-template-rows: 50px 64px;
  }
  .tc-actions .tc-jump {
    width: 64px;
    height: 64px;
  }
}
body.mobile #packs-grid,
body.mobile #sprites-grid {
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
}
body.mobile #packs-panel .code-top {
  flex-wrap: nowrap;
  overflow-x: auto;
}
body.mobile #packs-filter {
  min-width: 96px;
}
body.mobile #packs-all {
  white-space: nowrap;
}
body.mobile #packs-about {
  display: none;
}
body.mobile .sprite-tile img {
  background: #08090b;
}

/* Chat open beside the Games page: the cards reflow beside it (lead's staging fix, 10-27). On narrower windows the
   floating chat starts below the toolbar, so Play, Undo and the tools stay reachable. */
body:not(.chat-closed):not(.mobile) #games-page,
body:not(.chat-closed):not(.mobile) #guide-page {
  right: 320px;
}
@media (max-width: 1399px) {
  body:not(.chat-closed):not(.mobile) #games-page,
  body:not(.chat-closed):not(.mobile) #guide-page {
    right: 330px;
  }
  body:not(.mobile) .chat {
    top: 43px;
  }
}

/* Resizable panels (10-28, layout.js): one variable per panel edge. These are the defaults for each window size;
   dragging an edge sets the variable on <body>, which wins. Phones keep their own bottom-sheet layout. */
:root {
  --left-w: 210px;
  --right-w: 274px;
  --chat-w: 320px;
  --dock-h: 205px;
}
@media (max-width: 1399px) {
  :root {
    --left-w: 200px;
    --right-w: 260px;
    --chat-w: 330px;
  }
}
@media (max-width: 1150px) {
  :root {
    --left-w: 180px;
    --right-w: 240px;
    --dock-h: 190px;
  }
}
@media (max-height: 700px) {
  :root {
    --dock-h: 160px;
  }
}
/* minmax(…, size): a remembered size never squeezes the game view below 300 × 150 on a smaller window; the panels
   give way first. */
body:not(.mobile) .workspace {
  grid-template-columns: minmax(140px, var(--left-w)) minmax(300px, 1fr) minmax(200px, var(--right-w)) minmax(260px, var(--chat-w));
}
body:not(.mobile).chat-closed .workspace {
  grid-template-columns: minmax(140px, var(--left-w)) minmax(300px, 1fr) minmax(200px, var(--right-w));
}
body:not(.mobile) main {
  grid-template-rows: 43px minmax(150px, 1fr) minmax(110px, var(--dock-h));
}
body:not(.chat-closed):not(.mobile) #games-page,
body:not(.chat-closed):not(.mobile) #guide-page {
  right: var(--chat-w);
}
@media (max-width: 1399px) {
  body:not(.mobile) .workspace,
  body:not(.mobile).chat-closed .workspace {
    grid-template-columns: minmax(140px, var(--left-w)) minmax(300px, 1fr) minmax(200px, var(--right-w));
  }
  body:not(.mobile) .chat {
    width: min(var(--chat-w), calc(100vw - 340px));
  }
}
#splitters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}
.splitter {
  position: fixed;
  pointer-events: auto;
  touch-action: none;
}
.splitter[hidden] {
  display: none;
}
.splitter.cols {
  cursor: col-resize;
}
.splitter.rows {
  cursor: row-resize;
}
.splitter::after {
  content: "";
  position: absolute;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.12s;
}
.splitter.cols::after {
  inset: 0 3px;
}
.splitter.rows::after {
  inset: 3px 0;
}
.splitter:hover::after,
.splitter.dragging::after {
  opacity: 0.85;
}
body.resizing {
  user-select: none;
}
body.resizing-cols,
body.resizing-cols * {
  cursor: col-resize !important;
}
body.resizing-rows,
body.resizing-rows * {
  cursor: row-resize !important;
}
body.resizing #viewport,
body.resizing iframe {
  pointer-events: none;
}
#dock-size {
  /* Stays at the right end even when the tab row scrolls. */
  position: sticky;
  right: -8px;
  background: var(--head);
  box-shadow: -8px 0 8px var(--head);
  flex: none;
  margin-left: 6px;
  width: 26px;
  padding: 4px 0;
  font-size: 12px;
  color: var(--muted);
}
#dock-size:hover {
  color: var(--accent);
}
body.mobile #dock-size {
  display: none;
}
