/* ==========================================================
   .JPG CONVERTER — design tokens
========================================================== */
:root{
  --white:#FFFFFF;
  --ink:#1D1D1F;
  --surface:#F5F5F7;
  --line:#D2D2D7;
  --muted:#86868B;
  --radius-card:16px;
  --radius-pill:980px;
  --font: "PingFang TC", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Noto Sans TC", "Segoe UI", sans-serif;
  --font-mono: "SF Mono", ui-monospace, "Courier New", monospace;
  --ease: cubic-bezier(.22,.61,.36,1);
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; }
@media (min-width:981px){
  html.lock-scroll, html.lock-scroll body{ overflow:hidden; height:100%; }
}
body{
  font-family:var(--font);
  background:var(--white);
  color:var(--ink);
  -webkit-font-smoothing:antialiased;
  overflow-x:hidden;
}
h1,h2,h3,p{ margin:0; }
button{ font-family:inherit; }
::selection{ background:var(--ink); color:var(--white); }
:focus-visible{ outline:2px solid var(--ink); outline-offset:3px; }

/* Elements that already carry their own border get a border-color
   focus indicator instead of an extra outline ring, so focus never
   shows as two concentric frames. */
select:focus-visible,
input:focus-visible,
.btn-outline:focus-visible,
.btn-ghost:focus-visible,
.pos-grid button:focus-visible,
.custom-select-trigger:focus-visible,
.dropzone:focus-visible{
  outline:none;
  border-color:var(--ink);
}

.hidden{ display:none !important; }
.hidden-field{ display:none; }

/* ==========================================================
   HERO
========================================================== */
#hero{
  position:fixed;
  inset:0;
  background:var(--white);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:100;
  cursor:pointer;
  transition:opacity .6s var(--ease);
}
#hero.hero-exit{ opacity:0; pointer-events:none; }

.hero-inner{
  text-align:center;
  padding:0 24px;
}

.scramble-text{
  font-family:var(--font);
  font-weight:600;
  color:var(--ink);
  white-space:pre-wrap;
  min-height:1em;
}

#heroTitle{
  font-size:clamp(28px, 6vw, 64px);
  font-weight:1000;
  letter-spacing:.02em;
  -webkit-text-stroke:1px var(--ink);
}

.hero-features{
  margin-top:0;
  max-height:0;
  overflow:hidden;
  opacity:0;
  font-family:var(--font);
  font-weight:600;
  font-size:clamp(13px, 2vw, 17px);
  letter-spacing:.25em;
  word-spacing:.3em;
  color:var(--muted);
  transition:max-height .75s var(--ease), margin-top .75s var(--ease), opacity .7s var(--ease) .15s;
}
.hero-features.show{
  margin-top:22px;
  max-height:40px;
  opacity:1;
}

.hero-credit{
  position:fixed;
  bottom:36px;
  left:0;
  right:0;
  text-align:center;
  font-size:clamp(11px, 1.6vw, 14px);
  letter-spacing:.15em;
  word-spacing:.2em;
  color:var(--muted);
  opacity:0;
  transition:opacity .6s var(--ease);
}
.hero-credit.show{ opacity:1; }

@media (prefers-reduced-motion: reduce){
  .hero-features, .hero-credit{ transition:none; }
}

/* ==========================================================
   APP SHELL
========================================================== */
#app{
  opacity:0;
  transition:opacity .6s var(--ease);
  min-height:100vh;
  display:flex;
  flex-direction:column;
}
#app.app-visible{ opacity:1; }

.app-header{
  border-bottom:1px solid var(--line);
  padding:14px clamp(20px, 4vw, 48px);
}
.app-header-inner{
  display:flex;
  align-items:center;
  gap:clamp(20px, 4vw, 40px);
  max-width:1400px;
  margin:0 auto;
}
.logo-slot{
  width:44px;
  height:44px;
  border-radius:10px;
  flex-shrink:0;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  transition:background .15s, transform .15s var(--ease);
}
.logo-slot:hover{
  transform:scale(1.06);
}
.logo-slot:active{ transform:scale(.96); }
.logo-slot img{ width:30px; height:30px; display:block; }
.feature-nav{
  display:flex;
  gap:clamp(14px, 3vw, 36px);
  font-size:12px;
  letter-spacing:.12em;
  color:var(--muted);
  overflow-x:auto;
  scrollbar-width:none;
}
.feature-nav::-webkit-scrollbar{ display:none; }
.feature-nav span{ white-space:nowrap; }

.header-spacer{ flex:1; }

