:root {
  --bg1: #08101b;
  --bg2: #18334d;
  --panel: rgba(7, 16, 28, 0.88);
  --line: rgba(255, 255, 255, 0.18);
  --text: #eef8ff;
  --muted: rgba(238, 248, 255, 0.72);
  --tile-empty: #132538;
  --tile-solid: #8aa8c4;
  --blue: #3f8cff;
  --red: #ff5d6e;
}

* {
  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(63, 140, 255, 0.2), transparent 34%),
    radial-gradient(circle at 84% 22%, rgba(255, 93, 110, 0.16), transparent 28%),
    linear-gradient(155deg, var(--bg1), var(--bg2));
}

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

.app {
  width: min(1280px, 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: 16px;
}

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

h1,
h2,
h3 {
  margin: 0;
}

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

.subtitle,
.muted {
  margin: 6px 0 0;
  color: var(--muted);
}

.back-link {
  color: #08101b;
  background: linear-gradient(180deg, #d3ebff, #9fd0ff);
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 10px 14px;
  text-decoration: none;
  font-weight: 700;
}

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

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

label {
  display: grid;
  gap: 6px;
}

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

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 10px;
}

textarea {
  resize: vertical;
}

select option {
  background: #0e2438;
  color: #f5fbff;
}

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

button:hover,
button:focus-visible,
.back-link:hover,
.back-link:focus-visible {
  outline: none;
  background: rgba(255, 255, 255, 0.16);
}

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

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

.side-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.meta-fields {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.special-fields {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
}

.special-fields h3 {
  font-size: 16px;
}

.special-fields.is-disabled {
  opacity: 0.6;
}

.symmetry-note {
  margin: 0;
}

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

.layer-switch button {
  flex: 1;
}

.layer-switch button.active {
  border-color: rgba(159, 208, 255, 0.72);
  background: rgba(63, 140, 255, 0.24);
}

.grid-wrap {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  overflow: auto;
  background: rgba(0, 0, 0, 0.18);
  min-height: 360px;
  max-height: min(68vh, 760px);
  padding: 18px 16px 22px;
}

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

.grid-wrap::-webkit-scrollbar-thumb,
#json-editor::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.34);
  border-radius: 999px;
}

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

.level-grid {
  width: fit-content;
  min-width: 100%;
}

.level-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: -12px;
}

.level-row:first-child {
  margin-top: 0;
}

.level-row.row-odd {
  margin-left: 27px;
}

.cell {
  position: relative;
  width: 50px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  display: block;
  user-select: none;
}

.cell:hover,
.cell:focus-visible {
  background: transparent;
}

.cell-hex {
  width: 50px;
  height: 44px;
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(19, 37, 56, 0.48);
  display: grid;
  place-items: center;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(9, 17, 29, 0.2);
}

.cell.playable .cell-hex {
  background: linear-gradient(180deg, #bdd9f3, var(--tile-solid));
  color: #0b1624;
}

.cell.playable.has-battery .cell-hex {
  background: linear-gradient(180deg, #eefad9, #b8dfa6);
}

.cell.playable.has-jumper .cell-hex {
  background: linear-gradient(180deg, #fff3c8, #ffd99a);
}

.cell.expand-cell .cell-hex {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.56);
}

.cell.expand-cell:hover .cell-hex,
.cell.expand-cell:focus-visible .cell-hex {
  background: rgba(63, 140, 255, 0.24);
}

.cell.is-selected .cell-hex {
  border-color: rgba(255, 209, 102, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.18);
}

.cell.has-starts .cell-hex::after {
  content: "";
  position: absolute;
  inset: 6px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.cell-label {
  position: relative;
  z-index: 1;
  font-size: 11px;
  font-weight: 800;
}

.cell-special {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: 13px;
  font-weight: 800;
  color: #08101b;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.cell-special.is-battery {
  color: #365727;
}

.cell-special.is-jumper {
  color: #d46a00;
  font-size: 15px;
  letter-spacing: -1px;
}

.cell.playable.has-special .cell-hex {
  box-shadow: inset 0 0 0 1px rgba(9, 17, 29, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.cell-starts {
  position: absolute;
  left: 50%;
  bottom: 5px;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  gap: 4px;
  z-index: 2;
  pointer-events: none;
}

.start-badge {
  min-width: 18px;
  min-height: 18px;
  padding: 1px 4px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.5;
  color: #fff;
  text-align: center;
}

.start-badge.blue {
  background: linear-gradient(180deg, #86bcff, var(--blue));
}

.start-badge.red {
  background: linear-gradient(180deg, #ffacb5, var(--red));
}

.json-panel {
  padding: 10px 12px;
}

#json-details > summary {
  cursor: pointer;
  font-weight: 700;
}

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

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

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

.json-feedback {
  font-size: 13px;
  color: var(--muted);
}

.json-feedback.ok {
  color: #9ff0bb;
}

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

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

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

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

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

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

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

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

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