/* Editor de Biomas — página dedicada (dark, alinhada ao HUD do jogo). */

:root {
  --be-bg: #060a14;
  --be-panel: rgba(9, 15, 28, 0.92);
  --be-panel-border: rgba(148, 163, 184, 0.22);
  --be-text: #e2e8f0;
  --be-text-dim: #94a3b8;
  --be-accent: #38bdf8;
  --be-accent-soft: rgba(56, 189, 248, 0.16);
  --be-danger: #f87171;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--be-bg);
  color: var(--be-text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
}

.be-app {
  display: grid;
  grid-template-columns: 250px 1fr 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header header"
    "roster preview sidebar";
  gap: 10px;
  height: 100vh;
  padding: 10px;
}

/* ---- Header ---- */
.be-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--be-panel);
  border: 1px solid var(--be-panel-border);
  border-radius: 12px;
}

.be-header__meta {
  min-width: 0;
}

.be-header__title {
  margin: 0;
  font-size: 17px;
}

.be-header__subtitle {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--be-text-dim);
}

.be-status {
  flex: 1 1 auto;
  text-align: right;
  font-size: 12px;
  color: var(--be-text-dim);
}

.be-header__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---- Botões / inputs ---- */
.be-btn {
  margin: 0;
  padding: 6px 12px;
  border-radius: 7px;
  border: 1px solid var(--be-panel-border);
  background: rgba(15, 23, 42, 0.85);
  color: var(--be-text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.be-btn:hover {
  border-color: var(--be-accent);
}

.be-btn--primary {
  background: rgba(12, 74, 110, 0.75);
  border-color: rgba(56, 189, 248, 0.5);
}

.be-btn--danger:hover {
  border-color: var(--be-danger);
  color: var(--be-danger);
}

.be-btn--link {
  background: transparent;
}

.be-input,
.be-select,
.be-number {
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid var(--be-panel-border);
  background: rgba(2, 6, 16, 0.6);
  color: var(--be-text);
  font: inherit;
  font-size: 12px;
}

.be-number {
  width: 88px;
}

.be-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--be-text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.be-hint {
  font-size: 11px;
  color: var(--be-text-dim);
}

/* ---- Roster ---- */
.be-roster {
  grid-area: roster;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--be-panel);
  border: 1px solid var(--be-panel-border);
  border-radius: 12px;
  min-height: 0;
}

.be-roster__tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: rgba(2, 6, 16, 0.5);
  border-radius: 8px;
}

.be-tab {
  flex: 1;
  padding: 6px 2px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--be-text-dim);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.be-tab.is-active {
  color: var(--be-text);
  background: var(--be-accent-soft);
  border-color: rgba(56, 189, 248, 0.35);
}

.be-roster__list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.be-roster__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid var(--be-panel-border);
  background: rgba(15, 23, 42, 0.6);
  cursor: pointer;
  text-align: left;
  color: var(--be-text);
  font: inherit;
}

.be-roster__item.is-active {
  border-color: var(--be-accent);
  background: var(--be-accent-soft);
}

.be-roster__thumb {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid var(--be-panel-border);
  image-rendering: pixelated;
  flex: 0 0 auto;
}

.be-roster__name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.be-roster__sub {
  display: block;
  font-size: 10px;
  color: var(--be-text-dim);
}

/* ---- Preview ---- */
.be-preview {
  grid-area: preview;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--be-panel);
  border: 1px solid var(--be-panel-border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 0;
}

.be-canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  background: #04070f;
  cursor: grab;
}

.be-canvas:active {
  cursor: grabbing;
}

.be-preview__toolbar,
.be-preview__options {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-top: 1px solid var(--be-panel-border);
  background: rgba(6, 10, 20, 0.85);
}

.be-slider {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--be-text-dim);
}

.be-slider input {
  width: 110px;
}

.be-solo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--be-text-dim);
  margin-left: auto;
}

