/* 6bMapArts theme refinement layer over synced MapartStudio-Experimental CSS */
:root {
  color-scheme: dark;
  --left-panel-width: clamp(210px, 17vw, 300px);
  --side-panel-width: clamp(235px, 18vw, 320px);
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background-color: #0e1116;
  color: #e6e9ee;
  scrollbar-color: #262d38 #0e1116;
  --editor-panel-height: min(680px, max(340px, calc(100vh - 204px)));
  --workarea-height: clamp(240px, min(calc(var(--editor-panel-height) - var(--hotbar-height) - var(--hotbar-gap)), calc(100vw - var(--left-panel-width) - var(--side-panel-width) - 96px)), 626px);
  --hotbar-slot-size: clamp(20px, calc((var(--workarea-height) - 52px) / 10), 38px);
}

.mapart-studio-shell {
  height: auto;
  flex: 1 1 0;
  min-height: 0;
}

input[type="range"],
input[type="checkbox"],
input[type="radio"] {
  accent-color: #e8842c;
}

/* Match 6bMapArts button hierarchy while preserving icon/slot/swatch boxes */
button:not(.tool-icon-btn):not(.hotbar-slot):not(.sidebar-icon-btn):not(.layer-btn):not(.palette-icon-btn):not(.converter-exclude-colour) {
  background-color: #1e252f;
  color: #e6e9ee;
  border: 1px solid #262d38;
  font-family: inherit;
  transition: border-color 0.14s, background-color 0.14s, color 0.14s;
}

button:not(.tool-icon-btn):not(.hotbar-slot):not(.sidebar-icon-btn):not(.layer-btn):not(.palette-icon-btn):not(.converter-exclude-colour):hover:not(:disabled) {
  background-color: #252e3a;
  border-color: #e8842c;
}

.converter-primary,
#saveIndivBtn,
.reverse-primary,
.reverse-download,
.nbt-materials-file-button,
.layer-btn.active,
.layer-lock-toggle.active,
.palette-icon-btn.active {
  background-color: #e8842c;
  color: #1a1005;
  border-color: #e8842c;
}

.converter-primary:hover:not(:disabled),
#saveIndivBtn:hover:not(:disabled),
.reverse-primary:hover:not(:disabled),
.reverse-download:hover:not(:disabled),
.nbt-materials-file-button:hover {
  background-color: #f0a35e;
  border-color: #f0a35e;
  color: #1a1005;
}

.layer-btn.delete {
  background-color: rgba(229, 72, 77, 0.18);
  color: #fecaca;
  border-color: rgba(229, 72, 77, 0.55);
}

.layer-btn.delete:hover:not(:disabled) {
  background-color: #e5484d;
  color: #ffffff;
  border-color: #e5484d;
}

.studio-tabbar {
  border-bottom: 1px solid #262d38;
}

.studio-tab {
  background: #161b23;
  color: #8b94a3;
  border-color: #262d38;
  border-bottom-color: transparent;
}

.studio-tab:hover:not(:disabled) {
  background: #1e252f;
  color: #e6e9ee;
  border-color: #262d38;
}

.studio-tab.active {
  background: #1e252f;
  color: #f0a35e;
  border-color: #262d38;
  border-top: 2px solid #e8842c;
  border-bottom-color: #1e252f;
}

.home-action {
  background: #161b23;
  border-color: #262d38;
  color: #e6e9ee;
}

.home-action:hover:not(:disabled) {
  background: #1e252f;
  border-color: #e8842c;
}

.home-action strong {
  color: #f0a35e;
}

.tool-icon-btn.active,
.layer-row.active {
  background: rgba(232, 132, 44, 0.16);
  border-color: #e8842c;
}

.reverse-eyebrow,
.reverse-report-head>div>span,
.reverse-drop-icon {
  color: #f0a35e;
}

.reverse-drop:hover,
.reverse-drop.drag-over,
.reverse-drop.has-file {
  background: rgba(232, 132, 44, 0.08);
  border-color: #e8842c;
}

.reverse-progress i {
  background: #e8842c;
}

/* Keep editor panels, canvas, hotbar, and palette inside viewport without overlap */
#workspaceEditor {
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 10px;
}

#workspaceEditor>h1 {
  font-size: clamp(20px, 2.4vh, 26px);
  margin: 2px 0;
}

#workspaceEditor>p {
  font-size: 13px;
  margin: 0 0 6px;
}

#workspaceEditor .toolbar {
  padding: 7px 10px;
  gap: 6px 8px;
  margin-bottom: 8px;
  max-width: min(1600px, calc(100vw - 24px));
}

#workspaceEditor .toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
}

