:root {
  --paper: #f4f2ee;
  --ink: #111;
  --mute: #6d6a64;
  --rule: #111;
  --soft: #e4e1da;
  --up: #1f6b45;
  --down: #b0362a;
  --shade: rgba(12, 12, 12, .96);
  --sans: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121211; --ink: #ecebe7; --mute: #8f8c85; --rule: #ecebe7; --soft: #2a2927;
    --up: #5fbf8a; --down: #e2705f; --shade: rgba(0, 0, 0, .94);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.35 var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; border-radius: 0; }
.solid { background: var(--ink); color: var(--paper); border: 2px solid var(--ink); padding: 6px 14px; font-weight: 700; }
.ghost { background: none; border: 2px solid var(--ink); padding: 6px 14px; font-weight: 700; }
.solid:hover, .ghost:hover { opacity: .8; }
input { font: inherit; color: inherit; background: var(--paper); border: 2px solid var(--ink); border-radius: 0; padding: 10px 12px; width: 100%; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--up); outline-offset: 2px; }

.mark { font-weight: 700; letter-spacing: -.02em; color: inherit; text-decoration: none; white-space: nowrap; }
.mark span { color: var(--mute); }
.mark em { font-style: normal; font-weight: 400; color: var(--mute); margin-left: .4em; }

/* ---------- gate ---------- */
body.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
#gate { width: min(360px, 100%); border-top: 6px solid var(--rule); padding-top: 14px; }
#gate h1 { font-size: 44px; letter-spacing: -.04em; margin: 4px 0 28px; line-height: 1; }
#gate label { display: block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
#gate button { margin-top: 12px; width: 100%; background: var(--ink); color: var(--paper); border: 0; padding: 12px; font-weight: 700; }
#err, .err { color: var(--down); min-height: 1.3em; margin: 10px 0 0; }

/* ---------- top bar ---------- */
.bar { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 4px solid var(--rule);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 10px 16px; }
.bar nav { display: flex; }
.bar nav a { color: inherit; text-decoration: none; font-weight: 700; padding: 6px 14px; border: 2px solid transparent; }
.bar nav a.on { background: var(--ink); color: var(--paper); }
.bar .actions { display: flex; gap: 8px; justify-content: flex-end; min-width: 0; }
#who { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 720px) {
  .bar { grid-template-columns: 1fr auto; padding: 8px 12px; }
  .bar nav { grid-column: 1 / -1; grid-row: 2; justify-content: stretch; }
  .bar nav a { flex: 1; text-align: center; padding: 6px 4px; }
  .mark em { display: none; }
  .solid, .ghost { padding: 5px 10px; }
}

main { padding: 16px; }
.empty { max-width: 46ch; margin: 12vh auto; text-align: center; color: var(--mute); }
.empty h2 { color: var(--ink); font-size: 28px; letter-spacing: -.03em; margin: 0 0 8px; }
.empty button { margin-top: 16px; }

