:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6862;
  --line: #e4e1da;
  --accent: #3d5afe;
  --accent-ink: #ffffff;
  --accent-soft: #e6eaff;
  --good: #1b8a5a;
  --bad: #c62828;
  --gold: #d4a017;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1f1e1c;
    --text: #f1efe9;
    --muted: #a19d94;
    --line: #34322e;
    --accent: #7c8cff;
    --accent-ink: #0d0d1a;
    --accent-soft: #262b4d;
    --good: #4cc38a;
    --bad: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.top h1 { font-size: 1.15rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: .78rem; font-weight: 600; padding: 4px 10px; border-radius: 99px; background: var(--line); color: var(--muted); white-space: nowrap; }
.pill.open { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.closed { background: var(--accent-soft); color: var(--accent); }

/* forms */
.who { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 18px 0 6px; }
@media (min-width: 640px) { .who { grid-template-columns: 2fr 1fr; } .who.nocode { grid-template-columns: 1fr; max-width: 420px; } }
label.field { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; }
input[type=text], input[type=number], input[type=password] {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px; /* >=16px stops iOS zoom */ }
input:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; }
.hint { color: var(--muted); margin: 12px 0; }
.hint strong { color: var(--text); }

/* buttons */
.btn { border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 650; cursor: pointer;
  background: var(--line); color: var(--text); min-height: 44px; transition: transform .08s, opacity .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.good { background: var(--good); color: #fff; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: .85rem; }

/* image grid */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 16px; } }
.card { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface);
  box-shadow: var(--shadow); border: 3px solid transparent; cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent; transition: border-color .15s, transform .12s; }
.card:active { transform: scale(.985); }
.card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--line); }
.card .meta { display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-height: 42px; }
.card .tag { font-weight: 800; font-size: .95rem; width: 28px; height: 28px; border-radius: 8px; display: grid;
  place-items: center; background: var(--line); flex: none; }
.card .label { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.card .tick { position: absolute; top: 8px; left: 8px; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.85); border: 2px solid rgba(0,0,0,.15); display: grid; place-items: center;
  font-weight: 900; color: transparent; transition: all .15s; }
.card .zoom { position: absolute; top: 8px; right: 8px; width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: rgba(0,0,0,.45); color: #fff; font-size: 18px; cursor: zoom-in; display: grid; place-items: center; }
.card.sel { border-color: var(--accent); }
.card.sel .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.card.sel .tag { background: var(--accent); color: var(--accent-ink); }
.card.dim { opacity: .55; }
.card .live { margin-left: auto; font-size: .8rem; font-weight: 700; color: var(--muted); }
.card.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-5px); } 40%,80% { transform: translateX(5px); } }

/* bottom bar */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 20px rgba(0,0,0,.08); }
.bar .wrap { display: flex; align-items: center; gap: 12px; padding: 0; }
.bar .count { flex: 1; font-size: .92rem; color: var(--muted); }
.bar .count strong { color: var(--text); }
.dots { display: inline-flex; gap: 4px; margin-right: 6px; vertical-align: middle; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); display: block; }
.dots i.on { background: var(--accent); }
.bar .btn { min-width: 150px; }

/* panels / messages */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin: 18px 0; }
.center { text-align: center; padding: 48px 16px; }
.center .big { font-size: 3rem; margin-bottom: 8px; }
.saved { display: flex; gap: 10px; align-items: center; background: color-mix(in srgb, var(--good) 14%, transparent);
  color: var(--good); border-radius: 10px; padding: 10px 14px; margin-top: 12px; font-weight: 600; font-size: .92rem; }

