:root {
  --bg: #151412;
  --panel: #22201d;
  --panel-2: #2b2924;
  --panel-3: #353129;
  --line: #464136;
  --text: #f4efe4;
  --muted: #b7ad9a;
  --soft: #857b69;
  --accent: #41d0b8;
  --accent-2: #f2c14e;
  --danger: #ff6b6b;
  --ok: #8bd46e;
  --shadow: rgba(0, 0, 0, 0.35);
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  overflow: hidden;
}

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

button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #312e28;
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  background: #38342c;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.primary,
.mode-btn.active,
.bottom-tab.active {
  border-color: rgba(65, 208, 184, 0.75);
  background: #214b43;
  color: #f4fffb;
}

button.small {
  min-height: 26px;
  padding: 0 8px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #1d1b18;
  box-shadow: 0 2px 18px var(--shadow);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 132px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #c98c3d;
  color: #17130c;
  font-weight: 900;
  text-decoration: none;
}

.brand-mark:hover,
.brand-mark:focus-visible {
  background: #e0a247;
  color: #17130c;
  outline: 2px solid rgba(65, 208, 184, 0.75);
  outline-offset: 2px;
}

.toolbar,
.mode-switch,
.scene-actions,
.test-controls,
.bottom-tabs,
.future-exports {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.mode-switch {
  justify-content: flex-end;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(184px, 15vw, 208px) minmax(420px, 1fr) clamp(248px, 20vw, 286px);
  min-height: 0;
}

.panel {
  min-height: 0;
  overflow: auto;
  padding: 10px;
  background: var(--panel);
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin: 10px 0 8px;
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 7px 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.text-input,
select,
textarea,
input[type="number"],
input[type="text"],
input[type="url"],
input[type="color"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #171613;
  color: var(--text);
  padding: 6px 8px;
}

input[type="color"] {
  height: 32px;
  padding: 3px;
}

textarea {
  min-height: 64px;
  resize: vertical;
}

.project-title {
  font-size: 15px;
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 7px 0;
  color: var(--muted);
  font-size: 13px;
}

.check-row.compact {
  margin: 0;
}

.scene-list {
  display: grid;
  gap: 6px;
}

.scene-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 7px;
  cursor: pointer;
}

.scene-item.active {
  border-color: var(--accent);
  background: #233b36;
}

.scene-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.scene-meta {
  color: var(--muted);
  font-size: 12px;
}

.start-pill,
.badge {
  border-radius: 999px;
  background: #3d3628;
  color: var(--accent-2);
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
}

.scene-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.scene-actions button:last-child {
  grid-column: 1 / -1;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: #11100e;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #1a1815;
}

#statusText {
  margin-left: 10px;
  color: var(--muted);
  font-size: 13px;
}

.stage-scroll {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.stage-frame {
  width: min(100%, 1120px);
  aspect-ratio: 16 / 9;
  border: 1px solid #5b5346;
  border-radius: 8px;
  background: #050505;
  box-shadow: 0 18px 60px var(--shadow);
  overflow: hidden;
}

#stageCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.properties-panel {
  display: grid;
  gap: 8px;
}

.prop-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.prop-row {
  display: grid;
  gap: 5px;
}

.prop-row.full {
  grid-column: 1 / -1;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.button-row button.danger {
  border-color: rgba(255, 107, 107, 0.7);
  color: #ffd8d8;
}

.subpanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 8px;
}

.subpanel h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.action-card,
.asset-card,
.inventory-row,
.variable-row,
.map-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1b1a17;
  padding: 8px;
}

.action-card {
  display: grid;
  gap: 7px;
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid rgba(70, 65, 54, 0.7);
  padding-top: 7px;
  margin-top: 7px;
}

.tool-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-panel {
  border-top: 1px solid var(--line);
  background: var(--panel);
  min-height: 118px;
  max-height: 184px;
  overflow: auto;
}

.bottom-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 0;
}

.bottom-tabs {
  min-width: 0;
}

.bottom-quick-action {
  flex: 0 0 auto;
  border-color: rgba(242, 193, 78, 0.65);
  color: #ffe6a3;
}

.bottom-content {
  padding: 8px 10px 10px;
}

.asset-grid,
.inventory-grid,
.variable-grid,
.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 8px;
}

.asset-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.asset-thumb {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #100f0d;
  overflow: hidden;
  color: var(--accent-2);
  font-weight: 900;
}

.asset-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.asset-title,
.map-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.asset-meta,
.map-meta {
  color: var(--muted);
  font-size: 12px;
}

.inventory-row textarea {
  min-height: 42px;
}

.player-inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 52px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: #171613;
}

.inv-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #2a261e;
  padding: 5px 10px;
  font-size: 13px;
}

.inv-chip img {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  object-fit: cover;
}

.hidden {
  display: none !important;
}

.export-dialog {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.export-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.export-check {
  margin: 14px 0;
}

.future-exports {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.message-box {
  width: min(720px, calc(100vw - 28px));
  border: 1px solid #6d614f;
  border-radius: 10px;
  background: #1f1c17;
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

.message-speaker {
  min-height: 20px;
  color: var(--accent-2);
  font-weight: 700;
}

.message-box h2 {
  margin: 3px 0 8px;
  font-size: 22px;
}

.message-box p {
  margin: 0;
  color: #e9dfcd;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .topbar,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell {
    min-height: auto;
  }

  .panel {
    max-height: none;
    border: 0;
  }

  .stage-scroll {
    min-height: 420px;
  }

  .bottom-panel {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .toolbar,
  .mode-switch,
  .scene-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .export-grid,
  .prop-grid {
    grid-template-columns: 1fr;
  }
}
