:root {
  --editor-panel: #071006;
  --editor-panel-raised: #10220b;
  --editor-line: #36591f;
  --editor-line-soft: #213b14;
  --editor-muted: #91ac76;
  --editor-shadow: #010301;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.editor-page {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 17% -8%, rgb(57 124 29 / 26%), transparent 31rem),
    radial-gradient(circle at 88% 36%, rgb(112 59 12 / 14%), transparent 25rem),
    linear-gradient(180deg, #081405, #020502 76%);
}

.editor-page button,
.editor-page select,
.editor-page a {
  -webkit-tap-highlight-color: transparent;
}

.editor-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: clamp(12px, 2.4vw, 28px) clamp(9px, 2.3vw, 26px) calc(18px + env(safe-area-inset-bottom));
}

.editor-masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 13px;
}

.editor-brand {
  min-width: 0;
}

.editor-title-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 11px 18px;
}

.editor-title-row h1 {
  flex: none;
}

.editor-badge {
  margin-bottom: 2px;
  padding: 5px 9px 4px;
  border: 1px solid #6f4313;
  border-radius: 4px;
  color: var(--gold);
  background: #10220b;
  box-shadow: inset 0 1px rgb(255 255 255 / 7%), 2px 3px 0 #020502;
  font-size: clamp(10px, 1.7vw, 14px);
  letter-spacing: .045em;
  text-transform: uppercase;
}

.editor-subtitle {
  margin: 7px 0 0;
  color: var(--editor-muted);
  font-size: clamp(10px, 1.5vw, 13px);
}

.editor-top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: none;
}

.editor-button,
.editor-icon-button {
  min-height: 38px;
  border: 1px solid var(--bark-light);
  border-radius: 6px;
  color: var(--cream);
  background: linear-gradient(#18310e, #0a1707);
  box-shadow: inset 0 1px rgb(255 255 255 / 10%), 0 2px 0 #000;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.editor-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 11px;
  text-decoration: none;
  font-size: 12px;
  line-height: 1.15;
}

.editor-icon-button {
  width: 42px;
  padding: 0;
  color: var(--gold);
}

.editor-button:hover,
.editor-button:focus-visible,
.editor-icon-button:hover,
.editor-icon-button:focus-visible,
.editor-page select:focus-visible {
  border-color: var(--gold);
  outline: 2px solid rgb(230 196 73 / 25%);
  outline-offset: 2px;
  color: #fff;
}

.editor-button:active,
.editor-icon-button:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px rgb(0 0 0 / 25%), 0 0 #000;
}

.editor-button:disabled,
.editor-icon-button:disabled {
  opacity: .42;
  cursor: default;
  filter: saturate(.55);
  transform: none;
}

.editor-language {
  min-width: 42px;
  color: var(--gold);
  font-weight: 800;
}