#workspaceEditor .toolbar input[type="file"] {
  max-width: 210px;
  font-size: 12px;
}

#workspaceEditor .toolbar button {
  padding: 6px 10px;
  font-size: 12.5px;
}

.editor-container {
  max-width: min(1600px, calc(100vw - 24px));
  gap: 12px;
  padding: 10px;
  flex: 0 0 auto;
  align-items: start;
}

.left-sidebar {
  grid-template-rows: minmax(72px, 0.9fr) auto minmax(72px, 0.72fr);
}

.tool-sidebar .sidebar-body {
  overflow-y: auto;
}

.tool-controls-row {
  grid-template-columns: auto 44px auto minmax(0, 1fr);
  gap: 5px;
}

.canvas-column {
  align-items: center;
  justify-content: space-between;
  height: auto;
  max-height: var(--editor-panel-height);
  align-self: center;
}

.canvas-container {
  flex: 0 0 auto;
}

.hotbar-area {
  width: 100%;
  max-width: 100%;
  gap: 10px;
  height: auto;
  min-height: var(--hotbar-height);
  flex: 0 0 auto;
}

.palette-panel {
  min-width: 0;
}

.palette-header {
  flex-wrap: wrap;
  gap: 6px 8px;
}

.palette-header h3 {
  font-size: 15px;
  white-space: nowrap;
}

.palette-actions {
  gap: 4px;
  flex-wrap: wrap;
}

.palette-icon-btn {
  width: 26px;
  height: 26px;
}

.palette.carpet-mode {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.converter-workspace {
  height: min(790px, calc(100vh - 88px));
}

.converter-canvas-stage {
  position: relative;
}

.converter-empty-state {
  left: 50%;
  top: 50%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: calc(100vw - 64px);
  padding: 6px 10px;
  color: #8b94a3;
  white-space: nowrap;
  line-height: 1.3;
}

.license-notice {
  position: static;
  flex: 0 0 auto;
  align-self: center;
  margin: 4px auto 0;
  max-width: min(1600px, calc(100vw - 24px));
  text-align: center;
  background: rgba(14, 17, 22, 0.92);
  border-color: #262d38;
  color: #8b94a3;
}

.license-notice a {
  color: #f0a35e;
}

/* Switch from fixed desktop frame to single clean vertical page flow on small viewports */
@media (max-width: 1100px), (max-height: 640px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body {
    padding: 0 10px 14px;
  }

  .mapart-studio-shell {
    height: auto;
    min-height: 100%;
    flex: 1 0 auto;
  }

  .workspace-stack,
  .workspace-view {
    flex: 1 0 auto;
    height: auto;
    overflow: visible;
  }

  .license-notice {
    position: static;
    flex: 0 0 auto;
    align-self: center;
    width: 100%;
    max-width: min(1600px, 100%);
    margin: 14px auto 0;
    text-align: center;
    background: rgba(14, 17, 22, 0.92);
    border-color: #262d38;
    color: #8b94a3;
    font-size: 10.5px;
    line-height: 1.4;
  }

  .home-panel {
    width: 100%;
  }

  .home-actions {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #workspaceConverter {
    padding: 8px 0 0;
    overflow: visible;
  }

  .converter-workspace {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(0, 0.94fr) minmax(0, 1.06fr);
    grid-template-rows: auto auto;
    gap: 12px;
  }

  .converter-workspace > .converter-panel:first-child .converter-panel-body {
    overflow: visible;
  }

  .converter-preview-panel {
    min-height: 440px;
  }

  .converter-preview-toolbar {
    flex-wrap: wrap;
    gap: 6px 8px;
  }

  .converter-preview-toolbar label {
    flex: 1 1 100%;
    min-width: 0;
  }

  .converter-preview-toolbar input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
  }

  #converterZoomValue {
    min-width: 0;
    flex: 1 1 auto;
    text-align: left;
  }

  #converterFitPreview {
    margin-left: auto;
  }

  .converter-right-panel {
    grid-column: 1 / -1;
    max-height: 520px;
  }
}

