:root {
  --bg1: #091326;
  --bg2: #1d3558;
  --panel: rgba(6, 16, 34, 0.84);
  --line: rgba(255, 255, 255, 0.2);
  --text: #e8f3ff;
  --accent: #ffd166;
  --tile-empty: #132538;
  --tile-solid: #7f8ea0;
  --edge-standard: #7f8ea0;
  --edge-soft: #25ff76;
  --edge-dangerous: #ff2d2d;
  --edge-empty: #132538;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 18%, rgba(115, 240, 165, 0.18), transparent 36%),
    radial-gradient(circle at 82% 22%, rgba(255, 209, 102, 0.22), transparent 34%),
    linear-gradient(150deg, var(--bg1), var(--bg2));
}

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

.app {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.top-bar,
.toolbar,
.edit-panel,
.json-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.top-bar {
  padding: 12px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
}

.subtitle {
  margin: 5px 0 0;
  opacity: 0.9;
}

.back-link {
  color: #132413;
  background: var(--accent);
  border: 1px solid rgba(0, 0, 0, 0.22);
  border-radius: 10px;
  padding: 9px 12px;
  text-decoration: none;
  font-weight: 700;
}

.toolbar {
  padding: 10px;
  display: grid;
  gap: 10px;
}

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

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

label {
  opacity: 0.95;
}

input[type="text"],
select,
textarea,
button {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

input[type="text"],
select {
  padding: 8px 10px;
}

select option {
  background: #0f243d;
  color: #f3fbff;
}

button {
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

button:hover,
button:focus-visible {
  background: rgba(255, 255, 255, 0.17);
  outline: none;
}

.edit-panel {
  padding: 10px;
  display: grid;
  grid-template-columns: minmax(220px, 270px) 1fr;
  gap: 12px;
}

.side-panel {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.12);
}

.layer-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.layer-switch button {
  flex: 1;
}

.layer-switch button.active {
  border-color: rgba(115, 240, 165, 0.75);
  background: rgba(115, 240, 165, 0.2);
}

.grid-wrap {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(0, 0, 0, 0.2);
  min-height: 320px;
  max-height: min(66vh, 620px);
  max-width: 100%;
}

.grid-wrap::-webkit-scrollbar,
.feature-list::-webkit-scrollbar,
#json-editor::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.grid-wrap::-webkit-scrollbar-thumb,
.feature-list::-webkit-scrollbar-thumb,
#json-editor::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.36);
  border-radius: 10px;
}

.grid-wrap::-webkit-scrollbar-track,
.feature-list::-webkit-scrollbar-track,
#json-editor::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.25);
}

.level-grid {
  --cols: 32;
  display: grid;
  grid-template-columns: repeat(var(--cols), 30px);
  grid-auto-rows: 30px;
  width: fit-content;
  min-width: 100%;
}

.cell {
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  position: relative;
  font-weight: 800;
  font-size: 11px;
  user-select: none;
  overflow: hidden;
  background: var(--tile-empty);
  color: #9bb1c8;
}

.cell-label {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

.cell.has-feature-overlay::after {
  content: attr(data-feature-label);
  position: absolute;
  top: 1px;
  right: 2px;
  max-width: calc(100% - 4px);
  padding: 1px 3px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  background: rgba(7, 18, 34, 0.86);
  color: #f6fbff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.cell.solid {
  color: #102034;
}

.cell-solid-body {
  position: absolute;
  background: var(--tile-solid);
  box-shadow: inset 0 0 0 1px rgba(8, 19, 36, 0.32);
}

.cell-edge {
  position: absolute;
  pointer-events: none;
}

.cell-edge.edge-standard {
  background: var(--edge-standard);
}

.cell-edge.edge-soft {
  background: var(--edge-soft);
}

.cell-edge.edge-dangerous {
  background: var(--edge-dangerous);
}

.cell-edge.edge-empty {
  background: var(--edge-empty);
}

.cell-edge-top,
.cell-edge-bottom {
  left: 0;
  right: 0;
  height: var(--marker-size, 5px);
}

.cell-edge-top {
  top: 0;
}

.cell-edge-bottom {
  bottom: 0;
}

.cell-edge-left,
.cell-edge-right {
  top: 0;
  bottom: 0;
  width: var(--marker-size, 5px);
}

.cell-edge-left {
  left: 0;
}

.cell-edge-right {
  right: 0;
}

.cell.expand-cell {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.55);
  font-weight: 700;
}

