:root {
  --bg: #f4f5f7;
  --surface: rgba(255, 255, 255, .88);
  --surface-solid: #ffffff;
  --surface-2: #eef0f3;
  --text: #15171a;
  --muted: #6e747c;
  --line: rgba(20, 24, 28, .09);
  --line-strong: rgba(20, 24, 28, .14);
  --brand: #ff7a1a;
  --brand-2: #ff9a4b;
  --brand-soft: rgba(255, 122, 26, .12);
  --shadow: 0 18px 55px rgba(24, 28, 33, .10);
  --shadow-soft: 0 8px 28px rgba(24, 28, 33, .08);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 13px;
  --danger: #d94c4c;
  --success: #1f9d65;
  --topbar: rgba(244, 245, 247, .78);
  --overlay: rgba(6, 8, 11, .86);
}

[data-theme="dark"] {
  --bg: #0d0f12;
  --surface: rgba(24, 27, 31, .88);
  --surface-solid: #171a1e;
  --surface-2: #20242a;
  --text: #f5f6f7;
  --muted: #9ca3ad;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .13);
  --brand: #ff7a1a;
  --brand-2: #ff9d53;
  --brand-soft: rgba(255, 122, 26, .14);
  --shadow: 0 18px 60px rgba(0, 0, 0, .32);
  --shadow-soft: 0 8px 28px rgba(0, 0, 0, .22);
  --topbar: rgba(13, 15, 18, .76);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 15% -10%, rgba(255, 122, 26, .12), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}
body.lightbox-open { overflow: hidden; }
button, input, select { font: inherit; }
button { color: inherit; }
button, select { cursor: pointer; }
img { max-width: 100%; }
[hidden] { display: none !important; }

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

.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; padding: 16px clamp(18px, 4vw, 58px);
  background: var(--topbar); backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px;
  color: white; font-weight: 900; font-size: 20px;
  background: linear-gradient(145deg, var(--brand), #f05e0d);
  box-shadow: 0 8px 24px rgba(255, 122, 26, .28);
}
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 15px; letter-spacing: .01em; }
.brand-copy small { color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.integrity-pill {
  display: inline-flex; align-items: center; gap: 8px; min-height: 38px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 0 13px; color: var(--muted); font-size: 12px; font-weight: 700;
}
.integrity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(31,157,101,.12); }
.icon-btn, .viewer-icon {
  width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--line);
  background: var(--surface); border-radius: 12px; font-size: 18px;
}

main { width: min(1560px, calc(100% - 32px)); margin: 0 auto; }
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: end;
  padding: clamp(46px, 7vw, 92px) 0 34px;
}
.eyebrow { margin: 0 0 12px; color: var(--brand); font-weight: 900; letter-spacing: .15em; font-size: 11px; }
.hero h1 { margin: 0; font-size: clamp(42px, 7vw, 92px); letter-spacing: -.055em; line-height: .94; }
.hero-copy { margin: 20px 0 0; max-width: 720px; color: var(--muted); line-height: 1.65; font-size: 15px; }
.hero-stats {
  display: grid; grid-template-columns: repeat(3, minmax(92px, auto)); gap: 10px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-soft);
  border-radius: var(--radius-lg); padding: 10px;
}
.hero-stats > div { display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px; }
.hero-stats > div + div { border-left: 1px solid var(--line); }
.hero-stats strong { font-size: 20px; }
.hero-stats span { font-size: 11px; color: var(--muted); }