.be-preview__footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--be-text-dim);
  border-top: 1px solid var(--be-panel-border);
  background: rgba(6, 10, 20, 0.85);
}

/* ---- Sidebar ---- */
.be-sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: var(--be-panel);
  border: 1px solid var(--be-panel-border);
  border-radius: 12px;
  min-height: 0;
}

.be-section {
  border: 1px solid var(--be-panel-border);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.45);
}

.be-section > summary {
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--be-text-dim);
  cursor: pointer;
  list-style: none;
}

.be-section > summary::before {
  content: "▸ ";
}

.be-section[open] > summary::before {
  content: "▾ ";
}

.be-section__body {
  padding: 4px 10px 10px;
}

.be-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.be-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Linha de checkbox (canal de grama, toco de árvore). */
.be-field--row {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.be-field__label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--be-text-dim);
}

.be-color {
  width: 46px;
  height: 30px;
  padding: 1px;
  border-radius: 7px;
  border: 1px solid var(--be-panel-border);
  background: rgba(2, 6, 16, 0.6);
  cursor: pointer;
}

/* ---- Chips de vegetação ---- */
.be-chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px 8px;
}

.be-chip-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
}

.be-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  border-radius: 9px;
  min-width: 0;
}

.be-chip:focus-visible {
  outline: 2px solid var(--be-accent, #38bdf8);
  outline-offset: 2px;
}

.be-chip__frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 4px;
  overflow: visible;
  background: rgba(2, 6, 16, 0.5);
  border: 1px solid rgba(74, 222, 128, 0.55);
  border-radius: 9px;
  box-shadow: inset 0 0 0 1px rgba(74, 222, 128, 0.22);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.be-chip:hover .be-chip__frame {
  transform: translateY(-1px);
}

.be-chip__img {
  width: auto;
  height: auto;
  max-width: 44px;
  max-height: 44px;
  object-fit: contain;
  image-rendering: pixelated;
}

.be-chip__name {
  max-width: 100%;
  font-size: 9px;
  color: var(--be-text-dim);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.be-chip.is-off .be-chip__frame {
  border-color: var(--be-panel-border);
  box-shadow: none;
}

.be-chip.is-off .be-chip__img {
  opacity: 0.28;
  filter: grayscale(0.9);
}

.be-chip.is-off .be-chip__name {
  opacity: 0.5;
}

.be-chip__weight {
  width: 52px;
  padding: 2px 3px;
  border-radius: 5px;
  border: 1px solid var(--be-panel-border);
  background: rgba(2, 6, 16, 0.6);
  color: var(--be-text);
  font: inherit;
  font-size: 10px;
  text-align: center;
}

.be-chip__cfg {
  position: absolute;
  top: -7px;
  right: -7px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.95);
  color: #cbd5e1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

.be-chip__cfg:hover,
.be-chip__cfg:focus-visible {
  color: #f8fafc;
  border-color: rgba(56, 189, 248, 0.7);
  background: rgba(14, 116, 144, 0.65);
  outline: none;
  transform: scale(1.08);
}

.be-chip.is-off .be-chip__cfg {
  opacity: 0.75;
}

/* ---- JSON ---- */
.be-json {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--be-panel-border);
  background: rgba(2, 6, 16, 0.6);
  color: var(--be-text);
  font: 11px/1.5 Consolas, "Cascadia Mono", monospace;
  white-space: pre;
}

.be-btn-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* ---- Density noise (GBA-style) ---- */
.be-noise {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

.be-noise__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.be-noise__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--be-text);
}

.be-noise__stats {
  font-size: 10px;
  color: var(--be-text-dim);
  text-align: right;
}

.be-noise__canvas {
  width: 100%;
  max-width: 260px;
  border-radius: 8px;
  border: 1px solid var(--be-panel-border);
  background: #12151c;
  image-rendering: pixelated;
}

.be-noise__hint {
  margin: 0;
  font-size: 10px;
}

