* { box-sizing: border-box; }

:root {
  --bg: #081019;
  --panel: #111a24;
  --panel-soft: #172330;
  --panel-deep: #0b131c;
  --text: #f4f7fa;
  --muted: #a4b0bd;
  --line: rgba(177, 194, 211, 0.16);
  --brand: #f26332;
  --brand-hover: #ff7a47;
  --brand-soft: rgba(242, 99, 50, 0.15);
  --ok: #86d69d;
  --warning: #ffd27a;
  --danger: #f18484;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  --radius: 20px;
}

html { scrollbar-gutter: stable; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-y: scroll;
  background:
    radial-gradient(circle at top left, rgba(242, 99, 50, 0.11), transparent 28rem),
    linear-gradient(180deg, #101923, var(--bg));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button {
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 850;
  min-height: 44px;
  padding: 0.7rem 0.95rem;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease, opacity 120ms ease;
}
button:hover { background: var(--brand-hover); transform: translateY(-1px); }
button:disabled { opacity: 0.42; cursor: not-allowed; transform: none; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .bucket:focus-visible {
  outline: 3px solid #9fd0ff;
  outline-offset: 3px;
}
.secondary-btn { background: #25313d; border: 1px solid var(--line); color: var(--text); }
.secondary-btn:hover { background: #324252; }
.compact-btn { padding: 0.52rem 0.72rem; font-size: 0.82rem; }
.hidden { display: none !important; }

.app { width: min(1500px, calc(100vw - 2rem)); margin: 0 auto; padding: 1.3rem 0 1rem; }
.topbar { min-height: 92px; display: flex; align-items: center; margin-bottom: 0.85rem; }
.brand-lockup { display: flex; align-items: center; gap: 0.9rem; }
.brand-icon { width: 58px; height: 58px; flex: 0 0 auto; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0.18rem; font-size: clamp(2.2rem, 4vw, 3.9rem); line-height: 0.95; letter-spacing: -0.035em; }
h2 { margin-bottom: 0.25rem; font-size: 1.08rem; }
.lede { margin-bottom: 0; color: var(--muted); font-size: 1.03rem; font-weight: 650; }

.controls-card, .bucket, .output-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,0.055), rgba(255,255,255,0.024));
  box-shadow: var(--shadow);
}
.controls-card { padding: 0.85rem; margin-bottom: 0.85rem; }
.controls-grid {
  display: grid;
  grid-template-columns: minmax(132px, 0.7fr) minmax(280px, 1.7fr) minmax(130px, 0.72fr) 86px 86px 120px minmax(170px, 0.95fr);
  gap: 0.72rem;
  align-items: end;
  min-height: 66px;
}
label, .field { display: grid; gap: 0.3rem; min-width: 0; }
label > span, .field-label, .quality-field > span { color: var(--muted); font-weight: 850; font-size: 0.79rem; }
select, input:not([type="range"]), .select-trigger {
  width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 11px;
  background: rgba(0,0,0,0.25); color: var(--text); padding: 0.6rem 0.68rem;
}
.format-field { grid-template-rows: auto minmax(2.2em, auto) auto; }
.format-note { min-height: 1em; color: var(--muted); font-size: 0.72rem; line-height: 1.25; }
.apply-all-control {
  min-height: 42px; align-self: end; display: inline-grid; grid-template-columns: auto 1fr; gap: 0.42rem; align-items: center;
  padding: 0.45rem 0.58rem; border: 1px solid var(--line); border-radius: 11px; background: rgba(0,0,0,0.18); color: var(--muted);
}
.apply-all-control input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.apply-all-control span { color: var(--text); font-size: 0.82rem; font-weight: 850; white-space: nowrap; }
.apply-all-control.active { border-color: rgba(242,99,50,0.46); background: rgba(242,99,50,0.1); }
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--brand); margin: 0; }

