:root {
  --bg: #0b0d10; --panel: #151920; --panel2: #1d222b; --line: #2a303b;
  --text: #eef1f5; --muted: #98a2b3; --accent: #3d8bff; --accent-2: #2f6fd6;
  --ok: #2bb673; --warn: #f5a524; --bad: #ef4444;
  --tap: 48px; --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; display: flex; flex-direction: column; overscroll-behavior-y: contain; }
[hidden] { display: none !important; }

.btn { min-height: var(--tap); min-width: var(--tap); padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  text-decoration: none; user-select: none; touch-action: manipulation; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.icon { padding: 0; font-size: 20px; }
.btn.block { width: 100%; margin: 8px 0; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar { order: 0; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(4px + var(--safe-t)) 8px 4px; background: rgba(11,13,16,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); }
.brand { font-size: 18px; margin: 0; flex: 1; }
.badge { font-size: 12px; color: var(--muted); max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge.fallback { color: var(--warn); }
.net { font-size: 12px; font-weight: 700; color: #111; background: var(--warn); padding: 2px 8px; border-radius: 99px; }

main { order: 2; flex: 1; padding: 12px 12px calc(96px + var(--safe-b)); width: 100%; max-width: 1800px; margin: 0 auto; }

/* Mobile default: thumb-reachable bottom bar */
.actionbar { order: 3; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b));
  background: rgba(21,25,32,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
.actionbar .btn { padding: 0 8px; }

.empty { text-align: center; color: var(--muted); padding: 12vh 16px 0; }
.empty h2 { color: var(--text); margin: 12px 0 4px; }
.hint { font-size: 14px; }
.desktop-only { display: none; }

.item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.item-head { display: flex; align-items: center; gap: 10px; }
.item-title { flex: 1; min-width: 0; }
.item-title .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-title .meta { color: var(--muted); }
.pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--panel2); color: var(--muted); white-space: nowrap; }
.pill.done { background: rgba(43,182,115,.15); color: var(--ok); }
.pill.failed { background: rgba(239,68,68,.15); color: var(--bad); }
.pill.processing, .pill.uploading { background: rgba(61,139,255,.15); color: var(--accent); }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.bar .fill { height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }
.item.is-done .bar { display: none; }
.warn { color: var(--warn); font-size: 13px; margin: 6px 0; }
.err { color: var(--bad); font-size: 13px; margin: 6px 0; }
.retry { margin-top: 4px; }

/* Results: 1 col phone, 2–3 tablet, 4+ desktop */
.grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px; align-items: start; }
.tile { margin: 0; background: var(--panel2); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.thumb { background: repeating-conic-gradient(#20252e 0 25%, #191d24 0 50%) 0 0/20px 20px; display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: auto; display: block; }
.tile figcaption { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 12px 0; }
.tile .ratio { font-weight: 800; font-size: 17px; }
.tile .res { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tile-actions { display: flex; gap: 8px; padding: 10px 12px 12px; }
.tile-actions .save { flex: 1; }
body.can-share.touch .tile-actions .dl { display: none; }

.drop { position: fixed; inset: 0; z-index: 50; background: rgba(61,139,255,.18); border: 3px dashed var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800; }

.sheet { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(88vw, 380px); background: var(--panel);
  border-right: 1px solid var(--line); padding: calc(10px + var(--safe-t)) 14px calc(14px + var(--safe-b)); overflow-y: auto;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; }
#historyList { list-style: none; padding: 0; margin: 8px 0; }
#historyList li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; min-height: 64px; cursor: pointer; }
#historyList li.active { background: var(--panel2); }
#historyList img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--panel2); }
#historyList .h-meta { flex: 1; min-width: 0; }
#historyList small { color: var(--muted); display: block; }
#historyList .del { min-width: 44px; }

.toast { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--safe-b));
  background: #000; color: #fff; padding: 12px 16px; border-radius: 12px; max-width: 92vw; font-size: 15px;
  border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.5); }

.login { align-items: center; justify-content: center; }
.login-card { width: min(92vw, 360px); margin: auto; display: flex; flex-direction: column; gap: 10px; text-align: center; padding: 24px; }
.login-card h1 { margin: 0 0 8px; }
.login-card label { text-align: left; color: var(--muted); font-size: 14px; }
.login-card input { min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line); background: var(--panel2);
  color: var(--text); padding: 0 14px; font-size: 17px; /* ≥16px stops iOS zoom-on-focus */ }
.error { color: var(--bad); margin: 0; }

@media (min-width: 600px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  /* Same component, moved to a sticky top toolbar */
  .actionbar { order: 1; position: sticky; top: 49px; bottom: auto; display: flex; justify-content: center;
    border-top: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .actionbar .btn { padding: 0 20px; }
  main { padding-bottom: 24px; }
  .toast { bottom: 24px; }
  .desktop-only { display: block; }
}
@media (min-width: 1200px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1600px) { .grid { grid-template-columns: repeat(6, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- static/web build additions ---- */
.settings { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 4px; }
.settings h3 { margin: 10px 0 8px; font-size: 15px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg .btn[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.settings .hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.empty .hint { margin: 6px 0; }

/* One card at a time on phones: swipeable, snapping carousel with ratio chips */
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px -2px 0; padding: 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--muted); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
@media (max-width: 899px) {
  .grid { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; scrollbar-width: none;
    margin-left: -12px; margin-right: -12px; padding: 0 12px; scroll-padding: 0 12px; overscroll-behavior-x: contain; }
  .grid::-webkit-scrollbar { display: none; }
  .tile { flex: 0 0 100%; scroll-snap-align: center; scroll-snap-stop: always; }
  .thumb { height: clamp(260px, calc(100dvh - 400px), 600px); background: #0f1216; }
  .tile.alpha .thumb { background: repeating-conic-gradient(#20252e 0 25%, #191d24 0 50%) 0 0/20px 20px; }
  .thumb img { width: auto; height: auto; max-width: 100%; max-height: 100%; }
}
@media (min-width: 900px) { .chips { display: none !important; } }
