:root {
  --paper: #f7f2e3;
  --paper-2: #efe7d0;
  --rule: #d9cdaa;
  --ink: #1b2a1c;
  --ink-soft: #4a5a43;
  --leaf: #1d3b1f;
  --leaf-deep: #0f2411;
  --rice: #c9e265;
  --sun: #f2c94c;
  --punch: #b8322a;
  --on-dark: #fbf8ee;
  --on-dark-soft: #dfe8cf;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100svh;
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  color: var(--on-dark);
  background: var(--leaf-deep);
  -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--rice); color: var(--leaf-deep); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Background sawah ---------- */
.scene {
  position: fixed; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, rgb(12 30 14 / .55) 0%, rgb(12 30 14 / .08) 32%, rgb(12 30 14 / 0) 50%, rgb(10 26 12 / .55) 100%),
    url("../img/sawah-900.jpg") 48% 62% / cover no-repeat;
  animation: drift 24s ease-in-out infinite alternate;
  transform-origin: 60% 60%;
}
@media (min-width: 901px) {
  .scene { background-image:
    linear-gradient(180deg, rgb(12 30 14 / .55) 0%, rgb(12 30 14 / .12) 40%, rgb(10 26 12 / .78) 100%),
    url("../img/sawah-1920.jpg"); }
}
@keyframes drift { from { transform: scale(1.02); } to { transform: scale(1.07) translate(-1%, -1%); } }

/* ---------- Layout ---------- */
.wrap {
  width: min(100%, 660px);
  margin-inline: auto;
  min-height: 100svh;
  padding: max(28px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
}

.intro { padding-top: 6svh; padding-bottom: 22px; text-shadow: 0 2px 18px rgb(0 0 0 / .35); }
.intro h1 {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: clamp(2.5rem, 11vw, 3.6rem);
  line-height: .95;
  letter-spacing: -.03em;
  margin: 0;
  text-wrap: balance;
  animation: rise .9s var(--ease-out) both;
}
.intro .sub {
  margin: 12px 0 0;
  font-size: 1.02rem;
  font-weight: 500;
  color: var(--on-dark-soft);
  animation: rise .9s var(--ease-out) .12s both;
}

/* ---------- Kertas suara ---------- */
.ballot {
  margin-top: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  box-shadow: 0 18px 40px -12px rgb(0 0 0 / .55), 0 2px 6px rgb(0 0 0 / .18);
  animation: paperIn 1s var(--ease-out) .25s both;
  position: relative;
}
.ballot::before { /* serat kertas halus */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgb(120 100 50 / .035) 0 1px, transparent 1px 3px);
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1.5px solid var(--rule);
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
}

.pick {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 10px;
  min-height: 188px;
  padding: 18px 6px 16px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background-color .35s var(--ease-out);
  animation: pickIn .8s var(--ease-out) backwards;
  animation-delay: calc(.75s + var(--i) * .22s);
}
.pick + .pick { border-left: 1.5px dashed var(--rule); }
.pick input { position: absolute; opacity: 0; pointer-events: none; }

