:root {
  --bg: #F7F6F3; --surface: #FFFFFF; --surface-2: #F9F9F8;
  --border: #EAEAEA; --border-strong: rgba(0,0,0,0.12);
  --text-primary: #111111; --text-secondary: #787774; --text-tertiary: #AEADA9;
  --accent: #111111; --accent-text: #FFFFFF; --accent-hover: #333333;
  --tag-blue-bg: #E1F3FE; --tag-blue-text: #1F6C9F;
  --tag-green-bg: #EDF3EC; --tag-green-text: #346538;
  --warning-bg: #FFF5E8; --warning-text: #9B5D00;
  --error-bg: #FDECEC; --error-text: #A23A3A;
  --success-bg: #EDF8F0; --success-text: #2D6A3D;
  --shadow: 0 2px 8px rgba(0,0,0,0.04);
  --radius: 10px; --radius-sm: 6px;
  --transition: 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
[data-theme="dark"] {
  --bg: #111111; --surface: #1A1A1A; --surface-2: #222222;
  --border: rgba(255,255,255,0.08); --border-strong: rgba(255,255,255,0.14);
  --text-primary: #EFEFEE; --text-secondary: #888784; --text-tertiary: #555452;
  --accent: #EFEFEE; --accent-text: #111111; --accent-hover: #CFCFCC;
  --tag-blue-bg: rgba(31,108,159,0.18); --tag-blue-text: #7CC3F0;
  --tag-green-bg: rgba(52,101,56,0.18); --tag-green-text: #8DC48F;
  --warning-bg: rgba(155,93,0,0.18); --warning-text: #F1C27B;
  --error-bg: rgba(162,58,58,0.18); --error-text: #F4A3A3;
  --success-bg: rgba(45,106,61,0.18); --success-text: #A5D9B0;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg); color: var(--text-primary);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}
nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(16px, 5vw, 48px); height: 56px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}
.nav-logo {
  font-family: 'Newsreader', Georgia, serif; font-size: 18px; font-weight: 500;
  letter-spacing: -0.03em; color: var(--text-primary); text-decoration: none;
  display: flex; align-items: center; gap: 6px;
}
.nav-logo span { font-style: italic; color: var(--text-secondary); }
.nav-right { display: flex; align-items: center; gap: 12px; }
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 9999px;
  background: var(--tag-blue-bg); color: var(--tag-blue-text);
}
.theme-btn {
  width: 34px; height: 34px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text-secondary);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), transform 150ms, box-shadow var(--transition);
  flex-shrink: 0;
}
.theme-btn:hover { background: var(--surface-2); box-shadow: var(--shadow); }
.theme-btn:active { transform: scale(0.95); }
.theme-btn svg { width: 16px; height: 16px; }
main {
  max-width: 960px; margin: 0 auto;
  padding: clamp(36px, 8vw, 72px) clamp(16px, 5vw, 32px) 80px;
}
.hero {
  margin-bottom: 32px; opacity: 0; transform: translateY(12px);
  animation: fadeUp 600ms cubic-bezier(0.16, 1, 0.3, 1) 100ms forwards;
}
.hero h1 {
  font-family: 'Newsreader', Georgia, serif;
  font-size: clamp(32px, 6vw, 54px); font-weight: 400;
  letter-spacing: -0.035em; line-height: 1.1; color: var(--text-primary); margin-bottom: 12px;
}
.hero h1 em { font-style: italic; color: var(--text-secondary); }
.hero p { font-size: 15px; color: var(--text-secondary); line-height: 1.6; max-width: 560px; }
.upload-zone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface); padding: 56px 32px; text-align: center; cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition), transform var(--transition);
  position: relative; overflow: hidden; opacity: 0; transform: translateY(12px);
  animation: fadeUp 600ms cubic-bezier(0.16, 1, 0.3, 1) 200ms forwards;
}
.upload-zone:hover, .upload-zone.drag-over, .upload-zone.is-ready {
  border-color: var(--text-secondary); background: var(--surface-2); box-shadow: var(--shadow);
}
.upload-zone.is-error {
  border-color: var(--error-text); background: var(--error-bg);
}
.upload-zone.is-processing {
  opacity: 0.8; transform: scale(0.99); pointer-events: none;
}
.upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-icon { width: 44px; height: 44px; margin: 0 auto 16px; color: var(--text-tertiary); }
.upload-zone h3 { font-size: 16px; font-weight: 500; color: var(--text-primary); margin-bottom: 6px; }
.upload-zone p { font-size: 13px; color: var(--text-secondary); }
.upload-zone .formats { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.format-badge {
  font-family: 'Geist Mono', monospace; font-size: 11px; padding: 2px 8px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface-2); color: var(--text-secondary);
}
.panel {
  display: none; gap: 20px; opacity: 0; transform: translateY(12px);
  margin-top: 24px;
  animation: fadeUp 500ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.panel.visible { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
@media (max-width: 620px) { .panel.visible { grid-template-columns: 1fr; } }
.img-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); overflow: hidden; position: relative;
}
.img-card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.img-card-header span {
  font-size: 12px; font-weight: 500; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-secondary);
}
.img-card-body {
  padding: 16px; min-height: 260px; display: flex;
  align-items: center; justify-content: center;
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 0 0 / 16px 16px;
}
.img-card-body img { max-width: 100%; max-height: 320px; object-fit: contain; border-radius: 4px; }
.controls-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px;
  border-radius: var(--radius-sm); font-family: 'DM Sans', sans-serif;
  font-size: 14px; font-weight: 500; cursor: pointer; border: none;
  transition: background var(--transition), transform 150ms, box-shadow var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); box-shadow: var(--shadow); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-reset {
  margin-left: auto; background: transparent; border: none;
  font-size: 13px; color: var(--text-secondary); cursor: pointer;
  padding: 8px 12px; border-radius: var(--radius-sm); font-family: 'DM Sans', sans-serif;
  transition: color var(--transition), background var(--transition);
}
.btn-reset:hover { color: var(--text-primary); background: var(--surface); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 10px;
  border: none; background: var(--surface);
  color: var(--text-secondary); cursor: pointer;
  transition: background var(--transition), color var(--transition), transform 150ms;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  transform: translateY(-1px);
}
.icon-btn svg { width: 16px; height: 16px; }

