:root {
  --bg-dark: #0f141c;
  --bg-panel: #161d28;
  --bg-card: #1d2635;
  --bg-hover: #263246;
  --border: #2a374b;
  --border-light: #384963;
  --text: #e6edf6;
  --text-muted: #93a3b8;
  --primary: #e06d3b;
  --primary-hover: #f27e4b;
  --accent: #3fb984;
  --danger: #e04f5f;
  --warning: #e5a93b;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Consolas', 'Courier New', monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* TOPBAR */
.topbar {
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
  border-radius: 6px;
  background: var(--bg-card);
  padding: 2px;
  border: 1px solid var(--border-light);
}

.brand h1 {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.2px;
}

.brand p {
  font-size: 11px;
  color: var(--text-muted);
}

.main-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-dark);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(224, 109, 59, 0.35);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* BUTTONS & INPUTS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: #4f6789;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11.5px;
}

.btn-block {
  width: 100%;
  padding: 9px 12px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary-hover);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #253347;
  border-color: #3a4f6d;
  color: #e2ecf9;
}

.btn-play {
  background: var(--accent);
  border-color: #52d199;
  color: #092217;
  font-weight: 700;
}

.btn-play:hover {
  background: #4cd096;
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  background: rgba(224, 79, 95, 0.16);
  border-color: var(--danger);
  color: #ff99a4;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-danger-ghost {
  border-color: rgba(224, 79, 95, 0.4);
  color: #ff99a4;
}

input[type="text"],
input[type="number"],
input[type="search"],
select,
textarea {
  background: var(--bg-dark);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 6px 9px;
  border-radius: 5px;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
}

/* TAB PANELS & LAYOUT */
.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tab-panel.active {
  display: flex;
}

.studio-layout {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.sidebar,
.inspector {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--border);
}

.inspector {
  border-left: 1px solid var(--border);
}

.panel-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.panel-head h2 {
  font-size: 13.5px;
  font-weight: 700;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
}

.badge.custom {
  background: rgba(63, 185, 132, 0.16);
  border-color: var(--accent);
  color: #6ee7b7;
}

/* FILTER BAR & ASSET GRID */
.filter-bar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 11.5px;
  cursor: pointer;
}

.pill:hover {
  color: var(--text);
}

.pill.active {
  background: var(--primary);
  border-color: var(--primary-hover);
  color: #fff;
  font-weight: 600;
}

.chk-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  cursor: pointer;
}

.chk-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.asset-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-content: start;
}

.asset-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  position: relative;
  transition: all 0.12s ease;
}

.asset-card:hover {
  border-color: #546e91;
  background: var(--bg-hover);
}

.asset-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(224, 109, 59, 0.35);
}

.asset-card.is-custom::after {
  content: '★';
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 11px;
  color: var(--accent);
}