.custom-select { position: relative; }
.select-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  text-align: left; font-weight: 760; cursor: pointer;
}
.select-trigger:hover { background: rgba(255,255,255,0.055); transform: none; }
.select-menu {
  position: absolute; z-index: 50; left: 0; top: calc(100% + 0.45rem);
  width: min(520px, 92vw); max-height: 520px; overflow-y: auto;
  padding: 0.55rem; border: 1px solid var(--line); border-radius: 16px;
  background: #dfe4e8; color: #131820; box-shadow: var(--shadow);
}
.select-section-title {
  margin: 0.9rem 0.25rem 0.35rem; color: #8b3d19;
  font-size: 0.72rem; font-weight: 950; letter-spacing: 0.08em; text-transform: uppercase;
}
.select-group-title {
  margin: 0.78rem 0.35rem 0.24rem; padding-bottom: 0.28rem;
  border-bottom: 1px solid rgba(19,24,32,0.2); color: #27313c;
  font-size: 0.78rem; font-weight: 850; letter-spacing: 0.04em; text-transform: uppercase;
}
.select-option {
  width: 100%; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  min-height: 44px; padding: 0.64rem 0.72rem; border-radius: 9px; background: transparent; color: #111820;
  text-align: left; font-size: 1rem; font-weight: 720;
}
.select-option:hover, .select-option.active { background: rgba(16, 102, 199, 0.14); color: #07111b; transform: none; }
.select-option.active::before { content: "✓"; margin-right: 0.35rem; color: #0b66c3; font-weight: 950; }
.select-option small { color: #4e5965; font-size: 0.82rem; font-weight: 760; }
.custom-option { margin-top: 0.55rem; border-top: 1px solid rgba(19,24,32,0.2); border-radius: 0; padding-top: 0.8rem; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; min-height: 42px;
  padding: 0.28rem; border: 1px solid var(--line); border-radius: 13px; background: rgba(0,0,0,0.18);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: grid; place-items: center; height: 100%; border-radius: 10px; color: var(--muted); font-weight: 850; font-size: 0.85rem; cursor: pointer; }
.segmented input:checked + span { background: var(--brand); color: #fff; }

.guide { position: relative; }
.guide summary {
  min-height: 42px; display: grid; place-items: center; list-style: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: 11px; background: #263341;
  color: var(--text); font-size: 0.9rem; font-weight: 850; padding: 0 0.8rem; white-space: nowrap;
}
.guide summary::-webkit-details-marker { display: none; }
.guide-pop {
  position: absolute; z-index: 40; right: 0; top: calc(100% + 0.5rem);
  width: min(520px, 92vw); max-height: 640px; overflow-y: auto; padding: 1rem;
  border: 1px solid var(--line); border-radius: 18px; background: #131e29; box-shadow: var(--shadow);
}
.guide-intro { margin-bottom: 0.8rem; color: #c2ccd6; line-height: 1.45; }
.guide-list { display: grid; gap: 0.85rem; }
.guide-list section { display: grid; gap: 0.25rem; }
.guide-list h2 {
  margin: 0; padding-bottom: 0.35rem; border-bottom: 1px solid var(--line);
  color: var(--text); font-size: 1.15rem; font-weight: 900;
}
.guide-list button {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center;
  padding: 0.65rem 0.7rem; background: transparent; border-radius: 9px; color: var(--text); text-align: left;
}
.guide-list button:hover { background: rgba(255,255,255,0.075); transform: none; }
.guide-list button span { font-weight: 780; }
.guide-list button small { color: var(--muted); font-weight: 680; white-space: nowrap; }

.position-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 0.72rem; align-items: end;
  min-height: 74px; margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px solid var(--line);
}
.position-grid label { min-height: 54px; }
.position-grid output { display: inline-block; min-width: 3.5ch; text-align: right; font-variant-numeric: tabular-nums; }

.workbench { display: grid; grid-template-columns: minmax(320px, 0.64fr) minmax(560px, 1.36fr); gap: 0.85rem; align-items: stretch; }
.workbench.single-mode { grid-template-columns: 1fr; }
.workbench.single-mode .bucket { display: none; }
.bucket {
  height: 690px; min-height: 690px; padding: 1rem; display: grid; place-items: center;
  border-style: dashed; border-width: 2px; text-align: center;
  background: radial-gradient(circle at top center, var(--brand-soft), transparent 20rem), linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.024));
  overflow: hidden;
}
.bucket.dragover { border-color: var(--brand-hover); background: rgba(242,99,50,0.12); }
.bucket-empty { width: 100%; max-width: 650px; display: flex; flex-direction: column; align-items: center; }
.drop-icon { width: 68px; height: 68px; margin-bottom: 1rem; display: grid; place-items: center; border-radius: 19px; background: var(--brand-soft); color: var(--brand-hover); font-size: 2.1rem; font-weight: 900; }
.bucket h2 { font-size: clamp(1.35rem, 2vw, 1.85rem); margin-bottom: 0.45rem; }
.paste-hint { color: var(--muted); font-size: 1.02rem; margin-bottom: 1.2rem; }
kbd { background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-bottom-color: rgba(255,255,255,0.24); padding: 0.12rem 0.4rem; border-radius: 7px; }
.bulk-helper { width: min(560px, 90%); margin: auto 0 0; padding-top: 4rem; color: #b4c0cb; font-size: 0.96rem; font-weight: 650; line-height: 1.5; text-align: center; }
.source-loaded { width: 100%; height: 100%; min-height: 0; }
.single-source-panel { width: 100%; height: 100%; display: grid; grid-template-rows: 1fr auto; gap: 0.85rem; align-items: center; justify-items: center; }
.single-source-panel img { width: 100%; height: 100%; min-height: 0; object-fit: contain; border-radius: 16px; border: 1px solid var(--line); background: repeating-conic-gradient(#151d25 0 25%, #202a34 0 50%) 50% / 24px 24px; }
.source-info p { margin: 0.2rem 0 0; color: var(--muted); }

.bulk-browser { width: 100%; height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0,1fr) auto; gap: 0.75rem; text-align: left; }
.bulk-browser-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.bulk-browser-head div { display: grid; gap: 0.18rem; }
.bulk-browser-head span { color: var(--muted); font-size: 0.83rem; }
.bulk-actions { display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap; justify-content: flex-end; }
.show-completed-control { display: inline-flex; align-items: center; gap: 0.38rem; color: var(--muted); font-size: 0.76rem; font-weight: 800; white-space: nowrap; cursor: pointer; }
.show-completed-control input { width: 15px; height: 15px; min-height: 15px; margin: 0; accent-color: var(--brand); }
.thumbnail-list { min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 0.55rem; padding-right: 0.25rem; padding-bottom: 0.35rem; }
.add-images-bar {
  position: sticky; bottom: 0; width: 100%; min-height: 38px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255,255,255,0.055); color: var(--text);
  font-size: 0.82rem; font-weight: 850; box-shadow: 0 -10px 18px rgba(7,10,14,0.28);
}
.add-images-bar:hover { background: rgba(242,99,50,0.14); border-color: rgba(242,99,50,0.45); transform: none; }
.thumbnail-item {
  position: relative; width: 100%; display: block;
  min-height: 74px; padding: 0.55rem; border: 1px solid transparent; border-radius: 12px; background: rgba(255,255,255,0.035); color: var(--text); text-align: left;
}
.thumbnail-item:hover { background: rgba(255,255,255,0.075); transform: none; }
.thumbnail-item.active { background: rgba(242,99,50,0.16); border-color: rgba(242,99,50,0.55); }
.thumbnail-select {
  width: 100%; min-height: 60px; padding: 0; padding-right: 2rem; display: grid; grid-template-columns: 86px minmax(0,1fr); gap: 0.7rem; align-items: center;
  border: 0; background: transparent; color: inherit; text-align: left;
}
.thumbnail-select:hover { background: transparent; transform: none; }
.thumbnail-item img { width: 86px; height: 58px; object-fit: contain; border-radius: 8px; background: repeating-conic-gradient(#151d25 0 25%, #202a34 0 50%) 50% / 16px 16px; }
.thumbnail-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; font-weight: 740; }
.remove-thumb {
  position: absolute; top: 0.35rem; right: 0.35rem; width: 22px; height: 22px; min-height: 22px; padding: 0;
  border-radius: 999px; border-color: rgba(255,107,107,0.24); background: rgba(255,107,107,0.08); color: rgba(255,156,156,0.7); line-height: 1; font-size: 0.9rem;
}
.remove-thumb:hover { background: #f04444; border-color: #ff6b6b; color: #fff; transform: none; }
.remove-thumb:focus-visible { outline: 3px solid rgba(255,107,107,0.56); outline-offset: 2px; background: #f04444; color: #fff; }

.output-card {
  height: 690px; min-height: 690px; padding: 1rem; display: grid;
  grid-template-rows: auto minmax(0, 1fr) 86px auto; gap: 0.75rem; overflow: hidden;
}
.output-head { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); gap: 1rem; align-items: center; min-height: 48px; }
.output-head h2 { margin: 0; font-size: 1.18rem; white-space: nowrap; }
.output-head button { min-height: 36px; border-radius: 10px; padding: 0.48rem 0.72rem; font-size: 0.82rem; }
.output-actions { display: flex; gap: 0.5rem; flex-wrap: nowrap; align-items: center; min-width: 0; }
.output-left { justify-content: flex-start; }
.output-right { justify-content: flex-end; }
.zip-filter { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.78rem; font-weight: 800; white-space: nowrap; cursor: pointer; }
.zip-filter input, .review-control input {
  appearance: auto; width: 16px; min-width: 16px; max-width: 16px; height: 16px; min-height: 16px; margin: 0; padding: 0;
  border-radius: 3px; background: initial; accent-color:#6f917b; flex: 0 0 auto;
}
.output-stage {
  min-height: 0; height: 100%; display: grid; place-items: center; overflow: hidden;
  border-radius: 16px; background: rgba(0,0,0,0.12);
}
.output-view {
  min-width: 1px; min-height: 1px; border: 1px solid var(--line); border-radius: 16px;
  overflow: hidden; display: grid; place-items: center; background: #0b131c;
  contain: layout paint size; box-shadow: 0 14px 34px rgba(0,0,0,0.28);
}
.output-view.empty {
  width: 100%; height: 100%; color: var(--muted); box-shadow: none;
  background-color: rgba(0,0,0,0.18);
  background-image: repeating-conic-gradient(#151d25 0 25%, #202a34 0 50%);
  background-size: 24px 24px;
}
.output-view.loaded { background: transparent; }
.output-loading { text-align: center; color: var(--muted); }
.output-loading strong { display: block; margin-bottom: 0.35rem; color: var(--text); }

.conversion-summary {
  height: 86px; display: grid; grid-template-columns: 1fr auto 1fr 1fr; gap: 0.75rem; align-items: center;
  border: 1px solid var(--line); border-radius: 14px; padding: 0.7rem 0.9rem; background: rgba(0,0,0,0.17);
}
.conversion-summary > div:not(.summary-arrow) { display: grid; gap: 0.14rem; min-width: 0; }
.summary-label { color: var(--muted); font-size: 0.73rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.conversion-summary strong { font-size: 0.98rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.conversion-summary span:not(.summary-label) { color: var(--muted); font-size: 0.87rem; font-variant-numeric: tabular-nums; }
.summary-arrow { color: var(--brand-hover); font-size: 1.45rem; font-weight: 900; }
.savings-block strong.smaller { color: var(--ok); }
.savings-block strong.larger { color: var(--warning); }
.savings-block strong.neutral { color: var(--muted); }
.message-line { min-height: 24px; margin: 0; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.message-line.ok { color: var(--ok); }
.message-line.warn { color: var(--warning); }
.message-line.error { color: var(--danger); }
.message-line.has-action {
  min-height: 0; display: flex; align-items: center; justify-content: center; gap: 0.7rem;
  flex-wrap: wrap; padding-top: 0.15rem;
  overflow: visible; white-space: normal; text-overflow: clip; text-align: left;
}
.message-line .message-copy { display: grid; gap: 0.7rem; min-width: 0; }
.message-line .message-copy span { color: rgba(255,255,255,0.84); font-size: 0.94rem; line-height: 1.35; }
.suggested-size-btn {
  min-height: 32px; padding: 0.36rem 0.6rem; border-radius: 9px;
  background: rgba(242,99,50,0.14); border-color: rgba(242,99,50,0.42);
  color: var(--text); font-size: 0.78rem; font-weight: 850; white-space: nowrap;
}
.suggested-size-btn:hover { background: rgba(242,99,50,0.24); transform: none; }

footer { padding: 0.9rem 0 0; color: var(--muted); font-size: 0.88rem; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; width: 100%; gap: 20px; }
footer nav { display: flex; align-items: center; justify-content: center; gap: 18px; justify-self: center; }
footer a { color: #fff; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-decoration: none; }

@media (max-width: 1160px) {
  .controls-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .preset-field { grid-column: span 2; }
  .quality-field { grid-column: span 2; }
  .position-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .position-grid .secondary-btn { grid-column: 1 / -1; justify-self: end; }
  .workbench { grid-template-columns: 1fr; }
  .bucket, .output-card { height: 650px; min-height: 650px; }
}

@media (max-width: 720px) {
  .app { width: min(100vw - 1rem, 1500px); padding-top: 0.7rem; }
  .topbar { min-height: 76px; }
  .brand-icon { width: 48px; height: 48px; }
  .controls-grid, .position-grid { grid-template-columns: 1fr 1fr; }
  .preset-field, .quality-field, .guide { grid-column: 1 / -1; }
  .position-grid .secondary-btn { grid-column: 1 / -1; justify-self: stretch; }
  .workbench { grid-template-columns: 1fr; }
  .bucket { height: 560px; min-height: 560px; }
  .output-card { height: 650px; min-height: 650px; grid-template-rows: auto minmax(0,1fr) auto auto; }
  .output-head { grid-template-columns: 1fr; justify-items: center; align-items: center; }
  .output-left, .output-right { justify-content: center; max-width: 100%; }
  .conversion-summary { height: auto; grid-template-columns: 1fr 1fr; }
  .summary-arrow { display: none; }
  .bulk-helper { padding-top: 2.5rem; }
  .guide-list button { align-items: flex-start; flex-direction: column; gap: 0.18rem; }
  .guide-list button small { white-space: normal; }
  footer { grid-template-columns: 1fr; text-align: center; }
  footer > span, footer nav { justify-self: center; }
}

@media (max-width: 760px) {
  .message-line.has-action {
    flex-direction: column; align-items: stretch; gap: 0.7rem; text-align: center;
  }
  .suggested-size-btn { justify-self: center; align-self: center; }
}

.compression-scale { display:grid; grid-template-columns:1fr 1fr; align-items:center; margin-top:.25rem; font-size:.7rem; color:var(--muted); }
.compression-scale span:last-child { text-align:right; }
.compression-track-wrap { position:relative; height:24px; display:flex; align-items:center; }
.compression-track-wrap .recommended-band { position:absolute; left:54%; width:14%; height:6px; border-radius:999px; background:rgba(242,99,50,.34); pointer-events:none; z-index:0; }
.compression-track-wrap input { position:relative; z-index:1; width:100%; background:transparent; }
.compression-track-wrap input::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, rgba(255,255,255,.2) 0 54%, rgba(242,99,50,.36) 54% 68%, rgba(255,255,255,.2) 68% 100%);
}
.compression-track-wrap input::-moz-range-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, rgba(255,255,255,.2) 0 54%, rgba(242,99,50,.36) 54% 68%, rgba(255,255,255,.2) 68% 100%);
}
.compression-note { display:block; color:#d98245; font-size:.72rem; margin-top:.1rem; }
.quality-field.is-lossless { opacity:.78; }
.quality-field.is-lossless .recommended-band { background:rgba(255,255,255,.14); }
.preview-title-row { display:flex; align-items:center; justify-content:center; gap:1rem; }
.review-control { display:inline-flex; align-items:center; gap:.4rem; font-size:.78rem; font-weight:800; color:var(--muted); cursor:pointer; white-space:nowrap; }
.thumbnail-item.reviewed { border-color:rgba(134,214,157,.9); box-shadow:0 0 0 2px rgba(134,214,157,.24), 0 0 18px rgba(134,214,157,.2); }
.thumbnail-item.completed { background: rgba(134,214,157,.09); }
.thumbnail-item .thumb-copy { min-width:0; display:grid; gap:.18rem; }
.thumbnail-item .thumb-state { color:#a6e8b8; font-size:.7rem; font-weight:900; letter-spacing:.02em; }
.output-view canvas { width:100%; height:100%; display:block; }
.output-view.processing {
  width: 100%; height: 100%; color: var(--text); box-shadow: none;
  background: radial-gradient(circle at center, rgba(242,99,50,.12), transparent 18rem), rgba(0,0,0,.18);
}
.processing-state { width: min(440px, 88%); display: grid; justify-items: center; gap: 0.55rem; text-align: center; }
.processing-state strong { color: var(--text); font-size: 1.28rem; letter-spacing: -0.02em; }
.processing-state span:not(.spinner) { color: #d9e3ec; font-size: 0.98rem; font-weight: 780; }
.processing-state small { color: var(--muted); line-height: 1.45; }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.18); border-top-color: var(--brand-hover); border-radius: 999px; animation: spin 900ms linear infinite; }
.progress-track { width: 100%; height: 6px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.12); }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--brand); transition: width 160ms ease; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: rgba(255,255,255,.58); }
  .progress-track span { transition: none; }
}
