:root {
  --ink: #1b2440;
  --muted: #5b6488;
  --bg: #fff6e6;
  --paper: #ffffff;
  --line: #e7dcc8;
  --indigo: #3b3fbf;
  --indigo-dark: #2a2d94;
  --yellow: #ffcf3f;
  --pink: #ff6b9a;
  --green: #36b26b;
  --blue: #4aa3ff;
  --red: #ef5b5b;
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
input, textarea { -webkit-user-select: text; user-select: text; font-family: inherit; }
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 8px 16px;
  border: 0; border-radius: 14px;
  background: var(--paper); color: var(--ink);
  font-size: 17px; font-weight: 700; text-decoration: none;
  box-shadow: 0 3px 0 rgba(27, 36, 64, 0.18), inset 0 0 0 2px rgba(27, 36, 64, 0.08);
  transition: transform 0.06s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(27, 36, 64, 0.18), inset 0 0 0 2px rgba(27, 36, 64, 0.08); }
.btn.primary { background: var(--yellow); }
.btn.stop { background: #ffd6d6; }
.btn.big { min-height: 56px; font-size: 20px; padding: 10px 22px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.45; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 14px; border: 0;
  background: rgba(255, 255, 255, 0.16); font-size: 22px; flex: none;
}
.icon-btn:disabled { opacity: 0.4; }
.icon-btn.ghost { background: rgba(255, 255, 255, 0.75); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15); }
.x { border: 0; background: transparent; font-size: 18px; width: 40px; height: 40px; border-radius: 10px; flex: none; }
.x:active { background: rgba(0, 0, 0, 0.06); }

@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.09); } }
.nudge { animation: nudge 1s ease-in-out infinite; box-shadow: 0 0 0 4px var(--yellow) !important; }

