:root {
  --ink: #111;
  --paper: #fffdf5;
  --yellow: #ffd60a;
  --red: #e63946;
  --blue: #2563eb;
  --green: #16a34a;
  --muted: #5b5b5b;
  --shadow: 4px 4px 0 var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: 'Rubik', system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--yellow);
  background-image: radial-gradient(rgba(0, 0, 0, .13) 1.5px, transparent 1.6px);
  background-size: 12px 12px;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .comic { font-family: 'Rubik Mono One', 'Rubik', sans-serif; font-weight: 400; letter-spacing: .5px; margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app { max-width: 640px; margin: 0 auto; padding: 0 16px 96px; }
.splash { text-align: center; padding: 30vh 0; font-family: 'Rubik Mono One', sans-serif; font-size: 22px; }

/* ---------- shared ---------- */
.panel {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: var(--shadow); padding: 14px; margin: 14px 0;
}
.section-title { font-size: 15px; margin: 22px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-title .count { background: var(--ink); color: #fff; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-family: 'Rubik', sans-serif; font-weight: 700; }
.muted { color: var(--muted); font-size: 14px; }
.btn {
  border: 3px solid var(--ink); border-radius: 12px; background: #fff; padding: 9px 14px;
  font-weight: 700; box-shadow: 3px 3px 0 var(--ink); white-space: nowrap;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.go { background: var(--green); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.yellow { background: var(--yellow); }
.btn.small { padding: 5px 10px; font-size: 14px; box-shadow: 2px 2px 0 var(--ink); }
.btn.wide { width: 100%; padding: 13px; font-size: 17px; }
.link { background: none; border: 0; padding: 4px; color: var(--blue); text-decoration: underline; font-size: 14px; }
.tag { display: inline-block; border: 2px solid var(--ink); border-radius: 99px; padding: 3px 10px; font-size: 13px; font-weight: 700; background: #fff; }
.tag.wait { background: #fde68a; }
.tag.ok { background: #fff; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; box-shadow: 2px 2px 0 var(--ink); }
.tick {
  width: 22px; height: 22px; flex: none; padding: 3px; vertical-align: -5px;
  background: var(--green); border: 2.5px solid var(--ink); border-radius: 50%; transform: rotate(-8deg);
}
.tick path { fill: none; stroke: #fff; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.btn .tick { background: none; border: 0; padding: 0; width: 20px; height: 20px; vertical-align: -4px; transform: none; }
.stars { font-weight: 700; color: #b45309; white-space: nowrap; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 44px; height: 44px; font-size: 24px; border-radius: 50%;
  border: 3px solid var(--ink); box-shadow: 2px 2px 0 var(--ink);
}
.avatar.big { width: 84px; height: 84px; font-size: 46px; }
.avatar.tiny { width: 28px; height: 28px; font-size: 15px; border-width: 2px; box-shadow: none; }
.bar { height: 16px; border: 2px solid var(--ink); border-radius: 99px; background: #fff; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--red); border-right: 2px solid var(--ink); min-width: 0; transition: width .4s; }
.bar > i[style*="width:0%"] { border-right: 0; }

/* ---------- header / nav ---------- */
.top {
  position: sticky; top: 0; z-index: 5; margin: 0 -16px; padding: 12px 16px;
  background: var(--red); color: #fff; border-bottom: 3px solid var(--ink);
  display: flex; align-items: center; gap: 12px;
}
.top .who { flex: 1; min-width: 0; }
.top .who b { display: block; font-family: 'Rubik Mono One', sans-serif; font-weight: 400; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 2px 2px 0 var(--ink); }
.top .who span { font-size: 13px; opacity: .95; }
.top .score { background: var(--yellow); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 4px 12px; font-family: 'Rubik Mono One', sans-serif; font-size: 18px; box-shadow: 3px 3px 0 var(--ink); transform: rotate(3deg); }
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; background: var(--paper);
  border-top: 3px solid var(--ink); display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav button { flex: 1; max-width: 160px; background: none; border: 0; padding: 8px 4px 10px; font-size: 12px; font-weight: 700; position: relative; }
.nav button span { display: block; font-size: 24px; line-height: 1.2; }
.nav button.on { background: var(--yellow); }
.nav .badge { position: absolute; top: 4px; left: 55%; background: var(--red); color: #fff; border: 2px solid var(--ink); border-radius: 99px; font-size: 11px; min-width: 20px; padding: 0 5px; }

/* ---------- login / setup ---------- */
.hero-title { text-align: center; padding: 34px 0 6px; }
.hero-title h1 { font-size: clamp(30px, 9vw, 46px); color: #fff; -webkit-text-stroke: 2px var(--ink); text-shadow: 4px 4px 0 var(--ink); transform: rotate(-2deg); }
.hero-title p { font-weight: 700; margin: 12px 0 0; }
.hero-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 22px; }
.hero-card {
  background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow);
  padding: 16px 8px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.hero-card:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.hero-card b { font-family: 'Rubik Mono One', sans-serif; font-weight: 400; font-size: 14px; overflow-wrap: anywhere; }
.hero-card small { color: var(--muted); }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 14px 0; }
.pin-dots i { width: 18px; height: 18px; border: 3px solid var(--ink); border-radius: 50%; background: #fff; }
.pin-dots i.on { background: var(--ink); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-pad button { padding: 14px 0; font-size: 22px; font-weight: 700; }

/* ---------- forms ---------- */
.field { display: block; margin: 10px 0; font-size: 14px; font-weight: 700; }
input[type=text], input[type=number], input[type=password], input:not([type]), select {
  width: 100%; margin-top: 4px; padding: 10px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; font-size: 16px; font-weight: 400;
}
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; min-height: 40px; padding: 4px 10px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; font-weight: 500; font-size: 14px; }
.chips.emoji span { font-size: 22px; padding: 2px; }
.chips.swatch span { border-radius: 50%; padding: 0; }
.chips input:checked + span { box-shadow: 0 0 0 3px var(--yellow), 0 0 0 6px var(--ink); }
.chips:not(.swatch) input:checked + span { background: var(--yellow); box-shadow: 2px 2px 0 var(--ink); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* ---------- missions ---------- */
.mission { display: flex; align-items: center; gap: 12px; padding: 12px; margin: 10px 0; }
.mission .ico { font-size: 30px; flex: none; }
.mission .body { flex: 1; min-width: 0; }
.mission .body b { display: block; overflow-wrap: anywhere; }
.mission .act { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; max-width: 46%; text-align: right; }
.mission.done { background: #f0fdf4; }
.mission.rejected { background: #fff1f2; }
.sentback { color: var(--red); font-size: 13px; font-weight: 700; margin-top: 3px; }
.progress-panel { display: flex; align-items: center; gap: 12px; }
.progress-panel .bar { flex: 1; }
.progress-panel b { font-family: 'Rubik Mono One', sans-serif; font-weight: 400; }

/* ---------- squad ---------- */
.racer { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 2px dashed #ccc; }
.racer:last-child { border-bottom: 0; }
.racer .place { font-family: 'Rubik Mono One', sans-serif; width: 26px; text-align: center; font-size: 18px; }
.racer .info { flex: 1; min-width: 0; }
.racer .info .line { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.racer .info .line b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.racer .meta { font-size: 12px; color: var(--muted); margin: 2px 0 5px; }
.reward { padding: 10px 0; border-bottom: 2px dashed #ccc; }
.reward:last-child { border-bottom: 0; }
.reward .line { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.reward.unlocked .bar > i { background: var(--green); }
.reward .who { display: flex; gap: 4px; margin-top: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.fame { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 2px dashed #ccc; font-size: 14px; }
.fame:last-child { border-bottom: 0; }

/* ---------- hq ---------- */
.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 2px dashed #ccc; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list-row .grow small { display: block; color: var(--muted); }
.list-row .btns { display: flex; gap: 6px; flex: none; }
.group-head { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 14px 0 2px; }
.group-head:first-child { margin-top: 0; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; padding: 12px; overflow-y: auto; }
.overlay .sheet { background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; box-shadow: 6px 6px 0 var(--ink); padding: 18px; width: 100%; max-width: 460px; margin: auto; }
.sheet h2 { font-size: 18px; margin-bottom: 8px; }
#toast { position: fixed; top: 76px; left: 0; right: 0; z-index: 30; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
#toast div {
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px 18px; font-family: 'Rubik Mono One', sans-serif; font-size: 16px; text-align: center;
  animation: pow 2.4s ease forwards;
}
#toast div.err { background: var(--red); color: #fff; font-family: 'Rubik', sans-serif; font-weight: 700; }
@keyframes pow {
  0% { transform: scale(.3) rotate(-8deg); opacity: 0; }
  12% { transform: scale(1.15) rotate(3deg); opacity: 1; }
  20%, 85% { transform: scale(1) rotate(-1deg); opacity: 1; }
  100% { transform: scale(.9); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #toast div { animation: none; }
  .bar > i { transition: none; }
}
@media (min-width: 520px) {
  .hero-grid { grid-template-columns: repeat(4, 1fr); }
  .overlay { align-items: center; }
}
