:root {
  color-scheme: dark;
  --bg: #070707;
  --surface: rgba(17, 17, 16, 0.9);
  --surface-solid: #141413;
  --control: rgba(255, 255, 255, 0.08);
  --control-hi: rgba(255, 255, 255, 0.16);
  --text: #f6f2ea;
  --muted: rgba(246, 242, 234, 0.58);
  --dim: rgba(246, 242, 234, 0.34);
  --accent: #48dcc2;
  --accent-soft: rgba(72, 220, 194, 0.18);
  --warm: #f2b25f;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  border: 0;
  color: var(--text);
}

button {
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--control);
  font-weight: 720;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: translateY(1px);
}

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

select {
  width: 100%;
  min-height: 38px;
  padding: 0 34px 0 12px;
  border-radius: 8px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) right 14px center / 6px 6px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) right 9px center / 6px 6px no-repeat,
    var(--control);
  appearance: none;
}

.app-shell {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-input {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: block;
  min-height: 100dvh;
  background: #090909;
}

.preview-panel {
  position: fixed;
  inset: 0;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 66px);
  overflow: hidden;
  background: #050505;
  touch-action: none;
}

#previewCanvas,
#hdrPreviewImage {
  grid-area: 1 / 1;
  max-width: 100vw;
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 72px);
  width: auto;
  height: auto;
  display: none;
  background: #0b0b0b;
  box-shadow: none;
  touch-action: none;
  transform-origin: center center;
  will-change: transform;
  transition: opacity 80ms ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#hdrPreviewImage {
  dynamic-range-limit: no-limit;
  object-fit: contain;
}

#previewCanvas.zoom-animating,
#hdrPreviewImage.zoom-animating {
  transition: transform 170ms ease;
}

.empty-state {
  width: min(320px, 88vw);
  min-height: 154px;
  margin-top: 30px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.empty-state strong {
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
}

.controls-panel {
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  min-height: 0;
  display: block;
  overflow: visible;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.tool-rail-shell {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100vw - 24px);
  height: 54px;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(16, 16, 15, 0.9);
  box-shadow: 0 16px 54px rgba(0, 0, 0, 0.48);
  transform: translateX(-50%);
  pointer-events: auto;
  backdrop-filter: blur(22px) saturate(1.15);
}

.tool-rail-shell::before,
.tool-rail-shell::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 2;
  width: 48px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.tool-rail-shell::before {
  left: 0;
  background: linear-gradient(90deg, rgba(16, 16, 15, 1) 0%, rgba(16, 16, 15, 0.86) 34%, rgba(16, 16, 15, 0) 100%);
}

.tool-rail-shell::after {
  right: 0;
  background: linear-gradient(270deg, rgba(16, 16, 15, 1) 0%, rgba(16, 16, 15, 0.86) 34%, rgba(16, 16, 15, 0) 100%);
}

.tool-rail-shell.can-scroll-left::before,
.tool-rail-shell.can-scroll-right::after {
  opacity: 1;
}

.tool-rail {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tool-rail::-webkit-scrollbar {
  display: none;
}

.tool-button {
  min-height: 42px;
  min-width: 44px;
  flex: 0 0 44px;
  padding: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}

.tool-button svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.tool-button.active {
  background: var(--control-hi);
  color: var(--text);
}

.tool-panel {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 74px);
  width: fit-content;
  max-width: calc(100vw - 24px);
  max-height: min(38dvh, 310px);
  min-width: min(300px, calc(100vw - 24px));
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 12px;
  overflow: auto;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.56);
  scrollbar-width: thin;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
  backdrop-filter: blur(22px) saturate(1.15);
}

.controls-panel.open .tool-panel {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.tool-section {
  display: none;
}

.tool-section.active {
  display: grid;
  gap: 10px;
  width: max-content;
  max-width: 100%;
}

.menu-section.active {
  gap: 8px;
  width: clamp(320px, 28vw, 390px);
}

.file-actions {
  display: flex;
  gap: 8px;
}

.menu-icon-action {
  min-width: 42px;
  min-height: 38px;
  padding: 0;
  background: var(--control);
}

.menu-icon-action svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.menu-icon-action.danger {
  color: #ff9a9f;
}

.menu-help {
  margin-left: auto;
  color: var(--muted);
  font-size: 16px;
  font-weight: 820;
}

.info-overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(5, 5, 5, 0.72);
  backdrop-filter: blur(18px) saturate(1.1);
}

.info-overlay[hidden] {
  display: none;
}

.info-sheet {
  position: relative;
  width: min(680px, 100%);
  max-height: 100%;
  overflow: auto;
  border-radius: 14px;
  background: rgba(18, 18, 17, 0.96);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.62);
  -webkit-overflow-scrolling: touch;
}

.info-close {
  position: sticky;
  top: 10px;
  z-index: 1;
  float: right;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  margin: 10px 10px 0 0;
  padding: 0;
  background: rgba(255, 255, 255, 0.1);
}

.info-close svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.info-content {
  padding: 26px 24px 30px;
}

.info-kicker {
  margin: 0 0 7px;
  color: var(--warm);
  font-size: 12px;
  font-weight: 820;
}