.asset-thumb {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    linear-gradient(45deg, #151c26 25%, transparent 25%),
    linear-gradient(-45deg, #151c26 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151c26 75%),
    linear-gradient(-45deg, transparent 75%, #151c26 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: #1c2533;
  border-radius: 4px;
  overflow: hidden;
}

.asset-thumb canvas {
  image-rendering: pixelated;
  max-width: 52px;
  max-height: 52px;
  object-fit: contain;
}

.asset-id {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-sub {
  font-size: 10px;
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* CENTER WORKSPACE & PIXEL EDITOR */
.center-work {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #0b0f16;
}

.work-toolbar {
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.group-label {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-right: 2px;
}

.tool-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 9px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
}

.tool-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.tool-btn.active {
  background: var(--primary);
  border-color: var(--primary-hover);
  color: #fff;
  font-weight: 600;
}

.canvas-stage {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}

.canvas-wrap {
  position: relative;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  border: 2px solid var(--border-light);
  background-image:
    linear-gradient(45deg, #171f2a 25%, transparent 25%),
    linear-gradient(-45deg, #171f2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #171f2a 75%),
    linear-gradient(-45deg, transparent 75%, #171f2a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #212b3a;
  line-height: 0;
}

#px-editor-canvas {
  image-rendering: pixelated;
  display: block;
  cursor: crosshair;
}

#px-grid-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  image-rendering: pixelated;
}

/* PALETTE BAR */
.palette-bar {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.color-current {
  display: flex;
  align-items: center;
  gap: 6px;
}

#px-color-picker {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  padding: 0;
}

#px-color-hex {
  width: 82px;
  font-family: var(--mono);
  text-transform: uppercase;
}

.pal-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.swatch:hover {
  transform: scale(1.18);
  z-index: 2;
}

.swatch.active {
  outline: 2px solid #fff;
  transform: scale(1.15);
}

/* INSPECTOR */
.inspector-body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-row label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.input-pair {
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-pair > * {
  flex: 1;
}

.input-pair > span,
.input-pair > button {
  flex: 0 0 auto;
}

.preview-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preview-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.preview-box span {
  font-size: 11px;
  color: var(--text-muted);
}

.preview-checker {
  width: 100%;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-image:
    linear-gradient(45deg, #151c26 25%, transparent 25%),
    linear-gradient(-45deg, #151c26 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151c26 75%),
    linear-gradient(-45deg, transparent 75%, #151c26 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: #1c2533;
  border-radius: 4px;
  overflow: hidden;
}

.preview-checker canvas {
  image-rendering: pixelated;
  max-width: 88px;
  max-height: 88px;
  object-fit: contain;
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.file-label {
  cursor: pointer;
  text-align: center;
}

/* TAB 2: MAP EDITOR */
.full-select {
  width: 100%;
}

.card-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-section h3 {
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
}

.muted-note {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.45;
}

.expand-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.expand-grid > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.expand-grid label {
  font-size: 10.5px;
  color: var(--text-muted);
}

.expand-grid input {
  width: 100%;
  padding: 4px 6px;
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mode-btn {
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.mode-btn:hover {
  background: var(--bg-hover);
}

.mode-btn.active {
  background: var(--primary);
  border-color: var(--primary-hover);
  color: #fff;
}

.grow-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.map-viewport {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  background: #090d13;
}

#map-editor-canvas {
  image-rendering: pixelated;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  border: 2px solid var(--border-light);
  cursor: crosshair;
  margin: auto;
}

.palette-mini-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  overflow: hidden;
}

.palette-item:hover {
  background: var(--bg-hover);
}

.palette-item.active {
  border-color: var(--primary);
  background: rgba(224, 109, 59, 0.18);
}

.palette-item canvas {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  object-fit: contain;
  flex-shrink: 0;
  background: #121822;
  border-radius: 3px;
}

.palette-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prop-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.prop-card h4 {
  font-size: 13px;
  color: #fff;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

/* TAB 3: PROPOSALS & ARCHITECTURE DOC */
.doc-container {
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.doc-hero {
  background: linear-gradient(135deg, #1d283a 0%, #151d29 100%);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 20px;
}

.doc-hero h2 {
  font-size: 18px;
  margin-bottom: 6px;
  color: #fff;
}

.doc-hero p {
  color: var(--text-muted);
  line-height: 1.5;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}

.doc-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

.doc-card h3 {
  font-size: 15px;
  color: var(--primary-hover);
  margin-bottom: 12px;
}

.doc-card ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  line-height: 1.55;
}

.doc-card code {
  font-family: var(--mono);
  background: var(--bg-card);
  padding: 1px 5px;
  border-radius: 4px;
  color: #8ce99a;
}

/* TOAST STACK */
.toast-stack {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: #1e293b;
  border-left: 4px solid var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 12.5px;
  animation: slideIn 0.2s ease;
}

.toast.error {
  border-left-color: var(--danger);
}

@keyframes slideIn {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