.editor-button-primary {
  border-color: #9a721d;
  color: #fff4a9;
  background: linear-gradient(#356d17, #153709);
  box-shadow: inset 0 1px rgb(255 255 255 / 14%), 0 3px 0 #020700;
  font-weight: 800;
}

.editor-button-subtle {
  color: #d8c884;
  border-color: #694017;
  background: linear-gradient(#251b0b, #100d06);
}

.editor-cabinet {
  position: relative;
  padding: clamp(8px, 1.5vw, 15px);
  overflow: hidden;
  border: 3px solid #2b1605;
  border-radius: 14px;
  background:
    linear-gradient(90deg, transparent 50%, rgb(255 220 104 / 4%) 50%) 0 0 / 6px 6px,
    linear-gradient(145deg, #81501b, #3d1c06 48%, #6e3a0d);
  box-shadow:
    inset 0 0 0 2px #a56724,
    inset 0 0 28px #170b02,
    0 16px 42px rgb(0 0 0 / 58%);
}

.editor-cabinet::before,
.editor-cabinet::after,
.editor-leaves::before,
.editor-leaves::after {
  content: "";
  position: absolute;
  z-index: 0;
  width: 92px;
  height: 24px;
  opacity: .7;
  background: radial-gradient(ellipse, #287211 0 34%, #113808 36% 58%, transparent 60%) 0 0 / 30px 20px;
  pointer-events: none;
}

.editor-cabinet::before { top: -3px; left: 8%; transform: rotate(-3deg); }
.editor-cabinet::after { right: 7%; bottom: -2px; transform: rotate(181deg); }
.editor-leaves::before { top: 2px; right: 24%; transform: rotate(3deg); }
.editor-leaves::after { bottom: 0; left: 25%; transform: rotate(178deg); }

.editor-toolbar,
.editor-workspace,
.editor-footer {
  position: relative;
  z-index: 1;
}

.editor-toolbar {
  display: grid;
  grid-template-columns: minmax(150px, .9fr) minmax(210px, 1fr) minmax(210px, 1.4fr);
  align-items: end;
  gap: 10px 14px;
  padding: 12px;
  border: 2px solid #050805;
  border-bottom-color: #244111;
  border-radius: 7px 7px 0 0;
  background:
    linear-gradient(90deg, rgb(255 255 255 / 2%) 1px, transparent 1px) 0 0 / 6px 6px,
    linear-gradient(180deg, #13290c, #081306);
  box-shadow: inset 0 1px rgb(255 255 255 / 5%);
}

.editor-field {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: #b9cf9c;
  font-size: 10px;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.editor-field select {
  width: 100%;
  min-height: 40px;
  padding: 7px 31px 7px 10px;
  border: 1px solid #567731;
  border-radius: 5px;
  color: #fff3ac;
  background:
    linear-gradient(45deg, transparent 50%, #e6c449 50%) calc(100% - 15px) 16px / 5px 5px no-repeat,
    linear-gradient(135deg, #e6c449 50%, transparent 50%) calc(100% - 10px) 16px / 5px 5px no-repeat,
    #071006;
  font: 12px ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  appearance: none;
  cursor: pointer;
}

.level-picker {
  display: grid;
  grid-template-columns: 42px minmax(110px, 1fr) 42px;
  align-items: end;
  gap: 7px;
}

.editor-status {
  align-self: center;
  min-height: 40px;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid #3b5f23;
  border-radius: 5px;
  color: #c7dcaa;
  background: #050b04;
  font-size: 11px;
  line-height: 1.45;
}

.editor-status[data-state="dirty"] {
  border-color: #987523;
  color: #f6dc72;
}

.editor-status[data-state="error"] {
  border-color: #a13d22;
  color: #ffb49e;
}

.editor-workspace {
  display: grid;
  grid-template-columns: minmax(0, 2.25fr) minmax(250px, .85fr);
  gap: 10px;
  padding: 10px 0;
}

.board-panel,
.palette-panel,
.validation-panel,
.file-action-panel,
.edit-action-group {
  border: 2px solid #050805;
  border-radius: 7px;
  background: var(--editor-panel);
  box-shadow: inset 0 0 0 1px var(--editor-line-soft), inset 0 0 22px rgb(0 0 0 / 24%);
}

.board-panel,
.palette-panel {
  min-width: 0;
  padding: 10px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-height: 39px;
  margin-bottom: 8px;
}

.panel-heading h2,
.validation-heading h2,
.file-action-heading h2 {
  margin: 0;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.panel-heading p,
.file-action-heading p {
  margin: 4px 0 0;
  color: var(--editor-muted);
  font-size: 10px;
  line-height: 1.4;
}

.board-readout {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px 12px;
  color: #7fa363;
  font-size: 9px;
  text-align: right;
  text-transform: uppercase;
}

.board-readout output {
  color: #fff0a4;
}

.board-frame {
  padding: clamp(4px, .8vw, 7px);
  border: 2px solid #9c6724;
  border-radius: 6px;
  background: #020402;
  box-shadow: 0 0 0 3px #050805, inset 0 0 16px #000;
}

.board-scroll {
  width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  background: #000;
  scrollbar-color: #6f4313 #050805;
}

#board-canvas {
  display: block;
  width: 100%;
  min-width: 320px;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
  outline: none;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: none;
}

#board-canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--gold);
}

.board-note {
  margin: 9px 2px 0;
  color: #789365;
  font-size: 9px;
  line-height: 1.45;
}

.palette-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.tile-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  max-height: 490px;
  padding: 2px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #6f4313 #050805;
}

.tile-palette:empty::before {
  content: "…";
  grid-column: 1 / -1;
  padding: 30px;
  color: #6f8e59;
  text-align: center;
}

.tile-palette button,
.tile-option {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 49px;
  padding: 4px 6px;
  border: 1px solid #31531d;
  border-radius: 5px;
  color: #d8e8bc;
  background: linear-gradient(145deg, #12280b, #071006);
  box-shadow: inset 0 1px rgb(255 255 255 / 4%);
  font: 10px/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.tile-palette button:hover,
.tile-palette button:focus-visible,
.tile-palette button[aria-pressed="true"],
.tile-option.is-selected {
  border-color: var(--gold);
  outline: none;
  color: #fff5b2;
  background: linear-gradient(145deg, #315d17, #102309);
}

.tile-palette button[aria-pressed="true"],
.tile-option.is-selected {
  box-shadow: inset 0 0 0 1px rgb(255 238 123 / 20%), 0 0 0 2px rgb(230 196 73 / 13%);
}

.tile-palette canvas,
.tile-palette img,
.tile-option-icon {
  display: block;
  width: 38px;
  height: 38px;
  object-fit: contain;
  background: #000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.editor-footer {
  display: grid;
  grid-template-columns: minmax(220px, .72fr) minmax(0, 2fr);
  gap: 10px;
}

.validation-panel {
  padding: 11px;
}

.validation-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--editor-line-soft);
}

.validation-light {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #caa52c;
  box-shadow: 0 0 8px rgb(230 196 73 / 58%);
}

.validation-panel[data-state="ok"] .validation-light {
  background: #45a526;
  box-shadow: 0 0 8px rgb(60 139 23 / 70%);
}

.validation-panel[data-state="error"] .validation-light {
  background: var(--danger);
  box-shadow: 0 0 8px rgb(231 59 32 / 70%);
}

.validation-list {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.validation-list li {
  position: relative;
  padding-left: 15px;
  color: #aeca91;
  font-size: 10px;
  line-height: 1.45;
}

.validation-list li::before {
  content: "•";
  position: absolute;
  left: 1px;
  color: #7ea962;
}

.validation-list li[data-severity="warning"] {
  color: #f0d377;
}

.validation-list li[data-severity="warning"]::before {
  content: "!";
  color: var(--gold);
}

.validation-list li[data-severity="error"] {
  color: #ffad96;
}

.validation-list li[data-severity="error"]::before {
  content: "×";
  color: var(--danger);
}

.validation-list li[data-severity="ok"]::before {
  content: "✓";
  color: #55b934;
}

.editor-actions {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.edit-action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px;
}

.edit-action-group .editor-button-primary {
  margin-left: auto;
}

.file-action-panel {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) minmax(310px, 1.35fr);
  gap: 9px 14px;
  align-items: center;
  padding: 10px;
}

.file-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 6px;
}

.file-action-grid .editor-button {
  width: 100%;
}

.draft-note {
  grid-column: 1 / -1;
  margin: 0;
  color: #789365;
  font-size: 9px;
  line-height: 1.45;
}

@media (max-width: 860px) {
  .editor-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .tile-palette {
    grid-template-rows: repeat(2, minmax(50px, auto));
    grid-auto-flow: column;
    grid-auto-columns: minmax(145px, 28vw);
    grid-template-columns: none;
    max-height: none;
    padding: 2px 2px 7px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .editor-footer {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 650px) {
  .editor-shell {
    padding-inline: 7px;
  }

  .editor-masthead {
    align-items: center;
    gap: 9px;
  }

  .editor-title-row {
    gap: 8px;
  }

  .editor-title-row h1 {
    font-size: clamp(27px, 10vw, 38px);
  }

  .editor-badge {
    margin-bottom: 0;
    font-size: 9px;
  }

  .editor-subtitle,
  .editor-brand .eyebrow {
    display: none;
  }

  .editor-top-actions {
    gap: 5px;
  }

  .editor-top-actions .editor-button {
    min-height: 36px;
    padding: 7px 8px;
    font-size: 10px;
  }

  .editor-cabinet {
    padding: 8px;
    border-radius: 10px;
  }

  .editor-toolbar {
    grid-template-columns: minmax(112px, .82fr) minmax(172px, 1.18fr);
    gap: 8px;
    padding: 9px;
  }

  .editor-status {
    grid-column: 1 / -1;
    min-height: 34px;
    padding: 7px 9px;
  }

  .editor-workspace {
    gap: 8px;
    padding: 8px 0;
  }

  .board-panel,
  .palette-panel {
    padding: 7px;
  }

  .panel-heading {
    min-height: 34px;
    margin-bottom: 7px;
  }

  .panel-heading p,
  .board-note {
    display: none;
  }

  .board-readout {
    display: grid;
    gap: 3px;
  }

  .board-frame {
    padding: 3px;
  }

  .tile-palette {
    grid-auto-columns: minmax(138px, 42vw);
  }

  .tile-palette button,
  .tile-option {
    min-height: 52px;
  }

  .file-action-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .file-action-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .edit-action-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .edit-action-group .editor-button,
  .edit-action-group .editor-button-primary {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 400px) {
  .editor-title-row h1 {
    font-size: 28px;
  }

  .editor-badge {
    display: none;
  }

  .editor-top-actions #editor-back span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  #editor-back {
    min-width: 42px;
    font-size: 18px;
  }

  .editor-toolbar {
    grid-template-columns: minmax(102px, .78fr) minmax(164px, 1.22fr);
  }

  .editor-icon-button {
    width: 38px;
  }

  .level-picker {
    grid-template-columns: 38px minmax(82px, 1fr) 38px;
    gap: 5px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .editor-shell {
    padding-block: 6px calc(8px + env(safe-area-inset-bottom));
  }

  .editor-masthead {
    margin-bottom: 6px;
  }

  .editor-brand .eyebrow,
  .editor-subtitle,
  .panel-heading p,
  .board-note,
  .draft-note {
    display: none;
  }

  .editor-title-row h1 {
    font-size: 28px;
  }

  .editor-toolbar {
    padding: 7px 9px;
  }

  .editor-workspace {
    grid-template-columns: minmax(0, 1.75fr) minmax(220px, .72fr);
    gap: 7px;
    padding: 7px 0;
  }

  .tile-palette {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-flow: row;
    grid-auto-columns: auto;
    max-height: 250px;
    overflow: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .editor-page *,
  .editor-page *::before,
  .editor-page *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
