/* Graph paper, like the grid the race is played on. */
body {
  overflow-x: hidden;
  background-image:
    linear-gradient(rgba(29, 29, 31, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 29, 31, 0.045) 1px, transparent 1px);
  background-size: 28px 28px;
}

#setup {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: grid;
  gap: 18px;
}

.top { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: start; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { margin: 2px 0 0; }
.mascot { width: 46px; height: 50px; flex: none; animation: hop 2.4s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes hop {
  0%, 70%, 100% { transform: translateY(0) scale(1, 1); }
  76% { transform: translateY(0) scale(1.12, 0.86); }
  84% { transform: translateY(-9px) scale(0.92, 1.1); }
  92% { transform: translateY(0) scale(1.08, 0.92); }
}
@media (prefers-reduced-motion: reduce) { .mascot { animation: none; } }

.join { display: flex; gap: 14px; align-items: center; min-width: 420px; }
.join-text h2 { margin-bottom: 2px; }
.join-text p { margin: 0 0 6px; }
.join-text b { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; overflow-wrap: anywhere; }
.join-text b.room-code { font-size: 26px; letter-spacing: 0.14em; vertical-align: -2px; }
.small { font-size: 13px; }
label.small select { margin-left: 6px; }

.qr { width: 150px; height: 150px; flex: none; }
.qr svg { width: 100%; height: 100%; display: block; border: 2px solid var(--ink); border-radius: 8px; background: #fff; }
.qr.small { width: 84px; height: 84px; }
.qr.tiny { width: 64px; height: 64px; }

.steps { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(480px, 1.7fr); gap: 18px; align-items: start; }
.step { display: grid; gap: 10px; }
.step h2 { margin-bottom: -2px; }
.step p { margin: 0; }

.mark { font-weight: 700; padding: 0 4px; border-radius: 4px; color: #fff; }
.mark.green { background: var(--green); }
.mark.red { background: var(--red); }
.mark.blue { background: var(--blue); }
.mark.orange { background: var(--orange); }
.mark.purple { background: var(--purple); }
.mark.ink { background: var(--ink); }
.legend-more { margin-top: -4px !important; }

/* Custom sprites: one slot per picture. */
.skins { display: grid; gap: 12px; }
.skins-head { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; }
.skins-head p { margin: 4px 0 0; max-width: 760px; }
.skins-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.skin {
  display: grid; justify-items: center; gap: 6px; padding: 10px 8px;
  border: 2px solid var(--line); border-radius: 12px; background: #fffdf7;
  transition: border-color 0.1s ease, background 0.1s ease;
}
.skin.custom { border-color: var(--ink); background: #fff; }
.skin.over { border-color: var(--green); border-style: dashed; background: #effbf4; }
.skin canvas { width: 64px; height: 64px; display: block; }
.skin b { font-size: 13px; text-align: center; }
.skin .row { justify-content: center; gap: 6px; }
.skin .button, .skin button { font-size: 12px; padding: 4px 9px; box-shadow: 2px 2px 0 var(--ink); }
.skin button.ghost { box-shadow: none; }
.skin input[type=file] { display: none; }

.camera { position: relative; aspect-ratio: 16 / 9; background: #1a1a1c; border-radius: 10px; overflow: hidden; border: 2px solid var(--ink); }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera .frame { position: absolute; left: 6%; right: 6%; top: 6%; bottom: 6%; border: 2px dashed rgba(255,255,255,0.75); border-radius: 6px; pointer-events: none; }
.camera-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #ddd; font-weight: 600; background: rgba(0,0,0,0.25); }
.phone-cam { margin-top: 4px; }
.draw-here { display: grid; gap: 6px; padding-top: 12px; border-top: 2px dashed var(--line); }
.draw-here button { justify-self: start; background: #fff7c2; font-family: var(--font-hand); font-size: 17px; }

.tabs .tab { box-shadow: none; border-color: var(--line); background: transparent; }
.tabs .tab.selected { border-color: var(--ink); background: #fff; box-shadow: 3px 3px 0 var(--ink); }
.grid-size { margin-left: auto; }

.editor-wrap { position: relative; border: 3px solid var(--ink); border-radius: 10px; overflow-x: auto; overflow-y: hidden; background: #fffdf7; }
#editor { width: 100%; height: auto; display: block; cursor: crosshair; touch-action: none; }
.editor-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-weight: 600; pointer-events: none; }

/* How hard the level is: five pips in the colour of its level. */
.rating {
  --level: var(--muted);
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 8px 12px; border: 2px solid var(--ink); border-radius: 12px; background: #fffdf7;
}
.rating-head { font-family: var(--font-hand); font-weight: 700; }
.rating-pips { display: inline-flex; gap: 3px; }
.rating-pips i { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: 4px; background: #fff; }
.rating-pips i.on { background: var(--level); }
#rating-label { font-family: var(--font-hand); font-size: 18px; color: var(--ink); text-decoration: underline 3px var(--level); text-underline-offset: 3px; }
.rating.impossible #rating-label { color: var(--red); text-decoration-color: var(--red); }
.rating.impossible #rating-text { color: var(--red); }
#rating-text { flex: 1 1 260px; }
.rating-path { margin-left: auto; }

/* Drawing tools: each shows its tile the way the race draws it. */
.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tools .tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px 4px 4px; font-size: 13px;
  background: #fffdf7; border-color: var(--line); box-shadow: none;
}
.tools .tool:hover { border-color: var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.tools .tool.selected { background: #fff; border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.tools .tool canvas { width: 32px; height: 32px; display: block; }
.tools kbd {
  font: 600 11px ui-monospace, Menlo, Consolas, monospace; color: var(--muted);
  border: 1.5px solid var(--line); border-radius: 5px; padding: 0 4px;
}
.tools .tool.selected kbd { color: var(--ink); border-color: var(--ink); }

.play-row { margin-top: 4px; }
button.big { font-size: 20px; padding: 12px 26px; }

#key-row input { font-size: 13px; }

/* Play view */
#play { position: fixed; inset: 0; background: var(--paper); }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud {
  position: absolute; top: 10px; left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none;
}
.hud-left { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; max-width: 70vw; }
#hud-players { display: flex; flex-wrap: wrap; gap: 6px; }
.hud-level:empty { display: none; }
.hud-player {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px 4px 6px;
  background: rgba(255,255,255,0.9); border: 2px solid var(--ink); border-radius: 999px; font-weight: 700; font-size: 14px;
}
.hud-player .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.hud-player .stat { font-weight: 500; color: var(--ink-soft); font-size: 12px; }
.hud-player.done { background: #fff7c2; }
.hud-join { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.9); border: 2px solid var(--ink); border-radius: 12px; padding: 6px 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

.banner {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-family: var(--font-hand); font-size: clamp(40px, 9vw, 120px); font-weight: 800;
  color: var(--ink); text-shadow: 5px 5px 0 #fff, 7px 7px 0 var(--ink); pointer-events: none; white-space: nowrap;
}
.banner.small { font-size: clamp(28px, 5vw, 64px); }

.play-controls { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.play-controls button { background: rgba(255,255,255,0.9); font-size: 13px; padding: 6px 10px; }
.play-controls button.selected { background: #fff7c2; border-color: var(--ink); }
body.zen .play-controls, body.zen #hud-join, body.zen #play-tools { display: none; }

/* Drawing on the race: a floating tool bar, icons only. */
#play-tools {
  position: absolute; right: 12px; bottom: 12px; display: none; gap: 6px; padding: 8px;
  background: rgba(255,255,255,0.94); border: 2px solid var(--ink); border-radius: 14px; box-shadow: 4px 4px 0 var(--ink);
}
#play-tools .tool span { display: none; }
#play-tools .tool { padding: 4px 6px 4px 4px; }
body.drawing #play-tools { display: flex; }
body.drawing #game { cursor: crosshair; touch-action: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 10;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

@media (max-width: 1000px) {
  .top { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr; }
  .join { min-width: 0; }
}