.be-noise__fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.be-noise__range {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.be-noise__range-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.be-noise__num {
  width: 72px;
  flex: 0 0 auto;
}

.be-noise__slider {
  width: 100%;
  accent-color: var(--be-accent, #38bdf8);
}

.be-noise__pan {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.be-noise__pan .be-number {
  width: 64px;
}

.be-noise--modal {
  margin-top: 0;
}

.be-noise--modal .be-noise__canvas {
  max-width: 100%;
  width: 100%;
}

/* ---- Detail summary (splat compact) ---- */
.be-detail-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.be-detail-summary__meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.be-detail-summary__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--be-text);
}

.be-detail-summary__dim {
  font-size: 11px;
  color: var(--be-text-dim);
}

/* ---- Detail modal ---- */
html.be-modal-open,
html.be-modal-open body {
  overflow: hidden;
}

.be-modal-root {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 24px;
}

.be-modal-root[hidden] {
  display: none !important;
}

.be-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 16, 0.72);
  backdrop-filter: blur(6px);
}

.be-modal {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: linear-gradient(180deg, #121826 0%, #0b101a 100%);
  box-shadow:
    0 0 0 1px rgba(56, 189, 248, 0.08),
    0 24px 64px rgba(0, 0, 0, 0.55);
  animation: be-modal-in 0.18s ease-out;
  overflow: hidden;
}

.be-modal--wide {
  width: min(760px, 100%);
}

@keyframes be-modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.be-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
}

.be-modal__identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.be-modal__thumb {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(2, 6, 16, 0.55);
  overflow: hidden;
}

.be-modal__thumb img {
  max-width: 40px;
  max-height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
}

.be-modal__titles {
  min-width: 0;
}

.be-modal__title {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  letter-spacing: 0.01em;
  color: var(--be-text);
}

.be-modal__subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--be-text-dim);
}

.be-modal__close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--be-text-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.be-modal__close:hover,
.be-modal__close:focus-visible {
  color: var(--be-text);
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.1);
  outline: none;
}

.be-modal__body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 18px;
}

.be-modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 16, 0.35);
}

.be-detail-layout {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.be-detail-card {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: rgba(2, 6, 16, 0.35);
}

.be-detail-card__title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--be-text-dim);
}

.be-detail-card__fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.be-detail-card--noise {
  min-width: 0;
}

/* Sombra da árvore — mesmo chão claro do buildings-viewer pra enxergar o offset. */
.be-detail-card--shadow {
  grid-column: 1 / -1;
}

.be-tree-shadow-preview {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 160px;
  padding: 12px 8px 8px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 15px,
      rgba(22, 70, 40, 0.1) 15px,
      rgba(22, 70, 40, 0.1) 16px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 15px,
      rgba(22, 70, 40, 0.1) 15px,
      rgba(22, 70, 40, 0.1) 16px
    ),
    linear-gradient(180deg, #b7d48a 0%, #9bc46a 55%, #87b45a 100%);
  border-radius: 8px;
  border: 1px solid rgba(55, 90, 40, 0.28);
  overflow: hidden;
}

.be-tree-shadow-preview canvas {
  image-rendering: pixelated;
  max-width: 100%;
  max-height: 220px;
}

.be-tree-shadow-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.be-tree-shadow-field__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--be-text-dim);
}

.be-tree-shadow-field__value {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--be-text);
}

.be-tree-shadow-range {
  width: 100%;
  accent-color: #5eead4;
}

.be-tree-shadow-field__row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.be-tree-shadow-field__row .be-number {
  width: 5.5rem;
}

@media (max-width: 720px) {
  .be-detail-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .be-app {
    grid-template-columns: 210px 1fr;
    grid-template-areas:
      "header header"
      "roster preview"
      "sidebar sidebar";
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: 100vh;
  }

  .be-preview {
    min-height: 60vh;
  }
}
