:root {
  --bg: #f3f4f6; --bg-elev: #ffffff; --fg: #1c2026; --muted: #5b6470; --line: #d3d8de;
  --btn: #ffffff; --btn-hover: #e9eef8; --accent: #2456c4; --accent-fg: #ffffff; --warn-bg: #fdf0c4; --warn-fg: #4a3b00;
  --bar-h: 44px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --bg-elev: #1f2226; --fg: #e7e9ec; --muted: #a2a9b3; --line: #353b43;
    --btn: #23272c; --btn-hover: #2c3440; --accent: #6f9cff; --accent-fg: #0b1020; --warn-bg: #4a3b00; --warn-fg: #fdf0c4;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg); min-height: 100dvh;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0.4em 0 0.6em; }
h2 { font-size: 1.15rem; margin: 0 0 0.5em; }

/* header */
.bar {
  position: sticky; top: 0; z-index: 5; height: var(--bar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.progress { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.track { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width 150ms; }
.count { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.langs { margin-left: auto; display: flex; flex: none; }
.langs button { border: 1px solid var(--line); background: var(--btn); padding: 2px 9px; font-size: 13px; min-height: 30px; }
.langs button:first-child { border-radius: 6px 0 0 6px; }
.langs button:last-child { border-radius: 0 6px 6px 0; }
.langs button + button { border-left: none; }
.langs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
body[data-screen="rate"] .brand { display: none; }
@media (min-width: 900px) { body[data-screen="rate"] .brand { display: block; max-width: 30vw; } }

/* text pages */
.page { max-width: 680px; margin: 0 auto; padding: 16px 16px 24px; }
.page p { margin: 0 0 1em; }
.example { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 0 0 1em; max-width: min(100%, 80vh); }
.example figure { margin: 0; }
.example img { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.example figcaption { font-size: 13px; color: var(--muted); margin-top: 4px; }
.primary {
  display: block; margin: 8px 0 16px; min-height: 50px; padding: 12px 32px; border: none; border-radius: 10px;
  background: var(--accent); color: var(--accent-fg); font-size: 17px; font-weight: 600;
}
.by { font-size: 14px; color: var(--muted); }
.by a { color: inherit; }
.budgets { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 0 0 1em; }
.budget {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 8px; min-height: 84px;
  background: var(--btn); border: 1px solid var(--line); border-radius: 12px;
}
.budget:hover, .vote button:hover { background: var(--btn-hover); }
.budget b { font-size: 22px; }
.budget span { font-size: 14px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
.ack { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.ack label { display: block; font-weight: 600; margin-bottom: 6px; }
.ack .row { display: flex; flex-wrap: wrap; gap: 8px; }
.ack input {
  flex: 1 1 220px; min-width: 0; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--fg);
}
.ack .row button { padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--btn); white-space: nowrap; }
.ack .note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.ack-msg { font-weight: 600; }
.foot { text-align: center; padding: 8px 16px 24px; }
.link { background: none; border: none; text-decoration: underline; color: var(--muted); font-size: 14px; padding: 8px; }
body[data-screen="rate"] .foot { display: none; }
dialog { max-width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px; padding: 20px; background: var(--bg-elev); color: var(--fg); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog p { font-size: 15px; }
dialog .primary { margin: 0; }
.offline-note { display: none; }
body.offline .offline-note {
  display: block; position: fixed; z-index: 20; left: 0; right: 0; top: var(--bar-h); margin: 0; padding: 6px 12px;
  background: var(--warn-bg); color: var(--warn-fg); font-size: 13px; text-align: center;
}

/* rating screen: fills the window below the header, never scrolls */
body[data-screen="rate"] { overflow: hidden; }
#rate {
  height: calc(100dvh - var(--bar-h)); display: flex; flex-direction: column;
  padding: 8px max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.ask { text-align: center; }
.ask .q { margin: 0; font-weight: 600; font-size: clamp(15px, 1.4vw + 9px, 20px); line-height: 1.3; }
.ask .small { margin: 2px 0 0; font-size: 12px; color: var(--muted); line-height: 1.3; }
.stage { position: relative; flex: 1; min-height: 0; margin: 8px 0; }
.cell {
  position: absolute; margin: 0; overflow: hidden; cursor: zoom-in;
  background: #fff; border: 1px solid var(--line); border-radius: 6px;
}
.cell img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.tag {
  position: absolute; left: 6px; top: 6px; padding: 1px 8px; border-radius: 4px; pointer-events: none;
  background: rgba(20, 22, 26, 0.72); color: #fff; font-size: 13px; font-weight: 600; line-height: 1.5;
}
.status { position: absolute; inset: 0; margin: 0; display: grid; place-items: center; color: var(--muted); text-align: center; }
.vote { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; max-width: 980px; margin: 0 auto; }
.vote button {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 6px 8px;
  background: var(--btn); border: 1px solid var(--line); border-radius: 10px; font-size: 16px; font-weight: 600; line-height: 1.2;
}
.vote button:active { background: var(--accent); color: var(--accent-fg); }
.vote kbd { display: none; font: 12px/1.6 system-ui, sans-serif; padding: 0 5px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-weight: 400; }
@media (hover: hover) and (pointer: fine) { .vote kbd { display: inline-block; } }
#rate .hint { margin: 6px 0 0; text-align: center; line-height: 1.3; }

/* phones held sideways: every pixel of height goes to the images */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --bar-h: 36px; }
  .langs button { min-height: 26px; }
  #rate { padding-top: 4px; }
  .ask { line-height: 1.2; font-size: 11px; }
  .ask .q { font-size: 14px; display: inline; }
  .ask .small { font-size: 11px; display: inline; margin-left: 6px; }
  .stage { margin: 4px 0; }
  .vote button { min-height: 40px; font-size: 15px; }
  #rate .hint { display: none; }
}

/* full-size viewer */
body.viewing { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 30; background: #101113; color: #e7e9ec; }
.vstage { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.vbox { position: absolute; transform-origin: 50% 50%; background: #fff; }  /* no will-change: it freezes the raster at scale 1 */
.vbox img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.vtop {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px;
  padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  background: rgba(16, 17, 19, 0.82);
}
.vhint { flex: 1; font-size: 12px; color: #b5bbc4; line-height: 1.3; }
.vclose { flex: none; width: 44px; height: 44px; border-radius: 22px; border: 1px solid #444a52; background: #23262b; font-size: 18px; }
.vbottom {
  position: absolute; bottom: 0; left: 0; right: 0; display: grid; gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(16, 17, 19, 0.85);
}
.vtabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.vtabs button { min-height: 44px; border: 1px solid #444a52; background: #23262b; font-weight: 600; }
.vtabs button:first-child { border-radius: 8px 0 0 8px; }
.vtabs button:last-child { border-radius: 0 8px 8px 0; }
.vtabs button + button { border-left: none; }
.vtabs button[aria-pressed="true"] { background: #e7e9ec; color: #101113; border-color: #e7e9ec; }
.viewer .vote button { background: #23262b; border-color: #444a52; color: #e7e9ec; }
.viewer .vote button:hover { background: #2f343b; }
.viewer .vote button:active { background: #e7e9ec; color: #101113; }
.viewer .vote { max-width: none; }
.viewer .vote kbd { color: #b5bbc4; border-color: #444a52; }
@media (min-width: 900px), (orientation: landscape) and (max-height: 500px) {
  .vbottom { grid-template-columns: minmax(240px, 1fr) 2fr; align-items: center; }
  .viewer .vote button { min-height: 44px; }
}
