:root {
  --bg: #07111f;
  --bg-elevated: rgba(13, 24, 42, 0.86);
  --bg-panel: rgba(15, 27, 46, 0.9);
  --bg-soft: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #e5eefc;
  --muted: #9fb2ce;
  --accent: #61c4ff;
  --accent-2: #a78bfa;
  --success: #5eead4;
  --danger: #fb7185;
  --warning: #fbbf24;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.35);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --transition: 180ms ease;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(96, 165, 250, 0.16), transparent 24%),
    radial-gradient(circle at top right, rgba(167, 139, 250, 0.12), transparent 26%),
    linear-gradient(180deg, #050c17 0%, #07111f 100%);
  color: var(--text);
  font-family: var(--font);
}

body {
  padding: 22px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
select {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(97, 196, 255, 0.7);
  background: rgba(255, 255, 255, 0.06);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
  background: transparent;
}

input[type="file"] {
  display: none;
}

code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(17, 29, 50, 0.92) 0%, rgba(9, 18, 33, 0.9) 100%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 780px;
  line-height: 1.55;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(97, 196, 255, 0.28), rgba(167, 139, 250, 0.28));
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-weight: 800;
  letter-spacing: 0.05em;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: 390px minmax(420px, 1fr) 340px;
  gap: 18px;
  min-height: calc(100vh - 180px);
}

.sidebar,
.viewer-panel {
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  padding-right: 2px;
}

.panel {
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--bg-panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.panel h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.75rem;
  color: #dbeafe;
  background: rgba(97, 196, 255, 0.12);
  border: 1px solid rgba(97, 196, 255, 0.18);
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 220px;
  padding: 18px;
  text-align: center;
  border-radius: 20px;
  border: 1.5px dashed rgba(97, 196, 255, 0.26);
  background:
    linear-gradient(180deg, rgba(97, 196, 255, 0.08) 0%, rgba(97, 196, 255, 0.02) 100%),
    rgba(255, 255, 255, 0.02);
  transition: transform var(--transition), border-color var(--transition), background var(--transition);
}

.dropzone.dragover {
  transform: translateY(-2px);
  border-color: rgba(97, 196, 255, 0.66);
  background:
    linear-gradient(180deg, rgba(97, 196, 255, 0.16) 0%, rgba(97, 196, 255, 0.06) 100%),
    rgba(255, 255, 255, 0.04);
}

.dropzone h3 {
  margin: 0;
  font-size: 1.05rem;
}

.dropzone p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.dropzone-icon {
  font-size: 2rem;
  opacity: 0.82;
}

.subpanel {
  padding: 14px;
  margin-top: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.subpanel-title {
  margin-bottom: 10px;
  font-weight: 600;
  color: #dbeafe;
}

.hint {
  margin: 10px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.55;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.button-grid-tight {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid label,
.export-panel label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-grid span,
.export-panel span {
  font-size: 0.88rem;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 0;
  color: var(--text);
}

.checkbox-row input {
  width: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  text-decoration: none;
  transition:
    transform var(--transition),
    background var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    opacity var(--transition);
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.primary {
  background: linear-gradient(135deg, rgba(97, 196, 255, 0.9), rgba(167, 139, 250, 0.8));
  color: #07111f;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(97, 196, 255, 0.18);
}

.button.secondary {
  background: rgba(97, 196, 255, 0.12);
  border-color: rgba(97, 196, 255, 0.18);
}

.button.ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
}

.button.outline {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.12);
}

.button.active {
  background: rgba(97, 196, 255, 0.16);
  border-color: rgba(97, 196, 255, 0.4);
  box-shadow: 0 0 0 1px rgba(97, 196, 255, 0.08) inset;
}

.compare-slider-wrap input:disabled {
  opacity: 0.45;
}

.button.small {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.button.inline-link {
  width: auto;
}

.button.block,
.upload-button {
  width: 100%;
}

.accordion-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.accordion-panel details {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.accordion-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 600;
  color: #dbeafe;
  user-select: none;
}

.accordion-panel summary::-webkit-details-marker {
  display: none;
}

.controls-stack {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
}

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

.control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-header label {
  color: var(--text);
  font-size: 0.93rem;
}

.control-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
}

.range-with-value {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.range-with-value strong {
  min-width: 42px;
  text-align: right;
  color: #dbeafe;
  font-variant-numeric: tabular-nums;
}

.export-note {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(97, 196, 255, 0.08);
  border: 1px solid rgba(97, 196, 255, 0.16);
  color: #dbeafe;
  line-height: 1.55;
}

.export-checkbox-row {
  margin-bottom: 6px;
}

.export-actions-grid {
  margin-top: 16px;
}

.export-result {
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.export-result-info {
  color: var(--muted);
  line-height: 1.55;
}

.export-result-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.viewer-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: rgba(10, 18, 34, 0.88);
  box-shadow: var(--shadow);
  min-height: 0;
}

.viewer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.compare-toolbar-group {
  flex: 1 1 260px;
  justify-content: center;
}

.compare-slider-wrap {
  min-width: 180px;
  flex: 1 1 180px;
}

.compare-slider-wrap input {
  padding: 0;
}

.checkbox-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.checkbox-chip input {
  width: auto;
}

.viewer-wrapper {
  position: relative;
  flex: 1 1 auto;
  min-height: 520px;
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.02) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.02) 75%, rgba(255,255,255,0.02)),
    linear-gradient(45deg, rgba(255,255,255,0.02) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.02) 75%, rgba(255,255,255,0.02));
  background-position: 0 0, 12px 12px;
  background-size: 24px 24px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.viewer-wrapper canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.viewer-wrapper.crop-cursor {
  cursor: crosshair;
}

