/* Mario Paint Together: cream paper, pink toolbars, chunky ink outlines, hard pixel shadows. */
:root {
  --paper: #fdf3d2;
  --paper-2: #fff9e8;
  --grid: #f1e2b4;
  --ink: #33211a;
  --ink-soft: #6b5546;
  --pink: #f7b6ee;
  --pink-deep: #e98ad9;
  --sky: #a9ecff;
  --sky-deep: #6fd0f2;
  --red: #e8202a;
  --blue: #2858d8;
  --green: #1f8a4c;
  --amber: #b86a00;
  --p1: #e8202a;
  --p2: #2858d8;
  --hud: 60px;
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --pixel: "Pixelify Sans", "Press Start 2P", ui-monospace, monospace;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font: 600 15px/1.45 var(--body);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 2px, transparent 2px),
    linear-gradient(90deg, var(--grid) 2px, transparent 2px);
  background-size: 32px 32px;
  display: grid;
  grid-template-rows: var(--hud) minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}

/* ---------- HUD ---------- */
.hud {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: 16px; min-width: 0; overflow: hidden;
  padding: 0 16px;
  background: var(--pink);
  border-bottom: 3px solid var(--ink);
  box-shadow: 0 3px 0 var(--pink-deep);
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand-word {
  font: 700 22px/1 var(--pixel); letter-spacing: 0.02em;
  color: var(--red); text-shadow: 2px 2px 0 var(--ink);
}
.brand-tag {
  font: 600 16px/1 var(--pixel); color: var(--ink);
  background: var(--paper-2); border: 2px solid var(--ink); border-radius: 4px; padding: 2px 6px;
}
.palette { display: flex; gap: 3px; flex: 1; min-width: 0; overflow: hidden; }
.palette i {
  width: 14px; height: 14px; flex: none; border-radius: 50%;
  background: var(--c); border: 2px solid var(--ink);
}
.hud-tools { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; margin-left: auto; min-width: 0; }

.chip {
  font: 800 13px/1 var(--body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
  padding: 6px 10px; border: 2px solid var(--ink); border-radius: 999px;
  background: var(--paper-2); box-shadow: 2px 2px 0 var(--ink);
}
.chip.me { background: var(--me, var(--p1)); color: #fff; }
.chip.them.on { background: var(--them, var(--p2)); color: #fff; }

.tool, .btn {
  font: 800 14px/1 var(--body); color: var(--ink); white-space: nowrap;
  background: var(--sky); border: 2px solid var(--ink); border-radius: 6px;
  padding: 8px 12px; cursor: pointer; box-shadow: var(--shadow-sm);
  transition: transform 60ms, box-shadow 60ms;
}
.tool:hover, .btn:hover { background: var(--sky-deep); }
.tool:active, .btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.tool:focus-visible, .btn:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.tool.icon { padding: 6px 8px; }
.tool.icon svg { width: 16px; height: 16px; display: block; }
.tool[aria-pressed="true"] { background: var(--paper-2); color: var(--ink-soft); }
.toggle { display: inline-flex; align-items: center; gap: 6px; }
.toggle input { appearance: none; width: 14px; height: 14px; margin: 0; border: 2px solid var(--ink); border-radius: 3px; background: var(--paper-2); }
.toggle input:checked { background: var(--green); box-shadow: inset 0 0 0 2px var(--paper-2); }
.toggle:has(input:checked) { background: #b8f0a8; }

.btn.primary { background: var(--red); color: #fff; }
.btn.primary:hover { background: #c8141d; }
.btn.ghost { background: var(--paper-2); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: var(--shadow-sm); }

/* ---------- Setup ---------- */
main { min-height: 0; position: relative; }
.setup { height: 100%; overflow: auto; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px 16px; }
.panel {
  background: var(--paper-2); border: 3px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow);
}
.hero { width: min(560px, 100%); padding: 28px; display: grid; gap: 22px; }
.hero h1 { margin: 0; font: 700 clamp(30px, 6vw, 44px)/1 var(--pixel); }
.hero h1 span:first-child { color: var(--red); text-shadow: 3px 3px 0 var(--ink); }
.hero h1 span:last-child { color: var(--blue); text-shadow: 3px 3px 0 var(--ink); }
.lede { margin: -8px 0 0; color: var(--ink-soft); }
.step { display: grid; gap: 10px; }
.step-head { display: flex; align-items: center; gap: 10px; font: 600 17px/1 var(--pixel); }
.step-head b {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--pink); border: 2px solid var(--ink); font: 800 14px/1 var(--body);
}
.drop {
  display: block; text-align: center; padding: 20px 14px; cursor: pointer;
  border: 3px dashed var(--ink-soft); border-radius: 8px; background: var(--paper);
  font-weight: 700;
}
.drop:hover, .drop.over { border-color: var(--red); background: #ffeef9; }
.drop input { display: none; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.or { color: var(--ink-soft); }
#code {
  width: 120px; font: 600 18px/1 var(--pixel); letter-spacing: 0.2em; text-transform: uppercase; text-align: center;
  padding: 8px 10px; border: 2px solid var(--ink); border-radius: 6px; background: #fff; color: var(--ink);
  box-shadow: inset 2px 2px 0 var(--grid);
}
.status { margin: 0; min-height: 1.4em; font-weight: 700; }
.status.ok { color: var(--green); }
.status.warn { color: var(--amber); }
.fine { margin: 0; font-size: 13px; color: var(--ink-soft); }

/* ---------- Game stage ---------- */
.stage {
  height: 100%; display: grid; place-items: center; align-content: center; gap: 12px; padding: 14px;
}
/* SNES pixels are 8:7, so the 256x224 picture is shown at the console's real shape. */
.screen {
  --aspect: 1.30612;
  position: relative;
  width: min(calc(100vw - 48px), calc((100dvh - var(--hud) - 48px) * var(--aspect)));
  aspect-ratio: var(--aspect);
  background: #000; border: 4px solid var(--ink); border-radius: 8px;
  box-shadow: 6px 6px 0 var(--ink), 0 0 0 10px var(--pink), 6px 6px 0 10px var(--ink);
  overflow: hidden; cursor: none; touch-action: none;
}
.screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.tag {
  position: absolute; pointer-events: none; white-space: nowrap;
  font: 800 12px/1 var(--body); color: #fff; background: var(--player, var(--p2));
  padding: 4px 7px; border: 2px solid var(--ink); border-radius: 5px; box-shadow: 2px 2px 0 var(--ink);
}
.bubble {
  position: absolute; left: 50%; transform: translateX(-50%); pointer-events: none; white-space: nowrap;
  font: 800 14px/1 var(--body); background: var(--paper-2); color: var(--ink);
  padding: 8px 12px; border: 3px solid var(--ink); border-radius: 8px; box-shadow: var(--shadow-sm);
}
.bubble.top { top: 12px; }
.bubble.bottom { bottom: 12px; }
.start {
  position: absolute; inset: 0; display: grid; place-items: center; border: 0; cursor: pointer;
  background: rgb(51 33 26 / 0.55);
}
.start span {
  font: 700 26px/1 var(--pixel); color: #fff; background: var(--red);
  padding: 16px 26px; border: 3px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow);
}
.start:hover span { background: #c8141d; }
.gnat-bar {
  display: flex; align-items: center; gap: 12px; font: 800 15px/1 var(--body);
  background: var(--paper-2); border: 3px solid var(--ink); border-radius: 8px; box-shadow: var(--shadow-sm);
  padding: 6px 6px 6px 14px;
}
body.in-gnat .screen { width: min(calc(100vw - 48px), calc((100dvh - var(--hud) - 110px) * var(--aspect))); }

/* In-game: where the other player is, with a one-click Follow / Join. */
.where {
  position: absolute; left: 10px; top: 10px; z-index: 2;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 20px);
  font: 800 14px/1 var(--body); background: var(--paper-2); color: var(--ink);
  padding: 5px; border: 3px solid var(--ink); border-radius: 8px; box-shadow: var(--shadow-sm);
  cursor: default;
}
.where .who {
  display: grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px;
  color: #fff; background: var(--them, var(--p2)); border: 2px solid var(--ink); border-radius: 5px;
}
.where span:nth-child(2) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* In-game popup, styled like Mario Paint's own panels. */
.dialog {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center;
  background: rgb(51 33 26 / 0.35); cursor: default;
}
.dialog-card {
  width: min(78%, 420px); padding: 16px 18px; display: grid; gap: 10px; text-align: center;
  background: var(--paper-2); border: 4px solid var(--ink); border-radius: 12px; box-shadow: 6px 6px 0 var(--ink);
}
.dialog-title {
  justify-self: center; font: 700 20px/1 var(--pixel); color: #fff; background: var(--pink-deep);
  padding: 7px 14px; border: 3px solid var(--ink); border-radius: 8px; text-shadow: 2px 2px 0 var(--ink);
  margin-top: -32px;
}
.dialog-card p { margin: 0; font-weight: 800; font-size: 16px; }
.dialog-acts { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 20; right: 16px; top: calc(var(--hud) + 16px);
  display: grid; gap: 10px; width: min(340px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: center;
  background: var(--paper-2); border: 3px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px; animation: pop 160ms steps(4) both;
}
.toast.out { animation: drop 160ms steps(4) both; }
.toast .who {
  grid-row: span 2; align-self: start;
  width: 30px; height: 30px; display: grid; place-items: center;
  font: 800 13px/1 var(--body); color: #fff; background: var(--tc, var(--ink));
  border: 2px solid var(--ink); border-radius: 6px;
}
.toast .msg { font-weight: 800; }
.toast .acts { display: flex; gap: 8px; }
@keyframes pop { from { transform: translateY(-10px) scale(0.92); opacity: 0; } }
@keyframes drop { to { transform: translateX(16px); opacity: 0; } }

@media (max-width: 1180px) { .palette { display: none; } }
@media (max-width: 920px) { .brand-tag, .chip.them { display: none; } }
@media (max-width: 760px) {
  :root { --hud: 54px; }
  .palette, .brand-tag { display: none; }
  .hud { gap: 8px; padding: 0 10px; }
  .brand-word { font-size: 18px; }
  .hud-tools { overflow-x: auto; }
  .chip.them, #copyLink { display: none; }
  .toasts { left: 16px; right: 16px; width: auto; top: auto; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .toast, .toast.out { animation: none; }
}
