@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap');

:root {
  --bg: #303841;
  --surface: #303841;
  --surface2: #303841;
  --surface3: #303841;
  --border: #7a8d96;
  --border-active: #9ab0bc;
  --text: #d8dee9;
  --text-dim: #8faabb;
  --text-bright: #edf0f4;
  --accent: #a4d59e;
  --accent2: #ccd9df;
  --success: #4ade80;
  --error: #f87171;
  --warning: #facc15;
  --radius: 6px;
  --sidebar-w: 272px;
  --filmstrip-h: 108px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── APP SHELL ──────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.main-area {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ─── VIEWPORT (left pane) ───────────────────────────── */
.viewport {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* View tabs at top of viewport */
.view-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 40px;
}

.view-tab {
  flex: 1;
  background: none;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0 16px;
  position: relative;
}

.view-tab:last-child {
  border-right: none;
}

.view-tab:hover {
  color: var(--text);
  background: var(--surface2);
}

.view-tab.active {
  color: var(--text-bright);
  background: var(--surface2);
}

.view-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
}

/* View area — contains 2D canvas, 3D canvas, drop zone, overlays */
.view-area {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #38424c 0%, #2a3340 100%);
}

#canvas2d,
#canvas3d {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ─── DROP ZONE ──────────────────────────────────────── */
.drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-zone.active {
  pointer-events: auto;
}

.drop-box {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 48px 64px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-dim);
  position: relative;
  pointer-events: auto;
}

.drop-box:hover,
.drop-box.dragover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(164, 213, 158, 0.06);
}

.drop-box input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-icon {
  font-size: 36px;
  margin-bottom: 12px;
  line-height: 1;
}

.drop-hint {
  font-size: 12px;
}

.drop-hint b {
  color: var(--accent);
}

/* ─── SELECTION HINT ─────────────────────────────────── */
.selection-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 10px;
  pointer-events: none;
}

.selection-hint-icon {
  font-size: 36px;
  opacity: 0.25;
}

.selection-hint-text {
  font-size: 12px;
  opacity: 0.5;
}

/* ─── CROP TOOLBAR (floating top) ────────────────────── */
.crop-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(48, 56, 65, 0.93);
  border: 1px solid var(--border-active);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 20;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.crop-toolbar-label {
  font-size: 10px;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding-right: 8px;
  border-right: 1px solid var(--border);
  margin-right: 2px;
}

/* Crop size indicator (floating bottom) */
.crop-size-info {
  position: absolute;
  bottom: 68px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(48, 56, 65, 0.88);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
  z-index: 10;
}

/* ─── 3D CONTROLS OVERLAY (floating bottom-left) ────── */
.controls-3d {
  position: absolute;
  bottom: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 20;
  pointer-events: none;
}

.controls-3d>* {
  pointer-events: auto;
}

.controls-left {
  display: flex;
  gap: 6px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 160px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

/* ─── IBL PICKER (floating top-right, 3D view) ──────── */
.ibl-picker {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0;
  background: rgba(48, 56, 65, 0.95);
  border: 1px solid var(--border-active);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  overflow: visible;
  min-width: 180px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.ibl-picker-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  transition: background 0.15s;
}

.ibl-picker-header:hover {
  background: rgba(255, 255, 255, 0.06);
}

.ibl-picker-thumb {
  width: 40px;
  height: 22px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}

.ibl-picker-label {
  flex: 1;
  font-size: 11px;
  color: var(--text);
  letter-spacing: 0.04em;
}

.ibl-picker-arrow {
  font-size: 9px;
  color: var(--text-dim);
  transition: transform 0.2s;
}

.ibl-picker.open .ibl-picker-arrow {
  transform: rotate(180deg);
}

.ibl-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: rgba(48, 56, 65, 0.98);
  border: 1px solid var(--border-active);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  min-width: 200px;
}

.ibl-picker-dropdown.hidden {
  display: none;
}

.ibl-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.ibl-option:last-child {
  border-bottom: none;
}

.ibl-option:hover {
  background: var(--surface2);
}

.ibl-option.active {
  background: rgba(164, 213, 158, 0.1);
}

.ibl-option img {
  width: 64px;
  height: 36px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}

.ibl-option span {
  font-size: 11px;
  color: var(--text);
  letter-spacing: 0.04em;
}

.ibl-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 8px;
  border-top: 1px solid var(--border);
}

.ibl-slider-label {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.ibl-slider-val {
  font-size: 11px;
  color: var(--text);
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* ─── RIGHT SIDEBAR ──────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Preset dropdown */
.preset-btn-wrap {
  position: relative;
}

.preset-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid var(--border-active);
  border-radius: var(--radius);
  z-index: 100;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.preset-dropdown.hidden {
  display: none;
}

.preset-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
  letter-spacing: 0.02em;
}

.preset-option:last-child {
  border-bottom: none;
}

.preset-option:hover {
  background: var(--surface3);
  color: var(--text-bright);
}

.preset-info {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.04em;
}

/* Resolution field */
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  width: 66px;
  flex-shrink: 0;
}

