/* Snowglobe Run: full-screen canvas town with a HUD, a dock and native <dialog> panels. */
:root {
  --ink: #17324d;
  --paper: #f7fbff;
  --sky: #9fd3f5;
  --accent: #d94848;
  --pine: #2f7a4f;
  --gold: #f2c14e;
  --line: #c7dcec;
  --ahead: #2f7a4f;
  --behind: #c2410c;
  font-family: "Fredoka", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sky); }
canvas#town { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; }

.hud {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: center;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 14px; font-size: 15px; box-shadow: 0 3px 0 var(--ink); white-space: nowrap;
}
.hud-total b { font-size: 18px; color: var(--accent); }
.hud-day { padding-left: 10px; border-left: 2px solid var(--line); }

.dock {
  position: fixed; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px; background: var(--paper);
  border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink);
}
.dock button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none; font: inherit; font-size: 22px; color: var(--ink);
  padding: 4px 8px; border-radius: 12px; cursor: pointer; min-width: 56px;
}
.dock button span { font-size: 11px; font-weight: 600; }
.dock button:hover, .dock button:focus-visible { background: #e3f1fb; outline: none; }

.toasts { position: fixed; top: 56px; left: 16px; right: 16px; display: grid; gap: 6px; justify-items: center; pointer-events: none; }
.toast {
  margin: 0; padding: 8px 14px; border-radius: 12px; background: var(--paper);
  border: 2px solid var(--ink); animation: fade 6s forwards; max-width: 420px;
}
.toast.error { border-color: var(--accent); color: var(--accent); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

.account { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 12px; font-size: 12px; background: #fffc; padding: 2px 8px; border-radius: 8px; }
@media (max-width: 640px) { .account { top: auto; bottom: 96px; right: 8px; } }

dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto;
  border: 4px solid var(--ink); border-radius: 22px; background: var(--paper); color: var(--ink);
  padding: 18px 20px; box-shadow: 0 6px 0 var(--ink);
}
dialog::backdrop { background: #17324d88; }
dialog h2 { margin: 0 0 10px; font-size: 24px; }
dialog h3 { margin: 18px 0 6px; font-size: 16px; }
.hint { font-size: 13px; opacity: .75; margin-top: 0; }
.error { color: var(--accent); }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff; border: 3px solid var(--ink); border-radius: 12px;
  padding: 6px 14px; box-shadow: 0 3px 0 var(--ink);
}
button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button.ghost { background: var(--paper); color: var(--ink); }
button.small { padding: 0 8px; box-shadow: none; border-width: 2px; }
button.link { background: none; border: 0; box-shadow: none; color: inherit; padding: 0; text-decoration: underline; font-weight: 400; }
button.strava { background: #fc4c02; }
dialog > form[method="dialog"] { margin-top: 16px; text-align: right; }
form.inline { display: inline; }

.stack { display: grid; gap: 10px; }
.stack label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.stack label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
input, select { font: inherit; font-size: 16px; padding: 6px 10px; border: 2px solid var(--ink); border-radius: 10px; background: #fff; color: var(--ink); }

.leaders { padding-left: 24px; margin: 0; }
.leaders li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.leaders b { margin-left: auto; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions { margin-left: auto; display: flex; gap: 6px; }

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin-bottom: 10px; }
.bar-label { font-weight: 600; }
.bar-label em { font-style: normal; font-size: 12px; }
.bar-label em.ahead { color: var(--ahead); }
.bar-label em.behind { color: var(--behind); }
.bar-num { font-size: 12px; text-align: right; }
.bar { grid-column: 1 / -1; position: relative; height: 16px; background: #e3eef6; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; }
/* Bars are scaled to one runner's even share of the goal (--goal set inline). */
.bar .fill { height: 100%; width: min(100%, calc(var(--pct) / (var(--goal) / var(--share)) * 100%)); }
.bar .pace { position: absolute; top: -2px; bottom: -2px; width: 3px; background: var(--ink); left: min(100%, calc(var(--pct) / (var(--goal) / var(--share)) * 100%)); }

.doors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.door {
  aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 10px; background: var(--pine); color: #fff;
  display: grid; place-items: center; position: relative; text-align: center; padding: 2px;
}
.door.open { background: #fff7e6; color: var(--ink); }
.door .num { position: absolute; top: 2px; left: 5px; font-size: 11px; font-weight: 700; }
.door .who { font-size: 26px; line-height: 1; }
.door .name { font-size: 9px; line-height: 1.1; }
@media (max-width: 400px) { .door .name { display: none; } }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; overflow: auto; }
.login .card { background: var(--paper); border: 4px solid var(--ink); border-radius: 22px; padding: 24px; text-align: center; max-width: 380px; box-shadow: 0 6px 0 var(--ink); }
.login h1 { margin: 0 0 8px; }
