/* A printed ballot, not a dashboard.
   House rules, kept deliberately: square corners, hairline rules instead of
   floating cards, one ink and one stamp red, no gradients, no blurred shadows,
   no dark mode. Paper does not have a dark mode. */

:root {
  --paper:       #EDE8DC;
  --paper-shade: #E2DCCB;
  --ink:         #17150F;
  --ink-2:       #4E4939;
  --faded:       #8F8672;
  --stamp:       #A72F1B;

  --serif: "Trirong", Georgia, serif;
  --sans:  "IBM Plex Sans Thai", "Helvetica Neue", Arial, sans-serif;
  /* Plex Mono has no Thai subset — Thai glyphs fall through to Plex Sans
     Thai, which is the same superfamily, rather than an OS default. */
  --mono:  "IBM Plex Mono", "IBM Plex Sans Thai", "SFMono-Regular", monospace;

  --gutter: clamp(1.25rem, 4vw, 2.75rem);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper-shade);
  color: var(--ink);
  font: 400 1rem/1.7 var(--sans);
  font-feature-settings: "liga" 1;
}

/* Paper grain. Cheap, static, and the single fastest way to stop a page
   reading as a rectangle of flat #fff. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='4' stitchTiles='stitch'/></filter><rect width='160' height='160' filter='url(%23g)'/></svg>");
}

::selection { background: var(--stamp); color: var(--paper); }

a { color: inherit; text-underline-offset: .2em; text-decoration-thickness: 1px; }

:focus-visible {
  outline: 2px dashed var(--stamp);
  outline-offset: 3px;
}

/* --------------------------------------------------------------- the sheet */

.sheet {
  max-width: 68rem;
  margin: clamp(0px, 3vw, 2.5rem) auto;
  background: var(--paper);
  border: 1px solid var(--ink);
  position: relative;
}

/* The heavy bar across the top of a printed form. */
.sheet::before {
  content: "";
  display: block;
  height: 7px;
  background: var(--ink);
}

/* ------------------------------------------------------------------ masthead */

.masthead {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 1rem 2rem;
  padding: 1.1rem var(--gutter) .7rem;
}

.wordmark {
  font: 500 .8rem/1.5 var(--mono);
  letter-spacing: .05em;
}

.wordmark b { font-weight: 500; border-bottom: 3px solid var(--stamp); padding-bottom: 3px; }

.meta {
  font: 400 .74rem/1.6 var(--mono);
  letter-spacing: .02em;
  color: var(--ink-2);
  text-align: right;
  white-space: nowrap;
}

/* Rules: one thick, one hair, 3px apart. Letterpress, not CSS default. */
.rule-double {
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 4px;
  margin: 0 var(--gutter);
}

.headline {
  padding: 1.6rem var(--gutter) 0;
}

.headline h1 {
  margin: 0;
  font: 300 clamp(2rem, 5.5vw, 3.4rem)/1.3 var(--serif);
  letter-spacing: -.005em;
  max-width: 22ch;
}

.headline p {
  margin: .85rem 0 0;
  max-width: 46ch;
  font-size: 1.02rem;
  color: var(--ink-2);
}

.deadline {
  margin: 1.4rem 0 0;
  padding: 0 var(--gutter);
  font: 400 .75rem/1.6 var(--mono);
  letter-spacing: .03em;
  color: var(--faded);
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  align-items: baseline;
}

.deadline .live::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-right: .5em;
  background: var(--stamp);
  vertical-align: baseline;
}

/* -------------------------------------------------------------- the entries */