.no {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: 3.4rem;
  line-height: 1;
  letter-spacing: -.04em;
  color: var(--leaf);
  font-variant-numeric: tabular-nums;
  transition: transform .5s var(--ease-out), color .3s;
}
.name {
  display: flex; flex-direction: column; gap: 2px;
  font-weight: 700;
  font-size: .9rem;
  letter-spacing: .02em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.name i { font-style: normal; color: var(--ink-soft); font-weight: 500; }

@media (hover: hover) {
  .pick:hover { background: var(--paper-2); }
  .pick:hover .no { transform: translateY(-2px); }
}
.pick:active .no { transform: scale(.94); }
.pick:has(input:focus-visible) { outline: 3px solid var(--leaf); outline-offset: -5px; border-radius: 10px; }

/* Lubang coblos */
.hole {
  position: absolute;
  left: var(--x, 50%); top: var(--y, 50%);
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 46% 54% 50% 50% / 55% 45% 55% 45%;
  background: radial-gradient(circle at 45% 40%, #0d1a0e 0 48%, #3a2f1c 62%, transparent 72%);
  box-shadow: 0 0 0 3px rgb(184 50 42 / .0);
  transform: scale(0) rotate(-20deg);
  pointer-events: none;
}
.check {
  position: absolute; top: 8px; right: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--punch); color: #fff;
  transform: scale(0);
  transition: transform .4s var(--ease-out);
}

.pick:has(input:checked) { background: #f1e4c2; }
.pick:has(input:checked) .no { color: var(--punch); }
.pick:has(input:checked) .check { transform: scale(1); transition-delay: .12s; }
.pick.punched .hole { animation: punch .55s var(--ease-out) forwards; }
.pick::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.pick.punched::after { animation: press .36s ease-out; }
.grid:has(input:checked) .pick:not(:has(input:checked)) { opacity: .55; }
.grid:has(input:checked) .pick { transition: opacity .35s, background-color .35s; }

/* ---------- Lokasi ---------- */
.loc {
  display: flex; align-items: center; gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--paper-2);
  font-size: .84rem;
  color: var(--ink-soft);
  min-height: 44px;
}
.loc .pin { flex: none; }
.loc-text { flex: 1; line-height: 1.35; }
.loc-retry {
  flex: none; border: 0; background: none; padding: 6px 4px;
  font: inherit; font-weight: 700; color: var(--leaf);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.loc[data-state="asking"] .pin { animation: bob 1s ease-in-out infinite; }
.loc[data-state="ok"] { color: var(--leaf); }
.loc[data-state="ok"] .pin { color: var(--leaf); }
.loc[data-state="denied"], .loc[data-state="error"] { color: #7a4a14; }

/* ---------- Tombol kirim ---------- */
.send {
  position: relative;
  width: 100%;
  margin-top: 12px;
  min-height: 56px;
  border: 0; border-radius: 14px;
  font: 700 1.05rem/1 "Plus Jakarta Sans", sans-serif;
  color: var(--on-dark);
  background: var(--leaf);
  box-shadow: 0 6px 16px -6px rgb(15 36 17 / .7);
  cursor: pointer;
  transition: transform .2s var(--ease-out), background-color .25s, box-shadow .25s;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.send:not(:disabled):active { transform: scale(.97); }
.send:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
.send:disabled { background: #cfc6aa; color: #5b5440; box-shadow: none; cursor: not-allowed; }
.send.ready { animation: nudge .5s var(--ease-out); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgb(255 255 255 / .35); border-top-color: #fff;
  display: none; animation: spin .8s linear infinite;
}
.send.loading .spinner { display: block; }

.msg { margin: 10px 2px 0; min-height: 1.2em; font-size: .88rem; font-weight: 600; color: var(--punch); }
.msg:empty { margin: 0; min-height: 0; }

/* ---------- Selesai ---------- */
.done {
  margin-top: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 18px 40px -12px rgb(0 0 0 / .55);
  animation: paperIn .8s var(--ease-out) both;
  outline: none;
}
.done-mark { color: var(--leaf); }
.done-mark path { stroke-dasharray: 50; stroke-dashoffset: 50; animation: draw .6s var(--ease-out) .25s forwards; }
.done h2 {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 1.6rem; line-height: 1.1; letter-spacing: -.02em;
  margin: 12px 0 8px; text-wrap: balance;
}
.done p { margin: 0; color: var(--ink-soft); line-height: 1.5; font-size: .95rem; }

.foot {
  margin-top: 16px;
  font-size: .78rem;
  line-height: 1.45;
  color: var(--on-dark-soft);
  text-align: center;
  opacity: .9;
}
.empty { grid-column: 1 / -1; padding: 24px; text-align: center; color: var(--ink-soft); }

/* ---------- Motion ---------- */
@keyframes rise   { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes paperIn{ from { opacity: 0; transform: translateY(40px) rotate(-1.2deg); } to { opacity: 1; transform: none; } }
@keyframes pickIn { from { opacity: 0; transform: translateY(18px); clip-path: inset(30% 0 0 0); } to { opacity: 1; transform: none; clip-path: inset(0); } }
@keyframes punch  { 0% { transform: scale(0) rotate(-20deg); } 55% { transform: scale(1.25) rotate(4deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes press  { 0% { box-shadow: inset 0 0 0 0 rgb(0 0 0 / 0); } 40% { box-shadow: inset 0 3px 12px rgb(60 40 10 / .25); } 100% { box-shadow: inset 0 0 0 0 rgb(0 0 0 / 0); } }
@keyframes nudge  { 0% { transform: scale(1); } 40% { transform: scale(1.03); } 100% { transform: scale(1); } }
@keyframes bob    { 50% { transform: translateY(-3px); } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes draw   { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  .scene { animation: none; }
}

/* Layar sangat sempit (≤340px) */
@media (max-width: 340px) {
  .no { font-size: 2.8rem; }
  .name { font-size: .8rem; }
  .pick { min-height: 168px; }
}
/* Layar lebar */
@media (min-width: 600px) {
  .wrap { justify-content: center; }
  .intro { padding-top: 0; }
  .ballot, .done { margin-top: 0; }
  .pick { min-height: 220px; }
  .no { font-size: 4.2rem; }
  .name { font-size: 1rem; }
}

/* ---------- Mode panitia ---------- */
.again {
  margin-top: 18px; width: 100%; min-height: 52px;
  border: 0; border-radius: 14px; cursor: pointer;
  background: var(--leaf); color: var(--on-dark);
  font: 700 1rem/1 "Plus Jakarta Sans", sans-serif;
}
.again:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
.panitia-badge { display: none; }
.mode-panitia .panitia-badge {
  display: block; margin: 12px 0 0; padding: 8px 12px; border-radius: 10px;
  background: rgb(242 201 76 / .92); color: #3b2c05;
  font-size: .82rem; font-weight: 700; text-align: center;
}
.mode-panitia .foot { display: none; }
.mode-panitia .panitia-badge a { color: inherit; }
