:root {
  color-scheme: light;
  font-family: "MS Sans Serif", Tahoma, Arial, sans-serif;
  background: #c0c0c0;
  color: #000;
}

* {
  box-sizing: border-box;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: auto;
  background: #c0c0c0;
  font-size: 12px;
}

body[data-view="public"] {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.app-shell {
  width: min(1240px, calc(100vw - 16px));
  min-height: 100vh;
  display: grid;
  align-content: start;
  gap: 8px;
  margin: 0 auto;
  padding: 8px 0 14px;
}

.game-window,
.panel {
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  border-radius: 0;
  background: #c0c0c0;
  box-shadow: 1px 1px 0 #808080;
}

.game-window {
  width: 100%;
  height: min(74vh, 820px);
  min-height: 560px;
  display: grid;
  grid-template-rows: 24px 1fr 42px;
  overflow: hidden;
}

.window-bar,
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.window-bar {
  height: 24px;
  padding: 2px 3px;
  background: #000080;
  color: #fff;
}

.window-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.window-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  display: inline-block;
  border: 1px solid #fff;
  background:
    linear-gradient(90deg, #000 0 2px, transparent 2px 4px, #000 4px 6px, transparent 6px),
    linear-gradient(#fff 0 3px, #c0c0c0 3px 10px, #808080 10px);
}

.window-actions {
  display: flex;
  gap: 2px;
}

.window-actions span {
  width: 16px;
  height: 14px;
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  background: #c0c0c0;
}

.viewport-frame {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #000;
}

.speech-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.speech-message {
  position: absolute;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  transform: translate(-50%, -100%);
  --speech-height: 48px;
}

.speech-message[data-agent="bruno"],
.speech-message.portrait-right {
  flex-direction: row-reverse;
}

.speech-portrait {
  width: var(--speech-height);
  height: var(--speech-height);
  flex: 0 0 var(--speech-height);
  box-sizing: border-box;
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  background: #808080;
  object-fit: cover;
  image-rendering: auto;
  box-shadow: 1px 1px 0 #000;
}

.speech-bubble {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 280px;
  min-width: 116px;
  min-height: 72px;
  box-sizing: border-box;
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  border-radius: 0;
  background: #ffffe1;
  padding: 7px 9px;
  box-shadow: 1px 1px 0 #000;
  color: #000;
  font-size: 12px;
  line-height: 1.25;
}

.speech-text {
  display: block;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 10px;
  height: 10px;
  border-right: 1px solid #404040;
  border-bottom: 1px solid #404040;
  background: #ffffe1;
  transform: translateX(-50%) rotate(45deg);
}

#sims-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  cursor: default;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: #000;
  background: #c0c0c0;
}

.loading.is-hidden {
  display: none;
}

.loading.has-startup-error {
  padding: 20px;
  pointer-events: auto;
}

.startup-error {
  width: min(430px, 100%);
  display: grid;
  gap: 10px;
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  background: #c0c0c0;
  padding: 16px;
  box-shadow: 1px 1px 0 #000;
  line-height: 1.4;
}

.startup-error strong {
  color: #000080;
  font-size: 14px;
}

.control-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 5px 6px;
  border-top: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  background: #c0c0c0;
}

.run-strip {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 5px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 24px;
  min-width: 72px;
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  border-radius: 0;
  background: #c0c0c0;
  color: #000;
  cursor: pointer;
  padding: 2px 10px;
  box-shadow: 1px 1px 0 #000;
}

button:active {
  border-color: #404040 #fff #fff #404040;
  box-shadow: none;
  padding: 3px 9px 1px 11px;
}

button:disabled {
  color: #808080;
  cursor: default;
  text-shadow: 1px 1px 0 #fff;
}

button:disabled:active {
  border-color: #fff #404040 #404040 #fff;
  box-shadow: 1px 1px 0 #000;
  padding: 2px 10px;
}

.ai-console {
  display: grid;
  grid-template-columns: repeat(4, minmax(230px, 1fr));
  gap: 8px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 7px;
}

.compact-panel h2,
.panel h2 {
  margin: -1px -1px 7px;
  padding: 3px 5px;
  background: #000080;
  color: #fff;
  font-size: 12px;
  line-height: 1.2;
}

.panel-title-row h2 {
  flex: 1;
}

.run-state {
  min-width: 82px;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #fff;
  padding: 3px 6px;
  color: #000;
  font-size: 12px;
  text-align: center;
}