/* results */
.winner { text-align: center; margin: 22px 0; }
.winner .crown { font-size: 2.6rem; animation: pop .6s cubic-bezier(.2,1.6,.4,1) both; }
.winner h2 { margin: 4px 0 14px; font-size: 1.5rem; }
.winner .wimgs { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); max-width: 820px; margin: 0 auto; }
.winner figure { margin: 0; border-radius: var(--radius); overflow: hidden; border: 4px solid var(--gold);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--gold) 20%, transparent), var(--shadow); background: var(--surface);
  animation: pop .7s .1s cubic-bezier(.2,1.4,.4,1) both; }
.winner figure img { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: #000; }
.winner figcaption { padding: 10px; font-weight: 700; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.rank { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.rank li { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; }
.rank img { width: 56px; height: 42px; object-fit: cover; border-radius: 8px; }
.rank .row1 { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; margin-bottom: 4px; }
.rank .track { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.rank .fill { height: 100%; width: 0; border-radius: 99px; background: var(--accent); transition: width .8s cubic-bezier(.2,.8,.2,1); }
.rank li.win .fill { background: var(--gold); }
.rank .n { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.92); display: flex; flex-direction: column; touch-action: pan-y; }
.lightbox .lbimg { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .lbbar { display: flex; gap: 10px; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); color: #fff; }
.lightbox .lbbar .t { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox .nav { background: rgba(255,255,255,.14); color: #fff; }
.lightbox .x { position: absolute; top: 12px; right: 12px; z-index: 2; width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff; border: 0; font-size: 22px; cursor: pointer; }

/* toast + offline */
.toast { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 30; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--bad); color: #fff; }
.offline { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 30; background: var(--bad); color: #fff;
  padding: 6px 14px; border-radius: 99px; font-size: .85rem; font-weight: 700; }

/* admin */
.admin-grid { display: grid; gap: 18px; grid-template-columns: 1fr; margin: 18px 0; }
@media (min-width: 900px) { .admin-grid { grid-template-columns: 1fr 1fr; } .admin-grid .wide { grid-column: 1 / -1; } }
.admin-grid .panel { margin: 0; }
.panel h2 { font-size: 1rem; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.panel h2 .sp { flex: 1; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stat { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.muted { color: var(--muted); font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--line); border-radius: 99px; padding: 4px 6px 4px 12px; font-size: .88rem; }
.chip button { border: 0; background: transparent; cursor: pointer; color: var(--muted); width: 24px; height: 24px; border-radius: 50%; }
.chip button:hover { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.thumbs { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.thumb { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.thumb img { display: block; width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.thumb .tb { padding: 8px; display: grid; gap: 6px; }
.thumb input { padding: 8px 10px; }
.thumb.out { opacity: .4; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); margin-bottom: 12px; cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.share { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.share .url { flex: 1; min-width: 200px; display: grid; gap: 8px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.check input { width: 20px; height: 20px; }
.hist li { margin-bottom: 4px; }

/* present mode */
.present { position: fixed; inset: 0; z-index: 15; background: var(--bg); overflow: auto; padding: 24px; }
.present .pclose { position: fixed; top: 14px; right: 14px; }
.present h1 { text-align: center; font-size: clamp(1.6rem, 4vw, 3rem); margin: 8px 0 20px; }
.present .pjoin { display: flex; gap: 32px; align-items: center; justify-content: center; flex-wrap: wrap; }
.present .purl { font-size: clamp(2rem, 6vw, 4.5rem); margin: 6px 0; font-weight: 800; word-break: break-all; }
.present .pcount { font-size: clamp(3rem, 9vw, 6rem); font-weight: 900; line-height: 1; margin-top: 18px; }
.present .chips { justify-content: center; margin-top: 16px; }
.present .chip { padding: 6px 14px; font-size: 1.05rem; animation: pop .4s both; }
.present .pactions { display: flex; justify-content: center; gap: 12px; margin-top: 28px; }
.row.gap-lg { gap: 18px; }
.row .sp { flex: 1; }
.stack { display: grid; gap: 12px; }
.tcenter { text-align: center; }
.row input[type=text], .row input[type=password] { flex: 1; min-width: 0; width: auto; }
