:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  font-synthesis: none;
  --ink: #080c10;
  --hud-inset: clamp(10px, 1.6vw, 24px);
  --hud-top: max(var(--hud-inset), env(safe-area-inset-top));
  --hud-bottom: max(var(--hud-inset), env(safe-area-inset-bottom));
  --sidebar: #101820;
  --surface: #15222b;
  --surface-raised: #1d2d37;
  --line: #324955;
  --line-strong: #62808b;
  --text: #eff8fa;
  --muted: #aec3cd;
  --secondary: #a1b6c0;
  --accent: #58e9f0;
  --accent-hover: #9df5fb;
  --accent-ink: #071619;
  --accent-soft: #163840;
  --danger: #ff6471;
  --coral-rail: #ff6471;
  --cyan-rail: #56b8c4;
  --overlay: #0b141eeb;
  --overlay-hover: #1b2b35;
  --overlay-ink: #f0f8fb;
  --code-font: ui-monospace, "Cascadia Code", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; overflow: hidden; background: var(--ink); color: var(--text); }
::selection { background: var(--accent); color: var(--accent-ink); }
textarea, input { caret-color: var(--accent); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; }
a { color: inherit; text-decoration: none; }
button, a { touch-action: manipulation; }
button:disabled { cursor: default; opacity: .48; }
a[aria-disabled="true"] { opacity: .48; pointer-events: none; }
button:hover:enabled, .control:hover:not([aria-disabled="true"]) { border-color: var(--line-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
svg { width: 1.2rem; height: 1.2rem; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }
.svg-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; margin: -1px; clip-path: inset(50%); overflow: hidden; }
.skip:focus { position: fixed; z-index: 5; top: .5rem; left: .5rem; padding: .8rem; background: var(--surface-raised); }

.masthead {
  position: absolute;
  z-index: 4;
  inset: var(--hud-top) var(--hud-inset) auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.brand, .masthead-right { display: flex; align-items: center; }
.brand {
  gap: 8px;
  min-height: 40px;
  padding: 7px 17px 7px 10px;
  color: var(--overlay-ink);
  font-family: var(--code-font);
  font-size: clamp(15px, 2vw, 20px);
  font-weight: 700;
  letter-spacing: .055em;
  text-transform: uppercase;
  pointer-events: auto;
}
.brand-accent { color: var(--accent); }
.brand-mark, .assistant-mark { display: grid; place-items: center; flex-shrink: 0; color: var(--accent); }
.brand-mark { width: 25px; height: 27px; }
.brand-mark svg { width: 23px; height: 23px; stroke-width: 1.2; }
.masthead-right { gap: 6px; pointer-events: auto; }
.control, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  font-size: 12px;
  white-space: nowrap;
}
.icon-button { width: 38px; min-width: 38px; padding: 0; }
.control svg, .icon-button svg { width: 16px; height: 16px; }
.control:focus-visible, .icon-button:focus-visible { outline-offset: 2px; }
.control.primary, .send-button { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.control.danger { color: var(--danger); border-color: var(--coral-rail); }
.control.primary:hover:enabled, .send-button:hover:enabled { background: var(--accent-hover); border-color: var(--accent-hover); }

/* Two inset shapes form a one-pixel rail without clipping the keyboard outline. */
:is(.brand, .scene-name, .masthead .control, .workspace .control, .walk-pad button) {
  --cut: 9px;
  --plate: var(--overlay);
  --rail: var(--cyan-rail);
  position: relative;
  isolation: isolate;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--overlay-ink);
}
:is(.brand, .scene-name, .masthead .control, .workspace .control, .walk-pad button)::before,
:is(.brand, .scene-name, .masthead .control, .workspace .control, .walk-pad button)::after {
  position: absolute;
  z-index: -2;
  inset: 0;
  background-image: linear-gradient(var(--rail), var(--rail));
  clip-path: polygon(var(--cut) 0, 100% 0, 100% calc(100% - var(--cut)), calc(100% - var(--cut)) 100%, 0 100%, 0 var(--cut));
  content: "";
  pointer-events: none;
}
:is(.brand, .scene-name, .masthead .control, .workspace .control, .walk-pad button)::after {
  z-index: -1;
  inset: 1px;
  background: var(--plate);
}
.masthead .brand { --cut: 12px; --rail: var(--accent); }
.masthead .control:not(.primary), .workspace .scene-name { --rail: var(--coral-rail); }
.masthead .control.primary {
  --rail: var(--accent);
  --plate: #185862;
  color: #e0fdff;
  background: none;
}
:is(.masthead .control, .workspace .control, .walk-pad button):hover:enabled {
  --plate: var(--overlay-hover);
  --rail: var(--accent);
  background: none;
}
.masthead .control.primary:hover:enabled { --plate: #216b76; background: none; }
.viewport .walk-pad button { --rail: var(--coral-rail); color: var(--danger); }
.viewport .walk-pad button:hover:enabled { --plate: #35242c; --rail: #ff8c96; }

.studio, .workspace { position: relative; height: 100dvh; overflow: hidden; }
.library-content { display: grid; gap: 18px; padding: 16px; }
.library-section { min-width: 0; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 0 5px 8px; }
.section-title h2 { margin: 0; color: var(--text); font-size: 14px; font-weight: 650; }
.section-title .icon-button { width: 34px; min-width: 34px; min-height: 34px; background: transparent; }
.world-list, .artifact-list { display: grid; gap: 4px; max-height: 260px; overflow: auto; }
.world-entry, .artifact-entry, .object-entry {
  display: flex;
  width: 100%;
  gap: 9px;
  align-items: center;
  min-width: 0;
  min-height: 41px;
  padding: 8px 10px;
  border-radius: 0;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  color: var(--muted);
  font-size: 13px;
}
button.world-entry:hover, button.object-entry:hover { background: var(--surface); }
.world-entry[aria-current="true"] {
  border-color: var(--cyan-rail);
  box-shadow: inset 2px 0 var(--accent);
  color: var(--text);
  background: var(--accent-soft);
}
.world-entry svg, .artifact-entry svg, .object-entry svg { width: 16px; height: 16px; color: var(--accent); }
.entry-text { min-width: 0; flex: 1; }
.entry-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-text small { display: block; color: var(--muted); font-size: 10.5px; line-height: 1.4; }
.artifact-entry { padding: 8px; gap: 7px; }
.artifact-entry input, .attachment-option input { max-width: fit-content; accent-color: var(--accent); }
.artifact-entry img { display: block; width: 27px; height: 27px; object-fit: cover; border-radius: 1px; }
.artifact-entry button { padding: 0; border: 0; width: 28px; min-width: 28px; height: 28px; background: transparent; }
.artifact-entry button svg { width: 13px; height: 13px; color: var(--muted); }
.upload-tile {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  text-align: left;
}
.upload-tile:hover { background: var(--surface); color: var(--text); }
.upload-tile svg { color: var(--accent); width: 17px; height: 17px; }
.library-footer { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.library-footer .control { justify-content: flex-start; background: transparent; color: var(--muted); white-space: normal; text-align: left; }

.workspace-heading {
  position: absolute;
  z-index: 3;
  inset: calc(var(--hud-top) + 57px) var(--hud-inset) auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.scene-name {
  min-width: 0;
  max-width: min(680px, 70%);
  padding: 11px 18px 11px 14px;
}
.scene-name::before { box-shadow: inset 0 -2px var(--danger); }
.workspace-heading h1 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: 0;
  font-size: clamp(20px, 2.55vw, 37px);
  font-weight: 660;
  line-height: 1.08;
  letter-spacing: -.025em;
  overflow-wrap: anywhere;
}
.workspace-actions { display: flex; gap: 6px; flex-shrink: 0; pointer-events: auto; }
.viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at 53% 33%, #123140 0%, #0b1c27 56%, #080d13 100%);
}
.viewport::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 48%, #03080d70 100%);
  content: "";
  pointer-events: none;
}
.viewport canvas { display: block; width: 100%; height: 100%; min-height: 0; outline-offset: -4px; cursor: grab; touch-action: none; }
.viewport canvas:active { cursor: grabbing; }
.viewport-caption { display: flex; align-items: center; gap: 6px; margin-top: 7px; color: var(--muted); font-size: 12px; }
.viewport-caption svg { width: 14px; height: 14px; color: var(--danger); }
.viewer-status { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(280px, 85%); text-align: center; color: var(--overlay-ink); font-size: 13px; pointer-events: none; z-index: 2; }
.workspace :is(.pet-call, .camera-reset, .flight-toggle, .avatar-open), .walk-pad { position: absolute; z-index: 2; }
.pet-call { top: calc(var(--hud-top) + 103px); right: var(--hud-inset); }
.camera-reset { right: var(--hud-inset); bottom: calc(var(--hud-bottom) + 46px); }
.flight-toggle { right: var(--hud-inset); bottom: calc(var(--hud-bottom) + 92px); }
.avatar-open { right: var(--hud-inset); bottom: calc(var(--hud-bottom) + 138px); }
.flight-toggle svg { rotate: -90deg; }
.workspace .flight-toggle[aria-pressed="true"] { --rail: var(--cyan-rail); color: var(--accent); }
.flight-toggle[aria-pressed="true"] svg { rotate: 90deg; }
.viewport .walk-pad button:active { --plate: #402330; --rail: var(--danger); }
.walk-pad { left: var(--hud-inset); bottom: var(--hud-bottom); display: grid; grid-template-columns: repeat(3, 42px); gap: 5px; }
.walk-pad button { width: 42px; min-width: 42px; height: 42px; touch-action: none; }
.walk-forward { grid-area: 1 / 2; }
.walk-left { grid-area: 2 / 1; }
.walk-back { grid-area: 2 / 2; }
.walk-right { grid-area: 2 / 3; }
.flight-up { grid-area: 1 / 1; }
.flight-down { grid-area: 1 / 3; }
.flight-down svg { rotate: 180deg; }
.viewport .walk-pad :is(.flight-up, .flight-down) { --rail: var(--cyan-rail); color: var(--accent); }
.walk-left svg { rotate: -90deg; }
.walk-back svg { rotate: 180deg; }
.walk-right svg { rotate: 90deg; }
.workspace-footer {
  position: absolute;
  z-index: 3;
  inset: auto var(--hud-inset) var(--hud-bottom);
  display: flex;
  justify-content: flex-end;
  align-items: end;
  gap: 10px;
  pointer-events: none;
}
.workspace-footer .control { pointer-events: auto; }
#camera-help {
  max-width: min(400px, calc(100% - 305px));
  padding: 8px 11px;
  border-left: 1px solid var(--coral-rail);
  background: var(--overlay);
  color: var(--muted);
  font-size: 12px;
}
#camera-help kbd { font-family: var(--code-font); font-size: .95em; font-weight: 700; color: var(--accent); }
.walk-keyboard { display: inline; }

dialog.conversation, dialog.library {
  position: fixed;
  inset: var(--hud-top) var(--hud-inset) auto auto;
  margin: 0;
  width: min(420px, calc(100% - 2 * var(--hud-inset)));
  max-height: calc(100dvh - var(--hud-top) - var(--hud-bottom));
  overscroll-behavior: contain;
}
dialog.conversation[open] {
  display: grid;
  grid-template-rows: auto minmax(48px, 1fr) auto;
  height: min(760px, calc(100dvh - var(--hud-top) - var(--hud-bottom)));
}
dialog.library { inset-inline: var(--hud-inset) auto; }
dialog:is(.conversation, .library)::backdrop { background: #04090d68; }
.conversation-heading { display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.assistant-mark {
  width: 32px;
  height: 32px;
  background: var(--accent-soft);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.assistant-mark svg { width: 17px; height: 17px; }
.conversation-heading h2 { margin: 0; font-size: 21px; font-weight: 650; line-height: 1.1; }
.conversation-heading p { margin: 4px 0 0; font-size: 12px; color: var(--accent); }
.provider-button { margin-left: auto; background: transparent; }
.transcript { overflow-y: auto; overscroll-behavior-y: contain; padding: 20px 16px; scrollbar-color: var(--line-strong) transparent; }
.chat-welcome { max-width: 300px; margin: clamp(8px, 4vh, 40px) auto 0; }
.chat-welcome h3 { margin: 9px 0 7px; font-size: 28px; font-weight: 650; line-height: 1.09; letter-spacing: -.025em; }
.chat-welcome p { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.prompt-list { display: grid; gap: 6px; margin-top: 16px; }
.prompt-list button {
  display: flex;
  align-items: center;
  text-align: left;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11.5px;
}
.prompt-list button:hover { color: var(--text); background: var(--surface); }
.prompt-list button svg { width: 13px; height: 13px; color: var(--accent); rotate: 90deg; }
.message { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; margin-bottom: 13px; }
.message[data-role="user"] span { color: var(--accent); }
.message span { color: var(--muted); font-size: 11px; font-weight: 620; }
.message p {
  max-width: 100%;
  padding: 8px 10px;
  margin: 0;
  border-left: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message[data-role="user"] p { background: var(--accent-soft); border-left-color: var(--accent); }
.composer { display: grid; gap: 8px; padding: 13px 15px 15px; border-top: 1px solid var(--line); }
.composer-field { background: var(--surface); border: 1px solid var(--line-strong); border-radius: 0; padding: 8px; }
.composer-field:focus-within { border-color: var(--accent); }
.composer-field textarea { width: 100%; min-height: 62px; max-height: 155px; padding: 7px; resize: vertical; display: block; color: var(--text); border: 0; outline: 0; background: transparent; font-size: 14px; }
.composer-field textarea::placeholder { color: var(--muted); }
.composer-field > div { display: flex; gap: 5px; align-items: center; }
.composer-field .icon-button { border-color: transparent; background: transparent; color: var(--muted); }
#new-location-mode { background: transparent; border-color: transparent; color: var(--muted); }
#new-location-mode[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--cyan-rail); }
.send-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  min-width: 38px;
  margin-left: auto;
  padding: 7px 13px;
  flex-shrink: 0;
  border: 1px solid;
  border-radius: 0;
  font-size: 12px;
}
.send-button:not(:focus-visible) {
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.send-button svg { width: 19px; height: 19px; stroke-width: 1.8; }
.compose-note { margin: 0; color: var(--secondary); font-size: 12px; line-height: 1.45; }
.attachment-status { color: var(--accent); font-size: 12px; overflow-wrap: anywhere; }

dialog {
  color: var(--text);
  width: min(470px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--cyan-rail);
  border-radius: 0;
  background: var(--sidebar);
  clip-path: polygon(13px 0, 100% 0, 100% calc(100% - 13px), calc(100% - 13px) 100%, 0 100%, 0 13px);
  scrollbar-color: var(--line-strong) var(--sidebar);
}
dialog::backdrop { background: #04090dc2; }
.dialog-heading, .conversation-heading {
  background-color: var(--sidebar);
  background-image:
    linear-gradient(135deg, transparent 44%, var(--cyan-rail) 45% 51%, transparent 52%),
    linear-gradient(90deg, var(--sidebar), #162630);
  background-position: -1px -1px, center;
  background-size: 15px 15px, auto;
  background-repeat: no-repeat;
}
.dialog-heading::after, .conversation-heading::after {
  position: absolute;
  top: 0;
  right: 0;
  width: 13px;
  height: 13px;
  background: var(--danger);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
  content: "";
  pointer-events: none;
}
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 17px; border-bottom: 1px solid var(--line); }
.dialog-heading h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; font-size: 24px; font-weight: 650; line-height: 1.15; }
.dialog-content { display: grid; gap: 12px; padding: 16px 17px 19px; font-size: 13px; }
.dialog-content > p, .dialog-content form p { margin: 0; color: var(--muted); }
.dialog-content label { display: grid; gap: 5px; color: var(--muted); min-width: 0; }
.dialog-content input, .dialog-content textarea, .dialog-content select {
  width: 100%;
  min-width: 0;
  min-height: 35px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}
.dialog-content input[type="file"]::file-selector-button {
  margin-right: 8px;
  padding: 6px 8px;
  border: 1px solid var(--cyan-rail);
  border-radius: 0;
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.dialog-content input[type="color"] { padding: 4px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 3px; }
.form-error { color: var(--danger); font-size: 12px; }
.export-options a { justify-content: flex-start; min-height: 58px; white-space: normal; }
.export-options a small { display: block; color: var(--muted); font-size: 11px; }
#objects { display: grid; gap: 3px; }
#objects > p { margin: 3px 0 7px; color: var(--muted); }
#model-prompt { justify-self: start; }
#world-details { border-top: 1px solid var(--line); padding-top: 10px; }
#world-details summary { cursor: pointer; color: var(--muted); }
#rename-form { margin-top: 11px; display: grid; gap: 7px; }
#inspect-content :is(img, video) { display: block; max-width: 100%; max-height: 38vh; margin: 0 auto; border-radius: 1px; }
.inspector-form { display: grid; gap: 10px; }
.inspector-coordinates { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.toast { position: fixed; z-index: 4; bottom: 18px; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 28px); padding: 10px 14px; border: 1px solid var(--cyan-rail); background: var(--surface-raised); color: var(--text); font-size: 13px; pointer-events: none; }
.toast[data-error="true"] { color: var(--danger); border-color: var(--coral-rail); }

@media (max-width: 680px) {
  .brand { padding: 7px 12px 7px 7px; font-size: 14px; letter-spacing: .04em; }
  .workspace-actions .control, .masthead-right .account-button { width: 44px; min-height: 44px; padding: 0; }
  .workspace-actions .control span, .masthead-right .account-button span { display: none; }
  .worlds-section, .materials-section { min-width: 0; }
  dialog.conversation, dialog.library { inset: auto var(--hud-inset) var(--hud-bottom); width: auto; max-height: calc(100dvh - 66px); }
  dialog.conversation[open] { height: min(700px, calc(100dvh - 66px)); }
  .chat-welcome { margin: 5px 0 0; }
  #camera-help { position: absolute; bottom: 98px; left: 0; max-width: min(240px, calc(100% - 116px)); }
}
@media (max-width: 440px) {
  .masthead-right .control { min-height: 44px; }
  .masthead-right .control:not(.account-button) { padding-inline: 8px; }
  .masthead-right { gap: 4px; }
  .workspace-actions { gap: 4px; }
  .scene-name { max-width: calc(100% - 104px); }
  .chat-welcome h3 { font-size: 26px; }
  .workspace-footer .control { padding-inline: 8px; }
  .send-button { padding-inline: 8px; }
  .send-button span { display: none; }
}
@media (max-width: 350px) {
  .brand { justify-content: center; width: 44px; min-height: 44px; padding: 7px; }
  .brand > span:last-child { display: none; }
  .masthead-right .control { font-size: 11px; gap: 4px; }
}
@media (pointer: coarse) {
  .walk-keyboard { display: none; }
  .walk-pad { grid-template-columns: repeat(3, 44px); }
  .walk-pad button { width: 44px; min-width: 44px; height: 44px; }
  .workspace-footer { min-height: 44px; }
  .workspace .control { min-height: 44px; }
  .camera-reset { bottom: calc(var(--hud-bottom) + 52px); }
  .flight-toggle { bottom: calc(var(--hud-bottom) + 104px); }
  .avatar-open { bottom: calc(var(--hud-bottom) + 156px); }
}
