:root {
  --ink: #fdfbff;
  --muted: #b9b3d6;
  --panel: rgba(27, 20, 64, 0.92);
  --panel-edge: #4b3c9c;
  --pill: rgba(20, 14, 48, 0.72);
  --accent: #ffd23f;
  --accent-ink: #3a2600;
  --bad: #ff5a5a;
  --paper: #fffdf6;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3fb4ff; color: var(--ink); font-family: var(--font); }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#view { position: fixed; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; color: var(--ink); cursor: pointer;
  background: #3a2d86; border: 2px solid #6a58d0; border-bottom-width: 4px; border-radius: 12px;
  padding: 8px 14px; font-size: 1rem; line-height: 1.1;
  transition: transform 0.06s ease, background 0.15s;
}
.btn:hover { background: #4a3aa6; }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: #c79a00; }
.btn.primary:hover { background: #ffe06e; }
.btn.huge { font-size: 1.5rem; padding: 14px 28px; width: 100%; margin-top: 12px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.off { opacity: 0.5; }

/* ---------- panels & screens ---------- */
.panel {
  background: var(--panel); border: 3px solid var(--panel-edge); border-radius: 20px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45); padding: 20px;
}
.screen, .modal {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: safe center;
  padding: 16px; z-index: 20; overflow-y: auto; touch-action: pan-y;
}
.screen { background: radial-gradient(ellipse at top, #ffe27a 0%, #ff8fb1 38%, #3a2d86 100%); }
.modal { background: rgba(10, 6, 30, 0.55); }
h1, h2 { margin: 0 0 12px; }
h1 { font-size: 2.2rem; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }

/* ---------- lobby ---------- */
.lobby-panel { width: min(920px, 100%); }
.lobby-cols { display: flex; gap: 28px; flex-wrap: wrap; }
.lobby-col { flex: 1 1 340px; min-width: 0; }
.lobby-panel label, .lobby-panel .label { display: block; font-weight: 700; margin: 14px 0 6px; }
.lobby-panel small { color: var(--muted); font-weight: 400; }
.tagline { color: var(--muted); margin: -4px 0 0; }
input {
  font: inherit; font-size: 1.2rem; width: 100%; margin-top: 6px; padding: 10px 12px; color: var(--ink);
  background: #120d33; border: 2px solid #5b4cb0; border-radius: 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--accent); }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color-btn { width: 44px; height: 44px; border-radius: 50%; border: 4px solid transparent; cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25); }
.color-btn.sel { border-color: #fff; transform: scale(1.12); }
.modes { display: flex; gap: 10px; }
.mode-btn {
  flex: 1; font: inherit; font-weight: 800; font-size: 1.05rem; color: var(--ink); cursor: pointer;
  background: #120d33; border: 3px solid #5b4cb0; border-radius: 14px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.mode-btn .mode-emoji { font-size: 2rem; }
.mode-btn small { font-size: 0.78rem; }
.maps { flex-wrap: wrap; gap: 8px; }
.map-btn { flex: 1 1 30%; font-size: 0.85rem; padding: 6px 4px; }
.map-btn .mode-emoji { font-size: 1.5rem; }
.mode-btn.sel { border-color: var(--accent); background: #2d2466; }
.how { margin-top: 14px; font-size: 0.92rem; color: var(--muted); }
.how p { margin: 4px 0; }
kbd { background: #2d2466; border: 1px solid #5b4cb0; border-bottom-width: 3px; border-radius: 6px; padding: 0 5px; font-family: inherit; }

.hero-row { display: flex; gap: 14px; align-items: stretch; }
.preview { width: 180px; height: 196px; border-radius: 16px; background: linear-gradient(#7fd0ff, #d6f3ff 70%, #3a3358 70%); border: 3px solid #5b4cb0; flex: none; }
.hero-buttons { display: flex; flex-direction: column; gap: 8px; flex: 1; justify-content: center; }
.hero-buttons .btn { font-size: 1.1rem; padding: 12px 10px; }
.gallery { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding: 4px 2px 8px; touch-action: pan-x; }
.gallery:empty { display: none; }
.card {
  flex: none; width: 68px; height: 84px; padding: 3px; border-radius: 12px; cursor: pointer;
  background: var(--paper); border: 4px solid transparent; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.card img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.card.sel { border-color: var(--accent); transform: translateY(-3px); }
.extras { display: flex; gap: 10px; }
.extra {
  flex: 1; font: inherit; font-weight: 800; color: var(--ink); cursor: pointer; display: flex; align-items: center; gap: 10px;
  background: #120d33; border: 3px solid #5b4cb0; border-radius: 14px; padding: 6px 10px;
}
.extra canvas { width: 56px; height: 56px; background: var(--paper); border-radius: 10px; }

/* ---------- drawing studio ---------- */
.studio {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; gap: 8px;
  background: #2d2466; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.studio-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.studio-bar h2 { margin: 0; font-size: 1.4rem; text-align: center; }
.studio-bar .btn { font-size: 1.2rem; padding: 10px 18px; }
.studio-main { flex: 1; min-height: 0; display: flex; gap: 10px; }
.studio-side { display: flex; flex-direction: column; gap: 8px; align-items: center; flex: none; width: 76px; overflow-y: auto; touch-action: pan-y; }
.studio-side.wide { width: 172px; align-items: stretch; }
.sheet-wrap { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
.sheet-box { position: relative; height: 100%; max-width: 100%; display: flex; align-items: center; justify-content: center; }
.sheet-box canvas { max-height: 100%; max-width: 100%; height: 100%; width: auto; border-radius: 14px; display: block; }
#sheet-guide { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); }
#sheet { position: absolute; inset: 0; margin: auto; touch-action: none; cursor: crosshair; }
.tool {
  width: 64px; height: 64px; flex: none; font-size: 1.8rem; cursor: pointer; display: grid; place-items: center;
  background: #120d33; border: 3px solid #5b4cb0; border-radius: 16px; color: var(--ink); padding: 0;
}
.tool.sel { border-color: var(--accent); background: #4a3aa6; }
.brushes { display: flex; flex-direction: column; gap: 8px; }
.brush i { display: block; border-radius: 50%; background: #fff; }
.swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.25); cursor: pointer; padding: 0;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}
.swatch.sel { border-color: #fff; transform: scale(1.12); box-shadow: 0 0 0 3px var(--accent); }
.swatches.small { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.side-label { font-weight: 700; font-size: 0.9rem; margin: 10px 0 6px; }
.kinds { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.kind { font-size: 0.95rem; padding: 8px 6px; }
.kind.sel { background: var(--accent); color: var(--accent-ink); border-color: #c79a00; }
.studio-tip { font-size: 0.85rem; color: var(--muted); margin: 10px 0 0; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud button { pointer-events: auto; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  gap: 10px; padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}
.hud-left, .hud-right { display: flex; gap: 8px; }
.hud-left { flex-direction: column; align-items: flex-start; }
.hud-center { position: absolute; left: 50%; transform: translateX(-50%); top: max(10px, env(safe-area-inset-top)); }
.pill {
  background: var(--pill); border-radius: 999px; padding: 5px 12px; backdrop-filter: blur(4px);
  font-weight: 700; display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.scores { display: flex; flex-direction: column; gap: 4px; }
.scores .pill { font-size: 0.9rem; padding: 3px 10px; }
.scores .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.scores .away { opacity: 0.5; }
.clock {
  background: var(--pill); border-radius: 999px; padding: 6px 16px; font-weight: 800; font-size: 1.5rem;
  display: flex; align-items: center; gap: 14px; backdrop-filter: blur(4px); white-space: nowrap;
}
.timer { font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--bad); animation: pulse 0.5s infinite alternate; }

.banner {
  position: absolute; top: 28%; left: 50%; transform: translate(-50%, -50%); text-align: center;
  font-size: clamp(2rem, 7vw, 4.5rem); font-weight: 900; color: #fff; white-space: nowrap;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 24px rgba(0, 0, 0, 0.35);
  animation: pop 0.3s ease-out;
}
.banner small { display: block; font-size: 0.4em; font-weight: 700; }

/* at the bottom, between the thumbs: the hooks are up in the sky */
.waiting { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(440px, 92vw); text-align: center; }
.waiting .panel { padding: 10px 16px 12px; }
.waiting .btn.huge { margin-top: 0; }
.waiting p { margin: 8px 0 0; font-size: 0.9rem; }
.join-url { font-weight: 800; color: var(--accent); word-break: break-all; -webkit-user-select: text; user-select: text; pointer-events: auto; }

/* touch: ◀ ▶ under the left thumb, jump and rope under the right */
.touch { position: absolute; inset: 0; pointer-events: none; }
.pad {
  position: absolute; left: max(20px, env(safe-area-inset-left)); bottom: max(28px, env(safe-area-inset-bottom));
  width: 236px; height: 112px; display: flex; gap: 12px; pointer-events: auto; touch-action: none;
}
.pad span {
  flex: 1; display: grid; place-items: center; font-size: 2.6rem; color: #fff; border-radius: 26px;
  background: rgba(20, 14, 48, 0.45); border: 3px solid rgba(255, 255, 255, 0.45);
}
.pad[data-dir="-1"] .pad-l, .pad[data-dir="1"] .pad-r { background: rgba(255, 210, 63, 0.6); }
.tbtn {
  pointer-events: auto; touch-action: none; color: #fff; padding: 0; position: absolute; display: grid; place-items: center;
  background: rgba(20, 14, 48, 0.45); border: 3px solid rgba(255, 255, 255, 0.45); border-radius: 50%;
}
.tbtn.held { background: rgba(255, 210, 63, 0.6); }
.tbtn.jump { right: max(24px, env(safe-area-inset-right)); bottom: max(28px, env(safe-area-inset-bottom)); width: 116px; height: 116px; font-size: 3rem; }
.tbtn.rope { right: max(156px, calc(env(safe-area-inset-right) + 136px)); bottom: max(70px, env(safe-area-inset-bottom)); width: 116px; height: 116px; font-size: 3rem; }

/* ---------- result ---------- */
.result-panel { width: min(480px, 100%); text-align: center; }
.result-panel h2 { font-size: 2rem; }
.result-panel .big { font-size: 4rem; margin: 6px 0; }
.result-panel table { margin: 10px auto; border-collapse: collapse; font-size: 1.2rem; font-weight: 700; }
.result-panel td { padding: 4px 10px; text-align: left; }
.result-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.result-buttons .btn { font-size: 1.2rem; padding: 12px 18px; }

/* ---------- portrait hint (tablets and phones only) ---------- */
.rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .rotate {
    display: flex; position: fixed; inset: 0; z-index: 50; flex-direction: column; align-items: center; justify-content: center;
    background: #1b1440; font-size: 1.4rem; font-weight: 700;
  }
  .rotate div { font-size: 4rem; animation: tilt 1.6s ease-in-out infinite; }
}

@media (max-height: 500px) {
  .pad { width: 196px; height: 92px; }
  .tbtn.jump, .tbtn.rope { width: 92px; height: 92px; font-size: 2.3rem; }
  .tbtn.rope { right: max(128px, calc(env(safe-area-inset-right) + 112px)); bottom: max(54px, env(safe-area-inset-bottom)); }
  .clock { font-size: 1.15rem; padding: 4px 12px; }
  .banner { top: 34%; }
  .tool { width: 48px; height: 48px; font-size: 1.4rem; }
  .studio-side { width: 58px; }
  .studio-side.wide { width: 150px; }
  .studio-bar .btn { font-size: 1rem; padding: 7px 14px; }
  .studio-tip { display: none; }
  .waiting { width: min(340px, 92vw); }
  .waiting p.muted { display: none; }
}

@keyframes pop { from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.55; } }
@keyframes tilt { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-90deg); } }
