:root {
  --bg-app: #121318;
  --bg-panel: #181a20;
  --bg-elevated: #20232a;
  --bg-hover: #2a2d36;
  --accent: #00e5ff;
  --accent-hover: #00c4db;
  --text: #f5f7fb;
  --text-muted: #8d94a5;
  --border: #2a2f39;
  --sidebar-width: 320px;
  --viewport-width: 50%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg-app);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  overflow: hidden;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
}

button,
.btn-upload,
select {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: 120ms ease;
}

button:hover,
.btn-upload:hover,
button.active {
  background: var(--bg-hover);
  border-color: #3f4754;
}

button.primary {
  background: var(--accent);
  color: #03121a;
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.small {
  padding: 6px 8px;
  font-size: 12px;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #5d67ff);
  color: #03121a;
  font-size: 18px;
  font-weight: 700;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-btn {
  min-width: 92px;
}

.main-shell {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: 260px;
  max-width: 420px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 0 0 auto;
}

.sidebar-header {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 15px;
  margin-bottom: 2px;
}

.sidebar-header span {
  font-size: 12px;
  color: var(--text-muted);
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-upload {
  display: block;
  text-align: center;
}

input[type="file"] {
  display: none;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

select {
  width: 100%;
}

.layer-props {
  display: none;
  gap: 10px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.slider-val {
  color: var(--text-muted);
  font-family: Consolas, monospace;
}

.full {
  width: 100%;
}

.panel-help {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.resizer {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.04);
  position: relative;
  user-select: none;
  pointer-events: auto;
}

.sidebar-resizer {
  width: 6px;
  cursor: col-resize;
  transition: background 0.2s;
}

.sidebar-resizer:hover {
  background: rgba(0, 229, 255, 0.2);
}

.view-resizer {
  width: 8px;
  cursor: col-resize;
  transition: background 0.2s;
}

.view-resizer:hover {
  background: rgba(0, 229, 255, 0.2);
}

.work-area {
  flex: 1;
  display: grid;
  grid-template-columns: var(--viewport-width, 50%) 8px minmax(320px, 1fr);
  min-width: 0;
  min-height: 0;
}

.viewport-panel,
.texture-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0f1117;
}

.panel-head {
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
}

.viewport-frame {
  flex: 1;
  position: relative;
  background: radial-gradient(circle at center, #20242d 0%, #151821 100%);
  min-height: 0;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#stats {
  position: absolute;
  top: 12px;
  left: 12px;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(7, 10, 15, 0.78);
  color: var(--text);
}

#workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0);
  background-size: 22px 22px;
}

#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  background: #222;
}

.layer-wrapper {
  position: absolute;
  border: 1px solid transparent;
  z-index: 20;
}

.layer-wrapper.active {
  border: 1px dashed var(--accent);
  z-index: 30;
}

.layer {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

.handles {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.layer-wrapper.active .handles {
  display: block;
}

.handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: auto;
}

.handle.tl {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}

.handle.tr {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}

.handle.bl {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

.handle.br {
  bottom: -6px;
  right: -6px;
  cursor: nwse-resize;
}

.handle.rotate {
  top: -24px;
  left: 50%;
  margin-left: -5px;
  background: var(--accent);
  border-color: #fff;
  cursor: grab;
}

.handle.rotate:active {
  cursor: grabbing;
}

#context-menu {
  display: none;
  position: fixed;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  z-index: 1000;
}

.menu-item {
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--accent);
  color: #000;
}

.shortcut {
  color: var(--text-muted);
  font-size: 11px;
}

.menu-item:hover .shortcut {
  color: #000;
}

#hierarchy {
  max-height: 220px;
  overflow: auto;
  font-size: 13px;
}

.hier-list {
  list-style: none;
  padding-left: 6px;
}

.hier-item .hier-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  cursor: pointer;
}

.hier-item.selected>.hier-label {
  background: rgba(0, 229, 255, 0.16);
  border-radius: 4px;
}

.hier-expander {
  width: 14px;
  color: var(--text-muted);
}

.hier-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hier-item>ul {
  margin-left: 14px;
}

#inspector {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
}

#texturePreviewContainer {
  margin-top: 8px;
}

#texturePreviewContainer img,
#texturePreviewContainer canvas {
  width: 100%;
  max-height: 150px;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #111;
}

#texturePreviewContainer a {
  display: block;
  color: var(--text);
  text-decoration: none;
}

.preview-overlay {
  display: none;
}