.editor {
  --editor-top: calc(0.6rem + env(safe-area-inset-top, 0px));
  --editor-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  --editor-left: calc(var(--gutter) + env(safe-area-inset-left, 0px));
  --editor-right: calc(var(--gutter) + env(safe-area-inset-right, 0px));
  position: relative;
  height: 100%;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: #25251b;
}

#editor-map {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#editor-map[data-tool="pan"] { cursor: grab; }
#editor-map[data-dragging] { cursor: grabbing; }
#editor-map:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.editor-title,
.editor-actions,
.editor-tools,
.editor-zoom,
.editor-hint,
.editor-status,
.editor-distance { position: absolute; }

.editor-title {
  inset-block-start: var(--editor-top);
  inset-inline-start: var(--editor-left);
  max-width: calc(100% - 13.5rem);
  pointer-events: none;
  text-shadow: 0 2px 3px #17120e, 1px 0 #17120e, -1px 0 #17120e;
}

.editor-title h1 {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.55rem);
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  line-height: 1.2;
}

.editor-title svg { flex: none; }
.editor-title p { margin: 0.3rem 0 0; font-size: 0.875rem; font-weight: 700; overflow-wrap: anywhere; }

.editor-actions, .editor-tools, .editor-zoom {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.editor-actions { inset-block-start: var(--editor-top); inset-inline-end: var(--editor-right); }
.editor-tools { inset-block-end: var(--editor-bottom); inset-inline-start: 50%; transform: translateX(-50%); }
.editor-zoom { inset-block-end: var(--editor-bottom); inset-inline-end: var(--editor-right); }

.editor-sticker {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 2px;
  border: 0;
  border-radius: 0.55rem;
  background: transparent;
  color: #fff4da;
  touch-action: manipulation;
  line-height: 1;
}

.editor-sticker :is(svg, img) {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px #18130fe0);
  transition: transform 120ms, filter 120ms;
}

.editor-sticker:is(:hover, :active):not(:disabled) { background: transparent; }
.editor-sticker:hover:not(:disabled) :is(svg, img) { transform: translateY(-2px); }
.editor-sticker:active:not(:disabled) :is(svg, img) { transform: translateY(1px) scale(0.95); }
.editor-sticker:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.editor-sticker[aria-pressed="true"] { background: #392b1aeb; box-shadow: inset 0 0 0 1px #ffca75; }
.editor-sticker[aria-pressed="true"] :is(svg, img) { filter: drop-shadow(0 1px 3px #eba54b7a); }
.editor-sticker:disabled { opacity: 0.48; }

.editor-hint, .editor-status {
  inset-inline-start: var(--editor-left);
  max-width: min(31rem, calc(100% - var(--editor-left) - var(--editor-right)));
  margin: 0;
  padding: 0.4rem 0.6rem;
  border-radius: 0.35rem;
  background: #26221bea;
  color: #fff2d9;
  font-size: 0.8125rem;
  pointer-events: none;
}

.editor-hint { inset-block-start: calc(var(--editor-top) + 3.9rem); }
.editor-status { inset-block-end: calc(var(--editor-bottom) + 3.35rem); }
.editor-status[data-error] { color: #ffc099; }

.editor-distance:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  inset-block-end: calc(var(--editor-bottom) + 3.35rem);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  padding: 0.25rem;
  border: 1px solid #75634c;
  border-radius: 0.55rem;
  background: var(--panel);
  white-space: nowrap;
}

.editor-distance output { min-width: 6rem; text-align: center; font-variant-numeric: tabular-nums; }
.editor-distance button { min-width: 44px; }
.editor:has(.editor-distance:not([hidden])) .editor-status { inset-block-end: calc(var(--editor-bottom) + 6.9rem); }
.editor-dialog { --dialog-width: 32rem; }

.editor-settings-grid, .editor-file-cards, .editor-file-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.editor-field { display: grid; align-content: start; gap: 0.3rem; font-weight: 700; font-size: 0.875rem; }
.editor-field-wide { grid-column: 1 / -1; }
.editor-field input {
  min-width: 0;
  min-height: 44px;
  padding: 0.4rem 0.55rem;
  border: 1px solid #75634c;
  border-radius: 0.35rem;
  background: #342c23;
  color: #fff2d9;
  font: inherit;
  font-weight: 400;
}
.editor-field input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.editor-settings-grid > button { align-self: end; }
.editor-error { margin: 0; color: #ffc099; font-size: 0.875rem; }
.editor-error:empty { display: none; }
.editor-file-actions { margin-block-start: 0.8rem; }

.editor-course-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  min-width: 0;
  padding: 0.375rem;
  text-align: left;
}

.editor-course-card canvas { display: block; width: 100%; height: auto; border-radius: 0.25rem; image-rendering: pixelated; }
.editor-course-card span { padding: 0.25rem; overflow-wrap: anywhere; }

@media (max-width: 43rem) {
  .editor-zoom { inset-block-end: calc(var(--editor-bottom) + 3.35rem); }
  .editor:has(.editor-distance:not([hidden])) .editor-zoom { inset-block-end: calc(var(--editor-bottom) + 6.9rem); }
  .editor-status { inset-block-end: calc(var(--editor-bottom) + 6.85rem); }
  .editor:has(.editor-distance:not([hidden])) .editor-status { inset-block-end: calc(var(--editor-bottom) + 10.4rem); }
}

@media (max-width: 25rem) {
  .editor-actions { gap: 0.0625rem; }
  .editor-actions .editor-sticker { width: 44px; height: 44px; }
  .editor-title { max-width: calc(100% - 12.5rem); }
  .editor-title svg { width: 22px; height: 17px; }
  .editor-hint { inset-block-start: calc(var(--editor-top) + 4.4rem); }
}

@media (prefers-reduced-motion: reduce) {
  .editor-sticker :is(svg, img) { transition: none; }
  .editor-sticker:is(:hover, :active) :is(svg, img) { transform: none; }
}
