/* ============================================
   SVG to 3D Glass Icon — UI Styles
   ============================================ */

@font-face {
  font-family: 'Avito Sans Text Mono';
  src: url('/3d-icons/fonts/AvitoSansTextMono-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* CSS Custom Properties */
:root {
  --font-mono: 'Avito Sans Text Mono', ui-monospace, monospace;

  /* Light theme (default) */
  --bg-primary:   #ffffff;
  --bg-secondary: #f0f1f2;
  --bg-tertiary:  #e5e6e7;
  --bg-input:     #f0f1f2;
  --bg-fill:      #d9d9da;
  --text-primary:   #000000;
  --text-secondary: #86909a;
  --text-muted:     #86909a;
  --border-color:   rgba(0,0,0,0.1);
  --ring-color:     #000000;
  --btn-primary-bg:   #21292e;
  --btn-primary-text: #f0f6fc;
  --viewer-bg:    #ffffff;
}

[data-theme="dark"] {
  --bg-primary:   #21292e;
  --bg-secondary: #2a3439;
  --bg-tertiary:  #323b41;
  --bg-input:     #2a3439;
  --bg-fill:      #3d484f;
  --text-primary:   #f0f6fc;
  --text-secondary: #c1c9d0;
  --text-muted:     #7a8891;
  --border-color:   rgba(255,255,255,0.1);
  --ring-color:     #f0f6fc;
  --btn-primary-bg:   #f0f6fc;
  --btn-primary-text: #21292e;
  --viewer-bg:    #000000;
}

/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  font-weight: 400;
  line-height: 12px;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Layout */
.app {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  align-items: center;
}

/* Mobile warning */
#mobile-warning {
  display: none;
  height: 100%;
  width: 100%;
  padding: 24px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.6;
  align-items: center;
  justify-content: center;
  text-align: center;
}

#mobile-warning p {
  max-width: 520px;
}

/* ── UI Panel ── */
.ui-panel {
  width: 288px;
  flex-shrink: 0;
  height: 100%;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) transparent;
  transition: background-color 0.3s ease;
}

.ui-panel::-webkit-scrollbar { width: 6px; }
.ui-panel::-webkit-scrollbar-track { background: transparent; }
.ui-panel::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

.panel-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-content > .fieldset:not(:first-child):has(.fieldset-label),
.panel-content > .advanced-divider,
.panel-content > .export-actions {
  margin-top: 22px;
}

/* ── 3D Viewer ── */
.viewer {
  flex: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--viewer-bg);
  transition: background-color 0.3s ease;
}

.viewer-inner {
  position: relative;
  width: min(100%, 100vh);
  aspect-ratio: 1;
  max-width: 100%;
  max-height: 100vh;
}

#c {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.load-overlay {
  position: absolute;
  inset: 0;
  background: #ffffff;
  z-index: 10;
  pointer-events: none;
  transition: opacity 0.6s ease-out;
}
.load-overlay.fade-out { opacity: 0; }

.viewer-export-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 5;
  height: 32px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background 0.15s;
}
.viewer-export-btn:hover { background: var(--bg-tertiary); }

/* ── Desktop-only breakpoint ── */
@media (max-width: 1024px) {
  .app          { display: none; }
  #mobile-warning { display: flex; }
}

/* ── Input Groups (file input) ── */
.input-group {
  display: flex;
  flex-direction: column;
}

.fieldset > .input-group {
  margin-top: 18px;
}

/* ── Fieldset grouping ── */
.fieldset {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.fieldset-label {
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text-primary);
  line-height: 14px;
  height: auto;
  display: flex;
  align-items: center;
  margin: 0;
}

/* Collapsible sections */
.fieldset-label.expandable {
  cursor: pointer;
  list-style: none;
  user-select: none;
  justify-content: space-between;
  gap: 4px;
  width: 100%;
}
.fieldset-label.expandable::-webkit-details-marker { display: none; }

.collapsible-section { width: 100%; }

.arrow-icon {
  display: block;
  flex-shrink: 0;
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 0.2s ease;
}
.collapsible-section[open] > summary .arrow-icon {
  transform: rotate(180deg);
}

