:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-2: #e9edf2;
  --border: #c7d0dc;
  --text: #17212f;
  --muted: #687384;
  --accent: #1f6feb;
  --accent-2: #0f5ec9;
  --danger: #c93c3c;
  --shadow: 0 10px 32px rgba(31, 43, 60, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  height: 34px;
  padding: 0 11px;
}

button:hover {
  border-color: #95a6ba;
  background: #f8fafc;
}

button:active {
  transform: translateY(1px);
}

.app {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 240px;
  grid-template-rows: 48px minmax(0, 1fr);
  height: 100%;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  z-index: 3;
}

.brand {
  width: 112px;
  font-weight: 700;
  letter-spacing: 0;
}

.menu {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tools,
.layers {
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px;
  z-index: 2;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool {
  width: 100%;
  padding: 0 6px;
}

.tool.active {
  border-color: var(--accent);
  background: #e8f1ff;
  color: #0b4fb3;
  font-weight: 650;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field[hidden] {
  display: none;
}

.field input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field output {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.zoomControl {
  margin-top: 0;
}

.canvasSizeField {
  margin-top: auto;
}

.canvasSize {
  width: 100%;
  height: 34px;
  padding: 5px 6px;
  text-align: left;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  min-height: 34px;
}

.toggle input {
  width: 16px;
  height: 16px;
}

.stageWrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 0;
  background: #d7dde5;
}

canvas {
  display: block;
  width: 800px;
  height: 500px;
  background: #fff;
  border: 1px solid #9aa8b8;
  box-shadow: none;
  touch-action: none;
}

.stageWrap.panning,
.stageWrap.panning canvas {
  cursor: grabbing;
}

.stageWrap.panReady,
.stageWrap.panReady canvas {
  cursor: grab;
}

.layers {
  border-right: 0;
  border-left: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
}

#deleteLayerBtn {
  border-color: #e0a5a5;
  color: var(--danger);
}

.layerList {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.layerItem {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.layerItem.active {
  border-color: var(--accent);
  background: #e8f1ff;
}

.layerSwatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.layerName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layerMeta {
  color: var(--muted);
  font-size: 12px;
}

.dropHint {
  position: fixed;
  inset: 62px 254px 14px 174px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  background: rgba(232, 241, 255, 0.84);
  color: #0b4fb3;
  font-size: 22px;
  font-weight: 800;
  pointer-events: none;
  z-index: 5;
}

.app.dragging .dropHint {
  display: flex;
}

.textEditor {
  position: fixed;
  z-index: 10;
}

.textEditor textarea {
  width: 280px;
  min-height: 92px;
  max-height: 280px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  padding: 6px 8px;
  box-shadow: var(--shadow);
  outline: none;
  resize: both;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 76px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) 170px;
  }

  .topbar {
    min-height: 56px;
    align-items: flex-start;
    padding-top: 8px;
  }

  .brand {
    width: auto;
    padding-top: 8px;
  }

  .stageWrap {
    padding: 0;
  }

  .layers {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .dropHint {
    inset: 70px 12px 182px 88px;
  }
}