.input-pair {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
}

.input-pair span {
  color: var(--text-dim);
  font-size: 12px;
}

.input-pair input {
  flex: 1;
  min-width: 0;
}

/* Panel toggle buttons */
.panel-toggles {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
}

.panel-toggle:hover {
  border-color: var(--border-active);
  color: var(--text);
}

.panel-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(164, 213, 158, 0.08);
}

.toggle-arrow {
  font-size: 9px;
  transition: transform 0.2s;
  color: var(--text-dim);
}

.panel-toggle.active .toggle-arrow {
  transform: rotate(180deg);
  color: var(--accent);
}

/* Inline sub-panels (appear directly under their toggle button) */
.sub-panel-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 0 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
  overflow-x: hidden;
}

.sub-panel-content.hidden {
  display: none;
}

/* Sidebar bottom actions */
.sidebar-bottom {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

/* ─── RENAME SECTION ─────────────────────────────────── */
.rename-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-bottom: 2px;
}

.rename-label {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.rename-options {
  display: flex;
  gap: 14px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.radio-option input[type="radio"] {
  width: auto;
  accent-color: var(--accent);
  cursor: pointer;
}

.rename-startnum {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rename-startnum input[type="number"] {
  width: 72px;
}

/* ─── SHARED FORM ELEMENTS ───────────────────────────── */
.section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 2px;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-name {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

select,
input[type="number"],
input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: var(--radius);
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

select:focus,
input:focus {
  border-color: var(--border-active);
}

select option {
  background: var(--surface2);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hidden {
  display: none !important;
}

.conditional {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s;
  max-height: 300px;
  opacity: 1;
}

.conditional.hidden {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  display: unset !important;
}

.palette-swatch {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ─── IMAGE ADJUSTMENTS PANEL ───────────────────────────── */
.adj-slider-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  width: 100%;
}

.adj-slider-row .field-name {
  width: 90px;
  flex-shrink: 0;
}

.adj-slider {
  flex: 1;
  width: 0;
  min-width: 0;
}

.adj-val {
  font-size: 11px;
  color: var(--text);
  width: 30px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

label.field.adj-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

/* ─── BUTTONS ────────────────────────────────────────── */
.btn {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  padding: 7px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #1a2820;
  border-color: var(--accent);
  font-weight: 500;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-active);
  color: var(--text-bright);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: transparent;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface2);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: var(--border);
}

.btn-danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

.btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(164, 213, 158, 0.08);
}

/* ─── FILMSTRIP ──────────────────────────────────────── */
.filmstrip {
  height: var(--filmstrip-h);
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: center;
}

.filmstrip::-webkit-scrollbar {
  height: 4px;
}

.filmstrip::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.film-add {
  flex-shrink: 0;
  width: 52px;
  height: 86px;
  border: 2px dashed var(--border);
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  gap: 3px;
  font-size: 18px;
  transition: all 0.15s;
  user-select: none;
}

.film-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.film-add-label {
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.film-item {
  flex-shrink: 0;
  width: 133px;
  height: 86px;
  border-radius: 5px;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  background: #2a333d;
  transition: border-color 0.15s;
  user-select: none;
}

.film-item:hover {
  border-color: var(--border-active);
}

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

.film-item.done {
  border-color: rgba(74, 222, 128, 0.4);
}

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

.film-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.film-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.78);
  font-size: 8.5px;
  padding: 2px 5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.film-dots {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 3px;
  align-items: center;
}

.film-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.film-dot.crop {
  background: var(--accent);
}

.film-dot.done {
  background: var(--success);
}

.film-dot.error {
  background: var(--error);
}

/* ─── STATUS & MISC ──────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

.status-badge.pending {
  background: rgba(122, 141, 150, 0.15);
  color: var(--text-dim);
}

.status-badge.processing {
  background: rgba(164, 213, 158, 0.12);
  color: var(--accent);
}

.status-badge.done {
  background: rgba(74, 222, 128, 0.12);
  color: var(--success);
}

.status-badge.error {
  background: rgba(248, 113, 113, 0.12);
  color: var(--error);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner {
  width: 10px;
  height: 10px;
  border: 2px solid rgba(164, 213, 158, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ─── FOOTER ─────────────────────────────────────────── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  padding: 0 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.app-footer-title {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.app-footer-link {
  font-size: 11px;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: color 0.15s;
}

.app-footer-link:hover {
  color: var(--accent);
}

/* ─── TOAST ──────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease;
  max-width: 300px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ─── EXPORT BUTTON ROW ─────────────────────────────── */
.export-btn-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ─── SCROLLBAR ──────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-active);
}