/* Midterm Madness */
:root {
  --ink: #1D1B3F;
  --muted: #4B4A6E;
  --paper: #F2F6FF;
  --dot: #D3DEF7;
  --line: #E3E9F6;
  --yellow: #FFD84D;
  --dem: #2459E8;
  --rep: #D7352B;
  --ind: #7B3FBF;
  --dem-light: #AFC3F5;
  --rep-light: #F2AEA8;
  --ind-light: #CDB5E8;
  --green: #2FA35B;
  --green-light: #BFF0CD;
  --red-light: #FFC9C4;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background-color: var(--paper);
  background-image: radial-gradient(var(--dot) 2px, transparent 2px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--dem); }
a:hover { color: var(--ink); }
button { font-family: inherit; }
.page { min-height: 100vh; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 24px 16px 56px; display: flex; flex-direction: column; gap: 22px; }
.wrap-narrow { max-width: 640px; }
.banner { background: var(--yellow); border-bottom: 3px solid var(--ink); padding: 8px 16px; font-size: 14px; font-weight: 700; text-align: center; }

/* Masthead */
.mast { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.mast-brand { display: flex; align-items: center; gap: 14px; }
.mast-flag { width: 76px; height: auto; display: block; transform: rotate(-4deg); }
.mast-title { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 46px; line-height: 1; letter-spacing: -0.5px; }
.mast-tag { font-size: 18px; font-weight: 700; color: var(--muted); margin-top: 8px; }
.mast-big .mast-flag { width: 88px; }
.mast-big .mast-title { font-size: 54px; line-height: 0.95; }
.mast-big .mast-tag { font-size: 20px; margin-top: 10px; }
.mast-right { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.mast-right a { color: var(--ink); font-weight: 700; font-size: 15px; }
.sticker { background: var(--yellow); padding: 0 10px; border: 3px solid var(--ink); border-radius: 12px; display: inline-block; transform: rotate(-2deg); }
.pill { background: #fff; border: 3px solid var(--ink); border-radius: 12px; box-shadow: 4px 4px 0 var(--ink); padding: 8px 14px; font-weight: 800; font-size: 15px; }
.pill-dark { background: var(--ink); color: #fff; box-shadow: none; }

/* Cards and type */
.card { background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 20px; }
.card.pop { box-shadow: 6px 6px 0 var(--ink); }
.card.green { background: var(--green-light); }
.card.red { background: var(--red-light); }
.h-display { font-family: 'Baloo 2', sans-serif; font-weight: 800; line-height: 1; }
.h1 { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 38px; line-height: 1; margin: 0; }
.h2 { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 30px; line-height: 1; margin: 0; }
.h3 { font-family: 'Baloo 2', sans-serif; font-weight: 700; font-size: 22px; line-height: 1.1; margin: 0; }
.label { font-size: 12px; font-weight: 800; letter-spacing: 0.8px; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 14px; font-weight: 700; color: var(--muted); }
.lead { font-size: 18px; font-weight: 700; color: var(--muted); margin: 0; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.note-box { background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 12px 16px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 22px; border-radius: 14px; border: 3px solid var(--ink); background: var(--yellow); box-shadow: 4px 4px 0 var(--ink); color: var(--ink); font-family: 'Baloo 2', sans-serif; font-size: 20px; font-weight: 800; text-decoration: none; cursor: pointer; }
.btn:hover { color: var(--ink); transform: translate(1px, 1px); box-shadow: 3px 3px 0 var(--ink); }
.btn-white { background: #fff; }
.btn-small { min-height: 40px; padding: 0 14px; font-family: 'Nunito', sans-serif; font-size: 14px; border-width: 2px; box-shadow: 2px 2px 0 var(--ink); border-radius: 10px; }
.btn-block { display: flex; width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 15px; font-weight: 800; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=url], .field input[type=number] {
  height: 52px; border: 3px solid var(--ink); border-radius: 12px; padding: 0 14px; font-family: inherit; font-size: 17px; font-weight: 700; width: 100%; background: #fff; color: var(--ink);
}
.field .hint { font-size: 13px; font-weight: 600; color: var(--muted); }
.flash { border: 3px solid var(--ink); border-radius: 14px; padding: 12px 16px; font-weight: 700; }
.flash-info { background: #fff; }
.flash-good { background: var(--green-light); }
.flash-bad { background: var(--red-light); }

/* Mascot */
.mascot { display: flex; align-items: center; gap: 10px; }
.mascot img { width: 116px; height: auto; display: block; border-radius: 10px; }
.bubble { background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; padding: 10px 14px; font-weight: 800; font-size: 16px; max-width: 260px; }
.bubble-white { background: #fff; max-width: none; font-size: 17px; }

/* Progress */
.progress { height: 16px; background: var(--line); border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; }
.progress > div { height: 100%; background: var(--dem); transition: width 0.3s ease; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; font-weight: 800; font-size: 14px; }
.chip { background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 2px 10px; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 10px; }
.tab { min-height: 52px; padding: 0 22px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; color: var(--ink); font-family: 'Baloo 2', sans-serif; font-size: 21px; font-weight: 700; cursor: pointer; }
.tab small { font-family: 'Nunito', sans-serif; font-size: 14px; font-weight: 800; }
.tab.on { background: var(--yellow); box-shadow: 4px 4px 0 var(--ink); font-weight: 800; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 2px solid var(--ink); background: #fff; font-weight: 800; font-size: 14px; cursor: pointer; color: var(--ink); }
.filter.on { background: var(--ink); color: #fff; }

/* Balance bars */
.bal-label { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px; font-weight: 800; margin-bottom: 4px; }
.bal-label.today { color: var(--muted); }
.bal-wrap { position: relative; }
.bal { display: flex; height: 34px; border: 3px solid var(--ink); border-radius: 10px; overflow: hidden; background: var(--line); }
.bal.today { border: 2px solid #8C8BA8; background: #EEF1F8; }
.bal > div { display: flex; align-items: center; justify-content: center; font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; color: #fff; transition: width 0.4s ease; }
.bal.today > div { font-weight: 700; font-size: 16px; color: var(--ink); }
.bal-maj { position: absolute; top: -5px; bottom: -5px; border-left: 3px dashed var(--ink); pointer-events: none; }
.seg-D { background: var(--dem); } .seg-R { background: var(--rep); } .seg-I { background: var(--ind); } .seg-V { background: #DDE0EA; color: var(--ink) !important; }
.bal.today .seg-D { background: var(--dem-light); } .bal.today .seg-R { background: var(--rep-light); } .bal.today .seg-I { background: var(--ind-light); }
.verdict { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 22px; line-height: 1.2; }

/* House slider */
.house-bar { position: relative; height: 34px; margin: 12px 0; }
.house-bar .bal { position: absolute; inset: 0; }
input.bar-slider { position: absolute; left: -9px; top: -9px; width: calc(100% + 18px); height: 52px; -webkit-appearance: none; appearance: none; background: transparent; margin: 0; cursor: ew-resize; outline: none; }
input.bar-slider::-webkit-slider-runnable-track { height: 52px; background: transparent; border: none; }
input.bar-slider::-moz-range-track { height: 52px; background: transparent; border: none; }
input.bar-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 52px; border-radius: 9px; background: var(--yellow); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); }
input.bar-slider::-moz-range-thumb { width: 18px; height: 52px; border-radius: 9px; background: var(--yellow); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); box-sizing: border-box; }
input.bar-slider:focus-visible::-webkit-slider-thumb { outline: 3px solid var(--dem); outline-offset: 2px; }
input.bar-slider.unset::-webkit-slider-thumb { background: #fff; }
input.bar-slider.unset::-moz-range-thumb { background: #fff; }

/* Race cards */
.race { background: #fff; border: 3px solid var(--ink); border-radius: 20px; padding: 20px; display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; }
.race-head { flex: 0 0 150px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.race-state { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 32px; line-height: 1; }
.race-sub { font-size: 14px; font-weight: 700; color: var(--muted); }
.tag { background: var(--paper); border: 2px solid var(--ink); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 800; }
.tag-flip { background: var(--yellow); font-size: 13px; }
.cands { flex: 1 1 360px; display: flex; flex-wrap: wrap; gap: 12px; align-items: stretch; }
.cand { flex: 1 1 150px; min-height: 68px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; box-shadow: 4px 4px 0 var(--ink); color: var(--ink); text-align: left; padding: 8px 14px; cursor: pointer; }
.cand .nm { display: block; font-size: 19px; font-weight: 800; }
.cand .st { display: block; font-size: 13px; font-weight: 700; color: var(--muted); }
.cand.sel { box-shadow: 2px 2px 0 var(--ink); transform: translate(2px, 2px); color: #fff; }
.cand.sel .st { color: #fff; }
.cand.sel.p-D { background: var(--dem); } .cand.sel.p-R { background: var(--rep); } .cand.sel.p-I { background: var(--ind); }
.cand:disabled { cursor: default; }
.inc { display: inline-block; margin: 2px 0; font-size: 11px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase; background: var(--yellow); border: 2px solid var(--ink); border-radius: 6px; padding: 0 6px; color: var(--ink); }
.cand.sel .inc { background: transparent; border-color: #fff; color: #fff; }
.race-info { flex: 1 1 290px; display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.poll-line { font-size: 16px; font-weight: 800; }
.crowd { display: flex; height: 16px; border: 3px solid var(--ink); border-radius: 9px; overflow: hidden; margin: 4px 0 6px; background: var(--line); }
.crowd > div { height: 100%; }
.crowd-legend { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 14px; font-weight: 700; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; border: 2px solid var(--ink); margin-right: 5px; vertical-align: -1px; }
.bg-D { background: var(--dem); } .bg-R { background: var(--rep); } .bg-I { background: var(--ind); }

@keyframes wiggle { 0%, 100% { transform: rotate(0deg); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
.wig { animation: wiggle 1.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .wig { animation: none !important; } }

/* Tables */
.table-box { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 15px; font-weight: 700; }
table.grid th { text-align: left; padding: 8px 6px; border-bottom: 3px solid var(--ink); }
table.grid td { padding: 10px 6px; border-bottom: 2px solid var(--line); vertical-align: middle; }
table.grid .num { text-align: right; }
table.grid tr.me td { background: #FFF6CC; }
.rank { font-family: 'Baloo 2', sans-serif; font-size: 20px; font-weight: 800; }
.res-tag { display: inline-block; min-width: 90px; text-align: center; border: 2px solid var(--ink); border-radius: 8px; font-weight: 800; padding: 2px 6px; }
.res-right { background: var(--green-light); } .res-wrong { background: var(--red-light); } .res-wait { background: var(--paper); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat { background: #fff; border: 3px solid var(--ink); border-radius: 16px; box-shadow: 4px 4px 0 var(--ink); padding: 14px 16px; }
.stat.yellow { background: var(--yellow); }
.stat .big { font-family: 'Baloo 2', sans-serif; font-weight: 800; font-size: 44px; line-height: 1.05; }

/* Switch */
.switch { display: flex; align-items: center; gap: 12px; background: none; border: none; padding: 0; color: var(--ink); text-align: left; cursor: pointer; min-height: 44px; }
.switch .track { flex: 0 0 auto; width: 52px; height: 30px; border: 3px solid var(--ink); border-radius: 16px; background: var(--line); display: flex; align-items: center; padding: 0 3px; }
.switch .knob { width: 18px; height: 18px; border-radius: 9px; background: #fff; border: 2px solid var(--ink); }
.switch.on .track { background: var(--green); }
.switch.on .knob { margin-left: 22px; }
.switch b { display: block; font-size: 16px; }
.switch span.d { display: block; font-size: 14px; font-weight: 600; color: var(--muted); }

.hero-card { padding: 10px; }
.hero-card img { width: 100%; height: auto; display: block; border-radius: 12px; }
.picks-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.pick-cell { display: flex; justify-content: space-between; gap: 8px; align-items: center; border: 2px solid var(--dot); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 800; z-index: 10; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.show { opacity: 1; }

@media (max-width: 640px) {
  .mast-title { font-size: 36px; }
  .mast-big .mast-title { font-size: 42px; }
  .mast-flag { width: 58px; }
  .race-head { flex-basis: 100%; }
  .race-state { font-size: 28px; }
  .tab { padding: 0 14px; font-size: 18px; }
  .h1 { font-size: 32px; }
  .mascot img { width: 92px; }
}
@media print {
  body { background: #fff; }
  .no-print, .banner { display: none !important; }
  .card, .stat { box-shadow: none !important; break-inside: avoid; }
}
