:root {
  --bg: #f6f5f2; --panel: #ffffff; --text: #1d1d1f; --muted: #6b6b70; --line: #dddad3;
  --accent: #2f6fdf; --accent-text: #fff; --mine: #1e9e5a; --danger: #c43d3d; --notice: #fff4d6;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17181b; --panel: #222327; --text: #ececee; --muted: #9b9ca3; --line: #36373d;
          --accent: #5b8ff0; --mine: #3cc27a; --danger: #e06666; --notice: #3b3423; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.2rem; margin: .4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .error { color: var(--danger); min-height: 1.2em; }
.grow { flex: 1; min-width: 180px; }

header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
nav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; }
nav a { padding: .35rem .7rem; border-radius: 999px; text-decoration: none; color: var(--text); }
nav a.active { background: var(--accent); color: var(--accent-text); }
.who { display: flex; gap: .8rem; align-items: center; font-size: .9rem; }
main { max-width: 1400px; margin: 0 auto; padding: 1rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.narrow { max-width: 380px; margin: 3rem auto; display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; gap: .5rem; align-items: center; }
.wrap { flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
input, select, button, .button { font: inherit; border-radius: 8px; border: 1px solid var(--line); padding: .45rem .7rem;
  background: var(--panel); color: var(--text); }
input:not([type=checkbox]) { min-width: 0; }
input.num { width: 5.5rem; }
button, .button { cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
button:hover:not(:disabled), .button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.on { background: var(--mine); border-color: var(--mine); color: #fff; }
button.big { padding: .7rem 1.2rem; font-size: 1.05rem; }
button.danger { color: var(--danger); }
button.link { border: none; background: none; color: var(--accent); padding: .2rem 0; text-align: start; }

.grid { display: grid; gap: .8rem; }
.grid.photos { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid.items { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile { position: relative; display: block; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4/3; background: var(--line); }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: .35rem .6rem; color: #fff; font-size: .85rem;
  background: linear-gradient(transparent, rgba(0,0,0,.7)); }

.item-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.item-card.mine { border-color: var(--mine); box-shadow: 0 0 0 2px var(--mine); }
.item-card > a { display: block; background: var(--line); }
.item-card img { width: 100%; aspect-ratio: 1; height: auto; object-fit: contain; display: block; background: #0001; }
.item-meta { padding: .5rem .6rem 0; flex: 1; }
.item-card .row { padding: .5rem .6rem .6rem; justify-content: space-between; }
.pick { flex-direction: row; align-items: center; gap: .4rem; color: var(--text); }
.badge { display: inline-block; min-width: 1.4em; padding: 0 .35em; margin-inline-start: .3em; border-radius: 999px; background: var(--accent); color: #fff; text-align: center; font-size: .8rem; }
.merge-bar { position: sticky; top: 3.5rem; z-index: 5; }

/* photo viewer */
.toolbar { margin-bottom: .8rem; gap: 1rem; }
.photo-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .photo-layout { grid-template-columns: 1fr; } }
/* the stage shrinks to the image's rendered box so the SVG overlay lines up exactly */
.stage-wrap { display: flex; justify-content: center; background: #0003; border-radius: var(--radius); }
.stage { position: relative; line-height: 0; overflow: hidden; user-select: none; -webkit-user-select: none; }
.stage img { display: block; max-width: 100%; max-height: 82vh; width: auto; height: auto; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
.overlay.drawing { cursor: crosshair; touch-action: none; }
.seg { fill: hsl(var(--h) 85% 55% / .14); stroke: hsl(var(--h) 90% 60%); cursor: pointer; transition: fill .12s; }
.seg:hover { fill: hsl(var(--h) 85% 55% / .32); }
.seg.mine { fill: rgba(30, 158, 90, .25); stroke: var(--mine); }
.seg.selected { fill: hsl(var(--h) 85% 55% / .38); stroke: #fff; }
.overlay.drawing .seg, .overlay.drawing .label { pointer-events: none; opacity: .6; }
.draft { fill: rgba(255, 210, 0, .25); stroke: #ffd200; stroke-dasharray: 8 6; pointer-events: none; }
.label { cursor: pointer; }
.label circle { fill: hsl(var(--h) 70% 38%); stroke: #fff; stroke-width: 2.5; }
.label.mine circle { fill: var(--mine); }
.label text { fill: #fff; font-weight: 700; font-family: system-ui, sans-serif; pointer-events: none; }
.side { position: sticky; top: 4.2rem; max-height: calc(100vh - 5rem); overflow: auto; }
.panel-thumb { width: 100%; max-height: 220px; object-fit: contain; background: #0001; border-radius: 8px; }
.item-name { font-weight: 400; margin-inline-start: .5rem; }
.side .row { margin: .5rem 0; flex-wrap: wrap; }
.side .row input { flex: 1; }
.seg-list { list-style: none; padding: 0; margin: .5rem 0; columns: 2; }
.mine-text { color: var(--mine); font-weight: 600; }
.mini img, .mini-img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; display: block; }
.mgr-tools { border-top: 1px dashed var(--line); margin-top: 1rem; padding-top: .3rem; }
.danger-zone { border-top: 1px dashed var(--line); margin-top: 1rem; padding-top: .8rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.notice { background: var(--notice); padding: .5rem .7rem; border-radius: 8px; }
.draw-tools button.on { color: #fff; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: start; padding: .45rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
tr.contested td { background: color-mix(in srgb, var(--danger) 9%, transparent); }
tr.inactive td { opacity: .55; }
.num-cell { text-align: center; font-variant-numeric: tabular-nums; }
.chip { display: inline-block; padding: .1rem .55rem; margin: .1rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: .85rem; }
.mine-row img { flex: none; }
.mine-row input { width: 100%; margin-top: .3rem; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%); background: #222; color: #fff;
  padding: .6rem 1rem; border-radius: 8px; transition: transform .2s; max-width: 90vw; z-index: 50; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

@media (max-width: 600px) {
  main { padding: .7rem; }
  header { gap: .4rem; }
  .who { width: 100%; justify-content: space-between; }
  .side { position: static; max-height: none; }
}

/* Google sign-in */
.center { text-align: center; align-items: center; }
.gbtn { min-height: 44px; display: flex; justify-content: center; }