/* ==========================================================
   MAIN BODY LAYOUT
========================================================== */
.app-body{
  flex:1;
  max-width:1400px;
  width:100%;
  margin:0 auto;
  padding:20px clamp(20px, 4vw, 48px) 16px;
  display:grid;
  grid-template-columns:1fr 320px;
  gap:32px;
  align-items:start;
}
@media (max-width:980px){
  .app-body{ grid-template-columns:1fr; }
  .settings{ order:2; position:static; max-height:none; overflow-y:visible; }
  .stage{ order:1; }
}

/* ==========================================================
   STAGE (thumbnail area)
========================================================== */
.stage-toolbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  flex-wrap:wrap;
  margin-bottom:18px;
}
.stats{
  font-size:13px;
  color:var(--muted);
}
.stage-actions{ display:flex; gap:10px; }

.dropzone{
  border:1px dashed var(--line);
  border-radius:var(--radius-card);
  padding:32px 20px;
  text-align:center;
  background:var(--surface);
  cursor:pointer;
  transition:border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible{ border-color:var(--ink); }
.dropzone.dragging{
  border-color:var(--ink);
  background:var(--surface);
  animation:dropzone-breathe 1.2s ease-in-out infinite;
}
.dropzone.importing{
  border-color:var(--ink);
  background:var(--surface);
  cursor:wait;
  pointer-events:none;
  animation:dropzone-breathe 1.2s ease-in-out infinite;
}
@keyframes dropzone-breathe{
  0%, 100%{ box-shadow:0 0 0 0 rgba(29,29,31,0); }
  50%{ box-shadow:0 0 0 6px rgba(29,29,31,.06); }
}
@media (prefers-reduced-motion: reduce){
  .dropzone.dragging, .dropzone.importing{ animation:none; }
}
.dropzone-cta{ font-size:17px; font-weight:600; margin-bottom:6px; }
.dropzone-sub{ font-size:13px; color:var(--muted); }

.grid{
  margin-top:18px;
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(200px,1fr));
  gap:18px;
}

.card{
  background:var(--white);
  border:1px solid var(--line);
  border-radius:var(--radius-card);
  overflow:hidden;
  transition:transform .2s var(--ease), box-shadow .2s var(--ease);
  animation:card-in .4s var(--ease) backwards;
}
@keyframes card-in{
  from{ opacity:0; transform:translateY(10px); }
  to{ opacity:1; transform:translateY(0); }
}
@media (prefers-reduced-motion: reduce){
  .card{ animation:none; }
}
.card:hover{
  transform:translateY(-3px);
  box-shadow:0 14px 30px rgba(0,0,0,.08);
}
.card .thumb{
  position:relative;
  aspect-ratio:4/3;
  background:var(--surface);
  overflow:hidden;
}
.card .thumb img{
  width:100%; height:100%; object-fit:cover; display:block;
  transition:transform .35s var(--ease);
  cursor:zoom-in;
}
.card:hover .thumb img{ transform:scale(1.06); }
.card .thumb .remove-btn{
  position:absolute; top:8px; right:8px;
  width:24px; height:24px; border-radius:50%;
  background:rgba(255,255,255,.9);
  border:1px solid var(--line);
  color:var(--ink);
  font-size:13px; line-height:1;
}
.card .select-check{
  position:absolute; top:8px; left:8px; z-index:2;
  width:24px; height:24px; border-radius:7px;
  background:rgba(255,255,255,.9);
  border:1px solid var(--line);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
}
.card .select-check input{ width:15px; height:15px; margin:0; accent-color:var(--ink); }
.card .status-tag{
  position:absolute; bottom:8px; left:8px;
  font-size:10px; letter-spacing:.06em;
  padding:3px 8px; border-radius:var(--radius-pill);
  background:rgba(255,255,255,.92);
  border:1px solid var(--line);
  color:var(--muted);
}
.card .status-tag.done{ color:#1D1D1F; border-color:var(--ink); }
.card.selected{ box-shadow:0 0 0 2px var(--ink); }
.card.dragging-card{ opacity:.4; }
.card.drop-target{ outline:2px dashed var(--ink); outline-offset:-3px; }
.card{ cursor:grab; touch-action:pan-y; }
.card:active{ cursor:grabbing; }
.card .progress-track{ height:2px; background:var(--surface); overflow:hidden; }
.card .progress-fill{
  height:100%; width:0%; background:var(--ink); transition:width .25s;
  position:relative;
}
.card .progress-fill.active::after{
  content:"";
  position:absolute; top:0; left:0; right:0; bottom:0;
  background:linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  animation:progress-shimmer 1.1s linear infinite;
}
@keyframes progress-shimmer{
  from{ transform:translateX(-100%); }
  to{ transform:translateX(100%); }
}
.card .meta{ padding:12px 14px 14px; }
.card .fname{ font-size:12.5px; font-weight:500; word-break:break-all; margin-bottom:3px; }
.card .dims{ font-size:11.5px; color:var(--muted); }
.card .arrow{ font-size:11.5px; color:var(--ink); margin-top:2px; }
.card .exif-toggle{
  margin-top:8px; background:none; border:none; padding:0;
  font-size:11px; color:var(--muted); text-decoration:underline;
  text-underline-offset:2px;
}
.card .exif-panel{
  display:none; margin-top:8px; padding:10px;
  background:var(--surface); border-radius:8px;
  font-size:11px; font-family:var(--font-mono);
}
.card .exif-panel.open{ display:block; }
.card .exif-panel div{ display:flex; justify-content:space-between; gap:8px; padding:2px 0; color:var(--ink); }
.card .exif-panel .k{ color:var(--muted); }
.card .dl-row{ margin-top:10px; }

/* ==========================================================
   SETTINGS PANEL
========================================================== */
.settings{
  position:sticky;
  top:24px;
  max-height:calc(100vh - 48px);
  overflow-y:auto;
}
.setting-group{
  padding:16px 0;
  border-bottom:1px solid var(--line);
}
.setting-group:first-child{ padding-top:0; }
.setting-group:last-child{ border-bottom:none; }
.setting-group h2{
  font-size:12px;
  letter-spacing:.1em;
  color:var(--muted);
  margin-bottom:10px;
  font-weight:600;
}
.field-label{
  display:block;
  font-size:12.5px;
  color:var(--ink);
  margin:13px 0 7px;
}
.field-label:first-child{ margin-top:0; }
.value-badge{ color:var(--muted); font-family:var(--font-mono); }

#qualityField{ margin-top:8px; }

select, input[type="text"], input[type="number"]{
  width:100%;
  padding:9px 12px;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--white);
  color:var(--ink);
  font-size:14px;
}
select:focus, input:focus{ border-color:var(--ink); }
input[type="range"]{ width:100%; accent-color:var(--ink); }
input[type="file"]{ font-size:12.5px; }