/* Group labels (left / right / up / front) */
.group-label {
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 8px;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text-secondary);
  line-height: 12px;
  margin-top: 4px;
  margin-bottom: 0;
}
.group-label:first-child { margin-top: 0; }

/* Advanced divider */
.advanced-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}
.advanced-divider::before,
.advanced-divider::after {
  content: "";
  height: 1px;
  background: var(--border-color);
  flex: 1;
}
.advanced-divider > span {
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text-secondary);
  line-height: 12px;
  white-space: nowrap;
}

/* ── Field rows ── */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 24px;
}

.field-name {
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text-primary);
  line-height: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.fields-group,
.field-rows-tight,
.subgroup-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.collapsible-section > .fields-group {
  margin-top: 18px;
}

.subgroup {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
}

.fields-group > .subgroup:not(:first-child),
.subgroup-stack > .subgroup:not(:first-child),
.fields-group > .subgroup + .field-row {
  margin-top: 22px;
}

.subgroup-label {
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 9px;
  font-weight: 400;
  text-transform: uppercase;
  color: var(--text-secondary);
  line-height: 12px;
  margin: 0 0 14px;
}

/* Fixed-width right-side control */
.field-control {
  width: 120px;
  flex-shrink: 0;
}

/* ── File Input ── */
.file-input {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 10px;
  background: var(--bg-secondary);
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  transition: background-color 0.2s ease;
}
.file-input:hover { background: var(--bg-tertiary); }

.file-input input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.file-icon, .file-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.file-name {
  flex: 1;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Button Groups ── */
.button-group {
  display: flex;
  gap: 4px;
}

.option-btn {
  flex: 1;
  height: 32px;
  padding: 0 8px;
  line-height: 32px;
  background: var(--bg-input);
  border: none;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.option-btn:hover  { background: var(--bg-fill); }
.option-btn.selected {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

/* ── Bump Pattern Tabs ── */
.pattern-tabs {
  display: grid;
  grid-template-columns: repeat(4, 59px);
  gap: 4px;
  width: 248px;
}

.pattern-card {
  width: 59px;
  height: 59px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.pattern-card:hover {
  background: var(--bg-tertiary);
}

.pattern-card.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid var(--text-primary);
  border-radius: 6px;
  pointer-events: none;
}

.pattern-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ── Sliders ── */
.slider-wrap {
  position: relative;
  width: 120px;
  height: 24px;
  flex-shrink: 0;
}

.slider {
  width: 100%;
  height: 24px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(
    to right,
    var(--bg-fill) 0,
    var(--bg-fill) var(--range-progress, 0%),
    var(--bg-input) var(--range-progress, 0%),
    var(--bg-input) 100%
  );
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  display: block;
}
.slider::-webkit-slider-runnable-track {
  height: 100%;
  background: transparent;
  border-radius: 6px;
}
.slider::-moz-range-track {
  height: 100%;
  background: transparent;
  border-radius: 6px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 0;
  height: 0;
  background: transparent;
  border: none;
}
.slider::-moz-range-thumb {
  width: 0;
  height: 0;
  background: transparent;
  border: none;
}

.slider-value {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  color: var(--text-secondary);
  pointer-events: none;
  white-space: nowrap;
  line-height: 1;
}

/* ── Color swatches ── */
.swatches-wrap {
  display: flex;
  gap: 4px;
  height: 24px;
  flex-shrink: 0;
  align-items: stretch;
}

.swatch {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s ease;
  box-sizing: border-box;
}
.swatch:hover { transform: scaleY(1.05); }
.swatch.active::after,
.swatch.selected::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--text-primary);
  border-radius: 6px;
  pointer-events: none;
}

/* Белый свотч фона — всегда с рамкой, чтобы не теряться на белом фоне */
.swatch-bg-light {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}

.swatch-custom {
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  color: var(--text-secondary);
}
.swatch-custom::before {
  content: '#';
  pointer-events: none;
}

/* Color display (background custom picker) */
.color-display-wrap {
  position: relative;
  width: 28px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 6px;
  cursor: pointer;
  flex-grow: 0;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
}
.bg-color-display { flex-shrink: 0; }
.bg-color-display::before {
  content: '#';
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  color: var(--text-secondary);
}
.bg-color-display.active::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 6px;
  border: 1.5px solid var(--text-primary);
  pointer-events: none;
}
.color-display { display: none; }
.color-hex     { display: none; }
.color-picker-hidden {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  font-size: 0;
  border: none;
  padding: 0;
}

