.mw-top {
  position: sticky;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  text-shadow: none;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
  gap: 14px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.mw-top a { display: inline-flex; align-items: center; }
.mw-top .mw-round { width: 28px; height: 28px; font-size: 12px; }
.mw-top a .mw-round { pointer-events: none; }
@media (hover: hover) { .mw-top a:hover .mw-round { background: var(--mw-hover); } }
.mw-top a:active .mw-round { background: var(--text); color: var(--bg); transform: scale(0.92); }
.mw-top .theme-toggle.mw-round { opacity: 1; font-size: 13px; }

.mw-top-left { grid-column: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.mw-top-tools { grid-column: 3; justify-self: end; display: flex; align-items: center; gap: 14px; }

.mw-menubar { display: flex; gap: 2px; }
.mw-menubar button {
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 4px 10px;
  opacity: 0.65;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}
@media (hover: hover) { .mw-menubar button:hover { opacity: 1; background: var(--mw-hover); } }
.mw-menubar button[aria-expanded="true"] { opacity: 1; background: var(--accent); color: #fff; }

.mw-flyout {
  position: fixed;
  z-index: 30;
  min-width: 260px;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  animation: mw-fly 0.2s var(--ease) both;
}
.mw-flyout[hidden] { display: none; }
.mw-flyout hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.mw-flyout hr[hidden] { display: none; }
.mw-presets.mw-flyout { width: 340px; padding: 12px; gap: 10px; }
.mw-presets .mw-row input { flex: 1 1 0; min-width: 0; }
.mw-presets select { width: 100%; }

.mw-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  padding: 9px 16px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.mw-item[hidden] { display: none; }
.mw-item:disabled { opacity: 0.4; cursor: default; pointer-events: none; }
.mw-item:focus-visible { background: var(--mw-hover); outline: none; }
@media (hover: hover) { .mw-item:hover { background: var(--mw-hover); outline: none; } }
.mw-item:active { background: var(--accent); color: #fff; }
.mw-item kbd { font: inherit; font-size: 12px; color: var(--mute); }
.mw-item:active kbd { color: inherit; }

@keyframes mw-fly { from { opacity: 0; transform: translateY(-8px); } }

.mw-lang { display: flex; align-items: center; gap: 6px; font-size: 14px; opacity: 0.6; transition: opacity 0.2s ease; }
.mw-lang:focus-within { opacity: 1; }
@media (hover: hover) { .mw-lang:hover { opacity: 1; } }
.mw-lang select {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 2px 0;
}
.mw-lang select option { background: #fff; color: #000; }

.mw-brand { grid-column: 2; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0; max-width: 40vw; text-align: center; line-height: 1.15; }

.mw-brand h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.02em; text-transform: lowercase; white-space: nowrap; line-height: 1.15; }
.mw-top .mw-brand span { max-width: 100%; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.mw-brand span,
.mw-note { color: var(--mute); font-size: 13px; }
.mw-swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.mw-swatches:empty { display: none; }
:where(.mw-page) .mw-swatches .mw-swatch { width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); cursor: pointer; }

.mw-page {
  padding: 18px var(--pad);
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) 24px minmax(280px, 0.7fr);
  align-items: start;
}

.mw-split {
  position: sticky;
  top: calc(var(--mw-top-h, 52px) + 18px);
  height: calc(100vh - var(--mw-top-h, 52px) - 36px);
  height: calc(100dvh - var(--mw-top-h, 52px) - 36px);
  cursor: col-resize;
  touch-action: none;
  display: flex;
  justify-content: center;
}

.mw-split::before {
  content: "";
  width: 2px;
  height: 100%;
  background: var(--line);
  transition: background 0.15s ease;
}

.mw-split.is-dragging::before,
.mw-split:focus-visible::before { background: var(--accent); }
@media (hover: hover) { .mw-split:hover::before { background: var(--accent); } }

.mw-split:focus-visible { outline: none; }

body.mw-resizing { cursor: col-resize; user-select: none; }

.mw-stage > .mw-split-h {
  position: static;
  height: 10px;
  margin: -5px 0;
  cursor: row-resize;
  flex-direction: column;
}
.mw-split-h::before { width: 100%; height: 2px; }
body.mw-resizing-h { cursor: row-resize; user-select: none; }

.mw-stage {
  --mw-gap: 18px;
  position: sticky;
  top: calc(var(--mw-top-h, 52px) + var(--mw-gap));
  height: calc(100vh - var(--mw-top-h, 52px) - 2 * var(--mw-gap));
  height: calc(100dvh - var(--mw-top-h, 52px) - 2 * var(--mw-gap));
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  min-height: 0;
}

.mw-canvas-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 160px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.mw-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.mw-stage > :not(.mw-canvas-wrap) { flex: none; }

.mw-stage > .mw-stage-bottom {
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mw-drop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--dim);
  pointer-events: none;
}

.mw-canvas-wrap.has-image .mw-drop { display: none; }

.mw-lit-tip {
  position: absolute;
  left: 8px;
  bottom: 8px;
  z-index: 2;
  max-width: calc(100% - 16px);
  margin: 0;
  padding: 4px 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  color: var(--mute);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
}

.mw-lit-tip[hidden],
.mw-canvas-wrap:has(.mw-tile-edit:not([hidden])) .mw-lit-tip { display: none; }

.mw-hdr-note { left: auto; right: 8px; bottom: auto; top: 8px; max-width: 280px; }

.mw-canvas-wrap canvas.mw-sun-dial {
  position: absolute;
  inset: auto 8px 8px auto;
  width: 128px;
  height: 128px;
  z-index: 3;
  cursor: grab;
  touch-action: none;
}
.mw-canvas-wrap canvas.mw-sun-dial:active { cursor: grabbing; }
.mw-sun-dial[hidden],
.mw-canvas-wrap:has(.mw-tile-edit:not([hidden])) .mw-sun-dial { display: none; }

#view-hdr { pointer-events: none; z-index: 1; }
#view-hdr[hidden] { display: none !important; }
.mw-canvas-wrap.is-hdr > #view-hdr {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.mw-canvas-wrap.is-over { outline: 2px solid var(--accent); }