/* native <select> stays in the DOM to hold state, but is visually replaced
   by the custom dropdown below it */
select.native-select-hidden{
  position:absolute;
  width:1px; height:1px;
  opacity:0; overflow:hidden;
  pointer-events:none;
}

.custom-select{
  position:relative;
  width:100%;
}
.custom-select-trigger{
  width:100%;
  display:flex; align-items:center; justify-content:space-between;
  gap:8px;
  padding:9px 12px;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--white);
  color:var(--ink);
  font-size:14px;
  text-align:left;
  cursor:pointer;
  transition:border-color .15s;
}
.custom-select-trigger:hover{ border-color:#b8b8bd; }
.custom-select.open .custom-select-trigger{ border-color:var(--ink); }
.custom-select-chevron{
  width:9px; height:9px;
  flex-shrink:0;
  border-right:1.5px solid var(--muted);
  border-bottom:1.5px solid var(--muted);
  transform:rotate(45deg);
  transition:transform .15s;
  margin-top:-3px;
}
.custom-select.open .custom-select-chevron{ transform:rotate(-135deg); margin-top:3px; }

.custom-select-list{
  list-style:none;
  margin:6px 0 0;
  padding:6px;
  position:absolute;
  top:100%; left:0; right:0;
  background:var(--white);
  border:1px solid var(--line);
  border-radius:12px;
  box-shadow:0 12px 28px rgba(0,0,0,.10);
  z-index:20;
  max-height:240px;
  overflow-y:auto;
  display:none;
}
.custom-select.open .custom-select-list{ display:block; }
.custom-select-option{
  padding:9px 10px;
  border-radius:7px;
  font-size:13.5px;
  color:var(--ink);
  cursor:pointer;
}
.custom-select-option:hover{ background:var(--surface); }
.custom-select-option.highlighted{ background:var(--surface); }
.custom-select-option.selected{ font-weight:600; }
.custom-select-option.selected::after{ content:"✓"; float:right; color:var(--ink); }

/* language pill dropdown reuses the same mechanism with a compact look */
.lang-custom-select .custom-select-trigger{
  border:1px solid var(--ink);
  border-radius:var(--radius-pill);
  padding:8px 14px;
  font-size:12px;
  font-weight:600;
  letter-spacing:.06em;
  width:auto;
}
.lang-custom-select .custom-select-trigger:hover{ background:var(--surface); }
.lang-custom-select .custom-select-list{
  left:auto; right:0;
  min-width:120px;
}
.lang-custom-select .custom-select-chevron{
  border-color:var(--ink);
  width:6px; height:6px;
}

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

.switch-row{
  display:flex; align-items:center; gap:10px;
  font-size:14px;
}
.switch-row input{ width:16px; height:16px; accent-color:var(--ink); }
.hint-text{ font-size:11.5px; color:var(--muted); margin-top:6px; }

.thumb .wm-preview,
.lightbox-media .wm-preview{
  position:absolute; inset:0; pointer-events:none; overflow:hidden;
}
.wm-preview .wm-text{
  position:absolute;
  white-space:nowrap;
  font-weight:600;
  text-shadow:0 1px 3px rgba(0,0,0,.4);
}
.wm-preview .wm-image{
  position:absolute;
  max-width:80%;
}

.pos-grid{
  display:grid; grid-template-columns:repeat(3,1fr); gap:5px;
  padding:6px; border:1px solid var(--line); border-radius:10px;
}
.pos-grid button{
  aspect-ratio:1; border:1px solid var(--line); border-radius:6px;
  background:var(--white); position:relative;
}
.pos-grid button::after{
  content:""; position:absolute; top:50%; left:50%;
  width:5px; height:5px; border-radius:50%;
  background:var(--muted); transform:translate(-50%,-50%);
}
.pos-grid button.active{ border-color:var(--ink); background:var(--surface); }
.pos-grid button.active::after{ background:var(--ink); }

/* ==========================================================
   BUTTONS
========================================================== */
.btn{
  font-size:14px;
  font-weight:600;
  border-radius:var(--radius-pill);
  padding:11px 20px;
  border:1px solid transparent;
  cursor:pointer;
  transition:background .15s, border-color .15s, color .15s, opacity .15s, transform .1s var(--ease);
}
.btn:active:not(:disabled){ transform:scale(.96); }
.btn.full{ width:100%; }
.btn-primary{ background:var(--ink); color:var(--white); }
.btn-primary:hover{ background:#000; }
.btn-outline{ background:var(--white); border-color:var(--ink); color:var(--ink); }
.btn-outline:hover{ background:var(--surface); }
.btn-ghost{ background:var(--surface); border-color:var(--surface); color:var(--ink); }
.btn-ghost:hover{ background:var(--line); }
.btn:disabled{ opacity:.4; cursor:not-allowed; }

/* ==========================================================
   FOOTER
========================================================== */
.app-footer{
  padding:8px 20px 28px;
  text-align:center;
}
.app-footer p{
  font-size:12px;
  color:var(--muted);
  letter-spacing:.02em;
}

/* ==========================================================
   TOAST
========================================================== */
.toast{
  position:fixed;
  left:50%;
  bottom:28px;
  transform:translate(-50%, 12px);
  background:var(--ink);
  color:var(--white);
  font-size:13px;
  font-weight:500;
  padding:12px 20px;
  border-radius:var(--radius-pill);
  box-shadow:0 12px 28px rgba(0,0,0,.18);
  opacity:0;
  pointer-events:none;
  z-index:200;
  max-width:min(90vw, 420px);
  text-align:center;
  transition:opacity .25s var(--ease), transform .25s var(--ease);
}
.toast.show{
  opacity:1;
  transform:translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce){
  .toast{ transition:opacity .15s linear; transform:translate(-50%, 0); }
}

/* ==========================================================
   LIGHTBOX (enlarged thumbnail preview)
========================================================== */
.lightbox{
  position:fixed;
  inset:0;
  background:rgba(20,20,20,.92);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:250;
  padding:40px;
  opacity:0;
  pointer-events:none;
  transition:opacity .2s var(--ease);
}
.lightbox.show{ opacity:1; pointer-events:auto; }
.lightbox-media{
  position:relative;
  display:inline-flex;
  max-width:100%;
  max-height:100%;
}
.lightbox-media img{
  display:block;
  max-width:100%;
  max-height:100%;
  border-radius:8px;
  box-shadow:0 20px 60px rgba(0,0,0,.4);
}
.lightbox-close{
  position:absolute;
  top:20px; right:24px;
  width:40px; height:40px;
  border-radius:50%;
  border:none;
  background:rgba(255,255,255,.12);
  color:var(--white);
  font-size:22px;
  line-height:1;
  cursor:pointer;
  transition:background .15s;
}
.lightbox-close:hover{ background:rgba(255,255,255,.22); }
@media (prefers-reduced-motion: reduce){
  .lightbox{ transition:opacity .1s linear; }
}

/* ==========================================================
   RESPONSIVE
========================================================== */
@media (max-width:640px){
  .app-header-inner{ gap:16px; flex-wrap:wrap; row-gap:10px; justify-content:space-between; }
  .header-spacer{ display:none; }
  .feature-nav{ gap:14px; }
  .grid{ grid-template-columns:repeat(auto-fill, minmax(150px,1fr)); gap:12px; }
  .dropzone{ padding:40px 16px; }
}
