* {
  box-sizing: border-box;
}

:root {
  --bg: #0a0908;
  --bg-viewport: #12100e;
  --panel: #161412;
  --panel-2: #1e1a16;
  --text: #f2ebe0;
  --muted: #a89478;
  --accent: #c9a24a;
  --accent-dim: #8a6b2e;
  --accent-2: #6b1f1f;
  --line: #3d3428;
  --ok: #3d6b45;
  --sidebar-w: 320px;
  --font-display: "Cinzel", Georgia, serif;
  --font-ui: "IBM Plex Sans", "Segoe UI", sans-serif;
}

body[data-theme="light"] {
  --bg: #e8e0d0;
  --bg-viewport: #ddd4c4;
  --panel: #f5f0e4;
  --panel-2: #ebe3d2;
  --text: #1a1612;
  --muted: #6b5e4a;
  --accent: #9a6b12;
  --accent-dim: #7a5510;
  --line: #c4b08a;
  --ok: #2f6f3e;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

.sidebar-left {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  box-shadow: inset -1px 0 0 #ffffff08;
}

.export-dock {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1f1810, #181410);
  flex-shrink: 0;
}

body[data-theme="light"] .export-dock {
  background: linear-gradient(180deg, #f0e8d8, #e8decc);
}

.export-dock button {
  margin: 0;
  width: 100%;
}

.panel-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #1a1612, #14110e);
  flex-shrink: 0;
}

body[data-theme="light"] .panel-tabs {
  background: linear-gradient(180deg, #ebe3d2, #e0d6c4);
}

.panel-tabs .rail-btn {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.panel-tabs .rail-btn:hover {
  color: var(--text);
  background: #ffffff0a;
}

.panel-tabs .rail-btn.active {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: #c9a24a14;
}

.tabs-spacer {
  flex: 1;
}

.tabs-mini select {
  font-size: 10px;
  padding: 4px 6px;
  width: auto;
  min-width: 52px;
}

.inspector {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-left: none;
  background: transparent;
  box-shadow: none;
}

.viewport-wrap {
  position: relative;
  min-width: 0;
  background: radial-gradient(ellipse at 50% 30%, #1f1a14 0%, var(--bg-viewport) 55%);
}

body[data-theme="light"] .viewport-wrap {
  background: radial-gradient(ellipse at 50% 30%, #f0e8d8 0%, var(--bg-viewport) 60%);
}

#viewport {
  width: 100%;
  height: 100%;
}

.viewport-hud {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}

.hud-group {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #0a0808c0;
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

body[data-theme="light"] .hud-group {
  background: #f5f0e4e0;
}

.hud-btn {
  margin: 0;
  padding: 5px 10px;
  font-size: 10px;
  border-radius: 5px;
  background: #2a2218;
  border: 1px solid var(--line);
  color: var(--text);
  cursor: pointer;
}

.hud-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
  filter: none;
}

.hud-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  padding: 0 6px;
  cursor: pointer;
}

.hud-toggle input {
  accent-color: var(--accent);
}

.hud-select {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--muted);
  padding: 0 4px;
}

.hud-select select {
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  max-width: 88px;
  cursor: pointer;
}

.progress-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: #00000088;
  backdrop-filter: blur(2px);
}

.progress-overlay.hidden {
  display: none;
}

.progress-card {
  min-width: 240px;
  padding: 16px 20px;
  border-radius: 10px;
  border: 1px solid var(--accent-dim);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: 0 12px 40px #00000080;
}

.progress-card p {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--accent);
  font-family: var(--font-display);
}

.progress-track {
  height: 6px;
  border-radius: 3px;
  background: #00000044;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.15s ease;
}

.inspector-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, #ffffff06, transparent),
    repeating-linear-gradient(90deg, transparent, transparent 8px, #c9a24a08 8px, #c9a24a08 9px);
}

.inspector-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.inspector-sub {
  margin: 4px 0 0;
  font-size: 10px;
  color: var(--muted);
}

.inspector-panel {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 20px;
  scrollbar-width: thin;
}

.inspector-panel[hidden] {
  display: none !important;
}

.tool-box,
.forge-panel,
.stl-addon-transforms {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: #00000018;
  box-shadow: inset 0 0 0 1px #ffffff06;
}

