/* Theme tokens */
:root {
  --fg: #5C6A72;
  --bg0: #FDF6E3;
  --bg1: #F4F0D9;
  --bg2: #EFEBD4;
  --bg3: #E6E2CC;
  --bg4: #E0DCC7;
  --muted: #829181;
  --red: #F85552;
  --orange: #F57D26;
  --yellow: #DFA000;
  --green: #8DA101;
  --blue: #3A94C5;
  --aqua: #35A77C;
  --purple: #DF69BA;
  --text-main: #5C6A72;
}

[data-theme="dark"] {
  --fg: #D3C6AA;
  --bg0: #2D353B;
  --bg1: #343F44;
  --bg2: #3D484D;
  --bg3: #475258;
  --bg4: #4F585E;
  --muted: #9DA9A0;
  --red: #E67E80;
  --orange: #E69875;
  --yellow: #DBBC7F;
  --green: #A7C080;
  --blue: #7FBBB3;
  --aqua: #83C092;
  --purple: #D699B6;
  --text-main: #D3C6AA;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  color: var(--fg);
  background: var(--bg0);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  margin: 8px 0;
}

.muted {
  color: var(--muted);
}

.card {
  background: var(--bg1);
  border: 1px solid var(--bg3);
  border-radius: 10px;
  padding: 16px;
  margin: 12px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.hidden {
  display: none;
}

button,
.button {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover,
.button:hover {
  filter: brightness(0.95);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

input[type="number"],
select,
input[type="range"] {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--bg4);
  background: var(--bg0);
  color: var(--fg);
}

/* Compare slider */
.compare {
  margin-top: 16px;
}

.compare-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  overflow: hidden;
  /* Responsive height based on current texture aspect ratio (set via JS). Fallback to square. */
  aspect-ratio: var(--aspect, 1 / 1);
}

.compare-wrapper img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#imgOriginal {
  clip-path: inset(0 50% 0 0);
  -webkit-user-drag: none;
  user-select: none;
}

#imgPreview {
  clip-path: inset(0 0 0 50%);
  -webkit-user-drag: none;
  user-select: none;
}

#compareSlider {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
}

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 1px);
  width: 2px;
  background: var(--purple);
  opacity: 0.8;
}

.theme-toggle {
  font-size: 14px;
}

/* Header Controls */
.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.github-link svg {
  width: 24px;
  height: 24px;
  fill: var(--fg);
  transition: opacity 0.2s;
}

.github-link:hover svg {
  opacity: 0.8;
}

/* Upload Drop Zone */
.drop-zone {
  position: relative;
  border: 2px dashed var(--bg4);
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  transition: all 0.2s ease;
  background: var(--bg2);
  cursor: pointer;
  margin-bottom: 16px;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--blue);
  background: var(--bg3);
}

.drop-zone-content {
  pointer-events: none;
  /* Let events pass to parent */
}

.upload-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.drop-text {
  font-size: 1.1em;
  font-weight: 500;
  margin: 0;
  color: var(--fg);
}

.drop-subtext {
  font-size: 0.9em;
  color: var(--muted);
  margin: 8px 0 0 0;
}

.file-name {
  margin-top: 12px;
  font-weight: bold;
  color: var(--blue);
}

/* Hide default file input but keep it functional */
#glbFile {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Switch Toggle Styles */
.theme-toggle-wrapper {
  display: flex;
  align-items: center;
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 30px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg3);
  -webkit-transition: .4s;
  transition: .4s;
  border: 1px solid var(--bg4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
  font-size: 14px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: var(--fg);
  -webkit-transition: .4s;
  transition: .4s;
  z-index: 2;
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

input:checked+.slider {
  background-color: var(--bg2);
}

input:focus+.slider {
  box-shadow: 0 0 1px var(--blue);
}

input:checked+.slider:before {
  -webkit-transform: translateX(30px);
  -ms-transform: translateX(30px);
  transform: translateX(30px);
  background-color: var(--yellow);
}

/* Icons inside the switch */
.icon {
  z-index: 1;
  line-height: 1;
  user-select: none;
}

.sun {
  color: var(--yellow);
  opacity: 0;
  transition: opacity 0.3s;
}

.moon {
  color: var(--fg);
  opacity: 1;
  transition: opacity 0.3s;
}

input:checked+.slider .sun {
  opacity: 1;
}

input:checked+.slider .moon {
  opacity: 0;
}