:root {
  color-scheme: dark;
  --bg: #151719;
  --panel: #202326;
  --panel-2: #292d31;
  --line: #3a4045;
  --text: #f0f2f2;
  --muted: #a8b0b4;
  --accent: #33b7a3;
  --accent-2: #e4b343;
  --danger: #df655c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 980px;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(420px, 1fr) 280px;
  width: 100vw;
  height: 100vh;
  min-height: 0;
}

.panel {
  min-height: 0;
  max-height: 100vh;
  padding-bottom: 14px;
  background: var(--panel);
  border-color: var(--line);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-left: 1px solid var(--line);
  overflow: hidden;
  padding-bottom: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 14px 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: #080c0f;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 16px;
}

h2 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.brand p,
.status-box p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.group {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.group > h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.group > h2::after {
  content: "-";
  margin-left: auto;
  color: var(--muted);
}

.group.collapsed > h2 {
  margin-bottom: 0;
}

.group.collapsed > h2::after {
  content: "+";
}

.group.collapsed > :not(h2) {
  display: none;
}

.file-button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button:disabled:hover {
  border-color: var(--line);
}

button.active {
  border-color: var(--accent);
  background: #22443f;
}

.field.disabled .segmented button.active {
  border-color: var(--line);
  background: var(--panel-2);
}

button.danger {
  border-color: rgba(223, 101, 92, 0.55);
}

button.danger:hover {
  border-color: var(--danger);
}

button.primary {
  border-color: var(--accent);
  background: #1f5a51;
}

.app-confirm {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.48);
  pointer-events: auto;
}

.app-confirm.hidden {
  display: none;
}

.app-confirm-panel {
  width: min(420px, 92vw);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.46);
  pointer-events: auto;
}

.app-confirm-panel h2 {
  margin-bottom: 8px;
}

.app-confirm-panel p {
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.app-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.app-confirm-actions button {
  min-width: 82px;
  padding: 0 14px;
}

.project-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 0 14px 12px;
}

.file-button input {
  display: none;
}

.project-actions .file-button {
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0 8px;
  font-size: 12px;
  text-align: center;
}

.project-actions #export3mfButton {
  grid-column: 1 / -1;
}

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

.segmented button {
  min-width: 0;
  padding: 0 8px;
}

.fill-mode-buttons {
  grid-template-columns: repeat(3, 1fr);
}

.paint-engine-buttons {
  grid-template-columns: 1fr;
}

.toggle-row.alpha2-legacy-organic,
.alpha2-legacy-organic {
  display: none;
}

.field {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.field span {
  color: var(--text);
}

.field.disabled {
  opacity: 0.55;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--text);
  font-size: 12px;
}

.toggle-row input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.toggle-row.disabled {
  opacity: 0.55;
}

.feature-status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  margin-left: auto;
  padding: 1px 5px;
  border: 1px solid #6f7780;
  border-radius: 4px;
  color: #c8cdd2;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.group > h2 > .feature-status-badge {
  float: right;
  margin-top: -1px;
}

.feature-parked {
  opacity: 0.45;
}

.tool-context-heading {
  display: flex;
  align-items: center;
  min-height: 30px;
  margin-top: 10px;
  padding: 0 2px;
  color: var(--text);
  font-size: 12px;
}

.tool-modifiers {
  margin-top: 12px;
  border-top: 1px solid var(--line);
}

.tool-modifiers summary {
  display: flex;
  align-items: center;
  min-height: 36px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.tool-modifiers summary::-webkit-details-marker {
  display: none;
}

.tool-modifiers summary::before {
  content: "+";
  width: 18px;
  color: var(--muted);
  font-weight: 700;
}

.tool-modifiers[open] summary::before {
  content: "-";
}

.tool-modifiers summary span {
  margin-left: auto;
  color: var(--muted);
  font-size: 11px;
}

.tool-modifier-content {
  padding: 0 2px 4px;
}

.context-hidden,
.context-parked {
  display: none !important;
}

.field-toggle {
  margin-top: 0;
}

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

.range-with-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px;
  align-items: center;
  gap: 8px;
}

.range-with-value.disabled {
  opacity: 0.55;
}

.value-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  color: var(--text);
}

.value-with-unit span {
  color: var(--muted);
  font-size: 12px;
}

.number-value {
  min-width: 0;
  width: 100%;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #252b31;
  color: var(--text);
  font: inherit;
  text-align: right;
}

.number-value:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(64, 211, 196, 0.25);
}

.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.swatch {
  position: relative;
  height: 34px;
  min-width: 0;
  border: 2px solid transparent;
  border-radius: 7px;
}

.swatch.active {
  border-color: var(--text);
}

.swatch.replace-target {
  border-color: rgba(64, 211, 196, 0.7);
  box-shadow: 0 0 0 1px rgba(64, 211, 196, 0.25);
}