.viewer-wrapper.pan-cursor {
  cursor: grab;
}

.viewer-wrapper.panning {
  cursor: grabbing;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 17, 31, 0.3);
}

.empty-state-card {
  max-width: 480px;
  padding: 26px;
  border-radius: 24px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 17, 30, 0.78);
  box-shadow: var(--shadow);
}

.empty-state-card h2 {
  margin: 10px 0 8px;
  font-size: 1.4rem;
}

.empty-state-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.empty-badge {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(97, 196, 255, 0.12);
  border: 1px solid rgba(97, 196, 255, 0.18);
  color: #dbeafe;
  font-size: 0.82rem;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.status-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-button {
  min-height: 58px;
  justify-content: flex-start;
  text-align: left;
}

.preset-button strong {
  font-size: 0.94rem;
}

.tool-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.info-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.histogram-canvas {
  width: 100%;
  min-height: 160px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  display: block;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  min-width: 260px;
  max-width: min(90vw, 420px);
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(8, 17, 30, 0.96);
  border: 1px solid rgba(97, 196, 255, 0.18);
  box-shadow: var(--shadow);
  color: var(--text);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: rgba(94, 234, 212, 0.28);
}

.toast.warning {
  border-color: rgba(251, 191, 36, 0.3);
}

.toast.error {
  border-color: rgba(251, 113, 133, 0.34);
}

@media (max-width: 1480px) {
  .workspace {
    grid-template-columns: 360px minmax(360px, 1fr) 320px;
  }
}

@media (max-width: 1240px) {
  body {
    padding: 16px;
  }

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

  .sidebar {
    overflow: visible;
  }

  .viewer-panel {
    min-height: 720px;
  }

  .viewer-wrapper {
    min-height: 500px;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 18px;
  }

  .brand {
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions .button,
  .topbar-actions .upload-button {
    flex: 1 1 calc(50% - 10px);
  }

  .form-grid,
  .preset-grid,
  .button-grid {
    grid-template-columns: 1fr;
  }

  .button-grid-tight {
    grid-template-columns: 1fr;
  }

  .viewer-panel {
    padding: 14px;
  }

  .viewer-wrapper {
    min-height: 420px;
  }

  .statusbar,
  .viewer-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .compare-toolbar-group {
    justify-content: flex-start;
  }
}


.export-helper-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.export-dimension-tools {
  margin-top: 14px;
}

input[type="color"] {
  inline-size: 100%;
  block-size: 42px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

@media (max-width: 760px) {
  .export-helper-grid {
    grid-template-columns: 1fr;
  }
}


.export-meta-note {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(167, 139, 250, 0.08);
  border: 1px solid rgba(167, 139, 250, 0.18);
  color: #e9ddff;
  line-height: 1.55;
}

.export-pack-actions {
  margin-top: 12px;
}

.export-helper-grid-wide {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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