:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1c2330; --muted: #5d6778; --line: #dde1e8;
  --accent: #2458d6; --ok: #1d7a46; --bad: #b3261e; --warn: #8a5a00; --chip: #eef1f6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --panel: #1b2029; --ink: #e6e9ef; --muted: #9aa3b2; --line: #2c3340;
    --accent: #7ea2ff; --ok: #5cc98b; --bad: #ff8a80; --warn: #f0b64a; --chip: #252c38;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
/* the header is dark in both themes: the ScratchMobile mark is white and red */
.top { display: flex; gap: 1.2rem; align-items: center; padding: .55rem 16px; background: #12151b; border-bottom: 1px solid #2c3340; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: .5rem; text-decoration: none; color: #e6e9ef; font-weight: 600; }
.brand img { height: 24px; display: block; }
.top nav { display: flex; gap: .9rem; }
.top nav a { color: #e6e9ef; text-decoration: none; padding: .2rem .1rem; border-bottom: 2px solid transparent; }
.top nav a:hover { border-bottom-color: #b91c2c; }
.who { margin-left: auto; color: #9aa3b2; font-size: .9rem; }
.who a { color: #e6e9ef; }
/* sign-in: a dark page with the mark, before anything else is known about the person */
body.signin { background: #12151b; }
body.signin .top { display: none; }
.signin-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.signin-card { background: #1b2029; color: #e6e9ef; border: 1px solid #2c3340; border-radius: 14px; padding: 2.2rem 2.4rem; width: min(420px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); }
.signin-card img { height: 40px; margin-bottom: 1.2rem; }
.signin-card h1 { font-size: 1.5rem; margin: 0 0 .3rem; color: #fff; }
.signin-card p { color: #9aa3b2; margin: .3rem 0 1.4rem; }
.signin-card .err { color: #ff8a80; margin-bottom: 1rem; }
.signin-card button { width: 100%; padding: .7rem 1rem; font-size: 1rem; background: #b91c2c; border-color: #b91c2c; }
.signin-card button:hover { background: #d3273a; }
.signin-card small { display: block; margin-top: 1rem; color: #6b7482; }
main { max-width: 1200px; margin: 0 auto; padding: 1rem 16px 4rem; }
h1 { font-size: 1.35rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
.muted { color: var(--muted); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
input, select, button { font: inherit; }
input[type=text], input[type=number], input[type=search] { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
button { padding: .4rem .8rem; border-radius: 6px; border: 1px solid var(--line); background: var(--chip); color: var(--ink); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.bad { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .85rem; }
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .8rem; background: var(--chip); }
.badge.processed, .badge.approved { color: var(--ok); }
.badge.failed, .badge.rejected { color: var(--bad); }
.badge.processing, .badge.uploading, .badge.pending { color: var(--warn); }
.drop { border: 2px dashed var(--line); border-radius: 8px; padding: 1.4rem 1.6rem; text-align: center; color: var(--muted); }
.drop img { margin: .6rem .3rem 0; }
.drop.over { border-color: var(--accent); color: var(--accent); }
.flags { margin: .3rem 0; padding-left: 1rem; color: var(--warn); font-size: .82rem; }
.err { color: var(--bad); font-size: .85rem; }
.center { text-align: center; padding: 4rem 1rem; }
.scan { margin-bottom: 1rem; }
.card { display: grid; grid-template-columns: 180px 1fr; gap: 1rem; margin-top: .8rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.card img { width: 180px; border: 1px solid var(--line); border-radius: 4px; cursor: zoom-in; background: var(--chip); }
.facts { min-width: 0; font-size: .9rem; }
.facts h3 { font-size: .95rem; margin: .7rem 0 .3rem; }
table.kv { width: auto; }
table.kv th { font-weight: 600; color: var(--muted); padding: .15rem .8rem .15rem 0; border: 0; white-space: nowrap; }
table.kv td { padding: .15rem .8rem .15rem 0; border: 0; overflow-wrap: anywhere; }
.mono, pre { font-family: ui-monospace, monospace; font-size: .8rem; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--chip); padding: .5rem; border-radius: 4px; max-height: 20rem; overflow: auto; }
td.low { color: var(--warn); font-weight: 600; }
td.ok { color: var(--ok); }
details summary { cursor: pointer; color: var(--accent); margin-top: .4rem; }
.zoom { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 10; cursor: zoom-out; }
.zoom img { max-width: 95vw; max-height: 95vh; background: #fff; }
@media (max-width: 560px) { .card { grid-template-columns: 1fr; } .card img { width: 100%; max-width: 260px; } }
.idline { margin: .3rem 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; border: 1px solid var(--line); border-radius: 4px; cursor: zoom-in; background: var(--chip); }
.gallery figcaption { font-size: .82rem; margin-top: .3rem; overflow-wrap: anywhere; }
span.low { color: var(--warn); font-weight: 600; }
span.ok { color: var(--ok); }
.imgwrap { position: relative; display: block; line-height: 0; }
.imgwrap img { width: 100%; }
.card .imgwrap { width: 180px; }
.area { position: absolute; border: 2px solid #ff00ff; background: rgba(255, 0, 255, .08); box-sizing: border-box; pointer-events: none; }
.hide-areas .area { display: none; }
.areas-toggle { display: block; margin: .3rem 0 .8rem; }
@media (max-width: 560px) { .card .imgwrap { width: 100%; max-width: 260px; } }
details.analysis { margin-bottom: .6rem; }
details.analysis summary { color: var(--ink); }
details.analysis .card { border-top: 0; }

/* the game page: what the detection saw for each card, one strip per card */
.detection { margin-bottom: 1rem; }
.detection .strip { display: flex; gap: .6rem; overflow-x: auto; padding: .4rem 0; }
.detection .strip figure { margin: 0; flex: 0 0 auto; width: 150px; }
.detection .strip img { width: 100%; border: 1px solid var(--line); border-radius: 4px; cursor: zoom-in; background: var(--chip); }
.detection .strip figcaption { font-size: .78rem; text-align: center; margin-top: .2rem; }

/* game details */
.details input, .details textarea { font: inherit; }
.details .sug { font-size: .78rem; border: 1px solid var(--line); border-radius: 3px; padding: 0 .3rem; }
.prop { border: 1px solid var(--line); border-radius: 4px; margin: .4rem 0; padding: .4rem .6rem; }
.prop legend input { font-weight: 600; }
.prop .kv th { width: 12rem; }

#add-scan { margin: 1rem 0; }
.filebtn { cursor: pointer; color: var(--accent); text-decoration: underline; font-size: .9rem; }

/* pipeline progress: a line with a spinner, then the card as soon as it is cut out */
.progress-line { display: flex; align-items: center; gap: .5rem; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: #b91c2c; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
img.preview { height: 260px; margin-top: .5rem; border: 1px solid var(--line); border-radius: 4px; cursor: zoom-in; }

/* a fact's readings, one click to use one */
.choices { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.choice { font-size: .8rem; padding: .15rem .5rem; border-radius: 999px; }
.choice.best { border-color: #b91c2c; }
.bar { height: 8px; background: var(--chip); border-radius: 999px; overflow: hidden; margin: .4rem 0; max-width: 420px; }
.bar > div { height: 100%; background: #b91c2c; border-radius: 999px; transition: width .6s ease; }
td.actions { white-space: nowrap; }
td.actions button { font-size: .8rem; padding: .2rem .5rem; }

/* notices, bottom right */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #1b2029; color: #e6e9ef; border: 1px solid #2c3340; border-left: 4px solid #b91c2c; border-radius: 8px; padding: .6rem .8rem; box-shadow: 0 8px 24px rgba(0,0,0,.35); display: flex; gap: .5rem; align-items: center; }
.toast a { color: #ff8a80; }
.toast button { margin-left: auto; background: none; border: none; color: #9aa3b2; font-size: 1.1rem; padding: 0 .2rem; }

/* the games list: one table, a row per state, so every column lines up */
table.games tr.state th { background: var(--chip); color: var(--ink); font-size: .95rem; padding-top: .6rem; }
table.games td:first-child { width: 7rem; }
table.games td:nth-child(3) { width: 6rem; }

.crumbs { font-size: .9rem; color: var(--muted); margin: .2rem 0 .4rem; }
.crumbs span { margin: 0 .25rem; }
a.button { display: inline-block; padding: .4rem .8rem; border-radius: 6px; border: 1px solid var(--line); background: var(--chip); color: var(--ink); text-decoration: none; }
a.button.primary { background: #b91c2c; border-color: #b91c2c; color: #fff; }

/* the area editor */
.editor { position: relative; width: 360px; max-width: 100%; user-select: none; touch-action: none; line-height: 0; }
.editor img { width: 100%; border: 1px solid var(--line); border-radius: 4px; }
.ed-box { position: absolute; border: 2px solid #ff00ff; background: rgba(255, 0, 255, .1); box-sizing: border-box; cursor: move; }
.ed-box.sel { border-color: #00e5ff; background: rgba(0, 229, 255, .15); }
.ed-box span { position: absolute; left: 2px; top: 2px; font-size: 10px; line-height: 1; color: #fff; background: rgba(0,0,0,.55); padding: 1px 3px; border-radius: 2px; }
.ed-handle { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: #ff00ff; border-radius: 2px; cursor: nwse-resize; }
.ed-box.sel .ed-handle { background: #00e5ff; }
#ed-list tr.sel td { background: var(--chip); }
.table-foot { text-align: right; padding: .6rem .5rem 0; font-size: .9rem; }
.table-foot a.muted { color: var(--muted); }

/* the game's own pictures: the clean front and back scans */
.scans { flex: 0 0 300px; display: flex; flex-direction: column; gap: .8rem; }
.scans figure { margin: 0; width: 100%; }
.scans img { width: 100%; border: 1px solid var(--line); border-radius: 4px; cursor: zoom-in; background: var(--chip); }
.scans figure.missing div { height: 400px; display: flex; align-items: center; justify-content: center; border: 1px dashed var(--line); border-radius: 4px; }
.scans figcaption { text-align: center; font-size: .8rem; margin-top: .2rem; }
@media (max-width: 700px) { .scans { flex-basis: 100%; } }

/* the scan helper: a line of small text at the bottom of Add game */
.helper-foot { margin-top: 2rem; padding-top: .8rem; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.helper-foot a { color: var(--muted); text-decoration: underline; }
.helper-foot #pair-out { color: var(--ink); margin-top: .6rem; }
/* the game's scans and the detection strips: room around each card */
.scans figure { padding: .5rem; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-sizing: border-box; }
.detection .strip figure { padding: .35rem; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }

/* the Add game feed, as a terminal */
.term { margin-top: .8rem; background: #0d1117; color: #c9d1d9; border: 1px solid #30363d; border-radius: 8px; padding: .7rem .9rem;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; max-height: 260px; overflow-y: auto; }
.term div::before { content: "$ "; color: #6e7681; }
.term .t { color: #6e7681; margin-right: .4rem; }
.term .ok { color: #7ee787; }
.term .err, .term .err .err { color: #ff7b72; }
.term a { color: #79c0ff; }

/* room between cards */
.row:has(> .drop) { gap: 1.5rem !important; }
section.scan { margin-bottom: 1.2rem; }
section.scan .card { margin: 1rem 0; padding: 1rem; border: 1px solid var(--line); border-radius: 8px; }
.detection { margin-bottom: 1.2rem; }
.scans { gap: 1.2rem; }
.helper-foot ul.helpers { list-style: none; padding: 0; margin: .3rem 0 .5rem; }
.helper-foot ul.helpers li { padding: .15rem 0; }
.helper-foot ul.helpers span { color: var(--muted); margin-right: .2rem; }
.helper-foot ul.helpers span.ok { color: var(--ok); }

.rotate { display: inline-flex; gap: .2rem; margin-left: .3rem; flex-wrap: wrap; }
.rotate button { font-size: .75rem; padding: .1rem .4rem; }
