:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #657080;
  --line: #d8dde5;
  --surface: #ffffff;
  --panel: #f6f7f9;
  --accent: #0b7f75;
  --accent-dark: #075d56;
  --blue: #255eb8;
  --blue-dark: #1d4b93;
  --amber: #9b5c00;
  --amber-dark: #754500;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  background: #e7ebf0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: #9ea9b8;
}

.primary {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  min-height: 100vh;
}

.stage {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 100vh;
  background: #101418;
}

.viewer {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 0;
  cursor: grab;
  outline: none;
}

.image-frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2px;
}

.viewer:active {
  cursor: grabbing;
}

#productImage {
  display: none;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: 50% 50%;
  user-select: none;
  pointer-events: none;
}

.image-border {
  border: 1px solid #c9ced6;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  color: #f2f6f8;
  pointer-events: none;
}

.empty-state strong {
  font-size: clamp(24px, 4vw, 42px);
}

.empty-state span {
  color: #c5ced8;
}

.start-ad-placeholder {
  position: relative;
  display: grid;
  place-items: center;
  width: min(1000px, calc(100vw - 460px), calc(100% - 48px));
  min-width: 320px;
  height: min(350px, 36vh);
  min-height: 180px;
  margin-top: 18px;
  border: 1px dashed rgba(216, 224, 232, .55);
  border-radius: 8px;
  color: #dce5ee;
  background: rgba(255, 255, 255, .08);
  pointer-events: auto;
}

.ad-label {
  position: absolute;
  bottom: calc(100% + 5px);
  left: 0;
  color: rgba(220, 229, 238, .8);
  font-size: 11px;
  line-height: 1;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.start-ad-placeholder.is-hidden {
  display: none;
}

.start-ad-link {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 8px;
}

.start-ad-link img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ad-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #17202a;
  border-color: rgba(216, 224, 232, .9);
  border-radius: 50%;
  background: rgba(255, 255, 255, .9);
  line-height: 1;
}

.viewer-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  display: flex;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 7px;
  background: rgba(15, 20, 26, .72);
  backdrop-filter: blur(8px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  min-width: 38px;
  height: 36px;
  padding: 0;
  color: #17202a;
  border-color: rgba(212, 218, 227, .95);
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .14);
  line-height: 1;
}

.icon-button:hover {
  border-color: #9ea9b8;
  background: #fff;
}

.icon-button svg,
.controls svg {
  display: block;
  width: 19px;
  height: 19px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.timeline {
  z-index: 8;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) minmax(140px, auto);
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  color: #fff;
  background: #151b22;
}

.stage:fullscreen {
  display: block;
  min-height: 100vh;
  background: #101418;
}

.stage:fullscreen .viewer {
  position: absolute;
  inset: 0;
}

.stage:fullscreen .image-frame {
  padding: 10px 10px 72px;
}

.stage:fullscreen .timeline {
  position: absolute;
  right: 16px;
  bottom: 16px;
  left: 16px;
  grid-template-columns: auto minmax(120px, 1fr) minmax(140px, auto);
  border-radius: 8px;
  background: rgba(21, 27, 34, .78);
  backdrop-filter: blur(8px);
}

.timeline span {
  overflow: hidden;
  color: #d8e0e8;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logo-overlay {
  position: absolute;
  z-index: 6;
  display: none;
  width: var(--logo-size, 18%);
  max-width: 45%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

.logo-overlay.is-visible {
  display: block;
}

.logo-overlay[data-position="top-left"] {
  top: 5%;
  left: 5%;
}

.logo-overlay[data-position="top-right"] {
  top: 5%;
  right: 5%;
}

.logo-overlay[data-position="bottom-left"] {
  bottom: 5%;
  left: 5%;
}

.logo-overlay[data-position="bottom-right"] {
  right: 5%;
  bottom: 5%;
}

.logo-overlay[data-position="bottom-center"] {
  bottom: 5%;
  left: 50%;
  transform: translateX(-50%);
}

.panel {
  overflow: auto;
  max-height: 100vh;
  padding: 18px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.panel-header {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -18px -18px 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 249, .94);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
}

.control-group {
  margin-bottom: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.group-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

.group-title h2 {
  margin-bottom: 0;
}

.group-title span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.project-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 14px;
}

.project-stats span {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 11px;
  background: #fff;
}

.project-stats strong {
  display: block;
  overflow: hidden;
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
}

input[type="color"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px;
  background: #fff;
}

.upload-grid,
.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 9px;
}

.file-picker {
  min-width: 0;
}

.file-picker input {
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  color: var(--ink);
  background: #fff;
}

.file-picker input::file-selector-button {
  margin-right: 10px;
  border: 1px solid #2E9D00;
  border-radius: 6px;
  padding: 8px 11px;
  color: #fff;
  background: #2E9D00;
  cursor: pointer;
}

.file-picker input::file-selector-button:hover {
  border-color: #247c00;
  background: #247c00;
}

.range-field span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.range-field strong {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.switch-list {
  display: grid;
  gap: 8px;
}

.switch-list .switch {
  margin-bottom: 0;
  padding: 9px 10px;
  border: 1px solid #e1e5eb;
  border-radius: 7px;
  background: #fbfcfd;
}

.drop-zone {
  margin: 8px 0 12px;
  padding: 14px;
  border: 1px dashed #9eabb9;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfd;
}

.drop-zone.dragover {
  color: var(--accent-dark);
  border-color: var(--accent);
  background: #eefaf8;
}

.wide-button {
  width: 100%;
  margin-bottom: 11px;
}

.button-row,
.section-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  max-width: 100%;
}

.button-row button {
  flex: 1 1 145px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-save {
  color: #fff;
  border-color: var(--blue);
  background: var(--blue);
}

.project-save:hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

.project-load {
  color: #fff;
  border-color: var(--amber);
  background: var(--amber);
}

.project-load:hover {
  border-color: var(--amber-dark);
  background: var(--amber-dark);
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-heading h2 {
  margin: 0;
}

.hint,
.status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status {
  min-height: 20px;
  margin-top: 10px;
}

.switch {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
}

.switch input {
  width: 18px;
  height: 18px;
}

.danger {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.export-group {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin-bottom: 0;
  box-shadow: 0 -10px 24px rgba(23, 32, 42, .08);
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.export-actions button {
  min-height: 40px;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
  }

  .stage {
    min-height: 62vh;
  }

  .panel {
    max-height: none;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .panel-header,
  .export-group {
    position: static;
  }

  .start-ad-placeholder {
    width: min(1000px, calc(100vw - 48px));
    height: min(350px, 32vh);
  }
}

@media (max-width: 560px) {
  .viewer-toolbar {
    right: 10px;
    left: 10px;
    flex-wrap: wrap;
  }

  .timeline {
    grid-template-columns: 1fr;
  }

  .project-stats,
  .upload-grid,
  .field-grid,
  .export-actions {
    grid-template-columns: 1fr;
  }

  .group-title {
    display: block;
  }

  .group-title span {
    display: block;
    margin-top: 3px;
  }

  .start-ad-placeholder {
    min-width: 0;
    height: 180px;
  }
}
