:root {
  --bg: #08080f;
  --surface: #0e0e1a;
  --surface-2: #161626;
  --border: rgba(255, 255, 255, 0.08);
  --text: #ececf6;
  --text-muted: #8989a8;
  --accent: #7c5cfc;
  --accent-dim: rgba(124, 92, 252, 0.14);
  --accent-glow: rgba(124, 92, 252, 0.28);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --font-h: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --r-sm: 8px;
  --r: 12px;
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f8f7ff;
  --surface: #ffffff;
  --surface-2: #eeeeff;
  --border: rgba(20, 20, 35, 0.10);
  --text: #11111d;
  --text-muted: #666686;
  --accent-dim: rgba(124, 92, 252, 0.10);
  --accent-glow: rgba(124, 92, 252, 0.18);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  width: 420px;
  min-width: 420px;
  max-width: 420px;
}

html:has(body.popup-body.is-tool-window.is-expanded),
html:has(body.popup-body.is-overlay) {
  width: 100%;
  min-width: 760px;
  max-width: none;
  height: 100%;
}

body.popup-body.is-expanded {
  width: 100%;
  min-width: 760px;
  max-width: none;
  min-height: 100vh;
  max-height: none;
}

body.popup-body {
  width: 420px;
  min-height: 540px;
  max-height: 600px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.popup-body.is-tool-window {
  height: 100vh;
  min-height: 100vh;
  resize: both;
}

body.popup-body.is-overlay {
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 100vh;
  min-height: 100vh;
  max-height: none;
}

body.popup-body.is-tool-window:not(.is-expanded) {
  width: 100%;
  min-width: 420px;
  max-width: none;
}

button,
input,
select {
  font: inherit;
}

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

.popup-app {
  display: flex;
  flex-direction: column;
  height: 600px;
  max-height: 600px;
  transition: height 0.34s cubic-bezier(0.22, 1, 0.36, 1), transform 0.34s cubic-bezier(0.22, 1, 0.36, 1), border-radius 0.34s ease;
  transform-origin: center center;
}

body.popup-body.is-expanded .popup-app {
  width: 100%;
  height: 100vh;
  max-height: none;
  border-radius: 16px;
  transform: translateY(0) scale(1);
}

body.popup-body.is-tool-window .popup-app {
  height: 100vh;
  max-height: none;
  border: 1px solid var(--border);
}

body.popup-body.is-overlay .popup-app {
  width: 100%;
  height: 100vh;
  max-height: none;
}

.popup-header {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.popup-header__inner {
  height: 54px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.popup-logo {
  font-family: var(--font-h);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0;
}

.popup-badge {
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

#theme-toggle {
  margin-left: auto;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.icon-btn[aria-pressed="true"] {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 8px 22px var(--accent-glow);
}

.lock-toggle__locked,
.expand-toggle__shrink {
  display: none;
}

body.popup-body.is-locked .lock-toggle__unlocked {
  display: none;
}

body.popup-body.is-locked .lock-toggle__locked {
  display: block;
}

body.popup-body.is-expanded .expand-toggle__grow {
  display: none;
}

body.popup-body.is-expanded .expand-toggle__shrink {
  display: block;
}

[data-theme="dark"] .theme-toggle__sun,
[data-theme="light"] .theme-toggle__moon {
  display: none;
}

.popup-main {
  flex: 1 1 auto;
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-color: color-mix(in srgb, var(--accent) 55%, var(--text-muted)) transparent;
  scrollbar-width: thin;
}

.popup-main::-webkit-scrollbar {
  width: 10px;
}

.popup-main::-webkit-scrollbar-track {
  background: transparent;
}

.popup-main::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 58%, var(--text-muted));
  background-clip: padding-box;
}

.popup-main::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
  background-clip: padding-box;
}

body.popup-body.is-expanded .popup-main {
  padding: 14px;
}

.popup-tools {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--r);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  background: color-mix(in srgb, var(--surface) 62%, transparent);
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.drop-zone__icon {
  color: var(--text-muted);
  margin-bottom: 9px;
  opacity: 0.75;
}

.drop-zone__title {
  font-family: var(--font-h);
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
}

.drop-zone__sub {
  margin-top: 3px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.drop-zone__formats {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  opacity: 0.7;
  letter-spacing: 0.04em;
}

.settings-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.settings-panel__inner {
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}

[data-resize-field][hidden] {
  display: none !important;
}

.settings-group {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.settings-group--checkbox {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.settings-group--wide {
  grid-column: 1 / -1;
}

.settings-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.custom-select {
  position: relative;
}

.custom-select select,
.settings-input {
  width: 100%;
  min-height: 34px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.42rem 0.75rem 0.42rem 0.55rem;
  color: var(--text);
  outline: none;
}

.custom-select select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.8rem;
}

.custom-select__chev {
  position: absolute;
  right: 0.62rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
}

.custom-select select:focus,
.settings-input:focus {
  border-color: var(--accent);
}

.settings-range {
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.settings-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 42%, var(--surface-2)) 100%);
  border: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}

.settings-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--text);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.settings-range::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, color-mix(in srgb, var(--accent) 42%, var(--surface-2)) 100%);
  border: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}

