:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --panel-2: #eef5f1;
  --ink: #1b2528;
  --muted: #65777c;
  --line: #d8e1e3;
  --accent: #217b68;
  --accent-2: #b54f38;
  --warn: #9a6a16;
  --bad: #b73535;
  --shadow: 0 16px 40px rgba(32, 46, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

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

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.toolbar h1,
.toolbar p,
.panel-head h2,
.panel-head p,
.blob-tools h2,
.blob-tools p {
  margin: 0;
}

.toolbar h1 {
  font-size: 22px;
}

.toolbar p,
.panel-head p,
.blob-tools p,
.file-summary small {
  color: var(--muted);
  font-size: 13px;
}

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

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.file-button input {
  display: none;
}

#exportPlayerBtn,
#exportMapBtn,
#loadMapBase64Btn {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.import-status {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  color: var(--muted);
  padding: 7px 10px;
}

.import-status.ok {
  border-color: #9cc9bd;
  background: #edf7f4;
  color: #245447;
}

.import-status.err {
  border-color: #e2a3a3;
  background: #fff0f0;
  color: #7a2020;
}

.editor-shell {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  border-radius: 8px;
}

.editor-shell.dragging {
  outline: 2px dashed var(--accent);
  outline-offset: 6px;
}

.sidebar,
.workbench,
.map-panel,
.blob-tools,
.data-panel,
.json-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  position: sticky;
  top: 16px;
  padding: 14px;
}

.file-summary {
  display: grid;
  gap: 5px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.file-summary span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-summary strong {
  font-size: 18px;
}

.tabs {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.tab {
  justify-content: flex-start;
  background: transparent;
}

.tab.active {
  background: var(--panel-2);
  border-color: #bcd2cb;
  color: var(--accent);
  font-weight: 700;
}

.validation-box {
  display: grid;
  gap: 8px;
}

.notice {
  border-left: 4px solid var(--accent);
  background: #edf7f4;
  border-radius: 6px;
  padding: 9px 10px;
  color: #245447;
  font-size: 13px;
}

.notice.warn {
  border-left-color: var(--warn);
  background: #fff7e5;
  color: #684711;
}

.notice.bad {
  border-left-color: var(--bad);
  background: #fff0f0;
  color: #7a2020;
}

.workbench {
  min-height: calc(100vh - 112px);
  padding: 16px;
}

.tab-panel {
  display: none;
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  min-height: 78px;
}

.stat small {
  display: block;
  color: var(--muted);
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 21px;
  overflow-wrap: anywhere;
}

.map-panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.panel-head.compact {
  align-items: center;
}

.panel-head h2,
.blob-tools h2 {
  font-size: 18px;
}

.legend,
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.preview-actions {
  justify-content: flex-end;
}

.preview-actions button.active {
  background: var(--panel-2);
  border-color: #bcd2cb;
  color: var(--accent);
  font-weight: 700;
}

.add-object-menu {
  position: relative;
}

.object-picker-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  width: min(560px, calc(100vw - 36px));
  max-height: min(620px, calc(100vh - 190px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(27, 37, 40, 0.16);
}

.object-picker-popover[hidden],
.object-picker-empty[hidden] {
  display: none;
}

.object-picker-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
}

.object-picker-viewport {
  position: relative;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: 8px;
  background: var(--panel);
}

#objectPickerCanvas {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

#objectPickerSpacer {
  width: 1px;
  min-height: 1px;
  pointer-events: none;
}

.object-picker-empty {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

.dot.map {
  background: var(--accent);
}

.dot.storage {
  background: var(--accent-2);
}

.map-canvas-wrap {
  position: relative;
  overflow: hidden;
  height: clamp(520px, calc(100vh - 245px), 780px);
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #419e34;
}

#objectMap {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  touch-action: none;
  cursor: grab;
}

#objectMap.dragging {
  cursor: grabbing;
}

#objectMap.placing-object {
  cursor: crosshair;
}

.map-edit-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.map-edit-group {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.map-edit-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.map-edit-title strong {
  color: var(--ink);
  font-size: 13px;
}

.map-edit-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-edit-fields {
  display: grid;
  grid-template-columns: repeat(5, minmax(72px, 1fr));
  gap: 8px;
  align-items: end;
}

.map-edit-fields input {
  min-height: 34px;
  padding: 5px 7px;
}

.check-label {
  align-content: end;
  grid-template-columns: auto 1fr;
  min-height: 55px;
}

.check-label input {
  width: auto;
  min-height: 0;
}

.map-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.preview-status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: min(680px, calc(100% - 24px));
  padding: 8px 10px;
  border: 1px solid rgba(216, 225, 227, 0.88);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

.preview-status.bad {
  border-color: #e2a3a3;
  background: rgba(255, 240, 240, 0.94);
  color: #7a2020;
}

.preview-tooltip {
  position: absolute;
  z-index: 2;
  max-width: 300px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(27, 37, 40, 0.94);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 10px 26px rgba(20, 30, 34, 0.22);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input {
  min-height: 38px;
  padding: 7px 9px;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(33, 123, 104, 0.2);
  border-color: var(--accent);
}

.blob-tools,
.json-block,
.data-panel {
  margin-top: 16px;
  padding: 14px;
}

.blob-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.map-data-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(420px, 1.1fr);
  gap: 16px;
}

.map-base64-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
  padding: 14px;
}

.map-base64-tools textarea,
.paste-dialog textarea {
  min-height: 96px;
  resize: vertical;
  padding: 9px;
  font-family: Consolas, "SFMono-Regular", monospace;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 880px;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafb;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected-row {
  background: #eef5f1;
}

td input {
  min-height: 32px;
  padding: 4px 6px;
}

td .tiny {
  width: 72px;
}

td .wide {
  width: 110px;
}

.danger {
  color: #fff;
  background: var(--bad);
  border-color: var(--bad);
}

.table-action {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.json-block textarea,
.data-panel textarea {
  min-height: calc(100vh - 210px);
  padding: 12px;
  resize: vertical;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.data-panel textarea {
  min-height: 360px;
}

.paste-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.paste-dialog::backdrop {
  background: rgba(27, 37, 40, 0.42);
}

.paste-dialog form {
  display: grid;
  gap: 14px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .toolbar,
  .editor-shell,
  .panel-head,
  .blob-tools,
  .map-data-grid {
    display: grid;
  }

  .panel-actions {
    justify-content: flex-start;
  }

  .preview-actions {
    justify-content: flex-start;
  }

  .object-picker-popover {
    right: auto;
    left: 0;
  }

  .map-edit-bar {
    grid-template-columns: 1fr;
  }

  .editor-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .tab {
    justify-content: center;
  }

  .stats-grid,
  .form-grid,
  .map-edit-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .toolbar-actions,
  .tabs,
  .stats-grid,
  .form-grid,
  .map-edit-fields {
    grid-template-columns: 1fr;
    display: grid;
  }

  .workbench {
    padding: 10px;
  }

  .object-picker-popover {
    position: fixed;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 130px);
  }

}
