:root {
  --bg: #e6e6e8;
  --backdrop-dim: rgba(240,240,242,.55);
  --sheet: #f4f4f4;
  --ink: #141414;
  --muted: #8a8a90;
  --btn: #ececee;
  --pill: linear-gradient(#fff, #f2f2f2);
  --pill-line: rgba(255,255,255,.95);
  --pill-shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.07);
  --line: #e4e4e8;
  --polaroid: #fff;
  --shadow: 0 1px 3px rgba(0,0,0,.18), 0 4px 10px rgba(0,0,0,.08);
  --red: #d92d20;
  --red-bg: #fde8e6;
  --amber: #3b3b3f;
  --amber-bg: transparent;
  --gray-bg: #eeeef1;
  --dash: #c5c5cb;
  --hero-bg: #f4f4f4;
  --hero-ink: #141414;
  --hero-muted: #7a7a7a;
  --hero-line: rgba(20,20,20,.13);
  --hero-chip: rgba(255,255,255,.65);
  --hero-btn: #fff;
  --hero-btn-ink: #141414;
  --frame: #fff;
  --sheet-bg: linear-gradient(#fafafa, #efefef);
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --hero-bg: #1e1c1a;
    --hero-ink: #f4f1ea;
    --hero-muted: #a29e95;
    --hero-line: rgba(255,255,255,.16);
    --hero-chip: rgba(255,255,255,.06);
    --hero-btn: #f4f1ea;
    --hero-btn-ink: #17171a;
    --frame: #f1eee8;
    --bg: #1b1b1e;
    --backdrop-dim: rgba(0,0,0,.45);
    --sheet: #2a2a2e;
    --ink: #f4f4f6;
    --muted: #9a9aa2;
    --btn: #3b3b40;
    --line: #3a3a40;
    --polaroid: #e9e9ec;
    --red: #ff7b72;
    --red-bg: #4a2220;
    --amber: #d4d4d8;
    --amber-bg: transparent;
    --pill: linear-gradient(#4a4a4f, #3b3b40);
    --pill-line: rgba(255,255,255,.12);
    --pill-shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 12px rgba(0,0,0,.3);
    --sheet-bg: linear-gradient(#303034, #26262a);
    --gray-bg: #38383d;
    --dash: #55555c;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* backdrop of polaroids */
.backdrop {
  position: fixed; inset: 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px 8px; padding: 12px 12px 0; align-content: start;
  overflow: hidden;
}
@media (min-width: 640px) { .backdrop { grid-template-columns: repeat(5, 1fr); } }
@media (min-width: 1000px) { .backdrop { grid-template-columns: repeat(8, 1fr); } }
.backdrop::after { content: ""; position: fixed; inset: 0; background: var(--backdrop-dim); pointer-events: none; }
.pol {
  background: var(--polaroid); padding: 4px; border-radius: 2px;
  box-shadow: var(--shadow); aspect-ratio: 3 / 4;
  transform: rotate(var(--r, 0deg));
}
.pol img, .pol i { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--gray-bg); }
.pol i { opacity: .6; }

/* sheet */
.sheet {
  position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
  margin: 0 auto; max-width: 440px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top));
  background: var(--sheet-bg); border-radius: 36px;
  padding: 18px 20px 22px; display: flex; flex-direction: column;
  box-shadow: 0 40px 90px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.06), inset 0 1px 0 rgba(255,255,255,.9);
  animation: rise .6s cubic-bezier(.2,1.25,.4,1);
}
@keyframes rise { from { transform: translateY(56px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet::after { content: ""; display: block; flex: none; width: 36%; height: 5px; margin: 14px auto -8px; border-radius: 3px; background: var(--ink); opacity: .75; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; }
.bar h1 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; flex: 1; }
.rbtn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--pill-line); background: var(--pill); box-shadow: var(--pill-shadow);
  color: var(--ink); display: grid; place-items: center; flex: none; padding: 0;
}
.rbtn:active { transform: scale(.94); }
body.is-start #back, body.is-start #close { visibility: hidden; }

.view { flex: 0 1 auto; min-height: 0; }