.swatch.empty {
  background:
    linear-gradient(135deg, transparent 46%, rgba(255, 255, 255, 0.22) 48%, rgba(255, 255, 255, 0.22) 52%, transparent 54%),
    var(--panel-2);
  border-style: dashed;
}

.swatch span {
  position: absolute;
  right: 6px;
  bottom: 4px;
  color: #fff;
  font-size: 11px;
  text-shadow: 0 1px 2px #000;
}

.color-tools {
  display: grid;
  grid-template-columns: 42px 42px 1fr;
  gap: 8px;
  margin-top: 8px;
}

.color-tools button,
.color-tools input {
  width: 100%;
  min-width: 0;
  height: 34px;
}

.color-tools input[type="color"] {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.color-tools input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  text-align: center;
  text-transform: uppercase;
}

.colour-name-readout {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 10px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.colour-name-readout strong {
  min-width: 0;
  color: var(--text);
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.palette-colour-actions,
.palette-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.palette-colour-actions button,
.palette-actions button {
  min-width: 0;
  padding: 0 8px;
}

.wide {
  width: 100%;
  margin-top: 8px;
}

.camera-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--text);
  font-size: 12px;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.action-grid .camera-control {
  grid-column: 1 / -1;
  margin: 0 0 2px;
}

.action-grid .wide {
  min-width: 0;
  min-height: 38px;
  margin: 0;
  padding: 4px 7px;
  font-size: 12px;
  line-height: 1.2;
}

.hidden {
  display: none !important;
}

.right-panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.right-panel-tabs button {
  min-width: 0;
  min-height: 32px;
  padding: 0 5px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.right-panel-tabs button:hover {
  border-color: var(--line);
  color: var(--text);
}

.right-panel-tabs button.active {
  border-color: var(--accent);
  background: #22443f;
  color: var(--text);
}

.right-panel-view {
  display: none;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.right-panel-view.active {
  display: block;
}

.right-panel-view[hidden] {
  display: none;
}

.right-panel .status-box {
  max-height: 154px;
  overflow: auto;
  border-top: 1px solid var(--line);
  background: #1c1f22;
}

.viewport {
  position: relative;
  min-width: 0;
  background: #303437;
}

.viewport.drag-over {
  outline: 2px solid var(--accent);
  outline-offset: -6px;
}

#viewer {
  display: block;
  width: 100%;
  height: 100%;
}

.viewport.paint-cursor #viewer {
  cursor: none;
}

#brushOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.viewport.has-image-stencil #brushOverlay {
  mix-blend-mode: normal;
}

.hud {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: calc(100% - 28px);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
}

.hud span {
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  background: rgba(21, 23, 25, 0.78);
}

.viewport.orienting .hud {
  bottom: 98px;
}

.orientation-dialog {
  position: absolute;
  left: 50%;
  bottom: 18px;
  display: grid;
  width: min(430px, calc(100% - 36px));
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(21, 23, 25, 0.94);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.32);
  transform: translateX(-50%);
}

.orientation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.orientation-header h2 {
  margin-bottom: 0;
}

.orientation-readout {
  display: flex;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.orientation-readout span {
  min-width: 54px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}

.orientation-readout strong {
  color: var(--text);
  font-weight: 700;
}

.orientation-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.orientation-actions button {
  min-width: 0;
  padding: 0 10px;
}

.orientation-gizmo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(42vw, 420px);
  aspect-ratio: 1;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.gizmo-ring,
.gizmo-dot {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.gizmo-ring {
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.32);
  transition: border-color 120ms ease, border-width 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
  z-index: 1;
}

.gizmo-ring-x {
  border-color: rgba(255, 76, 76, 0.9);
  transform: rotateX(66deg);
}

.gizmo-ring-y {
  border-color: rgba(73, 230, 104, 0.9);
  transform: rotateY(66deg);
}

.gizmo-ring-z {
  border-color: rgba(82, 148, 255, 0.9);
}

.orientation-gizmo.hover-ring-x .gizmo-ring-x,
.orientation-gizmo.hover-ring-y .gizmo-ring-y,
.orientation-gizmo.hover-ring-z .gizmo-ring-z {
  border-width: 3px;
  filter: brightness(1.35);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.45),
    0 0 32px rgba(255, 255, 255, 0.46);
}

.orientation-gizmo.selected-ring-x .gizmo-ring-x,
.orientation-gizmo.selected-ring-y .gizmo-ring-y,
.orientation-gizmo.selected-ring-z .gizmo-ring-z {
  border-width: 4px;
  border-color: #fff2a8;
  filter: brightness(1.65);
  box-shadow:
    0 0 0 4px rgba(255, 242, 168, 0.42),
    0 0 38px rgba(255, 242, 168, 0.68),
    0 0 70px rgba(0, 0, 0, 0.42);
}

.orientation-gizmo.selected-ring-x .gizmo-ring:not(.gizmo-ring-x),
.orientation-gizmo.selected-ring-y .gizmo-ring:not(.gizmo-ring-y),
.orientation-gizmo.selected-ring-z .gizmo-ring:not(.gizmo-ring-z) {
  opacity: 0.5;
}

