/* Light: squared school notebook with a red margin. Dark: chalkboard. */
:root {
  --paper: #fbfcfe;
  --grid: #dde8f4;
  --ink: #223a8e;
  --ink-soft: #56669a;
  --mark: #d9363e;
  --field: #ffffff;
  --line: #b9c8e0;
  --bar: #223a8e;
  --bar-track: #e5ecf7;
  --on-ink: #ffffff;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1e2c25;
    --grid: #263830;
    --ink: #edf0e7;
    --ink-soft: #a9b9ae;
    --mark: #f08c8c;
    --field: #24352d;
    --line: #3f544a;
    --bar: #ebe3aa;
    --bar-track: #2c3f35;
    --on-ink: #1e2c25;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font: 17px/1.5 "PT Sans", "Helvetica Neue", Arial, sans-serif;
}

.page {
  position: relative;
  max-width: 600px;
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(28px + env(safe-area-inset-top, 0px)) 20px calc(48px + env(safe-area-inset-bottom, 0px)) 72px;
}
.page::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 56px;
  border-left: 2px solid var(--mark);
  opacity: 0.55;
}

h1, h2, .hand {
  font-family: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  font-weight: 700;
}
h1 { font-size: 3rem; line-height: 1; margin: 0 0 0.4rem; }
h2 { font-size: 1.9rem; line-height: 1.1; margin: 1.75rem 0 0.25rem; }

.question { font-size: 1.2rem; font-weight: 700; margin: 0 0 0.25rem; }
.lede { margin: 0 0 1.5rem; color: var(--ink-soft); max-width: 34em; }
.hint { color: var(--ink-soft); font-size: 0.95rem; margin: 0 0 0.5rem; }

/* Form fields */
.field { margin: 0 0 1rem; }
label { display: block; font-weight: 700; margin: 0 0 4px; }
input {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

/* Option lists */
.list { list-style: none; margin: 0; padding: 0; }
.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 66px;
  border-bottom: 1px dashed var(--line);
}
.item-text { flex: 1; padding: 10px 0; }
.item-label { display: block; font-weight: 700; }
.item-detail { display: block; color: var(--ink-soft); font-size: 0.95rem; }

/* The teacher's red-pen rank mark, sitting in the margin */
.rank {
  position: absolute;
  left: -64px;
  top: 50%;
  width: 42px;
  height: 42px;
  margin-top: -21px;
  display: grid;
  place-items: center;
  color: var(--mark);
  font-family: "Caveat", "Segoe Print", cursive;
  font-weight: 700;
  font-size: 1.7rem;
  line-height: 1;
  border: 2px solid var(--mark);
  border-radius: 52% 46% 55% 44% / 48% 55% 45% 52%;
  transform: rotate(-7deg);
  animation: mark 0.22s ease-out;
}
@keyframes mark {
  from { transform: rotate(-7deg) scale(0.4); opacity: 0; }
  to { transform: rotate(-7deg) scale(1); opacity: 1; }
}

button { font: inherit; color: inherit; cursor: pointer; }
.pick {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 8px;
  padding: 0;
  text-align: left;
  background: none;
  border: 0;
}
.pick .add {
  flex: none;
  color: var(--ink-soft);
  font-size: 0.95rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--field);
}
.tools { display: flex; gap: 4px; flex: none; }
.tool {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  font-size: 1.05rem;
  line-height: 1;
}
.tool:disabled { opacity: 0.35; cursor: default; }

.empty { color: var(--ink-soft); padding: 12px 0; margin: 0; border-bottom: 1px dashed var(--line); }

.primary {
  display: block;
  width: 100%;
  margin: 1.75rem 0 0;
  padding: 14px 20px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: var(--on-ink);
  font-weight: 700;
  font-size: 1.05rem;
}
.primary:disabled { opacity: 0.5; cursor: default; }
.secondary {
  margin: 1rem 0 0;
  padding: 10px 16px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.msg { margin: 1rem 0 0; color: var(--mark); font-weight: 700; }
.msg:empty { display: none; }
.done { margin: 1.5rem 0 0; }
.done ol { padding-left: 1.3rem; margin: 0.5rem 0 0; }

a { color: inherit; text-underline-offset: 3px; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid var(--mark);
  outline-offset: 2px;
}

/* Results */
.winner {
  display: inline-block;
  font-size: 2.3rem;
  line-height: 1.1;
  margin: 0.25rem 0 0.25rem;
  padding: 0 0.3em;
  border: 2px solid var(--mark);
  border-radius: 55% 45% 52% 48% / 60% 50% 50% 40%;
  transform: rotate(-2deg);
}
.round { margin: 0 0 1.25rem; }
.round h2 { margin-top: 1.5rem; }
.bar-row { padding: 6px 0; }
.bar-head { display: flex; justify-content: space-between; gap: 12px; }
.bar-head .count { color: var(--ink-soft); white-space: nowrap; }
.bar { height: 10px; margin-top: 4px; background: var(--bar-track); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--bar); }
.out .bar-head .name {
  text-decoration: line-through;
  text-decoration-color: var(--mark);
  text-decoration-thickness: 2px;
}
.out .bar > span { background: var(--mark); }
.voters { columns: 2; column-gap: 24px; padding-left: 1.2rem; }

@media (max-width: 380px) {
  .page { padding-left: 64px; padding-right: 14px; }
  .page::before { left: 50px; }
  .rank { left: -60px; width: 38px; height: 38px; margin-top: -19px; font-size: 1.5rem; }
  .tool { width: 36px; height: 36px; }
  h1 { font-size: 2.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .rank { animation: none; }
}
#done-heading:focus { outline: none; }

/* Section tabs on the ballot */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 1.5rem 0 0;
  scroll-margin-top: calc(12px + env(safe-area-inset-top, 0px));
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  text-align: left;
}
.tab[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.tab-name { font-weight: 700; }
.tab-count { font-size: 0.85rem; opacity: 0.8; }

h3 { font-size: 1rem; margin: 1.25rem 0 0.25rem; }
.group { font-family: "Caveat", "Segoe Print", cursive; font-weight: 700; font-size: 1.6rem; line-height: 1.1; margin: 1rem 0 0; }
#section-title:focus { outline: none; }

/* Results: full standings with the package cutoff drawn in red pen */
.order { margin: 0.5rem 0 1rem; }
.order ol { margin: 0.25rem 0 0; padding-left: 1.4rem; }
.standings { list-style: none; margin: 0; padding: 0; }
.standings .bar-row { display: block; padding: 8px 0; }
.standings .meta { display: block; font-size: 0.85rem; color: var(--ink-soft); margin-top: 2px; }
.standings .cutoff { border-bottom: 2px dashed var(--mark); padding-bottom: 12px; margin-bottom: 6px; }
.standings .zero { opacity: 0.55; }