.settings-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--text);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}

.settings-range:focus-visible {
  outline: none;
}

.custom-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.custom-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.custom-check__box {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.custom-check__box::after {
  content: '';
  width: 8px;
  height: 4px;
  border-left: 2px solid transparent;
  border-bottom: 2px solid transparent;
  transform: rotate(-45deg) translateY(-1px);
}

.custom-check input:checked + .custom-check__box {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.custom-check input:checked + .custom-check__box::after {
  border-color: #fff;
}

.custom-check__label {
  line-height: 1.2;
}

.size-inputs {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.image-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.popup-body.is-expanded .image-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

body.popup-body.is-overlay:not(.is-expanded) .image-list {
  display: flex;
}

.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.image-card__preview {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--surface-2);
  overflow: hidden;
  touch-action: none;
}

.image-card__preview img {
  width: 100%;
  height: 100%;
  display: block;
}

.image-card__preview-badge,
.image-card__compare-toggle {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  border-radius: 999px;
}

.image-card__preview-badge {
  top: 8px;
  right: 8px;
  padding: 0.2rem 0.5rem;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(124, 92, 252, 0.3);
}

.image-card__ghost-label {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 0.2rem 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
}

.image-card__preview-tools {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 4;
  display: flex;
  gap: 6px;
}

.image-card__tool {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(8, 8, 15, 0.64);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.image-card__tool:hover,
.image-card__tool.is-active {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 84%, rgba(8, 8, 15, 0.64));
}

.image-card__preview--crop::after {
  content: '';
  position: absolute;
  inset: 12px;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  pointer-events: none;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
}

.image-card__preview--crop .image-card__preview-img {
  cursor: grab;
  transition: transform 0.12s ease;
}

.image-card__preview--crop:not(.is-dragging) .image-card__preview-img {
  transition: object-position 0.12s ease, transform 0.12s ease;
}

.image-card__preview--crop.is-dragging .image-card__preview-img {
  cursor: grabbing;
}

.image-card__crop-panel {
  position: absolute;
  left: 8px;
  right: 76px;
  bottom: 8px;
  z-index: 5;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  background: rgba(8, 8, 15, 0.66);
  backdrop-filter: blur(10px);
}

.image-card__aspect {
  min-width: 38px;
  height: 24px;
  padding: 0 0.45rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  cursor: pointer;
}

.image-card__aspect--icon {
  min-width: 28px;
  font-size: 0.78rem;
}

.image-card__aspect.is-active,
.image-card__aspect:hover {
  background: #fff;
  color: #08080f;
}

.image-card__compare-toggle {
  bottom: 8px;
  left: 8px;
  padding: 0.25rem 0.55rem;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 0;
  cursor: pointer;
}

.image-card__body {
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-card__name {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: anywhere;
  cursor: text;
}

.image-card__name:hover {
  color: var(--accent);
}

.image-card__controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
  align-items: center;
}

.image-card__toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.image-card__select,
.image-card__quality input {
  min-height: 28px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.image-card__select {
  width: 100%;
  padding: 0.28rem 0.42rem;
}

.image-card__quality {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 0.7rem;
}

.image-card__quality input {
  width: 48px;
  padding: 0.2rem 0.3rem;
}

.image-card__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.image-card__stat {
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.image-card__stat strong {
  display: block;
  color: var(--text);
  font-family: var(--font-h);
  font-size: 0.94rem;
  font-weight: 700;
}

.image-card__saved,
.is-positive {
  color: var(--success);
  font-weight: 700;
}

.image-card__saved--negative,
.is-negative {
  color: var(--danger);
  font-weight: 700;
}

.image-card__warning {
  color: var(--warning);
  font-size: 0.72rem;
}

.image-card__warning--info {
  color: var(--text-muted);
}

.image-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.image-card__btn,
.btn {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.image-card__btn {
  padding: 0.38rem 0.62rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 550;
}

.image-card__btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

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

.image-card__btn--primary:hover,
.btn--primary:hover {
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}

.btn {
  padding: 0.45rem 0.75rem;
  font-family: var(--font-h);
  font-size: 0.78rem;
  font-weight: 650;
}

.btn--sm {
  min-height: 30px;
  padding: 0.35rem 0.62rem;
  font-size: 0.72rem;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.summary-footer {
  position: sticky;
  bottom: -12px;
  z-index: 10;
  margin-top: auto;
  padding: 10px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
}

.summary-footer__stats {
  min-width: 0;
  color: var(--text);
  font-family: var(--font-h);
  font-size: 0.76rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.popup-footer {
  flex: 0 0 auto;
  padding: 9px 12px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.popup-footer__brandmark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 6px;
}

.popup-footer__link {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  text-decoration: none;
  opacity: 0.72;
}

.popup-footer__link:hover {
  color: var(--accent);
  opacity: 1;
}

.image-card--processing .image-card__preview {
  opacity: 0.62;
}

.image-card--disabled {
  opacity: 0.62;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 1000;
  max-width: calc(100% - 28px);
  transform: translateX(-50%) translateY(10px);
  padding: 0.58rem 0.9rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
  font-size: 0.8rem;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
