:root {
  color-scheme: light dark;
  --bg: light-dark(#f4f3ef, #151715);
  --panel: light-dark(#ffffff, #20231f);
  --panel-2: light-dark(#ece9df, #2a2d28);
  --text: light-dark(#1f211d, #f2f0e8);
  --muted: light-dark(#696d63, #bbb8ad);
  --line: light-dark(#d6d1c3, #3a3e37);
  --accent: light-dark(#a5432f, #d86d55);
  --accent-text: #fff9f2;
  --field: light-dark(#ffffff, #181a17);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app-shell {
  height: calc(100dvh - 44px);
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  overflow: hidden;
}
.craft-tabs { height: 44px; display: flex; gap: 4px; align-items: center; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.craft-tabs a { display: inline-flex; align-items: center; font-size: 13px; padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--text); }
.craft-tabs a[aria-current="page"] { background: var(--panel-2); color: var(--accent); }
.craft-tabs svg { width: 18px; height: 18px; }
.tool-picker { max-width: 780px; margin: 0 auto; padding: 36px 24px; }
.tool-picker h1 { font-size: 25px; margin-bottom: 24px; }
.tool-list { display: grid; gap: 12px; }
.tool-choice { display: grid; grid-template-columns: 40px minmax(0,1fr) 20px; align-items: center; gap: 16px; min-height: 88px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--panel); text-decoration: none; }
.tool-choice:hover { border-color: var(--accent); background: var(--panel-2); }
.tool-choice h2 { font-size: 18px; margin: 0; overflow-wrap: anywhere; }
.tool-choice>svg:first-child { width: 32px; height: 32px; color: var(--accent); }
.tool-choice>svg:last-child { width: 20px; height: 20px; }
#shapeFrame { width: 100%; height: calc(100dvh - 44px); border: 0; }
#layersFrame { width: 100%; height: calc(100dvh - 44px); border: 0; }
#textureFrame { width: 100%; height: calc(100dvh - 44px); border: 0; }
.craft-tabs { overflow-x: auto; }
.craft-tabs a { flex: none; }
[hidden] { display: none !important; }

.controls {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 22px;
  overflow: auto;
  min-height: 0;
}

.brand {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

h1, h2 {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.05;
}

h2 {
  font-size: 14px;
  margin-bottom: 12px;
}

section {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
  background: var(--field);
  font: inherit;
}

input[type="checkbox"] {
  width: auto;
}
.numeric-pair { display: grid; grid-template-columns: minmax(0,1fr) 78px; gap: 10px; align-items: center; min-width: 0; }
.numeric-pair input.numeric-entry { width: 78px; min-width: 0; padding: 6px; font-variant-numeric: tabular-nums; }
.numeric-pair input.numeric-slider { width: 100%; min-width: 0; }

input[type="range"] {
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  height: 24px;
  min-width: 0;
  cursor: pointer;
}
.setting-row { display: grid; grid-template-columns: minmax(0, 1fr) 30px; gap: 8px; align-items: start; }
.setting-row label { min-width: 0; }
.setting-row output { text-align: right; font-variant-numeric: tabular-nums; line-height: 16px; }
.setting-reset { width: 30px; height: 30px; padding: 6px; display: grid; place-items: center; background: transparent; border-color: transparent; }
.setting-reset svg { width: 16px; height: 16px; }
.setting-reset:disabled, #resetSettings:disabled { opacity: 0.3; cursor: default; filter: none; }
#resetSettings { display: flex; align-items: center; justify-content: center; gap: 8px; }
#resetSettings svg { width: 18px; height: 18px; }

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--panel-2);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.04);
}

button.primary {
  border-color: transparent;
  color: var(--accent-text);
  background: var(--accent);
}

.actions {
  display: grid;
  gap: 9px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.file-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
  min-height: 34px;
}
.file-actions svg { width: 17px; height: 17px; flex: none; }
.view-home svg { width: 26px; height: 26px; }
#configFile[hidden] { display: none; }
#configStatus { font-size: 13px; overflow-wrap: anywhere; }
#configStatus:empty { display: none; }
.download-list {
  display: grid;
  gap: 0;
}

.download-list button {
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 7px 4px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  font-size: 13px;
}
.download-list button:hover { background: var(--panel-2); }
.download-list svg, .export-heading svg { width: 16px; height: 16px; flex: none; }
.export-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.export-heading h2 { margin: 0; }
.export-heading button { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 8px; }

.workspace {
  padding: 0;
  border: 0;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 72%, transparent);
}

#modelStats {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.viewer {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background:
    radial-gradient(circle at 28% 18%, light-dark(rgba(165, 67, 47, .10), rgba(216, 109, 85, .10)), transparent 34%),
    linear-gradient(180deg, light-dark(#fbfaf7, #1b1e1a), light-dark(#ebe8df, #10120f));
}

.viewer:active {
  cursor: grabbing;
}

.viewer canvas {
  display: block;
}

.view-widget {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: auto;
}

.cube-stage {
  position: relative;
  width: 96px;
  height: 86px;
  flex: 0 0 auto;
  perspective: 440px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel) 54%, transparent);
  border: 1px solid color-mix(in srgb, var(--line) 68%, transparent);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .13);
  backdrop-filter: blur(8px);
}

.orientation-cube {
  position: absolute;
  left: 25px;
  top: 23px;
  width: 42px;
  height: 42px;
  transform-style: preserve-3d;
  transition: transform .12s ease-out;
}

.axis {
  position: absolute;
  font-size: 10px;
  font-weight: 850;
  line-height: 1;
  user-select: none;
}

.axis-x {
  right: 9px;
  bottom: 19px;
  color: #c65b4c;
}

.axis-y {
  left: 12px;
  bottom: 18px;
  color: #68ad74;
}

.axis-z {
  left: 55px;
  top: 9px;
  color: #8070d8;
}

.cube-face,
.view-home {
  font: inherit;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  color: var(--text);
  background: color-mix(in srgb, var(--panel-2) 92%, transparent);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  user-select: none;
}

.cube-face {
  position: absolute;
  inset: 0;
  width: 42px;
  height: 42px;
  border-radius: 3px;
  color: #26302a;
  background: rgba(216, 219, 213, .92);
  border-color: rgba(38, 48, 42, .18);
  backface-visibility: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .32);
}

.cube-face:hover,
.view-home:hover {
  filter: brightness(1.08);
}

.cube-face-front {
  transform: translateZ(21px);
  background: rgba(192, 201, 196, .96);
}

.cube-face-back {
  transform: rotateY(180deg) translateZ(21px);
  background: rgba(205, 209, 202, .96);
}

.cube-face-right {
  transform: rotateY(90deg) translateZ(21px);
  background: rgba(218, 220, 214, .96);
}

.cube-face-left {
  transform: rotateY(-90deg) translateZ(21px);
  background: rgba(211, 216, 210, .96);
}

.cube-face-top {
  transform: rotateX(90deg) translateZ(21px);
  background: rgba(232, 207, 182, .98);
}

.cube-face-bottom {
  transform: rotateX(-90deg) translateZ(21px);
  background: rgba(184, 190, 184, .96);
}

.view-home {
  position: absolute;
  left: 112px;
  bottom: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  box-shadow: 0 10px 22px rgba(0, 0, 0, .16);
  backdrop-filter: blur(8px);
}

.view-home span {
  transform: translateY(-.5px);
}

.notes {
  min-height: 54px;
  padding: 14px 20px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(160px, 28vh) minmax(0, 1fr);
  }

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .viewer {
    min-height: 0;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .hint {
    white-space: normal;
  }
}