label {
  display: grid;
  gap: 4px;
  color: #000;
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  border-radius: 0;
  background: #fff;
  color: #000;
  padding: 3px 5px;
}

input[type="range"] {
  border: 0;
  background: transparent;
  padding: 0;
}

input[type="checkbox"] {
  width: 13px;
  height: 13px;
  margin: 0;
}

textarea {
  min-height: 78px;
  resize: vertical;
  line-height: 1.32;
}

.settings-grid,
.runtime-grid,
.transform-grid,
.color-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 6px;
}

.transform-grid {
  grid-template-columns: repeat(4, minmax(86px, 1fr));
}

.color-grid {
  grid-template-columns: repeat(5, minmax(70px, 1fr));
}

input[type="color"] {
  min-height: 30px;
  padding: 2px;
}

.editor-panel {
  grid-column: span 2;
}

.environment-panel {
  grid-column: span 2;
}

.backup-panel {
  grid-column: span 2;
}

.character-manager-panel {
  grid-column: span 2;
}

.portrait-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  min-height: 74px;
  margin: 6px 0;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #808080;
  padding: 6px;
}

.portrait-item {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
}

.portrait-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border: 1px solid #202020;
}

.portrait-item button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  min-width: 22px;
  height: 22px;
  padding: 0;
  font-size: 16px;
  line-height: 18px;
}

.user-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 6px;
  align-items: end;
}

.primary-chat-panel {
  width: 100%;
}

.user-profile-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) 132px;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}

.user-profile-preview {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #808080;
  color: #fff;
  font-size: 24px;
  font-weight: 700;
}

.user-profile-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.user-profile-fields {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(120px, 0.6fr) minmax(180px, 1fr);
  gap: 8px;
}

.user-profile-row > button {
  min-height: 30px;
}

.user-chat-form label {
  margin: 0;
}

.user-chat-form button {
  min-height: 58px;
}

.transcript li.user strong {
  color: #000080;
}

[hidden] {
  display: none !important;
}

.editor-fieldset {
  min-width: 0;
  margin: 2px 0 7px;
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  padding: 7px;
}

.editor-fieldset legend {
  padding: 0 4px;
}

.range-line {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 6px;
  align-items: center;
}

.camera-zoom-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 6px;
  align-items: center;
}

.camera-zoom-line input[type="number"] {
  min-height: 24px;
  box-sizing: border-box;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #fff;
  padding: 3px 5px;
  text-align: right;
}

#speedValue {
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #fff;
  padding: 3px 4px;
  color: #000;
  text-align: right;
}

.check-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #fff;
  padding: 3px 6px;
  color: #000;
  cursor: pointer;
}

.action-grid,
.button-row,
.memory-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

.button-row button {
  flex: 1 1 110px;
}

.nudge-row {
  display: grid;
  grid-template-columns: repeat(4, 34px);
  gap: 4px;
  justify-content: center;
  margin: 0 0 7px;
}

.nudge-row button {
  width: 34px;
  min-width: 34px;
  height: 28px;
  padding: 0;
  font-size: 16px;
}

.nudge-row button:active {
  padding: 1px 0 0 1px;
}

#backgroundImageInput {
  min-height: 30px;
}

.memory-toolbar {
  align-items: center;
}

.memory-toolbar .check-control {
  flex: 1 1 120px;
}

.memory-toolbar button {
  flex: 1 1 118px;
  min-width: 118px;
}

.memory-textarea {
  min-height: 164px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
}

.api-note {
  margin: 6px 0 0;
  color: #000;
  line-height: 1.3;
}

.transcript-panel,
.event-panel {
  min-height: 230px;
}

.transcript,
.event-log {
  height: 184px;
  margin: 7px 0 0;
  padding: 0 5px;
  overflow: auto;
  list-style: none;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #fff;
}

.transcript li,
.event-log li {
  border-top: 1px dotted #808080;
  padding: 5px 0;
  line-height: 1.32;
}

.transcript li:first-child,
.event-log li:first-child {
  border-top: 0;
}

.transcript strong {
  color: #000080;
}

.event-log {
  color: #000;
}

