:root {
  --ink: #241b45;
  --paper: #fffdf6;
  --sky-top: #7ad7ff;
  --sky-bottom: #ffe9f3;
  --grass: #7ddc6b;
  --grass-dark: #4cb944;
  --gold: #ffcf3a;
  --good: #22b573;
  --bad: #ff5c7a;
  --purple: #8b5cf6;
  --shadow: 4px 4px 0 var(--ink);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 55%, #fff6d8 100%) fixed;
  overflow-x: hidden;
}
body.tribunal { --sky-top: #c4b5fd; --sky-bottom: #ffe1f0; }

main, .top, footer { width: min(760px, 100% - 32px); margin-inline: auto; position: relative; z-index: 1; }

/* ----- header ----- */
.top { text-align: center; padding: 28px 0 8px; }
.top h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: 3px 3px 0 #fff;
}
.tagline { margin: 6px 0 14px; font-weight: 600; opacity: 0.8; }

/* ----- shared bits ----- */
.chip {
  display: inline-block;
  padding: 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform 0.1s, box-shadow 0.1s;
}
.chip:hover { transform: translate(-1px, -1px) rotate(-1deg); box-shadow: 3px 3px 0 var(--ink); }
.chip[hidden] { display: none; }

.btn {
  padding: 12px 22px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--gold);
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn:hover { transform: translate(-2px, -2px) rotate(-0.5deg); box-shadow: 6px 6px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.big { font-size: 1.2rem; padding: 16px 28px; background: var(--purple); color: #fff; }
.btn.approve { background: var(--good); color: #fff; }
.btn.reject { background: var(--bad); color: #fff; }
.btn.ghost { background: #fff; }

.card, dialog {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 6px 6px 0 var(--ink);
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.narrow { max-width: 420px; margin: 32px auto; padding: 24px; }
h2 { margin: 0; font-weight: 900; }

.empty { text-align: center; font-weight: 700; opacity: 0.75; padding: 24px 0; }
.error { margin: 0; padding: 8px 12px; border: 3px solid var(--ink); border-radius: 12px; background: #ffd6de; font-weight: 700; }
.error[hidden] { display: none; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; }
.field small { align-self: flex-end; opacity: 0.6; font-weight: 700; }
input[type="password"], input[type="text"], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .avatar:focus-visible {
  outline: 4px solid var(--purple);
  outline-offset: 2px;
}
input[type="range"] { width: 100%; accent-color: var(--purple); }

/* ----- the hill ----- */
.hill {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 24px;
  height: 500px;
  margin-top: 8px;
  padding: 0 16px;
  border: 3px solid var(--ink);
  border-radius: 28px 28px 0 0;
  border-bottom: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 85% 18%, #fff4a8 0 34px, transparent 36px),
    linear-gradient(180deg, #a9e5ff 0%, #e4f7ff 100%);
}
.hill::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 26px;
  background: var(--grass);
  border-top: 3px solid var(--ink);
  z-index: 3;
}

.contender {
  --h: 110px;
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1;
  max-width: 260px;
  flex-direction: column;
  align-items: center;
  margin-bottom: 26px;
}
.avatar {
  font-size: 84px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  filter: drop-shadow(3px 4px 0 rgba(36, 27, 69, 0.25));
  transition: transform 0.4s;
}
.avatar.poked { animation: poke 0.6s; }
.crown {
  height: 0;
  font-size: 46px;
  line-height: 1;
  opacity: 0;
  transform: translateY(-40px) scale(0.3);
  transition: opacity 0.5s, transform 0.6s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.leader .crown { height: 46px; opacity: 1; transform: none; animation: bob 2s ease-in-out infinite; }
.leader .avatar { animation: victory 2.4s ease-in-out infinite; }
.leader .avatar { filter: drop-shadow(0 0 16px var(--gold)) drop-shadow(3px 4px 0 rgba(36, 27, 69, 0.25)); }
.trailing .avatar { transform: rotate(-8deg) scale(0.9); }
.trailing .avatar::after { content: "💧"; font-size: 28px; position: absolute; margin: -8px 0 0 -14px; animation: drip 1.8s infinite; }
.tied .avatar { animation: bob 2.6s ease-in-out infinite; }

.pedestal {
  width: 100%;
  height: var(--h);
  padding-top: 10px;
  border: 3px solid var(--ink);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  text-align: center;
  background: repeating-linear-gradient(45deg, #c7b3ff 0 14px, #b9a1ff 14px 28px);
  transition: height 1s cubic-bezier(0.3, 1.4, 0.5, 1);
  overflow: hidden;
}
.contender[data-id="anna"] .pedestal { background: repeating-linear-gradient(45deg, #ffc2dd 0 14px, #ffb0d2 14px 28px); }
.leader .pedestal { box-shadow: 0 0 0 4px var(--gold); }
.pname { font-weight: 900; font-size: 1.15rem; }
.pscore { font-size: clamp(2rem, 9vw, 3.2rem); font-weight: 900; line-height: 1.05; text-shadow: 2px 2px 0 #fff; }
.plabel { font-size: 0.75rem; font-weight: 800; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.08em; }

.verdict {
  margin: 0;
  padding: 16px 20px;
  border: 3px solid var(--ink);
  border-radius: 0 0 28px 28px;
  background: var(--paper);
  text-align: center;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}

.actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: center; margin: 28px 0; }

/* ----- feed & cases ----- */
.feed h2 { margin-bottom: 12px; text-shadow: 2px 2px 0 #fff; }
#feed, .cases { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.entry, .case {
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 3px 3px 0 var(--ink);
  animation: pop 0.35s backwards;
}
.entry { display: flex; gap: 12px; align-items: center; padding: 12px 14px; }
.entry.won, .case.won { border-left-width: 10px; border-left-color: var(--good); }
.entry.lost, .case.lost { border-left-width: 10px; border-left-color: var(--bad); }
.entry-avatar, .case-avatar { font-size: 34px; }
.entry-body { flex: 1; min-width: 0; }
.entry-reason { margin: 0; font-weight: 800; overflow-wrap: anywhere; }
.entry-meta { margin: 2px 0 0; font-size: 0.8rem; font-weight: 700; opacity: 0.65; }
.entry-note { margin: 6px 0 0; font-size: 0.85rem; font-style: italic; font-weight: 700; }
.entry-pts {
  min-width: 64px;
  padding: 4px 10px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 900;
  color: #fff;
}
.won .entry-pts { background: var(--good); }
.lost .entry-pts { background: var(--bad); }

.case { display: flex; flex-direction: column; gap: 8px; padding: 16px; transition: opacity 0.25s, transform 0.25s; }
.case.gone { opacity: 0; transform: scale(0.9) rotate(-2deg); }
.case-head { display: flex; align-items: center; gap: 10px; }
.case-title { flex: 1; font-size: 1.1rem; font-weight: 900; }
.case-actions { display: flex; gap: 10px; }
.case-actions .btn { flex: 1; }
.case > .btn { align-self: flex-start; padding: 8px 16px; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.tab {
  padding: 8px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
.tab.active { background: var(--gold); box-shadow: 2px 2px 0 var(--ink); }
.tab b { margin-left: 4px; padding: 0 7px; border-radius: 999px; background: var(--ink); color: #fff; font-size: 0.8rem; }
.tab.logout { margin-left: auto; }

footer { padding: 32px 0 24px; text-align: center; font-size: 0.85rem; font-weight: 700; opacity: 0.6; }

/* ----- dialog ----- */
dialog { width: min(480px, calc(100% - 24px)); max-height: calc(100vh - 24px); padding: 24px; color: var(--ink); overflow: auto; }
dialog::backdrop { background: rgba(36, 27, 69, 0.55); backdrop-filter: blur(3px); }
dialog[open] { animation: pop 0.3s; }
.close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}
.whoami { margin: -8px 0 0; font-weight: 700; }
.link { padding: 0; border: 0; background: none; color: var(--purple); font: inherit; font-weight: 800; text-decoration: underline; cursor: pointer; }
fieldset { margin: 0; padding: 0; border: 0; }
legend { padding: 0; margin-bottom: 8px; font-weight: 800; }
legend output { margin-left: 6px; padding: 2px 10px; border: 3px solid var(--ink); border-radius: 999px; background: var(--gold); }

.pills { display: flex; flex-wrap: wrap; gap: 10px; }
.pill { flex: 1; min-width: 130px; cursor: pointer; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  display: block;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  text-align: center;
  font-weight: 800;
  transition: transform 0.1s;
}
.pill:hover span { transform: rotate(-1deg); }
.pill input:checked + span { background: var(--gold); box-shadow: 3px 3px 0 var(--ink); transform: translate(-1px, -1px); }
.pill.won input:checked + span { background: #a8f0cd; }
.pill.lost input:checked + span { background: #ffb3c1; }
.pill input:focus-visible + span { outline: 4px solid var(--purple); outline-offset: 2px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ----- clouds, toast, confetti ----- */
.clouds { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.clouds span { position: absolute; font-size: 70px; opacity: 0.8; animation: drift 60s linear infinite; }
.clouds span:nth-child(1) { top: 6%; left: -10%; }
.clouds span:nth-child(2) { top: 30%; left: -10%; animation-duration: 90s; animation-delay: -30s; font-size: 50px; }
.clouds span:nth-child(3) { top: 62%; left: -10%; animation-duration: 75s; animation-delay: -55s; font-size: 90px; opacity: 0.5; }

#toast { position: fixed; bottom: 20px; left: 50%; z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; transform: translateX(-50%); width: min(420px, 100% - 32px); pointer-events: none; }
.toast-item { padding: 12px 18px; border: 3px solid var(--ink); border-radius: 14px; background: var(--gold); box-shadow: var(--shadow); font-weight: 800; animation: pop 0.3s; transition: opacity 0.4s, transform 0.4s; }
.toast-item.bad { background: #ffb3c1; }
.toast-item.out { opacity: 0; transform: translateY(10px); }

.rain { position: fixed; top: -60px; z-index: 200; pointer-events: none; animation: fall linear forwards; }

/* ----- animations ----- */
@keyframes pop { from { opacity: 0; transform: scale(0.85) translateY(8px); } }
@keyframes bob { 50% { transform: translateY(-8px) rotate(3deg); } }
@keyframes victory { 50% { transform: translateY(-10px) scale(1.06) rotate(-3deg); } }
@keyframes poke { 30% { transform: scale(1.35) rotate(-14deg); } 60% { transform: scale(0.9) rotate(10deg); } }
@keyframes drip { 0% { opacity: 0; transform: translateY(-10px); } 40% { opacity: 1; } 100% { opacity: 0; transform: translateY(24px); } }
@keyframes drift { to { transform: translateX(130vw); } }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); } }

@media (max-width: 520px) {
  .hill { height: 380px; gap: 12px; }
  .avatar { font-size: 60px; }
  .crown { font-size: 34px; }
  .leader .crown { height: 34px; }
  .entry-pts { min-width: 52px; font-size: 1.1rem; }
}

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