.toolbar-wrap { position: sticky; top: 74px; z-index: 25; padding: 10px 0; }
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px; border: 1px solid var(--line); background: var(--surface);
  backdrop-filter: blur(18px); border-radius: 18px; box-shadow: var(--shadow-soft);
}
.search-field {
  flex: 1 1 320px; max-width: 560px; min-height: 44px; display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid transparent; border-radius: 12px; padding: 0 13px;
}
.search-field:focus-within { border-color: rgba(255,122,26,.45); box-shadow: 0 0 0 4px var(--brand-soft); }
.search-icon { color: var(--muted); font-size: 20px; }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.search-field input::placeholder { color: var(--muted); }
.toolbar-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.select-wrap select, .tool-btn {
  min-height: 44px; border: 1px solid var(--line); background: var(--surface-solid); border-radius: 12px;
  padding: 0 13px; color: var(--text); font-weight: 750; font-size: 12px;
}
.tool-btn { display: inline-flex; align-items: center; gap: 8px; }
.tool-btn:hover, .select-wrap select:hover, .icon-btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.tool-btn.primary { color: white; border-color: transparent; background: linear-gradient(145deg, var(--brand), #f2670c); }
.tool-btn.ghost { color: var(--muted); }
.tool-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.selection-bar {
  margin: 8px 0 0; display: flex; justify-content: space-between; gap: 20px; align-items: center;
  padding: 12px 14px; border: 1px solid rgba(255,122,26,.28); background: var(--brand-soft); border-radius: 14px;
}
.selection-bar > div { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.selection-bar span { color: var(--muted); font-size: 12px; }
.selection-bar button { border: 0; border-radius: 10px; padding: 9px 12px; background: var(--brand); color: white; font-weight: 800; }

.gallery-section { padding: 18px 0 60px; }
.gallery-meta { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 10px 2px 18px; color: var(--muted); font-size: 12px; }
.gallery-meta p { margin: 0; }
.gallery-meta #resultLabel { color: var(--text); font-weight: 800; }

.gallery {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(10px, 1vw, 16px);
}
.photo-card {
  position: relative; min-width: 0; overflow: hidden; background: var(--surface-solid);
  border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-soft);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.photo-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--line-strong); }
.photo-card.selected { border-color: rgba(255,122,26,.7); box-shadow: 0 0 0 3px var(--brand-soft), var(--shadow); }
.photo-click { display: block; width: 100%; padding: 0; border: 0; background: transparent; text-align: left; }
.photo-frame { position: relative; overflow: hidden; background: var(--surface-2); }
.natural-layout .photo-frame { aspect-ratio: auto; min-height: 140px; }
.natural-layout .photo-frame img { width: 100%; height: auto; min-height: 140px; display: block; }
.crop-layout .photo-frame { aspect-ratio: 4 / 3; }
.crop-layout .photo-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-frame img { transition: transform .28s ease; }
.photo-card:hover .photo-frame img { transform: scale(1.018); }
.photo-overlay {
  position: absolute; inset: auto 0 0; padding: 46px 12px 11px;
  background: linear-gradient(transparent, rgba(0,0,0,.64)); color: white;
  opacity: 0; transition: opacity .2s ease;
}
.photo-card:hover .photo-overlay { opacity: 1; }
.photo-overlay strong { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-overlay span { font-size: 10px; opacity: .75; }
.select-photo {
  position: absolute; z-index: 4; top: 11px; right: 11px; width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.95); background: rgba(10,12,15,.34); backdrop-filter: blur(7px);
  display: grid; place-items: center; color: transparent; font-weight: 950; box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.photo-card.selected .select-photo { background: var(--brand); border-color: var(--brand); color: white; }
.photo-card-footer { padding: 10px 12px 11px; display: grid; gap: 3px; }
.photo-card-footer strong { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-card-footer span { color: var(--muted); font-size: 10px; }
.photo-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.photo-frame.loaded .photo-loading { display: none; }

.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-icon { font-size: 42px; margin-bottom: 14px; color: var(--brand); }
.empty-state h2 { color: var(--text); margin: 0 0 8px; }
.empty-state p { margin: 0; line-height: 1.6; }
.empty-state code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

.footer {
  width: min(1560px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 38px;
  border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 20px;
  color: var(--muted); font-size: 11px;
}

.lightbox { position: fixed; inset: 0; z-index: 100; }
.lightbox-backdrop { position: absolute; inset: 0; background: var(--overlay); backdrop-filter: blur(16px); }
.viewer {
  position: absolute; inset: clamp(10px, 2vw, 28px); display: grid; grid-template-rows: auto 1fr auto;
  overflow: hidden; border: 1px solid rgba(255,255,255,.12); border-radius: 22px; background: #0b0d10;
  box-shadow: 0 35px 90px rgba(0,0,0,.55); color: #f8f8f8;
}
.viewer-topbar, .viewer-bottom {
  min-height: 62px; display: flex; justify-content: space-between; gap: 20px; align-items: center;
  padding: 10px 14px; background: rgba(18,20,24,.96); border-color: rgba(255,255,255,.08);
}
.viewer-topbar { border-bottom: 1px solid rgba(255,255,255,.08); }
.viewer-bottom { border-top: 1px solid rgba(255,255,255,.08); }
.viewer-title { display: grid; gap: 2px; min-width: 0; }
.viewer-title strong { max-width: min(60vw, 760px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.viewer-title span { color: #8e959e; font-size: 10px; }
.viewer-actions, .zoom-controls { display: flex; align-items: center; gap: 7px; }
.viewer-actions button:not(.viewer-icon), .zoom-controls button {
  min-height: 38px; border: 1px solid rgba(255,255,255,.12); border-radius: 10px; background: #20242a; color: #f6f6f6;
  padding: 0 12px; font-size: 11px; font-weight: 800;
}
.viewer-icon { background: #20242a; border-color: rgba(255,255,255,.12); color: white; font-size: 24px; }
.viewer-stage { position: relative; min-height: 0; overflow: hidden; display: grid; place-items: center; background: #060708; }
.image-wrap { width: 100%; height: 100%; display: grid; place-items: center; overflow: auto; overscroll-behavior: contain; }
#viewerImage {
  max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain;
  transform-origin: center center; user-select: none; transition: transform .08s linear;
}
.nav-btn {
  position: absolute; z-index: 3; top: 50%; transform: translateY(-50%); width: 46px; height: 58px;
  border: 1px solid rgba(255,255,255,.12); border-radius: 14px; background: rgba(18,20,24,.70); color: white;
  font-size: 36px; backdrop-filter: blur(10px);
}
.nav-btn.prev { left: 14px; }
.nav-btn.next { right: 14px; }
.nav-btn:disabled { opacity: .25; cursor: default; }
.zoom-controls button { min-width: 38px; padding: 0 10px; }
#zoomLabel { width: 50px; text-align: center; color: #aeb4bc; font-size: 11px; }
.viewer-details { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; color: #9ba2aa; font-size: 10px; }
.viewer-details span + span::before { content: "•"; margin-right: 10px; color: #565d66; }

.toast-region { position: fixed; z-index: 200; right: 18px; bottom: 18px; display: grid; gap: 10px; pointer-events: none; }
.toast {
  width: min(370px, calc(100vw - 36px)); padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 13px; background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); font-size: 12px;
  animation: toast-in .2s ease;
}
.toast strong { display: block; margin-bottom: 2px; }
.toast span { color: var(--muted); line-height: 1.4; }
@keyframes toast-in { from { opacity: 0; transform: translateY(7px); } }

@media (max-width: 1250px) { .gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; }
  .hero-stats { width: fit-content; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .search-field { max-width: none; flex-basis: auto; }
  .toolbar-group { justify-content: flex-start; }
  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .toolbar-wrap { top: 72px; }
}
@media (max-width: 700px) {
  main, .footer { width: min(100% - 22px, 1560px); }
  .integrity-pill { display: none; }
  .hero { padding-top: 34px; gap: 24px; }
  .hero h1 { font-size: clamp(42px, 16vw, 68px); }
  .hero-stats { width: 100%; grid-template-columns: repeat(3, 1fr); }
  .hero-stats > div { padding: 10px 8px; }
  .hero-stats strong { font-size: 17px; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .photo-card { border-radius: 14px; }
  .photo-card-footer { padding: 8px 9px 9px; }
  .toolbar-wrap { position: relative; top: auto; }
  .toolbar-group { display: grid; grid-template-columns: 1fr 1fr; }
  .select-wrap select, .tool-btn { width: 100%; justify-content: center; }
  .select-wrap { grid-column: span 2; }
  .selection-bar { align-items: stretch; flex-direction: column; }
  .selection-bar button { align-self: stretch; }
  .gallery-meta .hint { display: none; }
  .footer { flex-direction: column; }
  .viewer { inset: 0; border-radius: 0; border: 0; }
  .viewer-actions #viewerSelectBtn { display: none; }
  .viewer-details { display: none; }
  .nav-btn { width: 40px; height: 50px; }
}
@media (max-width: 420px) {
  .tool-label { font-size: 11px; }
  .gallery { grid-template-columns: 1fr 1fr; }
  .photo-card-footer span { display: none; }
  .viewer-title strong { max-width: 42vw; }
}

/* Canon RAW + JPG/PNG support */
.format-badges {
  position: absolute;
  z-index: 3;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 6px;
  pointer-events: none;
}
.format-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(255,255,255,.26);
  border-radius: 999px;
  background: rgba(10,12,15,.62);
  color: #fff;
  backdrop-filter: blur(8px);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .08em;
  box-shadow: 0 4px 14px rgba(0,0,0,.16);
}
.format-badge.raw {
  border-color: rgba(255,154,75,.72);
  background: rgba(255,122,26,.88);
}
.raw-only-frame { min-height: 240px !important; }
.raw-only-placeholder,
.viewer-raw-placeholder {
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  gap: 8px;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 22%, rgba(255,122,26,.16), transparent 13rem),
    linear-gradient(145deg, #15191e, #0b0d10);
  color: #f5f6f7;
}
.raw-only-placeholder { min-height: 240px; }
.raw-only-placeholder strong {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  border-radius: 24px;
  background: linear-gradient(145deg, var(--brand), #e95e08);
  box-shadow: 0 16px 38px rgba(255,122,26,.24);
  font-size: 22px;
  letter-spacing: .05em;
}
.raw-only-placeholder span { font-size: 12px; font-weight: 800; }
.raw-only-placeholder small { max-width: 220px; color: #8f969f; line-height: 1.5; font-size: 10px; }
.viewer-raw-placeholder {
  width: min(520px, calc(100% - 80px));
  min-height: 260px;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.viewer-raw-placeholder strong { color: var(--brand-2); font-size: clamp(24px, 4vw, 42px); letter-spacing: -.03em; }
.viewer-raw-placeholder span { max-width: 440px; color: #9da4ad; line-height: 1.65; font-size: 12px; }
.viewer-topbar { flex-wrap: wrap; }
.viewer-actions { flex-wrap: wrap; justify-content: flex-end; }
.viewer-actions #viewerDownloadBothBtn { background: var(--brand); border-color: var(--brand); }
.viewer-actions #viewerDownloadRawBtn { border-color: rgba(255,122,26,.48); color: #ffc398; }

@media (max-width: 700px) {
  .viewer-topbar { gap: 8px; padding: 8px 10px; }
  .viewer-title { flex: 1 1 100%; }
  .viewer-actions { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; }
  .viewer-actions button:not(.viewer-icon) { padding: 0 7px; font-size: 10px; }
  .viewer-actions #viewerSelectBtn { display: none; }
  .viewer-actions #viewerDownloadPreviewBtn,
  .viewer-actions #viewerDownloadRawBtn,
  .viewer-actions #viewerDownloadBothBtn { width: 100%; }
  .viewer-icon { width: 38px; height: 38px; }
  .viewer-raw-placeholder { width: min(460px, calc(100% - 48px)); min-height: 220px; }
}

@media (max-width: 470px) {
  .viewer-actions { grid-template-columns: 1fr 1fr auto; }
  .viewer-actions #viewerDownloadBothBtn { grid-column: 1 / span 2; grid-row: 2; }
  .viewer-actions #viewerDownloadPreviewBtn { grid-column: 1; }
  .viewer-actions #viewerDownloadRawBtn { grid-column: 2; }
  .viewer-actions .viewer-icon { grid-column: 3; grid-row: 1; }
  .format-badges { top: 7px; left: 7px; gap: 4px; }
  .format-badge { min-height: 20px; padding: 0 6px; font-size: 8px; }
}
