:root {
  --bg: #1b1f1b; --ui: #1f241f; --ui2: #141914; --line: #2b3a2b; --text: #e8e8e8;
  --accent: #7bd96f; --btn: #2e7a2e; --btn-line: #185918; --warn: #ffce5b; --err: #ff6b6b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; color: var(--text);
  background:
    linear-gradient(#2f7d2f 0 18px, #2e6e2e 18px 20px, #2b5f2b 20px 22px, #274f27 22px 24px, #224422 24px 28px, #1f3b1f 28px 30px, #1c331c 30px 32px, var(--bg) 32px 100%)
    no-repeat, var(--bg);
  font: 16px/1.4 "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
}
.wrap { max-width: 1100px; margin: 48px auto; padding: 0 16px; }
.card {
  background: linear-gradient(0deg, #1e1e1e, #232323);
  border: 4px solid #3b3b3b; border-radius: 12px; box-shadow: 0 12px 24px rgba(0,0,0,.35); overflow: hidden;
}
.header {
  display: flex; align-items: center; gap: 14px; padding: 18px 20px;
  background: linear-gradient(#46b346, #369b36); border-bottom: 4px solid #2d7a2d;
  text-shadow: 1px 1px 0 #1b5, 2px 2px 0 #083;
}
.cube {
  width: 44px; height: 44px; border: 3px solid #2d7a2d; flex: none;
  background: linear-gradient(135deg, #4bd14b 0 50%, #36b236 50% 100%);
  box-shadow: inset -6px -6px 0 rgba(0,0,0,.15); transform: rotate(45deg);
}
h1 { margin: 0; font-size: 26px; letter-spacing: .5px; flex: 1; }
.logout { margin: 0; text-shadow: none; }
.wrap-narrow { max-width: 420px; }
.viewer.relogin { width: min(420px, calc(100vw - 32px)); }
.login { display: flex; flex-direction: column; gap: 10px; }
.login input {
  background: #111; color: var(--text); border: 1px solid #3b4a3b; border-radius: 8px; padding: 10px; font: inherit;
}
.login p { margin: 0; }
.content { padding: 20px; }
.hint { background: #213021; border: 1px solid #335c33; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; }
.warn-box { background: #33301b; border-color: #6b5f2a; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.err { color: var(--err); }
.ok { color: var(--accent); }
small, .muted { opacity: .8; }
a { color: var(--accent); }
code { background: #101410; padding: 2px 6px; border-radius: 6px; border: 1px solid #1f2a1f; word-break: break-all; }

.btn {
  display: inline-block; padding: 8px 12px; background: var(--btn); border: 2px solid var(--btn-line); border-radius: 10px;
  color: #fff; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; border-color: #3b4a3b; }
.btn-danger { background: #7a2e2e; border-color: #591818; }
.btn-small { padding: 4px 8px; font-size: 13px; border-radius: 8px; }

/* Upload */
.drop {
  border: 3px dashed #3e9340; background: rgba(62,147,64,.08);
  border-radius: 14px; padding: 18px; text-align: center; transition: .12s ease;
}
.drop.dragover { background: rgba(62,147,64,.20); transform: scale(1.01); }
.drop input[type=file] { display: none; }
.drop p { margin: 8px 0 0; }
.drop .btn { margin-top: 8px; }
.queue { margin-top: 14px; }
.item {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  background: var(--ui); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0;
}
.item .status { font-size: 13px; margin-top: 4px; }
.item select { background: #111; color: var(--text); border: 1px solid #3b4a3b; border-radius: 8px; padding: 6px 8px; font: inherit; }
.thumb {
  width: 56px; height: 56px; background: #111; border-radius: 8px; display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.thumb img { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.badge {
  display: inline-block; font-size: 12px; padding: 2px 6px; border-radius: 6px; border: 1px solid #3a3a3a; margin-left: 6px; background: #2b2b2b;
}
.progress { height: 8px; border-radius: 8px; background: #151515; border: 1px solid #2a2a2a; overflow: hidden; margin-top: 6px; }
.bar { height: 100%; width: 0%; background: linear-gradient(90deg, #48d348, #78f078); }
.queue-actions { display: flex; gap: 10px; }

/* Library */
.tabs { display: flex; gap: 6px; margin: 26px 0 0; border-bottom: 2px solid #3b3b3b; }
.tab {
  background: none; border: 2px solid transparent; border-bottom: none; color: var(--text); font: inherit; font-weight: 600;
  padding: 8px 14px; border-radius: 10px 10px 0 0; cursor: pointer; margin-bottom: -2px;
}
.tab[aria-selected=true] { background: var(--ui); border-color: #3b3b3b; }
.count { opacity: .7; font-weight: 400; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; padding-top: 16px; }
.empty { grid-column: 1 / -1; opacity: .7; padding: 20px 0; }
.file {
  background: var(--ui); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column;
}
.file-preview {
  height: 150px; background: repeating-conic-gradient(#202020 0 25%, #282828 0 50%) 50% / 20px 20px;
  display: flex; align-items: center; justify-content: center; cursor: pointer; border: none; padding: 0; width: 100%; position: relative;
}
.file-preview img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.file-preview .open3d {
  position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 3px 7px; border-radius: 6px;
}
.file-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.file-name { font-weight: 600; word-break: break-all; }
.file-url { display: flex; gap: 6px; }
.file-url input {
  flex: 1; min-width: 0; background: #101410; color: var(--text); border: 1px solid #1f2a1f; border-radius: 6px; padding: 4px 6px; font: 12px monospace;
}
.file-actions { display: flex; gap: 6px; justify-content: space-between; align-items: center; }

/* Viewer */
.viewer {
  width: min(1000px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 4px solid #3b3b3b; border-radius: 12px;
  background: #1e1e1e; color: var(--text);
}
.viewer::backdrop { background: rgba(0,0,0,.7); }
.viewer-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 2px solid #2d2d2d; }
.viewer-head strong { word-break: break-all; }
.viewer-body { display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.viewer-canvas { height: min(560px, 70vh); background: #10140f; position: relative; }
.viewer-canvas canvas { display: block; width: 100%; height: 100%; }
.viewer-side { padding: 14px; display: flex; flex-direction: column; gap: 12px; font-size: 14px; overflow: auto; max-height: min(560px, 70vh); }
.viewer-side h3 { margin: 0; font-size: 15px; }
.viewer-side label { display: flex; gap: 8px; align-items: center; }
.viewer-side input[type=number] {
  width: 64px; background: #111; color: var(--text); border: 1px solid #3b4a3b; border-radius: 6px; padding: 4px 6px; font: inherit;
}
.frame-name { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.frame-name input {
  flex: 1; min-width: 0; max-width: 280px; background: #111; color: var(--text); border: 1px solid #3b4a3b; border-radius: 6px; padding: 4px 6px; font: 13px monospace;
}
.editor-section > input[type=text] {
  background: #111; color: var(--text); border: 1px solid #3b4a3b; border-radius: 6px; padding: 5px 6px; font: 13px monospace;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #2b2b2b; border: 1px solid #3a3a3a; color: var(--text); border-radius: 999px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: 13px; }
.chip.active { background: var(--btn); border-color: var(--btn-line); }
.big { font-size: 22px; font-weight: 700; color: var(--accent); }

/* Editor */
.editor { width: min(1200px, calc(100vw - 32px)); }
.editor .viewer-body { grid-template-columns: 1fr 340px; }
.editor .viewer-side { max-height: min(680px, calc(100vh - 140px)); gap: 6px; }
.editor-actions { display: flex; gap: 8px; }
.editor-main { display: flex; flex-direction: column; gap: 8px; padding: 10px; min-width: 0; }
.editor-stage { position: relative; height: min(560px, calc(100vh - 230px)); min-height: 260px; background: #10140f; border-radius: 8px; overflow: hidden; }
.editor-stage-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.editor-info { font-size: 13px; opacity: .85; min-height: 1.4em; }
.editor-section { border-top: 1px solid #2d2d2d; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.editor-section:first-child { border-top: none; padding-top: 0; }
.editor-section select { background: #111; color: var(--text); border: 1px solid #3b4a3b; border-radius: 6px; padding: 5px 6px; font: inherit; }
.editor-section p { margin: 0; font-size: 12px; }
.editor-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.viewer-side .editor-slider { display: grid; grid-template-columns: 80px 1fr 40px; gap: 8px; align-items: center; }
.editor-slider output { text-align: right; font-variant-numeric: tabular-nums; }
.editor-thumb {
  max-width: 100%; max-height: 160px; align-self: flex-start; image-rendering: pixelated;
  background: repeating-conic-gradient(#2a2a2a 0 25%, #3a3a3a 0 50%) 50% / 12px 12px;
}
.item .edit-cell { display: flex; gap: 6px; align-items: center; }

@media (max-width: 760px) {
  h1 { font-size: 20px; }
  .header { padding: 14px; }
  .viewer-body, .editor .viewer-body { grid-template-columns: 1fr; }
  .editor-stage { height: 50vh; }
  .editor .viewer-side { max-height: none; }
  .viewer-head { flex-wrap: wrap; }
  .editor-actions { width: 100%; }
  .editor-actions .btn { flex: 1; white-space: normal; }
  .viewer-canvas { height: 50vh; }
  .viewer-side { max-height: none; }
  .item { grid-template-columns: 48px 1fr; }
  .item > :last-child { grid-column: 1 / -1; }
}
