:root {
  --bg: #111214; --panel: #1b1d21; --panel-2: #24272d; --line: #2f333a;
  --text: #ecedef; --muted: #8b919c;
  --keep: #2ecc71; --discard: #ff5c5c; --accent: #4f8cff; --warn: #f5b942;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, system-ui, sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
body { position: fixed; inset: 0; overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { margin: 0 0 .4em; font-weight: 600; }

/* ---------- buttons ---------- */
button { font: inherit; color: inherit; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; cursor: pointer; min-height: 44px; }
button:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.success { background: var(--keep); border-color: var(--keep); color: #052; font-weight: 700; }
.btn.danger  { background: var(--discard); border-color: var(--discard); color: #fff; font-weight: 700; }
.btn.ghost   { background: transparent; }
.btn.big     { flex: 1; font-size: 18px; min-height: 56px; }
.btn.full    { width: 100%; margin-top: 8px; }
.icon-btn { width: 44px; padding: 0; font-size: 20px; border-radius: 50%; }
.chip { border-radius: 999px; padding: 6px 14px; min-height: 36px; font-size: 14px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.row { display: flex; gap: 10px; }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
#login { align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: var(--panel); border-radius: 20px; padding: 28px; text-align: center; }
.pass-row { display: flex; gap: 8px; margin-top: 14px; }
.pass-row input { flex: 1; font: inherit; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); -webkit-user-select: text; user-select: text; }
.pass-row input.bad { border-color: var(--discard); }
.error { color: var(--discard); margin: 8px 0 0; }
.user-buttons { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.user-buttons button { font-size: 18px; min-height: 54px; }
#login-other { display: flex; gap: 8px; margin-top: 10px; }
#login-other input { flex: 1; font: inherit; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); -webkit-user-select: text; user-select: text; }

.topbar { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 12px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.meter { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.meter-bar { flex: 1; height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.meter.done .meter-fill { background: var(--keep); }
.meter.over .meter-fill { background: var(--warn); }
.meter.over #kept-count { color: var(--warn); font-weight: 700; }
.meter.done #kept-count { color: var(--keep); font-weight: 700; }
.pool-bar { position: relative; display: flex; height: 100%; }
.pool-bar i { display: block; height: 100%; transition: width .25s; }
.pool-bar .k { background: var(--keep); } .pool-bar .p { background: #555b66; } .pool-bar .d { background: rgba(255,92,92,.45); }
.pool-bar .tick { position: absolute; top: -3px; bottom: -3px; width: 2px; background: #fff; box-shadow: 0 0 0 1px #000; }
.viewbar .joint-status { color: var(--warn); }
.viewbar .joint-status.ok { color: var(--keep); }
#kept-count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.viewbar { display: flex; align-items: center; gap: 6px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.viewbar .tab { min-height: 40px; }
.viewbar span { margin-left: auto; }
.viewbar .shuffle { margin-left: 8px; min-height: 30px; padding: 4px 10px; font-size: 13px; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- swipe deck ---------- */
.deck { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 10px; }
.card { position: relative; max-width: 100%; max-height: 100%; border-radius: 14px; overflow: hidden;
  background: #000; box-shadow: 0 12px 40px rgba(0,0,0,.6); touch-action: none; will-change: transform;
  display: flex; align-items: center; justify-content: center; }
.card.snap { transition: transform .25s ease, opacity .25s ease; }
.card.fly  { transition: transform .32s cubic-bezier(.2,.7,.3,1), opacity .32s; }
.card img { max-width: calc(100vw - 20px); max-height: 100%; width: auto; height: auto; display: block; pointer-events: none; }
.stamp { position: absolute; left: 50%; transform: translateX(-50%) rotate(-8deg); padding: 6px 18px; border: 4px solid;
  border-radius: 10px; font-size: 34px; font-weight: 900; letter-spacing: 3px; opacity: 0; pointer-events: none; }
.stamp.keep    { top: 22px;    color: var(--keep);    border-color: var(--keep); }
.stamp.discard { bottom: 22px; color: var(--discard); border-color: var(--discard); }
.deck-empty { text-align: center; padding: 30px; }
.swipe-controls { display: flex; gap: 10px; padding: 8px 12px; }
.swipe-controls .ghost { min-width: 56px; }
.caption { margin: 0; text-align: center; padding: 0 12px calc(8px + var(--safe-b)); }

/* ---------- grid ---------- */
.filters { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; flex-shrink: 0; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
#grid-summary { margin: 0 12px 6px; }
.grid { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; gap: 4px; padding: 0 4px calc(20px + var(--safe-b));
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); grid-auto-rows: 180px; align-content: start; }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); grid-auto-rows: 220px; } }
.tile { position: relative; background: #000; border-radius: 6px; overflow: hidden; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.discard img { opacity: .35; }
.tile .badge { position: absolute; top: 6px; left: 6px; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; color: #fff; background: rgba(0,0,0,.6); }
.tile.keep .badge    { background: var(--keep); color: #052; }
.tile.discard .badge { background: var(--discard); }
.tile .corner { position: absolute; top: 6px; right: 6px; display: flex; align-items: center; gap: 4px; }
.tile .seq { font-size: 11px; color: #fff; text-shadow: 0 1px 3px #000; }
.tile .others { display: flex; gap: 3px; }
.tile .thumb { position: absolute; bottom: 6px; width: 42px; height: 42px; min-height: 0; padding: 0; border-radius: 50%;
  font-size: 20px; line-height: 1; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(4px); }
.tile .thumb.down { left: 6px; } .tile .thumb.up { right: 6px; }
.tile .thumb.up.on { background: var(--keep); border-color: var(--keep); }
.tile .thumb.down.on { background: var(--discard); border-color: var(--discard); }
.tile .thumb:active { transform: scale(.9); }
.tile .others span { width: 20px; height: 20px; border-radius: 50%; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; background: var(--keep); color: #052; border: 1px solid #052; }
.tile .others span.d { background: var(--discard); color: #fff; border-color: #400; }
.tile .others span.j { background: var(--accent); color: #fff; border-color: #124; }
.tile .others span.j.d { background: #7a3a7a; }
.grid-empty { grid-column: 1 / -1; text-align: center; padding: 40px 20px; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column; z-index: 20; }
.detail-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(6px + var(--safe-t)) 10px 6px; }
.detail-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; touch-action: none; overflow: hidden; }
.detail-stage img { max-width: 100%; max-height: 100%; will-change: transform; pointer-events: none; }
.detail-stage.snap img { transition: transform .25s, opacity .25s; }
.detail-stage.zoomed { overflow: auto; align-items: flex-start; justify-content: flex-start; touch-action: pan-x pan-y; }
.detail-stage.zoomed img { max-width: none; max-height: none; pointer-events: auto; }
.nav-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; border-radius: 10px;
  background: rgba(0,0,0,.45); font-size: 32px; padding: 0; border: none; }
.nav-arrow.left { left: 6px; } .nav-arrow.right { right: 6px; }
#detail .swipe-controls { padding-bottom: calc(10px + var(--safe-b)); }

.sheet { position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-body { width: min(560px, 100%); max-height: 85%; overflow-y: auto; background: var(--panel); border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#info-table { width: 100%; border-collapse: collapse; font-size: 14px; -webkit-user-select: text; user-select: text; }
#info-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-all; }
#info-table td:first-child { color: var(--muted); white-space: nowrap; width: 34%; word-break: normal; }
#info-table a { color: var(--accent); }

.toast { position: absolute; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 40;
  background: #2a2d33; border: 1px solid var(--line); padding: 12px 16px; border-radius: 12px; max-width: 90%; font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); -webkit-user-select: text; user-select: text; }
.toast a { color: var(--accent); }
