html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #12161c;
  color: #e8eef7;
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  z-index: 5;
  background: #12161c;
}

#loading[hidden] {
  display: none;
}

#top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 10px 16px 8px;
  border-bottom: 1px solid #2a3340;
}

#top h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

#hud-play {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin: 0;
  color: #b7c2d0;
  font-size: 14px;
}

#hud-play[hidden] {
  display: none;
}

#hud-meta {
  margin: 0;
}

#shell {
  display: grid;
  grid-template-columns: 300px 1fr;
  flex: 1 1 auto;
  min-height: 0;
}

#stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#play-bar {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 10px 16px 8px;
  background: #12161c;
  border-bottom: 1px solid #2a3340;
}

body[data-screen="select"] #play-bar {
  display: flex;
}

#play-selected {
  font-size: 24px;
  font-weight: 750;
  letter-spacing: 0.04em;
  padding: 14px 48px;
  min-width: min(420px, 80%);
  width: min(480px, 85%);
  border-radius: 10px;
}

#game {
  flex: 1 1 auto;
  min-height: 0;
  height: 0;
  width: 100%;
}

body[data-screen="play"] #shell {
  grid-template-columns: 0 1fr;
}

body[data-screen="play"] #sidebar {
  display: none;
}

#sidebar {
  overflow: auto;
  padding: 12px 14px 20px;
  border-right: 1px solid #2a3340;
  background: #171c24;
}

#select-panel[hidden],
#editor-panel[hidden] {
  display: none;
}

h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

#level-search {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 10px;
  font: 14px "Segoe UI", system-ui, sans-serif;
  color: #e8eef7;
  background: #121826;
  border: 1px solid #4a5a70;
  border-radius: 6px;
  padding: 6px 8px;
}

#level-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.level-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid #2f3b4c;
  border-radius: 6px;
  background: #1d2430;
  color: #e8eef7;
  cursor: pointer;
}

.level-item:hover,
.level-item.active {
  border-color: #7ad36a;
  background: #24301f;
}

.level-item strong {
  font-size: 14px;
}

.level-item span {
  color: #8b97a8;
  font-size: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  font: 600 13px "Segoe UI", system-ui, sans-serif;
  color: #12161c;
  background: #7ad36a;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.06);
}

#ed-back,
#ed-load,
#ed-clear,
#open-file,
#open-editor {
  background: #d7dee8;
}

#ed-clear {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 10px;
}

.hint {
  color: #8b97a8;
  font-size: 12px;
  line-height: 1.4;
}

#editor-panel label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 12px;
  color: #b7c2d0;
}

#editor-panel input {
  width: 100%;
  box-sizing: border-box;
  font: 14px "Segoe UI", system-ui, sans-serif;
  color: #e8eef7;
  background: #121826;
  border: 1px solid #4a5a70;
  border-radius: 6px;
  padding: 6px 8px;
}

.size-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 10px;
}

#editor-panel .size-row label {
  margin-bottom: 0;
}

.size-resize {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.size-resize-spacer {
  font-size: 12px;
  visibility: hidden;
  user-select: none;
}

.size-resize #ed-resize {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1.15;
  border: 1px solid transparent;
  box-sizing: border-box;
}

.palette-label {
  margin: 4px 0 6px;
  font-size: 12px;
  color: #b7c2d0;
}

.palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.palette button {
  position: relative;
  padding: 0;
  aspect-ratio: 1;
  overflow: hidden;
  background: #0e1218;
  border: 2px solid #2f3b4c;
  border-radius: 4px;
  filter: none;
}

.palette button:hover {
  filter: none;
  border-color: #7ad36a;
}

.palette button.active {
  border-color: #ffe066;
}

.palette button canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  user-select: none;
  background: #0e1218;
}