.ballot {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  margin: 1.5rem var(--gutter) 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

/* Columns divided by rules, the way a page of newsprint is — not three
   detached cards floating on a background. */
.entry + .entry { border-left: 1px solid var(--ink); }

.entry {
  padding: 1.5rem 1.25rem 1.6rem;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.entry-head {
  display: flex;
  align-items: baseline;
  gap: .7rem;
  margin-bottom: .9rem;
}

.ordinal {
  font: 300 2.6rem/1 var(--serif);
  color: var(--ink);
  min-width: 1.2em;
}

.entry-label {
  font: 400 .95rem/1.4 var(--sans);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.entry-label:empty::before {
  content: "ไม่มีชื่อกำกับ";
  color: var(--faded);
  font-style: italic;
}

.plate {
  position: relative;
  border: 1px solid var(--ink);
  background: var(--paper-shade);
  aspect-ratio: 4 / 5;
  overflow: hidden;
}

.plate img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Held back until the image decodes, so nothing pops in half-drawn. */
.plate img[data-loading] { opacity: 0; }
.plate img { transition: opacity .35s ease; }

.stamp {
  position: absolute;
  right: -.35rem;
  bottom: .9rem;
  transform: rotate(-8deg);
  padding: .28rem .8rem;
  border: 2px solid var(--stamp);
  outline: 1px solid var(--stamp);
  outline-offset: 2px;
  color: var(--stamp);
  background: rgba(237, 232, 220, .82);
  font: 600 .88rem/1.5 var(--serif);
  letter-spacing: .02em;
  mix-blend-mode: multiply;
}

/* ------------------------------------------------------------------ picking */

.pick {
  margin-top: 1.1rem;
  width: 100%;
  padding: .72rem 1rem;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 0;
  font: 500 .82rem/1.5 var(--mono);
  letter-spacing: .03em;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, color .12s ease;
}

.pick:hover:not(:disabled) {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--ink);   /* hard offset, like a printed block */
}

.pick:active:not(:disabled) {
  transform: translate(0, 0);
  box-shadow: 0 0 0 var(--ink);
}

.pick[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.pick:disabled { cursor: default; color: var(--faded); border-color: var(--faded); }

/* -------------------------------------------------------------------- tally */

.tally {
  margin-top: 1.1rem;
  min-height: 3.6rem;
}

.tally[hidden] { display: none; }

.bar {
  height: 11px;
  border: 1px solid var(--ink);
  background: var(--paper-shade);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ink);
  transition: width .7s cubic-bezier(.2, .7, .2, 1);
}

.entry.leading .bar span { background: var(--stamp); }

.figures {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .6rem;
  margin-top: .5rem;
  font: 400 .76rem/1.5 var(--mono);
  letter-spacing: .02em;
  color: var(--ink-2);
}

.figures .pct { font-size: 1.15rem; color: var(--ink); }
.entry.leading .figures .pct { color: var(--stamp); }

.marks { margin-top: .45rem; color: var(--ink-2); }
.marks svg { display: block; }

/* ------------------------------------------------------------------ footers */

.colophon {
  margin: 0 var(--gutter);
  padding: 1.2rem 0 1.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: .6rem 1.6rem;
  justify-content: space-between;
  align-items: baseline;
  font: 400 .75rem/1.7 var(--mono);
  letter-spacing: .02em;
  color: var(--faded);
}

.colophon button {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--faded);
  padding: 0 0 1px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.colophon button:hover { color: var(--stamp); border-color: var(--stamp); }

/* ------------------------------------------------------------------ notices */

.notice {
  margin: 1.5rem var(--gutter);
  padding: 1.1rem 1.3rem;
  border: 1px solid var(--ink);
  border-left: 5px solid var(--stamp);
  font-size: .95rem;
}

.notice h2 {
  margin: 0 0 .4rem;
  font: 300 1.5rem/1.4 var(--serif);
}

.notice p { margin: 0; color: var(--ink-2); max-width: 52ch; }

.empty {
  padding: clamp(2.5rem, 9vw, 5rem) var(--gutter) clamp(3rem, 10vw, 6rem);
}

.empty h2 { margin: 0 0 .6rem; font: 300 clamp(1.8rem,4.5vw,2.6rem)/1.35 var(--serif); }
.empty p  { margin: 0; max-width: 44ch; color: var(--ink-2); }

/* A single flash of red when a vote lands, then it settles. */
@keyframes ink-in {
  from { opacity: 0; transform: rotate(-8deg) scale(1.5); }
  60%  { opacity: 1; }
  to   { opacity: 1; transform: rotate(-8deg) scale(1); }
}

.stamp { animation: ink-in .28s cubic-bezier(.3, 1.5, .5, 1) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}

/* --------------------------------------------------------------- narrow --- */

@media (max-width: 860px) {
  .ballot { grid-template-columns: 1fr; }
  .entry + .entry { border-left: 0; border-top: 1px solid var(--ink); }
  .plate { aspect-ratio: 3 / 2; }
  .masthead { grid-template-columns: 1fr; align-items: start; }
  .meta { text-align: left; }
  .sheet { margin: 0; border-left: 0; border-right: 0; }
}
