:root {
  --bg: #e3f7cf;
  --bg2: #ffe0b6;
  --panel: rgba(255,255,255,0.86);
  --panel-border: #bfe0f5;
  --ink: #2a3766;
  --muted: #7686b0;
  --accent: #ff9b2f;
  --accent2: #62bd65;
  --red: #ff6378;
  --blue: #5a93ff;
  --good: #4ed98a;
  --warn: #ffd05a;
  --grape: #b48bff;
  --radius: 22px;
  --radius-sm: 14px;
  --pop: 0 6px 0; /* used for squishy bottom edge color via box-shadow */
  font-family: 'Fredoka', 'Varela Round', 'Segoe UI', system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Fredoka', 'Varela Round', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(120% 90% at 18% -10%, #fff4d5 0%, rgba(255,244,213,0) 46%),
    radial-gradient(120% 90% at 90% 8%, #ffd3aa 0%, rgba(255,211,170,0) 42%),
    linear-gradient(165deg, #f7ffe9 0%, var(--bg2) 28%, var(--bg) 62%, #e8f1c8 100%);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  font-weight: 500;
}
/* ---------- ambient depth: film grain over the canvas backdrop ---------- */
/* A fine paper texture so large fills don't read as plasticky. The animated
   valley itself is painted by js/menubg.js on #menuScene underneath. */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: 0.42; mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}
#app { height: 100%; position: relative; z-index: 1; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; }

/* ---------- animated valley backdrop (canvas, see js/menubg.js) ---------- */
#menuScene {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  width: 100%; height: 100%; display: block;
}

