:root {
  --bg: #0f172a;
  --panel: #1a2540;
  --panel-border: #2c3a5e;
  --text: #e8ecf7;
  --muted: #93a0bf;
  --accent: #4fd1c5;
  --accent-dark: #2fa79a;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 24px 20px 8px;
  text-align: center;
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px 18px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  color: var(--accent);
}

.gallery {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.gallery-item {
  position: relative;
  border: 2px solid transparent;
  background: #0f1830;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  width: 140px;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}

.badge-3d {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--accent);
  color: #06231f;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.gallery-item:hover {
  transform: translateY(-2px);
}

.gallery-item.selected {
  border-color: var(--accent);
}

.gallery-item img {
  width: 100%;
  height: 50px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}

.gallery-thumb-3d {
  width: 100%;
  height: 50px;
  background: #fff;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.gallery-item span {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text);
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.mode-tab {
  background: #0f1830;
  color: var(--muted);
  border: 1px solid var(--panel-border);
}

.mode-tab.active {
  background: var(--accent);
  color: #06231f;
  border-color: var(--accent);
}

.capture-controls,
.adjust-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}

button, .file-btn {
  background: var(--accent);
  color: #06231f;
  border: none;
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

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

button:not(:disabled):hover,
.file-btn:hover {
  background: var(--accent-dark);
}

.file-btn {
  display: inline-block;
}

.hidden {
  display: none;
}

.camera-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto 12px;
}

.camera-wrapper:has(#video.hidden) {
  display: none;
}

#video {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  border-radius: 10px;
  transform: scaleX(-1);
  background: #000;
}

#video.hidden {
  display: none;
}

#video.video-offscreen {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  max-height: none;
}

.shutter-btn {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.shutter-btn:active {
  background: var(--accent);
}

.snap-btn {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.snap-btn:active {
  background: var(--accent);
}

.stage-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-stack {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}

#stage {
  max-width: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#stage3d {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#stage3d.hidden {
  display: none;
}

.status-msg {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  margin: 0;
  font-size: 0.8rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 10px;
  border-radius: 6px;
  text-align: center;
}

.status-msg:empty {
  display: none;
}

.adjust-controls label {
  display: flex;
  flex-direction: column;
  font-size: 0.75rem;
  color: var(--muted);
  gap: 4px;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 4px 0 0;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 20px;
}