@media (max-width: 960px) {
  body {
    --editor-panel-height: auto;
    --workarea-height: min(480px, calc(100vw - 44px));
    --hotbar-slot-size: clamp(24px, calc((min(480px, 100vw - 44px) - 24px) / 10.5), 36px);
    --left-panel-width: 100%;
    --side-panel-width: 100%;
  }

  #workspaceEditor {
    overflow: visible;
    width: 100%;
    padding: 6px 0 10px;
  }

  #workspaceEditor .toolbar {
    width: 100%;
    max-width: 100%;
    justify-content: flex-start;
  }

  .editor-container {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    justify-items: stretch;
    align-items: start;
    padding: 8px;
    gap: 12px;
  }

  .canvas-column {
    order: -1;
    align-self: start;
    width: 100%;
    max-width: min(100%, 480px);
    height: auto;
    max-height: none;
    margin: 0 auto;
    gap: 8px;
  }

  .canvas-container {
    width: 100%;
    max-width: min(100%, 480px);
    height: auto;
    max-height: min(68vh, 480px);
    aspect-ratio: 1 / 1;
  }

  .hotbar-area {
    width: 100%;
    max-width: 100%;
    gap: 8px;
    height: auto;
    min-height: var(--hotbar-slot-size);
    flex: 0 0 auto;
  }

  .left-sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: auto auto;
    gap: 10px;
  }

  .left-sidebar > .tool-sidebar {
    grid-column: 1 / -1;
  }

  .tool-sidebar .sidebar-body {
    overflow: visible;
  }

  .custom-palette-section,
  .left-sidebar > .sidebar-section:last-child {
    max-height: 220px;
  }

  .tool-icon-grid {
    grid-template-columns: repeat(auto-fill, minmax(36px, 42px));
    justify-content: start;
  }

  .palette-panel,
  body[data-palette-mode="carpet"] .palette-panel {
    width: 100%;
    height: auto;
    max-height: 440px;
  }

  .palette {
    padding-right: 4px;
  }
}

@media (max-width: 680px) {
  body {
    padding: 0 8px 14px;
  }

  .studio-tabbar {
    width: 100%;
    flex-wrap: wrap;
    overflow: visible;
    gap: 5px;
    padding: 8px 0;
  }

  .studio-tab {
    min-width: 0;
    max-width: none;
    flex: 1 1 auto;
    height: auto;
    min-height: 32px;
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 6px;
    border-bottom-color: #262d38;
  }

  .studio-tab.active {
    border-bottom-color: #e8842c;
  }

  .converter-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 10px;
    padding: 8px;
    overflow: visible;
  }

  .converter-preview-panel {
    min-height: 320px;
    height: min(58vh, 420px);
  }

  .converter-right-panel {
    max-height: 480px;
  }

  .converter-actions button {
    flex: 1 1 calc(50% - 4px);
  }

  .left-sidebar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }

  #workspaceNbtMaterials {
    padding: 12px 2px 20px;
    overflow: visible;
  }

  .nbt-materials-heading h1 {
    font-size: clamp(24px, 7vw, 34px);
  }

  .nbt-materials-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .nbt-materials-action-buttons {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nbt-materials-grid {
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
  }

  .nbt-materials-panel {
    min-height: 190px;
    max-height: 340px;
  }

  #workspaceReverse {
    padding: 12px 2px 20px;
    overflow: visible;
  }

  .reverse-hero h1 {
    font-size: clamp(28px, 8vw, 44px);
  }

  .reverse-hero p {
    font-size: 14px;
  }

  .reverse-drop {
    min-height: 150px;
    padding: 14px;
  }

  .reverse-result.visible,
  .reverse-report dl > div {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  #workspaceHome {
    align-items: flex-start;
    padding: 12px 0 14px;
  }

  .home-panel {
    gap: 12px;
  }

  .home-panel h1 {
    font-size: clamp(26px, 8vw, 34px);
  }

  .home-panel p {
    font-size: 13.5px;
  }

  .home-actions {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }

  .home-action {
    min-height: 0;
    padding: 13px 14px;
    gap: 4px;
  }

  .home-action strong {
    font-size: 16px;
  }

  .home-action span {
    font-size: 13px;
  }

  .converter-file-field {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
  }

  .converter-file-control input[type="file"] {
    flex: 0 0 108px;
    width: 108px;
    max-width: 108px;
  }

  .converter-field {
    grid-template-columns: minmax(82px, 0.78fr) minmax(0, 1.22fr);
    gap: 6px;
  }

  .converter-inline.three {
    grid-template-columns: minmax(0, 1fr);
  }

  #workspaceEditor .toolbar label {
    width: 100%;
    flex-wrap: wrap;
  }

  #workspaceEditor .toolbar input[type="file"] {
    flex: 1 1 160px;
    max-width: 100%;
  }

  #workspaceEditor .toolbar button {
    flex: 1 1 auto;
    min-width: 0;
  }

  .tool-icon-grid {
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  }

  .hotbar-area {
    gap: 6px;
  }

  .color-picker-window,
  .material-list-window,
  .replace-color-window,
  .text-tool-popup,
  .converter-preset-window {
    left: 8px;
    top: 12px;
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: calc(100vh - 24px);
  }
}