/* ---------- buttons / fields ---------- */
.btn {
  appearance: none; border: 2.5px solid #fff;
  background: linear-gradient(180deg, #ffffff, #eaf6ff);
  color: var(--ink);
  padding: 11px 20px; border-radius: 999px; font-size: 15px; cursor: pointer;
  font-family: inherit; font-weight: 700; letter-spacing: .2px;
  transition: transform .08s cubic-bezier(.34,1.56,.64,1), filter .15s ease, box-shadow .12s ease;
  box-shadow: 0 5px 0 #c8def0, 0 9px 14px rgba(70,120,160,0.18);
}
.btn:hover { transform: translateY(-2px) rotate(-.6deg); filter: brightness(1.03); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #c8def0, 0 3px 8px rgba(70,120,160,0.18); }
.btn.primary {
  background: linear-gradient(180deg, #ffc45a 0%, #ff8a2f 48%, #62bd65 100%);
  border-color: #fff; color: #fff;
  text-shadow: 0 2px 0 rgba(96,52,22,0.28);
  box-shadow: 0 6px 0 #d65f25, 0 12px 22px rgba(255,138,47,0.3);
}
.btn.primary:hover { filter: brightness(1.06) saturate(1.05); }
.btn.primary:active { box-shadow: 0 2px 0 #d65f25, 0 4px 10px rgba(255,138,47,0.28); }
/* glossy light streak that periodically sweeps across primary buttons */
.btn.primary { position: relative; overflow: hidden; isolation: isolate; }
.btn.primary::after {
  content: ""; position: absolute; top: -20%; left: -65%; width: 42%; height: 140%;
  background: linear-gradient(105deg, transparent, rgba(255,255,255,0.55), transparent);
  transform: skewX(-18deg); pointer-events: none;
  animation: btnSheen 5.5s ease-in-out infinite;
}
.btn.primary:hover::after { animation-duration: 1.7s; }
@keyframes btnSheen { 0% { left: -65%; } 24%, 100% { left: 135%; } }
.btn.ghost { background: rgba(255,255,255,0.5); box-shadow: 0 4px 0 rgba(190,216,236,0.6); }
.btn.ghost:active { box-shadow: 0 1px 0 rgba(190,216,236,0.6); }
.btn.tiny { padding: 6px 13px; font-size: 13px; box-shadow: 0 4px 0 #cfe3f2, 0 6px 10px rgba(70,120,160,0.14); }
.btn.tiny:active { transform: translateY(3px); box-shadow: 0 1px 0 #cfe3f2; }
.btn.team-red  { border-color: #fff; color: #fff; background: linear-gradient(180deg,#ff8a9a,#ff5d73); box-shadow: 0 5px 0 #d9374f, 0 9px 14px rgba(255,99,120,.3); }
.btn.team-blue { border-color: #fff; color: #fff; background: linear-gradient(180deg,#86b0ff,#4f86ff); box-shadow: 0 5px 0 #3461d6, 0 9px 14px rgba(90,147,255,.3); }
.btn.sel-on { outline: 3px dashed var(--accent2); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.3); transform: none; }
.sel {
  width: 100%; padding: 11px 14px; border-radius: 999px; font-family: inherit; font-weight: 600;
  background: #fff; color: var(--ink); border: 2.5px solid var(--panel-border); font-size: 14px;
  cursor: pointer;
}
.sel:focus { outline: 3px solid rgba(41,192,255,.4); border-color: var(--accent); }
.row { display: flex; gap: 10px; }
.row.tight { gap: 8px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 500; }
.small { font-size: 12.5px; }

/* ---------- menu ---------- */
#menu { flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 20px; }
.card {
  width: min(440px, 94vw); background: var(--panel); border: 3px solid #fff;
  border-radius: 30px; padding: 28px; backdrop-filter: blur(10px) saturate(1.1);
  box-shadow:
    0 26px 60px rgba(75,108,140,.28),
    0 6px 18px rgba(75,108,140,.12),
    inset 0 2px 0 rgba(255,255,255,.9),
    inset 0 0 0 2px rgba(191,224,245,.5);
  position: relative;
}
.card::before {
  content: ""; position: absolute; top: 16px; right: 22px; width: 60px; height: 60px;
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 34% 30%, rgba(255,255,255,.9), rgba(255,255,255,.1) 50%, transparent 70%);
  opacity: .7;
}
.logo {
  font-family: 'Baloo 2', 'Fredoka', sans-serif;
  font-size: 44px; margin: 0 0 6px; text-align: center; letter-spacing: .5px; font-weight: 800;
  line-height: 1.05;
  background:
    linear-gradient(115deg, transparent 32%, rgba(255,255,255,0.9) 48%, transparent 60%) 220% 0 / 250% 100% no-repeat,
    linear-gradient(180deg, #5fb85a 0%, #ff9b2f 50%, #d94c28 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 rgba(40,90,140,.18));
  animation: logoBob 3.2s ease-in-out infinite, logoSheen 5s ease-in-out infinite;
}
@keyframes logoBob { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-6px) rotate(1deg); } }
@keyframes logoSheen { 0% { background-position: 220% 0, 0 0; } 55%, 100% { background-position: -130% 0, 0 0; } }
.tag { text-align: center; color: var(--muted); margin: 0 0 20px; font-weight: 500; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; padding-left: 6px; }
.field small { color: #93a2c8; font-weight: 500; }
.field input {
  width: 100%; padding: 12px 16px; border-radius: 999px; font-size: 16px; font-family: inherit; font-weight: 600;
  background: #fff; border: 2.5px solid var(--panel-border); color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder, .chatform input::placeholder, .gamechat-input::placeholder { color: #aab8d8; font-weight: 500; }
.field input:focus, .chatform input:focus, .gamechat-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(41,192,255,.18); }
.help { margin-top: 20px; border-top: 2.5px dashed var(--panel-border); padding-top: 16px; }
.help h3 { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.help ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
.help li { margin-bottom: 4px; }
.help li::marker { color: var(--accent2); }
.help b { color: var(--ink); font-weight: 700; }
.credit { color: #8294bc; font-size: 12px; font-weight: 500; }

/* ---------- public rooms list (home page) ---------- */
.public-rooms { margin-top: 20px; border-top: 2.5px dashed var(--panel-border); padding-top: 16px; }
.public-rooms h3 {
  margin: 0 0 10px; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 188px; overflow-y: auto; }
.room-list::-webkit-scrollbar { width: 8px; }
.room-list::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 999px; }
.room-empty { padding: 8px 4px; }
.room-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: linear-gradient(180deg,#ffffff,#f1f9ff); border: 2px solid #e4f1fb; border-radius: var(--radius-sm);
}
.room-meta { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.room-code-tag {
  font-family: 'Baloo 2', ui-monospace, monospace; letter-spacing: 2.5px; font-weight: 800; font-size: 15px; color: #298a3e;
}
.room-sub { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.join-room { flex: none; }

/* ---------- menu views (home / join / how-to) ---------- */
.menu-view { display: none; }
.menu-view.active { display: block; }
.menu-actions { display: flex; flex-direction: column; gap: 12px; }
.btn.big { width: 100%; padding: 15px 22px; font-size: 18px; }
.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.view-title { margin: 0; font-family: 'Baloo 2','Fredoka',sans-serif; font-weight: 800; font-size: 22px; }
.back-btn { flex: none; }
.code-join { margin-top: 16px; }
.code-join > .btn { width: 100%; }
.code-entry { display: flex; gap: 8px; }
.code-entry input {
  flex: 1; min-width: 0; padding: 12px 16px; border-radius: 999px; font-size: 16px; font-family: inherit; font-weight: 700;
  letter-spacing: 2px; text-align: center;
  background: #fff; border: 2.5px solid var(--panel-border); color: var(--ink);
}
.code-entry input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(41,192,255,.18); }
.code-entry .btn { flex: none; }
.help.no-border { margin-top: 8px; border-top: none; padding-top: 0; }
/* inside the Join view the rooms list leads, so drop its top divider */
.menu-view .public-rooms { margin-top: 8px; border-top: none; padding-top: 0; }

/* ---------- lobby ---------- */
#lobby { align-items: stretch; }
.lobby-wrap { width: min(1160px, 96vw); margin: auto; padding: 18px; }
.lobby-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.lobby-head h2 { margin: 0; display: flex; align-items: center; gap: 12px; font-family: 'Baloo 2','Fredoka',sans-serif; font-weight: 800; }
.code {
  font-family: 'Baloo 2', ui-monospace, monospace; letter-spacing: 5px; font-weight: 800; color: #298a3e;
  background: #fff; padding: 5px 16px; border-radius: 999px; border: 2.5px solid var(--panel-border);
  box-shadow: 0 4px 0 #cfe6f5;
}
.lobby-grid { display: grid; grid-template-columns: 1fr 1.12fr 1fr; gap: 16px; }
.panel {
  background: var(--panel); border: 3px solid #fff; border-radius: var(--radius); padding: 18px;
  box-shadow:
    0 16px 34px rgba(75,108,140,.18),
    0 4px 12px rgba(75,108,140,.10),
    inset 0 2px 0 rgba(255,255,255,.85),
    inset 0 0 0 2px rgba(191,224,245,.45);
}
.panel h3 { margin: 0 0 14px; font-size: 17px; font-weight: 700; font-family: 'Baloo 2','Fredoka',sans-serif; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.panel-title-row h3 { margin: 0; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.players li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  background: linear-gradient(180deg,#ffffff,#f1f9ff); border: 2px solid #e4f1fb; border-radius: var(--radius-sm);
  transition: transform .12s ease;
}
.players li:hover { transform: translateX(3px); }
.player-avatar {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; margin: -7px -3px -5px -7px;
  filter: drop-shadow(0 3px 3px rgba(40,70,100,.18));
}
.player-avatar svg { width: 100%; height: 100%; display: block; }
.pdot { width: 20px; height: 20px; border-radius: 50%; flex: none; border: 2px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,.18), inset 0 -2px 3px rgba(0,0,0,.18); }
.players .pdot { width: 14px; height: 14px; }
.pname { font-weight: 700; flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.08; }
.pname small { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: #e7eefb; color: var(--ink); font-weight: 700; letter-spacing: .3px; }
.badge.host { background: var(--warn); color: #6a4b00; }
.badge.ready { background: var(--good); color: #064d27; }
.badge.team-red { background: var(--red); color: #fff; }
.badge.team-blue { background: var(--blue); color: #fff; }
.badge.cpu { background: var(--grape); color: #fff; }
/* Per-bot difficulty: read-only badge (non-host) */
.badge.diff { background: #e7eefb; color: var(--ink); }
.badge.diff.diff-easy { background: var(--good); color: #064d27; }
.badge.diff.diff-medium { background: var(--warn); color: #6a4b00; }
.badge.diff.diff-hard { background: var(--red); color: #fff; }
.badge.diff.diff-insane {
  background: linear-gradient(135deg, #2a0b3d, #7b1341);
  color: #ffd6e8; border: 1px solid #ff4d8c;
  text-shadow: 0 0 6px rgba(255,77,140,.8);
}
/* Per-bot difficulty: host dropdown */
select.bot-diff {
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 3px 6px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(0,0,0,.15); background: #e7eefb; color: var(--ink);
}
.setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.setting > label { font-size: 13px; color: var(--muted); min-width: 64px; font-weight: 600; }
.setting .sel { flex: 1; }

.setup-panel { display: flex; flex-direction: column; }
.character-pick {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px;
  margin-bottom: 13px;
}
.character-card {
  position: relative; appearance: none; border: 2.5px solid #e4f1fb; border-radius: 16px;
  min-width: 0; height: 112px; padding: 7px 5px 8px; cursor: pointer;
  background:
    radial-gradient(circle at 50% 24%, rgba(255,255,255,.95), rgba(255,255,255,0) 34%),
    linear-gradient(180deg, #ffffff, #f0f9ff);
  color: var(--ink); font-family: inherit; font-weight: 800;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  box-shadow: 0 4px 0 #dcecf8;
  transition: transform .1s cubic-bezier(.34,1.56,.64,1), border-color .12s ease, box-shadow .12s ease;
}
.character-card:hover { transform: translateY(-2px); border-color: var(--dino-accent); box-shadow: 0 6px 0 #d2e6f6; }
.character-card:active { transform: translateY(2px); box-shadow: 0 1px 0 #dcecf8; }
.character-card.sel-on { border-color: #fff; box-shadow: 0 0 0 3px var(--dino-accent), 0 8px 17px rgba(40,70,120,.2); }
.character-card.sel-on::after {
  content: "✓"; position: absolute; top: -8px; right: -8px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--dino-accent); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(40,70,120,.28);
}
.character-art { width: 62px; height: 62px; display: block; margin-top: -3px; filter: drop-shadow(0 4px 5px rgba(40,70,100,.16)); }
.character-art svg { width: 100%; height: 100%; display: block; }
.character-name {
  width: 100%; margin-top: -1px; font-size: 12px; line-height: 1.05; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.character-card small { width: 100%; margin-top: 3px; color: var(--muted); font-size: 10.5px; font-weight: 700; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.setup-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 13px; }
.setup-card {
  appearance: none; min-width: 0; min-height: 92px; cursor: pointer; font-family: inherit; text-align: left;
  color: var(--ink); display: flex; align-items: center; gap: 10px; padding: 10px;
  background: linear-gradient(180deg,#ffffff,#eef8ff); border: 2.5px solid #e4f1fb; border-radius: 16px;
  box-shadow: 0 4px 0 #dcecf8; transition: transform .1s cubic-bezier(.34,1.56,.64,1), border-color .12s ease, box-shadow .12s ease;
}
.setup-card:hover { transform: translateY(-2px); border-color: var(--setup-accent, var(--accent)); box-shadow: 0 6px 0 #d2e6f6; }
.setup-card:active { transform: translateY(2px); box-shadow: 0 1px 0 #dcecf8; }
.setup-card.locked { opacity: .82; }
.setup-icon, .setup-thumb {
  width: 54px; height: 54px; flex: none; display: grid; place-items: center; border-radius: 12px; overflow: hidden;
  background: #fff; box-shadow: inset 0 0 0 2px rgba(255,255,255,.5), 0 2px 7px rgba(40,70,120,.14);
}
.setup-thumb { width: 66px; }
.setup-icon svg, .setup-thumb svg { width: 100%; height: 100%; display: block; }
.setup-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.setup-label { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; }
.setup-copy b { font-size: 14px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.setup-copy small { color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- mode + map visual pickers ---------- */
#lobby { overflow-y: auto; overflow-x: hidden; }
.lobby-grid { align-items: start; }
.pick-block { margin-bottom: 16px; }
.pick-head { display: block; font-size: 13px; font-weight: 800; color: var(--ink); margin: 0 0 9px 4px; letter-spacing: .2px; }
.mode-desc { margin: 9px 4px 0; min-height: 1.2em; }
.mode-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.map-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pick-card {
  position: relative; appearance: none; cursor: pointer; font-family: inherit; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 9px 6px 8px; border-radius: 16px;
  background: linear-gradient(180deg,#ffffff,#eef8ff); border: 2.5px solid #e4f1fb;
  box-shadow: 0 4px 0 #dcecf8;
  transition: transform .1s cubic-bezier(.34,1.56,.64,1), box-shadow .12s ease, border-color .12s ease;
}
.pick-card:hover:not(:disabled) { transform: translateY(-2px) rotate(-.5deg); border-color: #bfe0f5; box-shadow: 0 6px 0 #d2e6f6; }
.pick-card:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #dcecf8; }
.pick-card:disabled { cursor: default; opacity: .88; box-shadow: 0 3px 0 #e7eff7; }
.pick-card .pick-name { font-size: 12px; font-weight: 700; line-height: 1.12; text-align: center; }
.pick-card.sel-on { border-color: #fff; box-shadow: 0 0 0 3px var(--pc, var(--accent)), 0 7px 16px rgba(40,70,120,.2); }
.pick-card.sel-on::after {
  content: "✓"; position: absolute; top: -7px; right: -7px; width: 21px; height: 21px; border-radius: 50%;
  background: var(--pc, var(--accent)); color: #fff; font-size: 12px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 2px 5px rgba(40,70,120,.3);
}
.mode-card { --pc: var(--accent); }
.mode-card .pick-art { width: 100%; max-width: 50px; aspect-ratio: 1; }
.mode-card .pick-art svg { width: 100%; height: 100%; display: block; }
.mode-card.sel-on { background: linear-gradient(180deg,#ffffff,#f3fbff); }
.map-card { --pc: var(--accent2); padding: 7px; }
.map-thumb {
  width: 100%; aspect-ratio: 180 / 156; border-radius: 11px; overflow: hidden; display: block; line-height: 0;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.45), 0 2px 6px rgba(40,70,120,.16);
}
.map-thumb svg { width: 100%; height: 100%; display: block; }
.map-card.sel-on .map-thumb { box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper span { min-width: 24px; text-align: center; font-weight: 800; font-size: 17px; color: var(--accent); }
#readyBtn, #startBtn { width: 100%; margin-top: 10px; }

.setup-modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 22px;
}
.modal-scrim {
  position: absolute; inset: 0; appearance: none; border: 0; padding: 0; cursor: pointer;
  background: rgba(29,42,72,.38); backdrop-filter: blur(5px);
}
.modal-card {
  position: relative; width: min(900px, 96vw); max-height: min(720px, 88vh);
  background: rgba(255,255,255,.96); border: 3px solid #fff; border-radius: 24px; padding: 18px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 70px rgba(42,55,102,.34), inset 0 0 0 2px rgba(191,224,245,.5);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 22px; font-family: 'Baloo 2','Fredoka',sans-serif; font-weight: 800; }
.modal-tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 5px; margin-bottom: 12px;
  background: #eef7ff; border: 2px solid #d9edf9; border-radius: 999px;
}
.tab-btn {
  appearance: none; border: 0; border-radius: 999px; padding: 10px 14px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 800; color: var(--ink); background: transparent;
}
.tab-btn.sel-on { color: #fff; background: linear-gradient(180deg,#8cd96e,#52b85a); box-shadow: 0 3px 0 #369444; }
.setup-pane { min-height: 0; overflow-y: auto; padding: 3px 3px 8px; }
.setup-pane::-webkit-scrollbar { width: 10px; }
.setup-pane::-webkit-scrollbar-thumb { background: #bfe0f5; border-radius: 999px; border: 2px solid #f0f8ff; }
.modal-card .mode-pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.modal-card .map-pick { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.modal-card .pick-card { min-height: 104px; }
.modal-card .map-card { min-height: 132px; }
.setup-modal.hidden { display: none !important; }

.chat-panel { display: flex; flex-direction: column; }
.chatlog {
  flex: 1; min-height: 160px; max-height: 260px; overflow-y: auto;
  background: #f0f8ff; border: 2px solid #e4f1fb; border-radius: var(--radius-sm); padding: 10px;
  font-size: 13.5px; line-height: 1.55;
}
.chatlog.small { min-height: 0; font-size: 12px; }
.chatlog .ln { margin-bottom: 4px; word-wrap: break-word; }
.chatlog .who { font-weight: 800; }
.chatlog .sys { color: #e08a1a; font-style: italic; font-weight: 600; }

/* "typing…" indicator pinned at the bottom of a chat log */
.typing-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 2px; color: var(--muted); font-style: italic; font-size: .92em;
}
.typing-row .tname { font-weight: 800; font-style: normal; }
.dots { display: inline-flex; gap: 3px; }
.dots i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor;
  display: inline-block; animation: typingdot 1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typingdot { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-4px); opacity: 1; } }
.chatform { margin-top: 10px; }
.chatform input {
  width: 100%; padding: 11px 16px; border-radius: 999px; font-family: inherit; font-weight: 600;
  background: #fff; border: 2.5px solid var(--panel-border); color: var(--ink);
}

/* cute scrollbars */
.chatlog::-webkit-scrollbar { width: 10px; }
.chatlog::-webkit-scrollbar-track { background: transparent; }
.chatlog::-webkit-scrollbar-thumb { background: #bfe0f5; border-radius: 999px; border: 2px solid #f0f8ff; }
.chatlog::-webkit-scrollbar-thumb:hover { background: #9fd0ee; }

/* ---------- game ---------- */
#game { flex-direction: column; align-items: center; justify-content: flex-start; padding: 10px; gap: 10px; }
.hud-top { width: min(900px, 98vw); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer {
  font-family: 'Baloo 2','Fredoka',sans-serif; font-size: 32px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: 1px;
  color: var(--ink); background: #fff; padding: 4px 16px; border-radius: 999px;
  border: 2.5px solid var(--panel-border); box-shadow: 0 5px 0 #cfe6f5;
}
.timer.danger { color: #fff; background: linear-gradient(180deg,#ff8a9a,#ff5d73); border-color:#fff; box-shadow: 0 5px 0 #d9374f; animation: pulse .7s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.match-info { color: var(--muted); font-size: 14px; flex: 1; text-align: center; font-weight: 600; }
.stage {
  position: relative; line-height: 0; padding: 10px; border-radius: 26px;
  background: linear-gradient(180deg, #ffffff, #e6f4cf);
  border: 3px solid #fff;
  box-shadow:
    0 0 64px rgba(255,168,80,0.20),
    0 22px 52px rgba(61,101,132,.28),
    inset 0 2px 0 rgba(255,255,255,.9),
    inset 0 0 0 2px rgba(191,224,245,.6);
}
#board {
  display: block;
  background: #e3f7cf; border-radius: 18px;
  width: min(86vh, 96vw); height: auto; aspect-ratio: 600 / 520;
  box-shadow: 0 9px 22px rgba(61,101,132,.22), 0 0 0 2px rgba(43,68,104,.12);
  image-rendering: auto;
}
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; flex-direction: column; gap: 12px; text-align: center;
}
.overlay .big {
  font-family: 'Baloo 2','Fredoka',sans-serif;
  font-size: 84px; font-weight: 800; color: #fff;
  -webkit-text-stroke: 4px #ff9b2f;
  text-shadow: 0 6px 0 rgba(39,58,92,.35), 0 14px 30px rgba(0,0,0,.3);
  animation: popBounce .45s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popBounce { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.overlay .mid { font-family: 'Baloo 2','Fredoka',sans-serif; font-size: 32px; font-weight: 800; }
.overlay .sub {
  font-size: 17px; font-weight: 700; color: var(--ink); background: #fff; padding: 10px 20px; border-radius: 999px;
  pointer-events: auto; border: 2.5px solid var(--panel-border); box-shadow: 0 8px 22px rgba(73,94,126,.2);
  animation: popBounce .4s cubic-bezier(.34,1.56,.64,1);
}
.overlay .panel-over {
  background: #fff; border: 3px solid var(--accent); border-radius: 26px; padding: 24px 30px;
  pointer-events: auto; min-width: 320px; box-shadow: 0 20px 48px rgba(73,94,126,.28), inset 0 0 0 2px rgba(191,224,245,.5);
  animation: popBounce .45s cubic-bezier(.34,1.56,.64,1);
}
.overlay .panel-over h2 { margin: 0 0 14px; font-size: 32px; font-family: 'Baloo 2','Fredoka',sans-serif; font-weight: 800;
  background: linear-gradient(180deg,#5fb85a,#ff9b2f); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.go-banner {
  margin: 0 0 6px; font-family: 'Baloo 2','Fredoka',sans-serif; font-weight: 800; line-height: 1.05;
  font-size: 46px; letter-spacing: 1px; -webkit-text-stroke: 2px rgba(0,0,0,.12);
  animation: popBounce .5s cubic-bezier(.34,1.56,.64,1);
}
.go-banner.win  { color: #ffb02e; text-shadow: 0 3px 0 rgba(255,155,47,.35), 0 10px 22px rgba(255,155,47,.35); }
.go-banner.lose { color: #8294bc; text-shadow: 0 3px 0 rgba(73,94,126,.2); }
.go-banner.draw { color: #6aa9d6; text-shadow: 0 3px 0 rgba(73,94,126,.18); }
.winner-line {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 20px; font-weight: 800; color: var(--ink); margin-bottom: 4px;
}
.winner-line .pdot { width: 18px; height: 18px; }
.go-detail { font-size: 14px; font-weight: 700; color: #8294bc; margin-bottom: 14px; }
.sbrow { display: flex; justify-content: space-between; gap: 16px; padding: 6px 8px; font-size: 15px; font-weight: 600; border-bottom: 2px dashed #e4f1fb; border-radius: 8px; }
.sbrow:last-of-type { border-bottom: none; }
.sbrow .nm { display: flex; align-items: center; gap: 8px; }
.sbrow.winrow { background: linear-gradient(90deg, rgba(255,206,74,.22), rgba(255,206,74,.05)); border-bottom-color: transparent; font-weight: 800; }
.sbrow.winrow .crown { font-size: 15px; }

.hud-bottom { width: min(900px, 98vw); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mystats { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stat {
  display: flex; align-items: center; gap: 6px;
  background: linear-gradient(180deg, #ffffff, #eef7ff); border: 2.5px solid var(--panel-border);
  padding: 7px 13px; border-radius: 999px; font-weight: 800; font-size: 15px;
  box-shadow: 0 4px 0 #e0eef9, inset 0 1px 0 rgba(255,255,255,.9);
}
.stat .ic { font-size: 17px; }
.slot { min-width: 48px; justify-content: center; }
.slot.empty { opacity: .4; }
.scorestrip { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 6px; background: #fff; border: 2px solid var(--panel-border);
  padding: 5px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; box-shadow: 0 3px 0 #e8f2fb;
}
.chip.dead { opacity: .45; filter: grayscale(.5); }
.chip .pdot { width: 13px; height: 13px; }

.game-main { display: flex; align-items: stretch; justify-content: center; gap: 12px; max-width: 98vw; }
.gamechat { width: 260px; flex-shrink: 0; display: flex; flex-direction: column; }
.gamechat .chatlog { flex: 1; max-height: none; min-height: 0; background: rgba(240,248,255,.9); }
.gamechat-input {
  width: 100%; margin-top: 8px; padding: 9px 16px; border-radius: 999px; font-family: inherit; font-weight: 600;
  background: #fff; border: 2.5px solid var(--panel-border); color: var(--ink); font-size: 13px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: linear-gradient(180deg,#ff8a9a,#ff5d73); color: #fff; padding: 13px 22px; border-radius: 999px;
  font-weight: 800; border: 3px solid #fff;
  opacity: 0; transition: all .25s cubic-bezier(.34,1.56,.64,1); pointer-events: none; z-index: 100; max-width: 90vw;
  box-shadow: 0 10px 26px rgba(255,99,120,.4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 880px) {
  .lobby-grid { grid-template-columns: 1fr; }
  .character-pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .setup-summary { grid-template-columns: 1fr; }
  .modal-card .mode-pick, .modal-card .map-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-card { max-height: 90vh; padding: 14px; border-radius: 20px; }
  #game { padding: 6px; gap: 8px; }
  .game-main { flex-direction: column; align-items: center; width: min(900px, 100vw); }
  .hud-top, .hud-bottom, .gamechat { width: min(900px, 100vw); }
  .gamechat { flex-shrink: 1; }
  .gamechat .chatlog { max-height: 90px; }
  .stage { padding: 6px; border-radius: 20px; }
  #board { width: min(76vh, calc(100vw - 22px)); }
  .timer { font-size: 26px; }
  .match-info { font-size: 12.5px; }
  .stat { padding: 6px 10px; font-size: 13px; }
  .overlay .big { font-size: 62px; -webkit-text-stroke: 3px #ff9b2f; }
  .logo { font-size: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