.history-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px;
}

.history-actions {
  display: flex; align-items: center; gap: 6px;
  margin-top: -4px;
}
.progress-wrap { display: none; flex-direction: column; gap: 8px; width: 100%; }
.progress-wrap.visible { display: flex; }
.progress-bar-track { height: 2px; background: var(--border); border-radius: 2px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--text-primary); border-radius: 2px; width: 0%; transition: width 300ms ease; }
.progress-label { font-size: 12px; color: var(--text-secondary); font-family: 'Geist Mono', monospace; }
.status-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500;
  letter-spacing: 0.05em; text-transform: uppercase; padding: 3px 10px; border-radius: 9999px;
}
.status-badge.ready { background: var(--tag-green-bg); color: var(--tag-green-text); }
.status-badge.processing { background: var(--tag-blue-bg); color: var(--tag-blue-text); }
.status-badge.error { background: var(--error-bg); color: var(--error-text); }
.dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.dot.pulse { animation: pulse 1.2s ease infinite; }
.result-empty {
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 8px;
  color: var(--text-tertiary);
  text-align: center;
}
.result-empty span { font-size: 13px; }
.message-banner {
  display: none; margin-top: 16px; padding: 12px 14px; border-radius: 10px;
  font-size: 13px; line-height: 1.5; border: 1px solid transparent;
}
.message-banner.visible { display: block; }
.message-banner.info { background: var(--surface-2); border-color: var(--border); color: var(--text-secondary); }
.message-banner.warning { background: var(--warning-bg); border-color: rgba(155,93,0,0.2); color: var(--warning-text); }
.message-banner.error { background: var(--error-bg); border-color: rgba(162,58,58,0.2); color: var(--error-text); }
.message-banner.success { background: var(--success-bg); border-color: rgba(45,106,61,0.18); color: var(--success-text); }
.foot-note {
  margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 12px; opacity: 0; transform: translateY(12px);
  animation: fadeUp 600ms cubic-bezier(0.16, 1, 0.3, 1) 400ms forwards;
}
.foot-note-icon {
  width: 28px; height: 28px; border-radius: 6px; background: var(--surface);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); flex-shrink: 0;
}
.foot-note p { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.foot-note strong { color: var(--text-primary); font-weight: 500; }
@keyframes fadeUp { to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===== MOBILE UI ENHANCEMENTS ===== */

/* Priority 1 — Mobile main action buttons with larger corner radius and enhanced shadow */
@media (max-width: 768px) {
  .btn-primary {
    border-radius: 24px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: background var(--transition), transform 150ms, box-shadow 200ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .btn-primary:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
  }

  .btn-primary:active {
    transform: scale(0.96);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .btn-primary:disabled {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  }
}

/* Priority 2 — Mobile shell and layout with app-like appearance */
@media (max-width: 768px) {
  main {
    padding: clamp(20px, 5vw, 24px) clamp(12px, 4vw, 20px) 60px;
  }

  .hero {
    margin-bottom: 24px;
    padding: 0 8px;
  }

  .hero h1 {
    font-size: clamp(28px, 7vw, 42px);
  }

  .hero p {
    font-size: 14px;
    line-height: 1.6;
  }
}

/* Priority 3 — Rounded cards and surfaces for mobile */
@media (max-width: 768px) {
  .upload-zone {
    border-radius: 20px;
    padding: 48px 24px;
    border: 2px dashed var(--border-strong);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    transition: all 250ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .upload-zone:hover,
  .upload-zone.drag-over {
    border-radius: 24px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
  }

  .upload-zone.is-ready {
    border-radius: 20px;
    background: var(--surface);
  }

  .img-card {
    border-radius: 16px;
    border: 1.5px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .img-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
  }

  .img-card-body {
    padding: 20px;
    min-height: 280px;
  }

  .queue-panel,
  .history-panel {
    border-radius: 16px;
    padding: 16px;
    border: 1.5px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  .message-banner {
    border-radius: 16px;
    padding: 14px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  }
}

/* Priority 4 — Touch-friendly details */
@media (max-width: 768px) {
  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .btn {
    min-height: 48px;
    padding: 12px 20px;
  }

  .btn-reset {
    margin-left: 0;
    min-height: 44px;
    font-size: 14px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .icon-btn:active {
    transform: scale(0.92);
  }

  .tag {
    display: none;
  }

  .upload-icon {
    width: 48px;
    height: 48px;
  }

  .upload-zone h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
  }

  .upload-zone p {
    font-size: 14px;
    margin-bottom: 16px;
  }

  .format-badge {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
  }

  .status-badge {
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 11px;
  }

  .panel.visible {
    gap: 16px;
  }

  .progress-wrap {
    gap: 10px;
    margin-top: 8px;
  }

  .progress-bar-track {
    height: 3px;
    border-radius: 3px;
  }

  .progress-label {
    font-size: 13px;
  }
}

/* Priority 5 — Polished micro-interactions */
@media (max-width: 768px) {
  * {
    transition: background var(--transition), color var(--transition), border-color var(--transition);
  }

  button {
    transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .upload-zone input[type="file"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .item {
    border-radius: 12px;
    transition: all 200ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .item:active {
    transform: scale(0.96);
  }

  .item .remove {
    border-radius: 6px;
    transition: all 150ms ease;
  }

  .item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
}

/* Adjust panel layout and spacing for mobile */
@media (max-width: 768px) {
  nav {
    padding: 0 clamp(12px, 4vw, 24px);
  }

  .nav-logo {
    font-size: 16px;
  }

  .theme-btn {
    width: 38px;
    height: 38px;
  }

  .queue-history {
    gap: 12px;
  }

  .list {
    min-height: 80px;
    gap: 10px;
  }

  .item {
    width: 76px;
    height: 76px;
  }
}

@media (max-width: 480px) {
  .upload-zone {
    padding: 40px 20px;
    border-radius: 20px;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .btn-reset {
    margin-left: 0;
  }

  .hero h1 {
    font-size: clamp(24px, 6vw, 36px);
  }

  main {
    padding: clamp(16px, 4vw, 20px) clamp(12px, 3vw, 16px) 50px;
  }

  .upload-zone {
    padding: 40px 16px;
  }

  .panel.visible {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .queue-history {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.queue-history {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 20px;
}
.queue-panel, .history-panel { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface); }
.queue-panel h4, .history-panel h4 { margin: 0 0 8px 0; font-size: 13px; color: var(--text-secondary); }
.list { display: flex; gap: 8px; flex-wrap: wrap; min-height: 72px; }
.item { width: 72px; height: 72px; border-radius: 6px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; position: relative; }
.item img { width: 100%; height: 100%; object-fit: cover; }
.item .meta { position: absolute; left: 4px; bottom: 4px; right: 4px; font-size: 10px; color: var(--text-secondary); text-align: center; }
.item .remove { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.06); border-radius: 4px; padding: 2px 4px; font-size: 11px; cursor: pointer; }

@media (max-width: 620px) { .queue-history { grid-template-columns: 1fr; } }

/* History thumbnails: show pointer and download icon on hover */
.history-panel .item { cursor: default; }
.history-panel .item:hover { cursor: pointer; }
.history-panel .item::after {
  content: '';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpolyline points='7 10 12 15 17 10'/%3E%3Cline x1='12' y1='15' x2='12' y2='3'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}
.history-panel .item:hover::after { opacity: 1; transform: translateY(0); }