:root {
  --card: rgba(255, 255, 255, 0.82);
  --ink: #2b2340;
  --muted: #6d6585;
  --track: rgba(43, 35, 64, 0.12);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1b1630; color: var(--ink);
  font: 14px/1.35 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.card {
  background: var(--card);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  padding: 10px 14px;
}

#hud {
  position: fixed; top: 12px; left: 12px; right: 12px;
  display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start;
  pointer-events: none;
}
#petname { font-weight: 800; font-size: 20px; }
#age { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
#species { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#vote[hidden] { display: none; }
#vote { pointer-events: auto; min-width: 220px; display: grid; gap: 6px; }
.vote-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.vote-head span { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
#vote-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
#vote-opts button {
  position: relative; overflow: hidden; display: flex; justify-content: space-between; align-items: center; gap: 6px;
  font: inherit; font-weight: 700; font-size: 13px; color: var(--ink);
  background: rgba(43, 35, 64, 0.06); border: 2px solid transparent; border-radius: 10px;
  padding: 6px 9px; cursor: pointer; text-align: left;
}
#vote-opts button:hover { border-color: rgba(43, 35, 64, 0.2); }
#vote-opts button:focus-visible { outline: 3px solid #7c4dff; outline-offset: 1px; }
#vote-opts button[aria-pressed="true"] { border-color: #7c4dff; background: rgba(124, 77, 255, 0.12); }
#vote-opts button.lead .vname::after { content: " 👑"; }
#vote-opts .vname, #vote-opts .vcount { position: relative; z-index: 1; }
#vote-opts .vcount { color: var(--muted); font-variant-numeric: tabular-nums; }
#vote-opts i { position: absolute; inset: 0 auto 0 0; background: rgba(124, 77, 255, 0.14); transition: width 0.4s; }
.vote-wait { margin: 0; color: var(--muted); font-size: 13px; }
#bars { min-width: 210px; display: grid; gap: 5px; }
.bar { display: grid; grid-template-columns: 78px 1fr; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.bar i { display: block; height: 10px; border-radius: 6px; background: var(--track); overflow: hidden; }
.bar b { display: block; height: 100%; width: 0; border-radius: 6px; background: #4caf50; transition: width 0.4s, background 0.4s; }
#mess { font-size: 12px; color: var(--muted); min-height: 1em; }
#crowd { margin-left: auto; font-weight: 600; text-align: right; }
#crowd small { display: block; color: var(--muted); font-weight: 500; }

#log {
  position: fixed; left: 12px; bottom: 12px; width: min(300px, calc(100vw - 24px));
  max-height: 140px; overflow: hidden; font-size: 12px; padding: 8px 12px;
  pointer-events: none; display: flex; flex-direction: column-reverse; gap: 2px;
}
#log:empty { display: none; }
#log div { animation: fade 0.3s; }
#log b { font-weight: 700; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

#help {
  position: fixed; right: 12px; bottom: 12px; font-size: 12px; color: var(--muted);
  max-width: 270px; pointer-events: none;
}
#corner { position: fixed; right: 12px; top: 92px; display: flex; gap: 8px; }
#corner button { border: 0; cursor: pointer; font: inherit; font-weight: 600; color: var(--ink); }
#info-btn { width: 40px; padding: 10px 0; font-weight: 800; }
#corner button:focus-visible, #intro-go:focus-visible { outline: 3px solid #7c4dff; outline-offset: 2px; }

#intro {
  border: 0; padding: 0; border-radius: 20px; max-width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); color: var(--ink); background: #fffdf8;
  box-shadow: 0 20px 60px rgba(20, 10, 50, 0.35);
}
#intro::backdrop { background: rgba(20, 14, 45, 0.45); backdrop-filter: blur(3px); }
#intro[open] { animation: pop 0.25s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.intro-body { padding: 24px 24px 20px; display: grid; gap: 10px; font-size: 15px; line-height: 1.45; -webkit-user-select: text; user-select: text; }
.intro-body p { margin: 0; }
.intro-eyebrow { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: #7c4dff; }
#intro h1 { margin: 0 0 2px; font-size: 26px; line-height: 1.1; text-wrap: balance; }
.intro-status { background: rgba(124, 77, 255, 0.1); border-radius: 12px; padding: 10px 12px; font-weight: 600; }
.intro-status[hidden] { display: none; }
.intro-how { list-style: none; margin: 2px 0; padding: 0; display: grid; gap: 8px; }
.intro-how li { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 10px; }
.intro-how span { font-size: 22px; width: 34px; height: 34px; display: grid; place-items: center; background: rgba(43, 35, 64, 0.06); border-radius: 10px; }
#intro form { margin: 6px 0 0; }
#intro-go {
  width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; cursor: pointer;
  font: inherit; font-weight: 800; font-size: 16px; color: #fff; background: #ff7043;
}
#intro-go:hover { background: #f4511e; }
.intro-fine { font-size: 12px; color: var(--muted); text-align: center; }
.intro-fine a { color: inherit; }
@media (prefers-reduced-motion: reduce) { #intro[open] { animation: none; } }
#graves {
  position: fixed; right: 12px; top: 136px; width: min(320px, calc(100vw - 24px));
  max-height: 50vh; overflow: auto;
}
#graves h2 { margin: 0 0 6px; font-size: 16px; }
#graves ol { margin: 0; padding-left: 18px; font-size: 13px; }
#graves li { margin-bottom: 6px; }
#graves li small { color: var(--muted); display: block; }

@media (max-width: 640px) {
  #help { display: none; }
  #namecard { flex: 1; }
  #bars { min-width: 0; flex-basis: 100%; order: 3; }
  #vote { flex-basis: 100%; order: 4; min-width: 0; }
  #crowd { margin-left: 0; }
  #corner { top: auto; bottom: 12px; }
  #graves { top: auto; bottom: 60px; }
  #log { max-height: 80px; width: calc(100vw - 200px); }
  .intro-body { padding: 20px 18px 16px; font-size: 14px; }
  #intro h1 { font-size: 22px; }
}