/* ---- home --------------------------------------------------------------- */
#home { min-height: 100dvh; overflow: auto; }
.home-inner { max-width: 1040px; margin: 0 auto; padding: 28px 20px 60px; }
.home-head { text-align: center; margin-bottom: 22px; }
.home-head h1 { font-size: clamp(32px, 6vw, 52px); }
.logo { display: inline-block; animation: nudge 2.4s ease-in-out infinite; }
.lead { font-size: 20px; color: var(--muted); margin: 0; }
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin: 18px 0 28px; }
.starter {
  border: 0; border-radius: 24px; padding: 22px 16px 20px; text-align: center;
  background: var(--c); color: #fff;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.08s;
}
.starter:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.starter-icon { font-size: 76px; line-height: 1.1; }
.starter-name { font-size: 26px; font-weight: 800; margin-top: 6px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15); }
.starter-blurb { font-size: 16px; opacity: 0.95; margin-top: 4px; }
.starter.small { padding: 14px; }
.starter.small .starter-icon { font-size: 48px; }
.starter.small .starter-name { font-size: 20px; }
.my-games, .together { margin-top: 18px; }
.more-games { margin-top: 6px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 10px 0 18px; }
.gallery-card {
  display: flex; align-items: center; gap: 12px; text-align: left; border: 0; border-radius: 20px; padding: 12px 14px;
  background: var(--paper); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1), inset 6px 0 0 var(--c);
}
.gallery-card:active { transform: translateY(3px); }
.gallery-icon { font-size: 46px; flex: none; width: 60px; height: 60px; display: grid; place-items: center; border-radius: 16px; background: #f4f0e8; background: color-mix(in srgb, var(--c) 22%, white); }
.gallery-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gallery-text b { font-size: 19px; }
.gallery-text small { color: var(--muted); font-size: 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { font-size: 12px; font-weight: 800; background: #f4f0e8; border-radius: 8px; padding: 2px 7px; }
.game-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.saved { display: flex; align-items: center; background: var(--paper); border-radius: var(--radius); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); }
.saved-open { flex: 1; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; text-align: left; border: 0; background: none; padding: 12px; }
.saved-icon { grid-row: span 2; font-size: 34px; }
.saved-title { font-weight: 800; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved small { color: var(--muted); }
.together { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.join-box { background: var(--paper); border-radius: 20px; padding: 18px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); }
.join-box p { margin: 0 0 12px; color: var(--muted); }
.code-input {
  font-size: 34px; font-weight: 800; letter-spacing: 6px; text-transform: uppercase; text-align: center;
  width: 100%; padding: 10px; border-radius: 14px; border: 3px solid var(--line); background: #fffdf8;
}
.code-input.small { font-size: 22px; letter-spacing: 3px; width: auto; flex: 1; min-width: 140px; }

/* ---- game screen -------------------------------------------------------- */
#game { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--indigo); color: #fff; flex: none;
}
.title {
  font: inherit; font-weight: 800; font-size: 20px; color: #fff;
  background: transparent; border: 2px solid transparent; border-radius: 10px;
  padding: 4px 8px; width: 12em; min-width: 5em; flex: 0 1 auto;
}
.title:read-only { pointer-events: none; }
.mode-design .title { border-color: rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.08); }
.hud { font-size: 20px; font-weight: 800; white-space: nowrap; display: flex; gap: 12px; min-width: 0; overflow: hidden; }
.hud-bag { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hud-time.low { color: var(--yellow); animation: nudge 0.5s infinite; }
.spacer { flex: 1; }
.bar-btn { min-height: 46px; background: rgba(255, 255, 255, 0.95); }
.mode-toggle { display: flex; background: var(--indigo-dark); border-radius: 16px; padding: 4px; gap: 4px; flex: none; }
.mode-toggle button {
  border: 0; border-radius: 12px; min-height: 42px; padding: 6px 14px;
  font-size: 18px; font-weight: 800; background: transparent; color: #fff;
}
.mode-toggle button.on { background: var(--yellow); color: var(--ink); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.room-chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.15); font-size: 16px; white-space: nowrap;
}
.room-chip .avatars { font-size: 20px; letter-spacing: -2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: #aaa; }
.dot.ok { background: #5df08f; }
.dot.wait { background: var(--yellow); animation: nudge 0.8s infinite; }

.stage { flex: 1; display: flex; min-height: 0; }
.viewport { position: relative; flex: 1; min-width: 0; min-height: 0; background: #e9eef5; overflow: hidden; }
.viewport canvas { position: absolute; inset: 0; display: block; touch-action: none; }
.mode-design .viewport canvas { cursor: crosshair; }
.vp-tools { position: absolute; top: 10px; right: 10px; display: flex; gap: 8px; z-index: 3; }
.pan { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.pan-btn {
  position: absolute; pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid #fff; background: rgba(27, 36, 64, 0.72); color: #fff; font-size: 20px;
  display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
}
.pan-left { transform: translate(0, -50%); }
.pan-right { transform: translate(-100%, -50%); }
.pan-up { transform: translate(-50%, 0); }
.pan-down { transform: translate(-50%, -100%); }
.pan-btn[hidden] { display: none; }

.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
  background: rgba(20, 24, 60, 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.end { background: var(--paper); border-radius: 26px; padding: 26px 28px; text-align: center; box-shadow: 0 10px 0 rgba(0, 0, 0, 0.2); max-width: 92%; animation: pop-in 0.25s ease-out; }
.end-big { font-size: clamp(36px, 7vw, 60px); font-weight: 900; }
.end.won .end-big { color: var(--green); }
.end.lost .end-big { color: var(--red); }
.end-stats { font-size: 22px; margin: 6px 0 18px; color: var(--muted); font-weight: 700; }
.end .row { justify-content: center; }
.end-tip { margin: 14px 0 0; font-weight: 700; color: var(--indigo); }
@keyframes pop-in { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* touch controls */
.touch-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; display: none; }
body.touch .touch-layer:not([hidden]) { display: block; }
.pad { position: absolute; bottom: 12px; pointer-events: auto; touch-action: none; }
.pad-left { left: 12px; }
.pad-right { right: 12px; }
.pad-lr { width: 210px; height: 104px; }
.pad-dpad { width: 186px; height: 186px; }
.pad-jump { width: 124px; height: 124px; }
.pad-act { width: 100px; height: 100px; }
.pad-jump ~ .pad-act { right: 146px; bottom: 22px; }
.pad-dpad ~ .pad-act { width: 124px; height: 124px; }
.pad-btn {
  position: absolute; transform: translate(-50%, -50%);
  width: 86px; height: 86px; border-radius: 50%;
  display: grid; place-items: center; font-size: 34px; color: var(--ink);
  background: rgba(255, 255, 255, 0.55); border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2); pointer-events: none;
}
.pad-dpad .pad-btn { width: 64px; height: 64px; font-size: 28px; }
.pad-btn.big { width: 108px; height: 108px; font-size: 44px; }
.pad-btn.on { background: rgba(255, 207, 63, 0.92); transform: translate(-50%, -50%) scale(0.93); }

/* ---- designer panel ------------------------------------------------------- */
.panel { display: none; width: 410px; flex: none; flex-direction: column; min-height: 0; background: var(--bg); border-left: 3px solid var(--line); }
.mode-design .panel { display: flex; }
.tabs { display: flex; gap: 4px; padding: 6px; background: #f3e8d4; flex: none; }
.tab {
  flex: 1; border: 0; border-radius: 12px; padding: 6px 2px; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 52px;
}
.tab-icon { font-size: 22px; }
.tab-label { font-size: 12px; font-weight: 800; }
.tab.on { background: var(--paper); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.tab-body { flex: 1; overflow-y: auto; padding: 12px; -webkit-overflow-scrolling: touch; }
.hint { margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.tip { color: var(--muted); font-size: 15px; }
.tab-body h3 { margin-top: 18px; }

/* level */
.brushes { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; margin-bottom: 12px; }
.brush {
  border: 0; border-radius: 14px; background: var(--paper); padding: 6px 2px 4px;
  display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1), inset 0 0 0 2px rgba(0, 0, 0, 0.05);
}
.brush-emoji { font-size: 34px; line-height: 1.15; }
.brush-label { font-size: 12px; font-weight: 700; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.brush.on { background: #fff4c4; box-shadow: 0 0 0 4px var(--yellow), 0 3px 0 rgba(0, 0, 0, 0.1); }
.brush.start .brush-label { color: #a0780a; }
.brush.add { background: #eef6ff; }
.tools { margin-bottom: 10px; }

/* levels */
.levels { background: var(--paper); border-radius: var(--radius); padding: 8px; margin-bottom: 10px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06); }
.level-pills { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.level-pill {
  flex: none; display: flex; align-items: center; gap: 6px; border: 0; border-radius: 12px;
  min-height: 42px; padding: 4px 12px; background: #f4f0e8; font-weight: 700; font-size: 15px; max-width: 160px;
}
.level-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.level-pill b { background: var(--indigo); color: #fff; border-radius: 8px; min-width: 24px; padding: 1px 6px; }
.level-pill.on { background: #fff4c4; box-shadow: inset 0 0 0 3px var(--yellow); }
.level-pill.add { background: #eef6ff; font-size: 22px; padding: 4px 16px; }
.level-tools { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.mini { border: 0; background: #f4f0e8; border-radius: 10px; min-height: 34px; padding: 2px 10px; font-weight: 700; font-size: 14px; }
.mini:disabled { opacity: 0.4; }
.gen-info { background: #eef6ff; border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; font-weight: 700; font-size: 15px; }
.auto-gen { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.auto-gen input { width: 24px; height: 24px; accent-color: var(--green); }

/* 🎲 generator */
.gen-head { display: flex; align-items: center; justify-content: space-between; }
.gen-head h3 { margin: 0; }
.gen-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; margin-bottom: 10px; }
.gen-type { border: 0; border-radius: 14px; background: var(--paper); padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 1px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08); }
.gen-type .e { font-size: 28px; }
.gen-type small { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.15; }
.gen-type.on { background: #fff4c4; box-shadow: 0 0 0 3px var(--yellow); }
.gen-type:disabled { opacity: 0.4; }
.roles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.role { border: 0; border-radius: 12px; background: var(--paper); display: flex; flex-direction: column; align-items: center; min-width: 62px; padding: 4px 6px; box-shadow: inset 0 0 0 2px #cfd8ff; }
.role span { font-size: 26px; line-height: 1.1; }
.role small { font-size: 11px; font-weight: 800; color: var(--muted); }
.role.none { opacity: 0.6; }
.seed-row { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; flex-wrap: wrap; }
.seed-input { font-size: 18px; font-weight: 800; padding: 8px 10px; border-radius: 12px; border: 2px solid #cfd8ff; width: 9em; }
.gen-note { background: #fff1bf; border-radius: 12px; padding: 8px 12px; font-weight: 700; }
.chance { border: 0; border-radius: 10px; background: #f4f0e8; min-height: 32px; padding: 2px 8px; font-weight: 800; font-size: 13px; margin-left: auto; }
.chance.on { background: #ffe9a8; }
.rule-top .switch { margin-left: 0; }
.hud-level, .hud-robot, .hud-bag { font-size: 0.85em; background: rgba(255, 255, 255, 0.15); border-radius: 10px; padding: 0 8px; }
.robot-result p { font-size: 18px; }
.rename .row { margin-top: 12px; }

/* physics */
.cam { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.label { font-weight: 800; }
.seg { display: flex; background: #eadfca; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; border-radius: 10px; min-height: 42px; padding: 4px 12px; font-weight: 800; font-size: 16px; }
.seg button.on { background: var(--paper); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.seg.small button { min-height: 36px; font-size: 14px; padding: 2px 10px; }
.slider { background: var(--paper); border-radius: var(--radius); padding: 10px 14px 6px; margin-bottom: 10px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06); }
.slider.star { box-shadow: 0 0 0 3px var(--yellow); }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; }
.val { font-weight: 800; color: var(--indigo); }
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row .lohi { font-size: 24px; width: 30px; text-align: center; }
input[type="range"] { flex: 1; height: 44px; -webkit-appearance: none; appearance: none; background: transparent; touch-action: none; }
input[type="range"]::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: #e4dccb; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 34px; height: 34px; margin-top: -12px; border-radius: 50%; background: var(--yellow); border: 3px solid #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3); }
input[type="range"]::-moz-range-track { height: 10px; border-radius: 5px; background: #e4dccb; }
input[type="range"]::-moz-range-thumb { width: 30px; height: 30px; border-radius: 50%; background: var(--yellow); border: 3px solid #fff; }

/* rules */
.rule { background: var(--paper); border-radius: var(--radius); padding: 8px 10px 10px; margin-bottom: 12px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); border-left: 6px solid var(--blue); }
.rule.off { opacity: 0.5; border-left-color: #bbb; }
.rule.todo { border-left-color: var(--yellow); }
.rule-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.rule-num { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.todo-tag { font-size: 13px; font-weight: 800; background: #fff1bf; border-radius: 8px; padding: 2px 8px; }
.switch { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 800; color: var(--muted); }
.switch input { width: 22px; height: 22px; accent-color: var(--green); }
.line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px 0; font-size: 18px; }
.kw { font-size: 12px; font-weight: 900; letter-spacing: 1px; color: #fff; background: var(--blue); border-radius: 8px; padding: 3px 7px; }
.then .kw { background: var(--green); }
.if .kw { background: var(--orange, #ff9a3c); }
.word.plain { text-decoration: none; cursor: default; font-size: 16px; }
.chance.cond { margin-left: 0; }
.kw.icon { border: 0; background: #e3efff; font-size: 20px; padding: 2px 6px; letter-spacing: 0; min-height: 36px; }
.word { border: 0; background: none; padding: 4px 2px; font-size: 18px; font-weight: 700; text-decoration: underline dotted rgba(27, 36, 64, 0.35); text-underline-offset: 5px; }
.blank {
  border: 0; border-radius: 12px; min-width: 46px; min-height: 44px; padding: 2px 8px;
  background: #f1f4ff; font-size: 28px; line-height: 1; box-shadow: inset 0 0 0 2px #cfd8ff;
}
.blank.where { font-size: 16px; font-weight: 800; }
.blank.fixed { display: inline-grid; place-items: center; background: transparent; box-shadow: none; }
.blank.empty { background: #fff1bf; box-shadow: inset 0 0 0 2px var(--yellow); animation: nudge 1.4s infinite; }
.num { display: inline-flex; align-items: center; background: #f1f4ff; border-radius: 12px; box-shadow: inset 0 0 0 2px #cfd8ff; }
.num button { border: 0; background: none; width: 38px; height: 44px; font-size: 22px; font-weight: 900; }
.num b { min-width: 28px; text-align: center; font-size: 20px; }
.say { font-size: 17px; padding: 8px 10px; border-radius: 10px; border: 2px solid #cfd8ff; min-width: 0; flex: 1 1 140px; }
.line .x { margin-left: auto; width: 34px; height: 34px; font-size: 14px; color: var(--muted); }
.add-then { border: 0; background: none; font-weight: 800; color: var(--green); font-size: 16px; padding: 6px 0; }

.recipes-btn { margin-bottom: 12px; background: #fff4c4; }
.recipe-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.recipe { display: flex; align-items: center; gap: 10px; text-align: left; border: 0; border-radius: 14px; background: var(--paper); padding: 10px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); }
.recipe-icon { font-size: 34px; flex: none; }
.recipe b { display: block; font-size: 17px; }
.recipe small { color: var(--muted); font-size: 14px; }
.modal.wide { width: min(760px, 100%); }

/* sprites */
.sprite { display: flex; gap: 10px; align-items: flex-start; background: var(--paper); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.08); }
.sprite.you { background: #fff4c4; align-items: center; }
.sprite-emoji { font-size: 40px; width: 64px; height: 64px; border: 0; border-radius: 14px; background: #f4f0e8; flex: none; }
.sprite-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.sprite-meta { font-size: 13px; color: var(--muted); font-weight: 600; }
.moves { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.move { border: 0; border-radius: 10px; background: #f4f0e8; padding: 4px 0; display: flex; flex-direction: column; align-items: center; font-size: 20px; }
.move small { font-size: 10px; font-weight: 700; color: var(--muted); }
.move.on { background: #fff4c4; box-shadow: inset 0 0 0 2px var(--yellow); }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.theme { border: 0; border-radius: 12px; min-height: 48px; font-weight: 800; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12); }
.theme.on { box-shadow: 0 0 0 4px var(--yellow); }

/* challenges */
.card { border-radius: 22px; min-height: 210px; margin-bottom: 12px; padding: 16px; background: var(--paper); box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12), inset 0 0 0 4px var(--kind, var(--indigo)); display: flex; flex-direction: column; gap: 12px; }
.card-kind { align-self: flex-start; background: var(--kind); color: #fff; font-weight: 900; border-radius: 10px; padding: 4px 10px; }
.card-text { font-size: 24px; font-weight: 800; flex: 1; }
.card.back { background: repeating-linear-gradient(45deg, #4b4fd6, #4b4fd6 14px, #3b3fbf 14px, #3b3fbf 28px); color: #fff; align-items: center; justify-content: center; text-align: center; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18); }
.card-back-face { font-size: 72px; }
.flip-in { animation: flip-in 0.45s ease-out; }
@keyframes flip-in { from { transform: perspective(600px) rotateY(90deg); } to { transform: perspective(600px) rotateY(0); } }
.stamps { margin: 14px 0; font-size: 18px; }
.glossary { background: var(--paper); border-radius: var(--radius); padding: 10px 14px; }
.glossary summary { font-weight: 800; font-size: 18px; cursor: pointer; }
.glossary dt { font-weight: 900; margin-top: 8px; color: var(--indigo); }
.glossary dd { margin: 0; }

/* ---- popovers, modals, toasts ------------------------------------------------ */
.pop-back { position: fixed; inset: 0; z-index: 40; }
.pop {
  position: fixed; z-index: 41; background: var(--paper); border-radius: 18px; padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25), 0 0 0 2px rgba(0, 0, 0, 0.05);
  max-width: min(92vw, 340px); max-height: 70vh; overflow: auto; animation: pop-in 0.12s ease-out;
}
.pop.wide { max-width: min(94vw, 440px); }
.pick-title { font-weight: 900; color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; margin: 2px 4px 8px; }
.pick-list { display: flex; flex-direction: column; gap: 4px; min-width: 220px; }
.pick-item { border: 0; background: #f6f3ec; border-radius: 12px; min-height: 46px; padding: 6px 12px; display: flex; align-items: center; gap: 10px; text-align: left; font-size: 17px; font-weight: 700; }
.pick-item.current { box-shadow: inset 0 0 0 3px var(--yellow); }
.pick-icon { font-size: 22px; width: 28px; text-align: center; }
.emoji-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 6px; }
.emoji-tab { border: 0; border-radius: 10px; background: #f6f3ec; white-space: nowrap; padding: 6px 10px; font-weight: 700; font-size: 14px; }
.emoji-tab.on { background: var(--yellow); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; }
.emoji-btn { border: 0; background: #f6f3ec; border-radius: 12px; font-size: 32px; height: 54px; }
.thing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; min-width: 240px; }
.thing-btn { border: 0; background: #f6f3ec; border-radius: 12px; padding: 6px 2px; display: flex; flex-direction: column; align-items: center; }
.thing-btn .e { font-size: 32px; }
.thing-btn .l { font-size: 11px; font-weight: 700; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.thing-btn.add { background: #eef6ff; }

.modal-back { position: fixed; inset: 0; z-index: 30; background: rgba(20, 24, 60, 0.5); display: grid; place-items: center; padding: 16px; }
.modal { position: relative; background: var(--bg); border-radius: 24px; padding: 22px; width: min(560px, 100%); max-height: 92dvh; overflow: auto; box-shadow: 0 12px 0 rgba(0, 0, 0, 0.2); animation: pop-in 0.18s ease-out; }
.modal-x { position: absolute; top: 10px; right: 10px; border: 0; background: rgba(0, 0, 0, 0.06); border-radius: 12px; width: 42px; height: 42px; font-size: 18px; }
.modal label { display: block; font-weight: 800; margin: 14px 0 6px; }
.name-input { font-size: 22px; padding: 10px 12px; width: 100%; border-radius: 14px; border: 3px solid var(--line); background: #fffdf8; }
.avatar-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar-pick button { font-size: 30px; border: 0; background: var(--paper); border-radius: 12px; aspect-ratio: 1; }
.avatar-pick button.on, .job-pick button.on { box-shadow: 0 0 0 4px var(--yellow); background: #fff4c4; }
.job-pick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.job-pick button { border: 0; background: var(--paper); border-radius: 12px; padding: 8px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.job-pick span { font-size: 26px; }
.job-pick small { font-size: 11px; font-weight: 800; line-height: 1.1; text-align: center; }
.err { color: var(--red); font-weight: 700; min-height: 1.2em; }
.confirm p { font-size: 20px; font-weight: 700; margin: 8px 40px 18px 0; }
.confirm .row { justify-content: flex-end; }
.share-code { background: var(--paper); border-radius: 18px; padding: 16px; text-align: center; margin: 12px 0; }
.code-big { font-size: 52px; font-weight: 900; letter-spacing: 6px; color: var(--indigo); }
.code-sub { color: var(--muted); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 140%); z-index: 60;
  background: var(--ink); color: #fff; font-weight: 700; padding: 12px 20px; border-radius: 999px;
  max-width: 92vw; text-align: center; transition: transform 0.25s; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }

/* ---- smaller screens ---------------------------------------------------------- */
@media (max-aspect-ratio: 1/1), (max-width: 820px) {
  .stage { flex-direction: column; }
  .mode-design .viewport { flex: 0 0 44%; }
  .panel { width: auto; flex: 1; border-left: 0; border-top: 3px solid var(--line); }
}
@media (max-width: 1000px) {
  .bar .label { display: none; }
  .title { width: 8em; font-size: 18px; }
  .hud { font-size: 17px; gap: 8px; }
}
@media (max-width: 640px) {
  .title { display: none; }
  .bar { gap: 5px; padding: 6px; }
  .icon-btn { width: 40px; height: 40px; font-size: 19px; }
  .mode-toggle button { padding: 6px 10px; }
  .pad-lr { width: 170px; height: 90px; }
  .pad-btn { width: 72px; height: 72px; }
  .pad-btn.big { width: 92px; height: 92px; }
  .pad-dpad { width: 160px; height: 160px; }
  .pad-dpad .pad-btn { width: 56px; height: 56px; }
  /* No room between the pads on a phone: 🅰️ goes above the jump button. */
  .pad-jump ~ .pad-act { right: 12px; bottom: 146px; }
}