/* ---------- board (masonry; aspect ratios known up front, so nothing shifts) ---------- */
.masonry { display: flex; gap: 10px; align-items: flex-start; }
.masonry .col { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tile { position: relative; display: block; padding: 0; border: 0; background: var(--soft); width: 100%; overflow: hidden; }
.tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile .badge { position: absolute; left: 0; bottom: 0; right: 0; display: flex; justify-content: space-between; gap: 8px;
  padding: 18px 8px 6px; font-size: 12px; font-weight: 700; color: #fff; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,.6)); opacity: 0; transition: opacity .15s; }
.tile:hover .badge, .tile:focus-visible .badge { opacity: 1; }
.tile .mine-vote { position: absolute; top: 6px; right: 6px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; }
.tile .mine-vote.up { background: var(--up); }
.tile .mine-vote.down { background: var(--down); }
.board-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 12px; font-size: 13px; color: var(--mute); }
.board-head b { color: var(--ink); }

/* ---------- swipe ---------- */
.swipe { display: grid; grid-template-rows: auto 1fr auto; height: calc(100dvh - 90px); max-width: 640px; margin: 0 auto; gap: 12px; }
@media (max-width: 720px) { .swipe { height: calc(100dvh - 110px); } }
.swipe .progress { display: flex; justify-content: space-between; font-size: 13px; color: var(--mute); }
.swipe .progress b { color: var(--ink); }
.deck { position: relative; min-height: 0; }
.card { position: absolute; inset: 0; display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.card.dragging { cursor: grabbing; }
.card .frame { position: relative; max-width: 100%; max-height: 100%; background: var(--soft); box-shadow: 0 10px 40px rgba(0,0,0,.18); }
.card img { display: block; max-width: 100%; max-height: calc(100dvh - 230px); pointer-events: none; -webkit-user-drag: none; }
.card.under { transform: scale(.96); opacity: .5; pointer-events: none; }
.stamp { position: absolute; top: 18px; padding: 4px 12px; border: 4px solid; font-weight: 800; font-size: 28px; letter-spacing: .04em; background: rgba(255,255,255,.85); opacity: 0; }
.stamp.yes { left: 18px; color: var(--up); border-color: var(--up); transform: rotate(-10deg); }
.stamp.no { right: 18px; color: var(--down); border-color: var(--down); transform: rotate(10deg); }
.card .by { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 10px 8px; color: #fff; font-size: 12px; font-weight: 700; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.controls .vote { padding: 14px; font-size: 16px; font-weight: 800; border: 3px solid; background: none; }
.controls .no { color: var(--down); border-color: var(--down); }
.controls .yes { color: var(--up); border-color: var(--up); }
.controls .no:hover { background: var(--down); color: var(--paper); }
.controls .yes:hover { background: var(--up); color: var(--paper); }
.controls .undo { border: 0; background: none; color: var(--mute); text-decoration: underline; padding: 8px; }
.controls .undo:disabled { visibility: hidden; }
.keys { text-align: center; font-size: 12px; color: var(--mute); }
@media (hover: none) { .keys { display: none; } }

/* ---------- ranking ---------- */
.rank-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; border-bottom: 2px solid var(--rule); padding-bottom: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.rank-head h2 { margin: 0; font-size: 28px; letter-spacing: -.03em; line-height: 1; }
.seg { display: flex; border: 2px solid var(--ink); }
.seg button { border: 0; background: none; padding: 4px 10px; font-size: 13px; font-weight: 700; }
.seg button.on { background: var(--ink); color: var(--paper); }
.podium { display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; gap: 10px; height: min(72vh, 760px); margin-bottom: 28px; }
.podium .p { position: relative; padding: 0; border: 0; background: var(--soft); overflow: hidden; text-align: left; }
.podium .p:first-child { grid-row: 1 / 3; }
.podium .p img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
.podium .p:hover img { transform: scale(1.02); }
.podium .cap { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px;
  padding: 40px 14px 12px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); }
.podium .n { font-size: clamp(40px, 7vw, 96px); font-weight: 800; letter-spacing: -.05em; line-height: .8; }
.podium .p:not(:first-child) .n { font-size: clamp(28px, 4vw, 56px); }
.podium .s { text-align: right; font-size: 13px; font-weight: 700; }
.podium .s big { display: block; font-size: 22px; }
@media (max-width: 720px) {
  .podium { grid-template-columns: 1fr 1fr; grid-template-rows: 2fr 1fr; height: 80vh; }
  .podium .p:first-child { grid-row: 1; grid-column: 1 / 3; }
}
.podium.n1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.podium.n2 { grid-template-rows: 1fr; }
.podium.n2 .p:first-child { grid-row: auto; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: grid; grid-template-columns: 3.2em 88px 1fr minmax(120px, 34%) 4em; gap: 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--soft); }
.list .rk { font-size: 22px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.list .th { padding: 0; border: 0; background: var(--soft); width: 88px; height: 66px; }
.list .th img { width: 100%; height: 100%; object-fit: cover; display: block; }
.list .who { font-size: 13px; color: var(--mute); min-width: 0; }
.list .who b { color: var(--ink); display: block; }
.list .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split { display: flex; height: 10px; background: var(--soft); }
.split i { display: block; height: 100%; }
.split .u { background: var(--up); }
.split .d { background: var(--down); margin-left: auto; }
.split-n { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.split-n .u { color: var(--up); } .split-n .d { color: var(--down); }
.list .sc { text-align: right; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sc.neg { color: var(--down); }
@media (max-width: 720px) {
  .list li { grid-template-columns: 2.2em 64px 1fr 3em; gap: 10px; }
  .list .th { width: 64px; height: 48px; }
  .list .bar-cell { grid-column: 3 / 5; grid-row: 2; }
  .list .who { grid-column: 3; }
}
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--mute); margin: 28px 0 6px; }

/* ---------- lightbox ---------- */
#lightbox { position: fixed; inset: 0; z-index: 50; background: var(--shade); color: #f4f2ee;
  display: grid; grid-template-columns: 56px 1fr 56px; grid-template-rows: 1fr auto; }
#lightbox[hidden] { display: none; }
#lightbox figure { margin: 0; grid-column: 2; grid-row: 1; display: grid; place-items: center; min-height: 0; padding: 16px 0 8px; }
#lightbox figure img { max-width: 100%; max-height: calc(100dvh - 120px); object-fit: contain; }
.lb-nav, .lb-close { background: none; border: 0; color: #f4f2ee; font-size: 40px; line-height: 1; }
.lb-prev { grid-column: 1; grid-row: 1; } .lb-next { grid-column: 3; grid-row: 1; }
.lb-close { position: absolute; top: 6px; right: 12px; z-index: 2; }
.lb-meta { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: center; padding: 10px 16px 16px; font-size: 13px; }
.lb-meta .names { color: #b9b6ae; max-width: 60ch; }
.lb-meta button { background: none; color: #f4f2ee; border: 2px solid #f4f2ee; padding: 6px 14px; font-weight: 700; }
.lb-meta button.yes.on { background: #5fbf8a; border-color: #5fbf8a; color: #111; }
.lb-meta button.no.on { background: #e2705f; border-color: #e2705f; color: #111; }
.lb-meta button.del { border-color: transparent; color: #b9b6ae; text-decoration: underline; }
@media (max-width: 720px) { #lightbox { grid-template-columns: 0 1fr 0; } .lb-nav { display: none; } }

/* ---------- misc ---------- */
#drop { position: fixed; inset: 0; z-index: 60; background: var(--shade); display: grid; place-items: center; padding: 24px; pointer-events: none; }
#drop div { border: 4px dashed #f4f2ee; color: #f4f2ee; font-size: 28px; font-weight: 800; padding: 60px; text-align: center; }
#drop[hidden] { display: none; }
#toast { position: fixed; left: 50%; top: 76px; transform: translateX(-50%); z-index: 70; background: var(--ink); color: var(--paper);
  padding: 10px 16px; font-weight: 700; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }
dialog { border: 0; border-top: 6px solid var(--rule); background: var(--paper); color: var(--ink); padding: 18px; width: min(380px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.03em; }
dialog p { margin: 0 0 14px; color: var(--mute); font-size: 14px; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