.forge-panel {
  border-color: var(--accent-dim);
  background: linear-gradient(135deg, #c9a24a0a, #00000020);
}

.tool-box h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.field {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.field > span {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}

.field output {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 56px;
  gap: 6px;
  align-items: center;
}

.checkbox {
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 8px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.forge-reverse-row {
  margin-top: -2px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--accent-dim);
  background: #c9a24a12;
}

.forge-reverse-row > span {
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
}

select,
input[type="number"] {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0f0d0b;
  color: var(--text);
  padding: 6px 8px;
  font-size: 11px;
}

body[data-theme="light"] select,
body[data-theme="light"] input[type="number"] {
  background: #fffef8;
}

input[type="file"] {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 6px;
  background: #00000015;
  color: var(--text);
  font-size: 10px;
}

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

button {
  width: 100%;
  margin-top: 4px;
  border: 1px solid #00000040;
  border-radius: 6px;
  padding: 8px 10px;
  color: #fff;
  background: linear-gradient(180deg, var(--ok), #2a5030);
  font-weight: 600;
  font-size: 11px;
  cursor: pointer;
  transition: filter 0.15s, border-color 0.15s;
}

button:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: none;
}

button.ghost {
  background: #ffffff10;
  color: var(--text);
  border-color: var(--line);
}

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

.btn-export-combined {
  background: linear-gradient(180deg, #3a5a72, #243848);
}

.btn-export-zip {
  background: linear-gradient(180deg, #6c4f25, #4f391a);
}

.export-block {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  background: #c9a24a0c;
}

.row-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

#gizmoModeBtn {
  background: linear-gradient(180deg, #4c6b68, #314744);
}

#resetSettingsBtn {
  background: linear-gradient(180deg, #6b5a2a, #4b3d1c);
}

#clearCacheBtn {
  background: linear-gradient(180deg, #784545, #552f2f);
}

#fitBaseToEmblemBtn,
#fitEmblemToBaseBtn {
  background: linear-gradient(180deg, #4b3d6c, #33284b);
}

.hint {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.forge-hint {
  margin-top: -4px;
  color: var(--accent-dim);
}

#status {
  white-space: pre-wrap;
  background: #00000028;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-size: 10px;
  line-height: 1.4;
  margin-top: 8px;
}

.license-note {
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
  margin-top: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #00000088;
  display: grid;
  place-items: center;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(680px, 92vw);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: 0 20px 50px #00000090;
  padding: 14px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.modal-head strong {
  font-family: var(--font-display);
  color: var(--accent);
}

.modal-close {
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
}

.library-browser {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px;
  min-height: 380px;
}

.library-sidebar {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  overflow: auto;
}

.library-category-list {
  display: grid;
  gap: 6px;
}

.library-cat-btn {
  text-align: left;
  background: #1a1612;
  border: 1px solid var(--line);
  margin: 0;
}

.library-cat-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.library-grid-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  overflow: auto;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.library-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  background: #0f0d0b;
}

.library-card.active {
  border-color: var(--ok);
}

.library-card.batch-picked {
  border-color: var(--accent);
}

.library-thumb {
  height: 72px;
  border-radius: 6px;
  background: #e8e8e8;
  margin-bottom: 4px;
  overflow: hidden;
}

.library-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.library-name {
  font-size: 9px;
  line-height: 1.2;
}

.library-hover-preview {
  position: fixed;
  z-index: 10001;
  width: 280px;
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  background: var(--panel);
  padding: 8px;
  pointer-events: none;
}

.library-hover-preview.hidden {
  display: none;
}

.library-hover-preview img {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #eee;
  border-radius: 6px;
}

.batch-selection-list {
  max-height: 120px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  display: grid;
  gap: 4px;
}

.batch-selection-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  font-size: 10px;
}

.batch-selection-item button {
  margin: 0;
  padding: 3px 8px;
  font-size: 9px;
}

button.danger {
  background: linear-gradient(180deg, #8b2f2f, #5f1f1f);
}

.modal-actions {
  margin-top: 10px;
}

.modal-card-wide {
  max-width: min(920px, 96vw);
}

.stl-library-actions {
  margin-bottom: 4px;
}

.stl-library-actions button {
  margin-top: 0;
}

.stl-selected-name {
  margin: 0 0 8px;
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
}

.stl-library-browser {
  display: grid;
  gap: 8px;
}

.stl-library-preview {
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: radial-gradient(circle at 50% 35%, #2a2622, #0f0d0b 70%);
  overflow: hidden;
}

.stl-library-preview canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stl-library-preview-name {
  margin: 0;
  font-size: 11px;
  color: var(--text);
  font-weight: 600;
}

.library-card.stl-card .library-thumb {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.library-card.stl-card.active {
  border-color: var(--ok);
  box-shadow: 0 0 0 1px #3ecf8e55;
}

@media (max-width: 960px) {
  :root {
    --sidebar-w: 280px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar-left {
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
}