.gizmo-dot {
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: var(--text);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.25);
  transform: translate(-50%, -50%);
  z-index: 2;
}

.gizmo-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid #151719;
  border-radius: 50%;
  background: #fff2a8;
  box-shadow:
    0 0 0 3px rgba(255, 242, 168, 0.35),
    0 0 22px rgba(255, 242, 168, 0.8);
  transform: translate(-50%, -50%);
  z-index: 4;
}

.gizmo-handle.active {
  width: 18px;
  height: 18px;
  box-shadow:
    0 0 0 4px rgba(255, 242, 168, 0.42),
    0 0 30px rgba(255, 242, 168, 0.95);
}

.region-list {
  display: grid;
  gap: 7px;
}

.region-substatus {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.region-row {
  display: grid;
  grid-template-columns: 18px 22px 1fr auto;
  gap: 8px;
  align-items: center;
  justify-content: stretch;
  width: 100%;
  min-height: 34px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  text-align: left;
}

.region-row.has-base-choice {
  grid-template-columns: 16px 18px 22px 1fr auto;
}

.region-row:hover {
  border-color: var(--accent);
}

.region-row.active {
  border-color: var(--accent);
  background: #22443f;
}

.region-row.active-section {
  box-shadow: inset 3px 0 0 var(--accent);
}

.region-row.hidden-region {
  opacity: 0.58;
}

.region-row.ghosted-region {
  opacity: 0.78;
}

.region-row.hidden-region .region-chip,
.region-row.ghosted-region .region-chip {
  outline: 1px solid rgba(230, 238, 238, 0.45);
  outline-offset: 2px;
}

.region-chip {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.region-expander {
  display: grid;
  place-items: center;
  justify-self: center;
  width: 17px;
  height: 17px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.region-row:hover .region-expander {
  border-color: var(--accent);
  color: var(--text);
}

.region-expander-disabled {
  border-color: transparent;
  color: transparent;
}

.region-row:hover .region-expander-disabled {
  border-color: transparent;
  color: transparent;
}

.region-base-radio {
  width: 13px;
  height: 13px;
  border: 2px solid var(--muted);
  border-radius: 999px;
  justify-self: center;
}

.region-row:hover .region-base-radio,
.region-row:focus-visible .region-base-radio {
  border-color: var(--accent);
}

.region-base-radio:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(54, 211, 194, 0.16);
}

.region-base-radio:active {
  box-shadow: inset 0 0 0 3px var(--panel-2);
  background: var(--accent);
}

.region-row strong {
  display: block;
  font-size: 12px;
}

.region-row span {
  color: var(--muted);
}

.region-row > span:last-child {
  justify-self: end;
}

.region-section-row {
  margin-left: 18px;
  width: calc(100% - 18px);
  min-height: 31px;
  background: #24282b;
}

.region-section-row.dragging-section {
  opacity: 0.55;
}

.region-section-row.drag-over-section {
  border-color: var(--accent-2);
  box-shadow: inset 0 0 0 1px var(--accent-2);
}

.region-section-row.manual-section-group {
  border-color: rgba(228, 179, 67, 0.55);
}

.region-section-row strong {
  font-size: 11px;
}

.region-section-row .section-name-action {
  cursor: text;
}

.region-section-row .section-name-action:hover {
  color: var(--accent-2);
}

.region-section-row .region-chip {
  width: 15px;
  height: 15px;
  border-radius: 4px;
}

.region-section-spacer {
  justify-self: center;
  width: 8px;
  height: 1px;
  background: var(--line);
}

.region-section-placeholder {
  margin-left: 18px;
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 11px;
}

.import-base-list {
  display: grid;
  gap: 8px;
}

.import-base-option {
  display: grid;
  grid-template-columns: 16px 16px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  justify-content: stretch;
  padding: 7px 8px;
  text-align: left;
}

.import-base-radio {
  width: 13px;
  height: 13px;
  border: 2px solid var(--muted);
  border-radius: 999px;
}

.import-base-option:hover .import-base-radio,
.import-base-option:focus-visible .import-base-radio {
  border-color: var(--accent);
}

.import-base-option:active .import-base-radio {
  box-shadow: inset 0 0 0 3px var(--panel-2);
  background: var(--accent);
}

.import-base-chip {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 3px;
}

.import-base-option strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.import-base-option span {
  color: var(--muted);
  font-size: 11px;
}

.region-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.boundary-actions {
  display: grid;
  grid-template-columns: 34px 34px;
  gap: 8px;
}

.boundary-actions button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.boundary-adjust-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.smooth-edge-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}

.smooth-edge-actions .wide {
  margin-top: 0;
}

@media (max-width: 1250px) {
  body {
    min-width: 900px;
  }

  .app-shell {
    grid-template-columns: 260px minmax(380px, 1fr) 260px;
  }

  .group {
    padding-right: 12px;
    padding-left: 12px;
  }
}