/* ── Orientation presets grid 3×3 ── */
.orient-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 100%;
}

.orient-card {
  aspect-ratio: 1;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s;
  overflow: hidden;
  position: relative;
}
.orient-card:hover  { background: var(--bg-tertiary); }
.orient-card.active { border-color: var(--text-primary); }

.orient-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  pointer-events: none;
}

/* ── HDRI selector ── */
.hdri-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 100%;
}

#secondary-hdri-cards {
  margin: 10px 0 6px;
}

.hdri-card {
  position: relative;
  aspect-ratio: 2 / 1;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s;
}

.hdri-card:hover { background: var(--bg-tertiary); }

.hdri-card.selected {
  border-color: var(--text-primary);
}

.hdri-preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 6px;
  pointer-events: none;
}

/* Loading spinner overlay */
.hdri-loading {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
  border-radius: 6px;
}

.hdri-card.loading .hdri-loading {
  display: flex;
}

.hdri-card.loading .hdri-loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: hdri-spin 0.7s linear infinite;
}

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

/* ── Export Buttons ── */
.export-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.export-actions .field-row {
  margin-bottom: 8px;
}

.export-btn {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  line-height: 32px;
  border: none;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  font-weight: 400;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.export-btn:hover { opacity: 0.85; }

.export-btn--primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}
.export-btn--secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
}

/* ── Mobile Toggle & Drawer ── */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 100;
  padding: 12px;
  background: var(--bg-primary);
  border: none;
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}
.mobile-toggle:hover { opacity: 0.9; }
.mobile-toggle .hidden { display: none; }

.mobile-drawer {
  display: none;
  position: fixed;
  inset: auto 0 0 0;
  z-index: 90;
  background: var(--bg-primary);
  border-radius: 16px 16px 0 0;
  max-height: 50vh;
  transform: translateY(calc(100% - 56px));
  transition: transform 0.3s ease;
}
.mobile-drawer.open { transform: translateY(0); }

.drawer-handle {
  width: 100%;
  padding: 16px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.handle-bar {
  width: 48px;
  height: 4px;
  background: var(--text-muted);
  border-radius: 2px;
}
.handle-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-variation-settings: 'wdth' 100;
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
}
.mobile-drawer.open .handle-text svg { transform: rotate(180deg); }

.drawer-content {
  overflow-y: auto;
  max-height: calc(50vh - 56px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  -webkit-overflow-scrolling: touch;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .app { flex-direction: column; }
  .ui-panel { display: none; }
  .mobile-toggle { display: flex; }
  .mobile-drawer { display: block; }
  .viewer {
    width: 100%;
    flex: 0 0 50vh;
    min-height: 50vh;
    min-width: 0;
    align-self: stretch;
  }
}

@media (max-width: 480px) {
  .panel-content, .drawer-content { padding: 16px; gap: 4px; }
  .slider-wrap, .field-control    { width: 100px; }
  .swatches-wrap                  { flex-wrap: wrap; }
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.input-group, .fieldset {
  animation: fadeIn 0.3s ease forwards;
}
.fieldset:nth-child(1) { animation-delay: 0.05s; }
.fieldset:nth-child(2) { animation-delay: 0.10s; }
.fieldset:nth-child(3) { animation-delay: 0.15s; }
.fieldset:nth-child(4) { animation-delay: 0.20s; }
.fieldset:nth-child(5) { animation-delay: 0.25s; }
.fieldset:nth-child(6) { animation-delay: 0.30s; }
.fieldset:nth-child(7) { animation-delay: 0.35s; }

/* ── Focus visible ── */
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--ring-color);
  outline-offset: 2px;
}