.info-content h1 {
  margin: 0 48px 14px 0;
  color: var(--text);
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

.info-content h2 {
  margin: 22px 0 7px;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

.info-content p {
  margin: 0 0 10px;
  color: rgba(246, 242, 234, 0.72);
  font-size: 14px;
  line-height: 1.48;
}

.info-content a {
  color: var(--warm);
  text-decoration: none;
}

.info-content a:focus-visible,
.info-content a:hover {
  color: var(--text);
  text-decoration: underline;
}

.info-links {
  display: grid;
  gap: 7px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
}

.info-links li {
  color: rgba(246, 242, 234, 0.72);
  font-size: 14px;
  line-height: 1.35;
}

.wand-section.active {
  gap: 8px;
  min-width: 0;
  width: max-content;
}

.wand-grid {
  display: grid;
  grid-template-columns: repeat(5, 58px);
  gap: 7px;
}

.wand-preset {
  min-width: 0;
  min-height: 58px;
  padding: 7px 4px 6px;
  flex-direction: column;
  gap: 5px;
  background: var(--control);
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
}

.wand-preset svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.wand-preset:active,
.wand-preset.selected {
  background: var(--control-hi);
  color: var(--text);
}

.auto-summary {
  min-height: 32px;
  margin: 0;
  color: rgba(246, 242, 234, 0.62);
  font-size: 11px;
  line-height: 1.35;
}

.section-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.control-row {
  display: grid;
  gap: 7px;
}

.control-row.compact {
  grid-template-columns: 66px minmax(0, 1fr);
  align-items: center;
}

.preset-picker {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px 40px 40px;
  gap: 7px;
  align-items: center;
}

.tool-section[data-section="look"].active {
  width: clamp(330px, 30vw, 430px);
}

.preset-reset,
.preset-apply,
.preset-save {
  min-width: 40px;
  min-height: 38px;
}

.control-row label,
.slider-head label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  margin: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.preview-mode-toggle {
  grid-template-columns: repeat(2, 1fr);
}

.segment {
  min-height: 32px;
  padding: 0 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.segment.active {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

.slider-stack {
  gap: 3px;
}

.slider-stack.active {
  width: clamp(320px, 30vw, 430px);
}

.slider-card {
  position: relative;
  padding: 4px 0;
}

.slider-head {
  min-height: 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 2px;
}

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

.slider-label-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.help-button {
  min-width: 18px;
  min-height: 18px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.help-button[aria-expanded="true"] {
  background: var(--control-hi);
  color: var(--text);
}

.slider-value {
  min-width: 54px;
  color: var(--warm);
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 760;
}

.slider-description {
  margin: 0;
  max-width: 28rem;
  color: rgba(246, 242, 234, 0.68);
  font-size: 11px;
  line-height: 1.35;
}

.slider-description[hidden] {
  display: none;
}

input[type="range"] {
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  accent-color: var(--accent);
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
}

input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 0;
  border-radius: 50%;
  background: #f7f2ea;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.36);
  appearance: none;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--accent-soft);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: #f7f2ea;
}

.export-box {
  margin-top: 0;
  padding-top: 0;
}

.button-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 7px;
  margin-top: 2px;
}

#exportUltra,
#exportJpeg,
#exportGain {
  min-height: 38px;
  gap: 6px;
  padding: 0 9px;
}

#exportUltra svg,
#exportJpeg svg,
#exportGain svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

#exportUltra {
  background: var(--accent);
  color: #06211c;
}

#exportJpeg,
#exportGain {
  background: var(--control);
}

@media (max-width: 860px) {
  .preview-panel {
    padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 58px);
  }

  #previewCanvas,
  #hdrPreviewImage {
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 64px);
  }

  .tool-panel {
    width: calc(100vw - 16px);
    bottom: calc(env(safe-area-inset-bottom) + 66px);
    max-height: min(34dvh, 270px);
  }

  .tool-section.active {
    gap: 8px;
    width: 100%;
  }

  .menu-section.active,
  .wand-section.active,
  .tool-section[data-section="look"].active,
  .slider-stack.active {
    width: 100%;
  }

  .wand-grid {
    grid-template-columns: repeat(5, minmax(44px, 1fr));
    gap: 5px;
  }

  .wand-preset {
    min-height: 50px;
    padding: 5px 2px 4px;
    border-radius: 9px;
    font-size: 10px;
  }

  .wand-preset svg {
    width: 19px;
    height: 19px;
  }

  .tool-rail-shell {
    width: calc(100vw - 16px);
    bottom: max(8px, env(safe-area-inset-bottom));
  }

  .tool-button svg {
    width: 21px;
    height: 21px;
  }

  .control-row.compact {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .preset-picker {
    grid-template-columns: minmax(0, 1fr) 36px 36px 36px;
    gap: 6px;
  }

  .preset-reset,
  .preset-apply,
  .preset-save {
    min-width: 36px;
    min-height: 34px;
  }

  .control-row label,
  .slider-head label {
    font-size: 11px;
  }

  select {
    min-height: 34px;
    font-size: 13px;
  }

  .segmented {
    padding: 2px;
  }

  .segment {
    min-height: 30px;
  }

  .slider-card {
    padding: 2px 0;
  }

  .slider-head {
    margin-bottom: 0;
  }

  .button-grid {
    grid-template-columns: 1.35fr 1fr 1fr;
    gap: 6px;
  }

  #exportUltra,
  #exportJpeg,
  #exportGain {
    min-height: 36px;
    padding: 0 8px;
    font-size: 13px;
  }

  .info-overlay {
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  }

  .info-sheet {
    border-radius: 12px;
  }

  .info-content {
    padding: 23px 18px 26px;
  }

  .info-content h1 {
    font-size: 24px;
  }

  .info-content p {
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  .tool-panel {
    width: calc(100vw - 14px);
  }

  .tool-rail-shell {
    width: calc(100vw - 14px);
  }
}