.cell.expand-cell:hover {
  background: rgba(115, 240, 165, 0.25);
  color: #eafff3;
}

.json-panel {
  padding: 10px;
}

#json-details > summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0;
}

#json-details[open] > summary {
  margin-bottom: 8px;
}

.json-body {
  display: grid;
  gap: 8px;
}

#json-editor {
  width: 100%;
  height: 270px;
  padding: 10px;
  font-family: "Consolas", "Courier New", monospace;
  resize: vertical;
}

.json-feedback {
  font-size: 13px;
  opacity: 0.95;
}

.json-feedback.error {
  color: #ff9595;
}

.json-feedback.ok {
  color: #8ff0b1;
}

.hidden-input,
.hidden {
  display: none !important;
}

.editor-dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 18, 34, 0.96);
  color: var(--text);
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
}

.editor-dialog.small-dialog {
  width: min(480px, calc(100vw - 24px));
}

.editor-dialog::backdrop {
  background: rgba(0, 0, 0, 0.56);
}

.dialog-body {
  margin: 0;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.dialog-body h3,
.dialog-body h4,
.surface-title {
  margin: 0;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.surface-controls {
  display: grid;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.surface-pad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  grid-template-areas:
    ". top ."
    "left all right"
    ". bottom .";
  justify-content: center;
  align-content: center;
  gap: 8px;
}

.edge-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-width: 3px;
  font-size: 0;
  line-height: 0;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}

.edge-btn.edge-top {
  grid-area: top;
}

.edge-btn.edge-right {
  grid-area: right;
}

.edge-btn.edge-bottom {
  grid-area: bottom;
}

.edge-btn.edge-left {
  grid-area: left;
}

.edge-btn.edge-all {
  grid-area: all;
}

.edge-btn.edge-standard {
  background: rgba(127, 142, 160, 0.9);
  border-color: var(--edge-standard);
  box-shadow: 0 0 0 1px rgba(127, 142, 160, 0.5), 0 0 10px rgba(127, 142, 160, 0.45);
}

.edge-btn.edge-soft {
  background: rgba(37, 255, 118, 0.68);
  border-color: var(--edge-soft);
  box-shadow: 0 0 0 1px rgba(37, 255, 118, 0.5), 0 0 12px rgba(37, 255, 118, 0.5);
}

.edge-btn.edge-dangerous {
  background: rgba(255, 45, 45, 0.72);
  border-color: var(--edge-dangerous);
  box-shadow: 0 0 0 1px rgba(255, 45, 45, 0.5), 0 0 12px rgba(255, 45, 45, 0.55);
}

.edge-btn.edge-empty {
  background:
    linear-gradient(135deg, rgba(19, 37, 56, 0.98) 0 42%, rgba(255, 255, 255, 0.08) 42% 58%, rgba(19, 37, 56, 0.98) 58% 100%);
  border-color: var(--edge-empty);
  box-shadow: 0 0 0 1px rgba(19, 37, 56, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.surface-empty-note {
  margin: 0;
  font-size: 13px;
  opacity: 0.88;
}

.feature-list {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px;
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow: auto;
}

.feature-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.04);
}

.feature-item .type {
  font-weight: 700;
}

.feature-fields {
  display: grid;
  gap: 8px;
}

.feature-fields input[type="text"],
.feature-fields input[type="number"],
.feature-fields select {
  width: 100%;
  padding: 8px 10px;
}

.feature-fields .check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.feature-fields details {
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
}

.feature-fields details > summary {
  cursor: pointer;
  font-weight: 700;
}

.hint-fields {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.dialog-menu {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 980px) {
  .edit-panel {
    grid-template-columns: 1fr;
  }

  .grid-wrap {
    max-height: 460px;
  }
}
