:root {
  --ink: #1b1f24;
  --ink2: #5b6573;
  --blue: #2f7cf6;
  --blue-d: #1d5fd0;
  --green: #00b06f;
  --green-d: #00965e;
  --red: #e5383b;
  --gold: #ffc531;
  --card: rgba(255, 255, 255, 0.95);
  --line: rgba(27, 31, 36, 0.1);
  --shadow: 0 6px 24px rgba(10, 30, 70, 0.18);
  --r: 14px;
  --font: "Fredoka", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: #a9d6ff; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
.off { display: none !important; }
.small { font-size: 14px; color: var(--ink2); }
.err { color: var(--red) !important; }
kbd { font: 600 12px var(--font); background: #eef1f5; border: 1px solid #d5dbe3; border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 700; font-size: 16px; cursor: pointer; text-decoration: none; background: var(--blue); color: #fff; box-shadow: 0 3px 0 var(--blue-d); transition: transform .06s, filter .15s; white-space: nowrap; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--blue-d); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.green { background: var(--green); box-shadow: 0 3px 0 var(--green-d); }
.btn.red { background: var(--red); box-shadow: 0 3px 0 #b5252a; }
.btn.big { font-size: 22px; padding: 14px 30px; border-radius: 16px; }
.btn.small { font-size: 14px; padding: 7px 12px; }
.btn.ghost { background: rgba(255,255,255,.9); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.btn.x-btn { background: #0f1419; box-shadow: 0 3px 0 #000; }
.hb { pointer-events: auto; border: 0; background: var(--card); border-radius: 12px; padding: 8px 12px; font-weight: 700; font-size: 15px; cursor: pointer; box-shadow: var(--shadow); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.hb:hover { background: #fff; }
.hb.make { background: var(--green); color: #fff; }
.x { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink2); }

/* ---------- game page */
body.game, body.editor { overflow: hidden; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.top-left { position: absolute; left: 14px; top: 12px; pointer-events: none !important; max-width: 40vw; }
.top-left .brand { pointer-events: auto; display: inline-block; background: rgba(255,255,255,.92); border-radius: 999px; padding: 3px 12px; font-weight: 700; font-size: 13px; text-decoration: none; box-shadow: var(--shadow); }
.obby-name { color: #fff; font-weight: 700; font-size: 24px; margin-top: 6px; text-shadow: 0 2px 6px rgba(0,0,0,.45); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.obby-sub { color: #fff; font-size: 14px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.timer { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); text-align: center; pointer-events: none !important; }
.timer .t { font-weight: 700; font-size: 38px; color: #fff; background: rgba(15, 20, 30, .45); border-radius: 16px; padding: 2px 18px; font-variant-numeric: tabular-nums; min-width: 140px; }
.timer.running .t { background: rgba(0, 150, 94, .75); }
.timer .hint { margin-top: 4px; color: #fff; font-size: 14px; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.top-right { position: absolute; right: 12px; top: 12px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; max-width: 50vw; pointer-events: none !important; }
.top-right > * { pointer-events: auto; }
.panel { position: absolute; background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; }
#p-board { right: 12px; top: 62px; width: 320px; max-height: calc(100vh - 140px); overflow: auto; }
.ph { display: flex; justify-content: space-between; align-items: center; font-size: 18px; position: relative; min-height: 24px; }
.ph .x { top: -4px; right: -4px; }
.psub { color: var(--ink2); font-size: 13px; margin: 2px 0 10px; }
.rows .row { display: grid; grid-template-columns: 34px 28px 1fr auto; align-items: center; gap: 8px; padding: 6px 4px; border-radius: 10px; font-weight: 600; }
.rows .row.me { background: #e6f0ff; }
.rk { text-align: center; font-size: 15px; }
.face { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; background: #f5cd30; display: inline-block; }
.face.blank { background: linear-gradient(135deg, #f5cd30, #e3b81f); }
.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tm { font-variant-numeric: tabular-nums; }
.empty { color: var(--ink2); text-align: center; padding: 10px; }
.chat { position: absolute; left: 12px; bottom: 12px; width: min(380px, 62vw); pointer-events: none !important; }
.chat .log { max-height: 170px; overflow: hidden; display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
.chat .line { align-self: flex-start; background: rgba(15, 20, 30, .5); color: #fff; padding: 3px 10px; border-radius: 10px; font-size: 14px; transition: opacity 1.2s; max-width: 100%; overflow-wrap: anywhere; }
.chat .line.sys { color: #d6e6ff; font-style: italic; }
.chat .line.gold { background: rgba(200, 140, 0, .8); }
.chat .line.old { opacity: 0; }
.chat input { pointer-events: auto; width: 100%; border: 0; border-radius: 12px; padding: 9px 12px; background: rgba(255,255,255,.88); box-shadow: var(--shadow); outline: none; font-size: 15px; }
.chat input:focus { background: #fff; }
.reset { position: absolute; right: 14px; bottom: 14px; border: 0; background: var(--card); border-radius: 12px; padding: 10px 14px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); }
.finish { position: absolute; left: 50%; top: 18%; transform: translateX(-50%); background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 22px 30px; text-align: center; width: min(420px, 92vw); animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.finish .fl { font-size: 16px; color: var(--ink2); font-weight: 600; }
.finish .ft { font-size: 58px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.finish .fs { font-size: 17px; margin: 4px 0 14px; font-weight: 600; }
.fb { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.flash { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(.8); color: #fff; font-size: 40px; font-weight: 700; text-shadow: 0 3px 10px rgba(0,0,0,.45); opacity: 0; pointer-events: none !important; white-space: nowrap; }
.flash.show { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); } 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(1); } }
@keyframes pop { from { transform: translateX(-50%) scale(.85); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

#title { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(180deg, rgba(20, 60, 140, .25), rgba(10, 20, 50, .45)); padding: 16px; z-index: 5; }
#title .card { background: var(--card); border-radius: 26px; box-shadow: var(--shadow); padding: 26px 28px 22px; width: min(460px, 100%); text-align: center; }
#title .kick { font-weight: 700; color: var(--blue); font-size: 15px; letter-spacing: .02em; }
#title h1 { font-size: 36px; margin: 4px 0 6px; line-height: 1.1; overflow-wrap: anywhere; }
#title .meta { color: var(--ink2); font-weight: 600; }
#title .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
#title .stats div { background: #f1f5fb; border-radius: 14px; padding: 10px; display: flex; flex-direction: column; }
#title .stats b { font-size: 24px; font-variant-numeric: tabular-nums; }
#title .stats span { font-size: 13px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#title .btn.big { width: 100%; font-size: 26px; padding: 16px; }
#title .how { margin-top: 14px; color: var(--ink2); font-size: 14px; }
#title p { color: var(--ink2); font-size: 17px; }
#load { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: linear-gradient(180deg, #2f7cf6, #8cc4ff); color: #fff; font-weight: 700; font-size: 18px; z-index: 6; }
.spin { width: 46px; height: 46px; border-radius: 10px; background: #f5cd30; animation: spin 1s cubic-bezier(.6, 0, .4, 1) infinite; box-shadow: 0 4px 0 #c9a419; }
@keyframes spin { to { transform: rotate(360deg); } }

/* touch controls */
#stick { display: none; position: fixed; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,255,255,.22); border: 3px solid rgba(255,255,255,.55); pointer-events: none; z-index: 3; }
#knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255,255,255,.75); }
#t-jump { display: none; position: fixed; right: 26px; bottom: 34px; width: 86px; height: 86px; border-radius: 50%; border: 3px solid rgba(255,255,255,.7); background: rgba(255,255,255,.3); color: #fff; font-size: 34px; z-index: 3; touch-action: none; text-shadow: 0 1px 4px rgba(0,0,0,.4); }
#t-jump.down { background: rgba(255,255,255,.6); }
body.touch.playing #t-jump { display: block; }
body.touch .reset { right: auto; left: 50%; transform: translateX(-50%); bottom: 12px; padding: 7px 12px; font-size: 14px; }
body.touch .chat input { display: none; }
body.touch .chat { bottom: 52px; width: 58vw; }

/* ---------- modal + toasts */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 20, 40, .45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal { position: relative; background: #fff; border-radius: 22px; box-shadow: var(--shadow); padding: 24px; width: min(480px, 100%); max-height: 92vh; overflow: auto; }
.modal h2 { margin: 0 0 8px; font-size: 26px; }
.modal p { color: var(--ink2); margin: 6px 0 12px; }
.modal ol { padding-left: 22px; margin: 10px 0 14px; display: grid; gap: 12px; font-weight: 600; }
.modal .btn { margin-top: 2px; }
.field { width: 100%; border: 2px solid #dfe5ee; border-radius: 12px; padding: 10px 12px; margin-top: 6px; outline: none; font-size: 15px; font-weight: 500; }
.field:focus { border-color: var(--blue); }
.cardimg { width: 100%; border-radius: 12px; display: block; margin: 6px 0; aspect-ratio: 1200 / 630; object-fit: cover; background: #eef3fa; }
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 30; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: rgba(15, 20, 30, .85); color: #fff; padding: 9px 16px; border-radius: 12px; font-weight: 600; transition: opacity .4s, transform .4s; text-align: center; }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* ---------- editor */
#bar { position: fixed; left: 0; right: 0; top: 0; height: 58px; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: rgba(255,255,255,.96); box-shadow: 0 2px 12px rgba(10,30,70,.12); z-index: 4; }
#bar .brand { font-weight: 700; text-decoration: none; color: var(--blue); font-size: 18px; }
#bar #name { border: 2px solid #dfe5ee; border-radius: 10px; padding: 7px 10px; width: 240px; font-weight: 600; outline: none; }
#bar #name:focus { border-color: var(--blue); }
#bar .grp { display: flex; gap: 6px; }
#bar .grp.right { margin-left: auto; }
#bar .hb { box-shadow: none; background: #eef2f7; }
.status { font-size: 14px; color: var(--ink2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.ok { color: var(--green-d); }
.status.warn { color: #b77700; }
.status.err { color: var(--red); }
#b-copy { display: none; }
body.live #b-copy { display: inline-flex; }
body.live #tools, body.live .edit-only { opacity: .45; pointer-events: none; }
#tools { position: fixed; left: 10px; top: 70px; display: flex; flex-direction: column; gap: 4px; background: rgba(255,255,255,.95); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px; z-index: 3; }
.tool { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; border: 0; background: none; padding: 7px 9px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px; text-align: left; }
.tool:hover { background: #eef3fa; }
.tool.sel { background: var(--blue); color: #fff; }
.tool.sel kbd { color: var(--ink); }
.tool .ic { width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; font-size: 15px; }
.tool .sw { box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
#props { right: 10px; top: 70px; width: 290px; max-height: calc(100vh - 84px); overflow: auto; z-index: 3; }
#props .lbl { font-size: 13px; color: var(--ink2); font-weight: 600; margin: 12px 0 4px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.num { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--ink2); font-weight: 600; margin-top: 6px; }
.num input, .num select { width: 100%; border: 2px solid #dfe5ee; border-radius: 8px; padding: 5px 6px; font-size: 14px; color: var(--ink); font-weight: 600; outline: none; background: #fff; }
.num input:focus, .num select:focus { border-color: var(--blue); }
.chk { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 600; margin-top: 10px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.swatch { aspect-ratio: 1; border-radius: 7px; border: 2px solid rgba(0,0,0,.12); cursor: pointer; padding: 0; }
.swatch.on { outline: 3px solid var(--blue); outline-offset: 1px; }
#props .fb { margin-top: 16px; justify-content: flex-start; }
#help { left: 210px; top: 70px; width: 420px; z-index: 5; font-size: 14px; }
#help ul { padding-left: 18px; margin: 6px 0 12px; display: grid; gap: 5px; }
#testbar { display: none; position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); background: rgba(255,255,255,.96); border-radius: 16px; box-shadow: var(--shadow); padding: 8px 10px 8px 16px; align-items: center; gap: 12px; z-index: 4; max-width: 94vw; }
#testbar .t { font-weight: 700; font-size: 26px; font-variant-numeric: tabular-nums; min-width: 84px; }
#testbar .msg { font-weight: 600; font-size: 14px; color: var(--ink2); max-width: 360px; }
body.testing #testbar { display: flex; }
body.testing #tools, body.testing #props, body.testing #help, body.testing .edit-only, body.testing #b-publish { display: none !important; }
body.testing #b-test { background: var(--red); box-shadow: 0 3px 0 #b5252a; }

/* ---------- home */
body.home { background: #eaf4ff; min-height: 100%; }
.sky { background: linear-gradient(180deg, #2f7cf6, #6fb1ff); }
.nav { display: flex; align-items: center; gap: 14px; max-width: 1100px; margin: 0 auto; padding: 16px 20px; }
.logo { font-weight: 700; font-size: 26px; color: #fff; text-decoration: none; text-shadow: 0 2px 0 rgba(0,0,0,.15); }
.live-pill { white-space: nowrap; margin-left: auto; background: rgba(255,255,255,.18); color: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.live-pill i { width: 9px; height: 9px; border-radius: 50%; background: #3dff9e; box-shadow: 0 0 0 4px rgba(61,255,158,.25); }
main { max-width: 1100px; margin: 0 auto; padding: 0 20px 40px; }
.hero { color: #fff; max-width: 1100px; margin: 0 auto; padding: 26px 20px 44px; }
.hero h1 { font-size: clamp(36px, 6vw, 60px); line-height: 1.02; margin: 0 0 16px; }
.hero h1 span { color: #ffe066; }
.hero p { font-size: 19px; max-width: 560px; opacity: .95; margin: 0 0 22px; }
.cta { display: flex; gap: 12px; flex-wrap: wrap; }
main h2 { font-size: 26px; margin: 26px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.ocard { background: #fff; border-radius: 18px; overflow: hidden; text-decoration: none; box-shadow: 0 4px 16px rgba(10,30,70,.1); transition: transform .12s, box-shadow .12s; display: flex; flex-direction: column; }
.ocard:hover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(10,30,70,.16); }
.thumb { position: relative; aspect-ratio: 1200 / 630; background: linear-gradient(135deg, #8cc4ff, #2f7cf6); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .noimg { width: 100%; height: 100%; display: grid; place-items: center; color: #fff; font-size: 54px; font-weight: 700; }
.thumb .here { position: absolute; left: 10px; top: 10px; background: var(--green); color: #fff; font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px; }
.info { padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 2px; }
.info b { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info span { color: var(--ink2); font-size: 14px; }
.info .rec { color: #8a6100; font-weight: 600; }
footer { text-align: center; color: var(--ink2); font-size: 13px; padding: 20px; }

@media (max-width: 720px) {
  .obby-name { font-size: 18px; }
  .timer .t { font-size: 28px; min-width: 100px; padding: 2px 12px; }
  .top-left { max-width: 34vw; }
  .top-right { max-width: 40vw; gap: 6px; }
  .hb { padding: 6px 9px; font-size: 13px; }
  .hb.make { display: none; }
  #p-board { left: 12px; right: 12px; width: auto; }
  #title h1 { font-size: 30px; }
  #bar #name { width: 130px; }
  #bar .status { display: none; }
  #tools { top: 66px; padding: 4px; }
  .tool span:not(.ic), .tool kbd { display: none; }
  .tool { grid-template-columns: 22px; }
  #props { left: 10px; right: 10px; width: auto; top: auto; bottom: 10px; max-height: 45vh; }
  #help { left: 10px; right: 10px; width: auto; }
  .nav .btn { display: none; }
  .hb .long { display: none; }
}

/* ---------- inside an X post (480 x 480 player card) */
#title .mk { display: inline-block; margin-top: 10px; font-size: 14px; font-weight: 600; color: var(--blue); text-decoration: none; }
body.embed .obby-sub { font-size: 12px; }
body.embed .obby-name { font-size: 17px; margin-top: 4px; }
body.embed .top-left .brand { font-size: 11px; padding: 2px 9px; }
body.embed .timer .t { font-size: 24px; min-width: 88px; padding: 1px 10px; border-radius: 12px; }
body.embed .timer .hint { font-size: 12px; }
body.embed .hb { padding: 5px 8px; font-size: 13px; border-radius: 10px; }
body.embed .chat { width: 58%; }
body.embed .chat .log { max-height: 84px; }
body.embed .chat .line { font-size: 12px; }
body.embed .chat input { padding: 6px 10px; font-size: 13px; }
body.embed .reset { padding: 6px 10px; font-size: 13px; }
body.embed #title { padding: 10px; }
body.embed #title .card { padding: 16px 18px 14px; border-radius: 20px; }
body.embed #title h1 { font-size: 26px; }
body.embed #title .meta { font-size: 13px; }
body.embed #title .stats { margin: 10px 0; gap: 8px; }
body.embed #title .stats div { padding: 6px; }
body.embed #title .stats b { font-size: 18px; }
body.embed #title .btn.big { font-size: 22px; padding: 11px; }
body.embed #title .how { margin-top: 8px; font-size: 12px; }
body.embed .finish { top: 14%; padding: 14px 18px; }
body.embed .finish .ft { font-size: 42px; }
body.embed .finish .fs { font-size: 15px; margin-bottom: 10px; }
body.embed #p-board { top: 50px; max-height: calc(100vh - 110px); }
body.embed #t-jump { width: 70px; height: 70px; right: 16px; bottom: 20px; font-size: 28px; }
body.embed .top-right { flex-wrap: nowrap; gap: 5px; max-width: none; }
body.embed #b-sound, body.embed .hb .long { display: none; }
body.embed .top-left { max-width: 30%; }