.status { display: flex; align-items: flex-start; gap: 10px; margin: 18px 4px 16px; min-height: 44px; }
.sdot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 7px; background: var(--red); }
.is-working .sdot { animation: pulse 1.4s ease-in-out infinite; }
.is-done .sdot { background: var(--ink); animation: none; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
.stt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stt b { font-size: 19px; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stt span { font-size: 14px; color: var(--muted); }
.spin {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; opacity: .7;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stacks { display: flex; justify-content: space-around; gap: 8px; }
.col { flex: 1; text-align: center; min-width: 0; }
.stack { position: relative; width: 104px; height: 124px; margin: 0 auto 6px; }
.card {
  position: absolute; left: 50%; top: 50%; width: 80px; height: 96px;
  margin: -48px 0 0 -40px; background: var(--polaroid); padding: 4px; border-radius: 3px;
  box-shadow: var(--shadow);
}
.card img { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--gray-bg); }
.card.p0 { transform: rotate(-3deg); z-index: 3; }
.card.p1 { transform: rotate(5deg) translate(3px,-1px); z-index: 2; }
.card.p2 { transform: rotate(-9deg) translate(-4px,1px); z-index: 1; }
.card.dash { background: transparent; box-shadow: none; border: 1.5px dashed var(--dash); }
.lab { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.val { font-size: 14px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.fly {
  position: fixed; z-index: 20; margin: 0; pointer-events: none;
  background: var(--polaroid); padding: 4px; border-radius: 3px; object-fit: cover;
  box-shadow: 0 10px 24px rgba(0,0,0,.28); will-change: transform;
}

.removed { text-align: center; margin: 10px 0 14px; }
.big { font-size: 26px; font-weight: 600; margin-top: 1px; font-variant-numeric: tabular-nums; transition: color .4s; }
.is-done .big { color: var(--ink); }

.pill {
  position: relative; width: 100%; min-height: 56px; border: 1px solid var(--pill-line); border-radius: 28px;
  background: var(--pill); box-shadow: var(--pill-shadow); color: var(--ink); font-size: 17px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 52px;
  transition: opacity .3s, transform .15s cubic-bezier(.3,1.5,.5,1), color .3s;
}
.pill:active:not(:disabled) { transform: scale(.975); }
.pill:disabled { box-shadow: none; background: var(--btn); color: var(--muted); border-color: transparent; cursor: default; }
.pill .check path { stroke: var(--sheet); }
.pill .check { position: absolute; right: 16px; top: 50%; margin-top: -11px; display: none; }
.pill .spin { display: none; }
.is-working #dl .spin { display: inline-block; }
.is-done #dl .check { display: block; }
.link {
  display: block; margin: 8px auto 0; min-height: 44px; padding: 0 18px;
  background: none; border: 0; color: var(--ink); font-size: 15px; font-weight: 500;
}

.note { text-align: center; color: var(--muted); font-size: 12px; margin: 6px 0 0; flex: none; }

.details { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 8px -8px 0; padding: 0 8px; overscroll-behavior: contain; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; flex-wrap: wrap; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .th { width: 64px; height: 76px; flex: none; background: var(--polaroid); padding: 3px; border-radius: 3px; box-shadow: var(--shadow); }
.item .th img { display: block; width: 100%; height: 100%; object-fit: cover; background: var(--gray-bg); }
.item .body { flex: 1; min-width: 0; }
.item h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 14px; margin: 0 6px 6px 0; max-width: 100%; overflow-wrap: anywhere; }
.badge.high { background: var(--red-bg); color: var(--red); }
.badge.medium { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--muted); }
.badge.low { background: var(--gray-bg); color: var(--muted); }
.fields { margin: 2px 0 6px; }
.meta { font-size: 12px; color: var(--muted); line-height: 1.5; }
.none { font-size: 13px; color: var(--muted); margin: 0 0 4px; }
.err { font-size: 13px; color: var(--red); margin: 0; }
.dlone {
  margin-top: 8px; min-height: 40px; padding: 0 16px; border: 1px solid var(--pill-line); border-radius: 20px;
  background: var(--pill); box-shadow: var(--pill-shadow); font-size: 14px; font-weight: 600; color: var(--ink);
}

.rep { flex: 0 0 100%; min-width: 0; margin-top: 4px; }
.rebuilt { margin: 0 0 8px; padding: 8px 12px; border-radius: 12px; background: var(--gray-bg); color: var(--ink); font-size: 13px; line-height: 1.4; }
.sec { background: var(--btn); border-radius: 14px; margin-top: 8px; overflow: hidden; }
.sec > summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; padding: 0 14px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; border-radius: 14px; }
.chev { width: 8px; height: 8px; flex: none; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .2s; margin-right: 4px; }
.sec[open] > summary .chev { transform: rotate(45deg); }
.gh { display: flex; align-items: center; gap: 8px; padding: 10px 14px 4px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.gt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.gc { font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.high { background: var(--red); }
.dot.medium { background: var(--ink); }
.rows { margin: 0 8px 8px; background: var(--sheet); border-radius: 10px; overflow: hidden; }
.kv { display: flex; gap: 10px; padding: 8px 10px; border-top: 1px solid var(--line); font-size: 13px; line-height: 1.35; }
.kv:first-child { border-top: 0; }
.kv .k { flex: 0 0 40%; min-width: 0; color: var(--muted); overflow-wrap: break-word; }
.kv .v { flex: 1; min-width: 0; overflow-wrap: anywhere; word-break: break-word; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; }
.kv.stack { flex-direction: column; gap: 2px; }
.kv.stack .k { flex: none; color: var(--ink); font-weight: 500; }
.kv.stack .v { font-family: var(--font); font-size: 12px; color: var(--muted); }
.edits { margin: 0 8px 8px; padding: 8px 10px 8px 28px; background: var(--sheet); border-radius: 10px; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.edits li { margin: 3px 0; }
@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }

.dropmsg {
  position: fixed; inset: 0; z-index: 30; display: none; align-items: center; justify-content: center;
  background: rgba(20,20,20,.88); color: #fff; font-size: 22px; font-weight: 600; text-align: center; pointer-events: none;
}
body.dragging .dropmsg { display: flex; }

@media (max-width: 359px) {
  .sheet { padding: 12px 14px; border-radius: 32px; }
  .stack { width: 92px; }
  .big { font-size: 22px; }
}
@media (max-height: 560px) { .stack { height: 100px; } }
@media (prefers-reduced-motion: reduce) {
  .sheet { animation: none; }
  .spin { animation-duration: 2.4s; }
  .pill, .big { transition: none; }
}

/* ---------- start-state hero ---------- */
body.is-start { background: var(--hero-bg); }
body.is-start .sheet, body.is-start .backdrop { display: none; }
.hero {
  position: fixed; inset: 0; z-index: 5; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--hero-bg); color: var(--hero-ink);
  padding: 0 20px;
  transition: opacity .45s ease, visibility 0s linear .45s;
}
body:not(.is-start) .hero { opacity: 0; visibility: hidden; pointer-events: none; }
.cards { position: absolute; inset: 0; pointer-events: none; }
.pc { position: absolute; transition: transform .5s ease, opacity .4s ease; }
body:not(.is-start) .pc { opacity: 0; transform: scale(.92); }
.pi {
  position: relative; width: 100%; height: 100%; background: var(--frame);
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 10px 26px rgba(0,0,0,.09);
  animation: drift var(--dur, 10s) ease-in-out var(--dl, 0s) infinite alternate;
}
.pi > svg { display: block; width: 100%; height: 100%; }
@keyframes drift { from { transform: translateY(0); } to { transform: translateY(4px); } }
.pin {
  position: absolute; z-index: 2; right: -7px; bottom: -7px; width: 24px; height: 24px; border-radius: 50%;
  background: #e5372b; box-shadow: 0 3px 8px rgba(229,55,43,.45); display: grid; place-items: center;
}
.pin svg { display: block; }

.center {
  position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; text-align: center;
  width: 100%; max-width: 800px; padding: 8px 0;
}
.mark { width: 44px; height: 44px; color: var(--hero-ink); }
.mark svg { display: block; }
.headline {
  margin: 22px 0 0; font-family: var(--serif); font-weight: 300; font-style: normal;
  font-size: clamp(28px, 4.4vw, 64px); line-height: 1.15; letter-spacing: -.015em;
  text-wrap: balance; color: var(--hero-ink);
}
.sub {
  margin: 20px 0 0; max-width: 34em; font-size: clamp(16px, 1.5vw, 20px); line-height: 1.45;
  color: var(--hero-muted); text-wrap: balance;
}
.cta {
  margin-top: 30px; height: 56px; padding: 0 30px 0 24px; border: 1px solid rgba(0,0,0,.06); border-radius: 99px;
  background: var(--hero-btn); color: var(--hero-btn-ink); font-size: 17px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.09);
  transition: transform .25s cubic-bezier(.3,1.6,.5,1), box-shadow .2s;
}
.cta:hover:not(:disabled) { transform: scale(1.03); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 10px 26px rgba(0,0,0,.13); }
.cta:active:not(:disabled) { transform: scale(.97); }
.cta:disabled { opacity: .5; cursor: default; }
.cta-ico { flex: none; }
.h-hint { display: none; margin: 12px 0 0; font-size: 13px; color: var(--hero-muted); }
@media (hover: hover) and (pointer: fine) { .h-hint { display: block; } }
.trust { margin: 14px 0 0; font-size: 13px; color: var(--hero-muted); }
@media (max-width: 360px) { .trust { font-size: 12px; } }
@media (max-width: 640px) { .center { padding-bottom: 0; } .mark { width: 40px; height: 40px; } .headline { margin-top: 16px; } .sub { margin-top: 14px; }  }
@media (max-height: 640px) { .headline { margin-top: 14px; } .sub { margin-top: 12px; } .cta { margin-top: 20px; height: 52px; } .trust { margin-top: 10px; } }
@media (prefers-reduced-motion: reduce) {
  .pi { animation: none; }
  .pc, .hero, .cta { transition: none; }
}