@media (max-width: 1120px) {
  .ai-console {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: calc(100% - 8px);
    min-height: 480px;
    padding: 4px 0 10px;
  }

  .game-window {
    height: clamp(420px, calc(315px + 20vw), 470px);
    min-height: 420px;
    grid-template-rows: 24px 1fr 62px;
  }

  .public-game-window {
    height: clamp(360px, calc(280px + 24vw), 460px);
    min-height: 360px;
  }

  .control-panel {
    align-items: flex-start;
  }

  .run-strip {
    justify-content: flex-start;
  }

  .run-strip button {
    min-width: 62px;
  }

  .ai-console {
    grid-template-columns: 1fr;
  }

  .settings-grid,
  .runtime-grid,
  .transform-grid,
  .color-grid {
    grid-template-columns: 1fr;
  }

  .editor-panel,
  .environment-panel,
  .backup-panel,
  .character-manager-panel {
    grid-column: auto;
  }

  .user-chat-form {
    grid-template-columns: 1fr;
  }

  .user-profile-row {
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: start;
  }

  .user-profile-preview {
    width: 64px;
    height: 64px;
  }

  .user-profile-fields {
    grid-template-columns: 1fr;
  }

  .user-profile-row > button {
    grid-column: 1 / -1;
  }

  .user-chat-form button {
    min-height: 30px;
  }

  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="number"],
  input[type="search"],
  input[type="url"],
  input[type="file"],
  select,
  textarea {
    font-size: 16px;
  }
}
/* Public Firebase view */
.public-shell {
  max-width: 1180px;
}

.public-game-window {
  width: 100%;
  grid-template-rows: 24px 1fr;
}

.public-live-state {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.public-live-state span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d84135;
  box-shadow: 0 0 0 2px rgba(216, 65, 53, 0.2);
}

.public-chat-panel {
  width: 100%;
}

.public-chat-form {
  margin-bottom: 4px;
}

.public-chat-panel > .api-note {
  margin: 4px 0 8px;
}

.public-chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.queue-state {
  font-size: 12px;
  font-weight: 700;
  color: #39423b;
}

.public-transcript {
  display: flex;
  flex-direction: column;
  gap: 7px;
  height: min(30vh, 280px);
  min-height: 150px;
  margin: 6px 0 0;
  padding: 10px;
  overflow-y: auto;
  list-style: none;
  background: #e8ece6;
  border: 1px solid #798379;
}

.public-message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: min(82%, 720px);
}

.public-message.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.public-message-portrait {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  aspect-ratio: 1;
  overflow: hidden;
  background: #5f6d63;
  color: #fff;
  border: 1px solid #414a43;
  font-weight: 700;
}

.public-message-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.public-message-content {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 7px 9px;
  background: #fff;
  border: 1px solid #899287;
}

.user-message .public-message-content {
  background: #dfe9df;
}

.public-message-content strong {
  font-size: 11px;
}

.public-message-content span {
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.public-profile-row {
  margin: 8px 0 12px;
}

body[data-view="public"] #sims-canvas {
  cursor: default;
}

body[data-view="public"] .loading.has-startup-error {
  background: rgba(192, 192, 192, 0.78);
}

.age-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  background: rgba(0, 0, 0, 0.82);
}

.age-gate[hidden] {
  display: none;
}

.age-gate-window {
  width: min(660px, 100%);
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  background: #c0c0c0;
  box-shadow: 2px 2px 0 #000;
}

.age-gate-content {
  padding: 16px;
  font-size: 14px;
  line-height: 1.45;
}

.age-gate-content h1 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0;
}

.age-gate-content p {
  margin: 0 0 11px;
}

.age-gate-warning {
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  background: #ffffe1;
  padding: 10px;
  font-weight: 700;
}

.age-gate-content ul {
  display: grid;
  gap: 7px;
  margin: 0 0 12px;
  padding-left: 22px;
}

.age-gate-confirmation {
  font-weight: 700;
}

.age-gate-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.age-gate-buttons button {
  min-height: 34px;
}

#ageGateAccept {
  border-color: #fff #202020 #202020 #fff;
  font-weight: 700;
}

.age-gate-denied {
  min-height: 180px;
  align-content: center;
  text-align: center;
}

.firebase-admin-panel {
  width: 100%;
}

@media (max-width: 700px) {
  .public-message {
    max-width: 94%;
  }

  .public-profile-row {
    align-items: stretch;
  }

  .age-gate {
    place-items: start center;
    padding: 6px;
  }

  .age-gate-content {
    padding: 12px;
    font-size: 13px;
  }

  .age-gate-content h1 {
    font-size: 17px;
  }

  .age-gate-buttons {
    display: grid;
    grid-template-columns: 1fr;
  }

  .age-gate-buttons button {
    width: 100%;
    min-height: 40px;
    font-size: 16px;
  }
}
