@font-face { font-family: 'Press Start 2P'; src: url('fonts/press-start-2p.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Pixelify Sans'; src: url('fonts/pixelify-sans-500.woff2') format('woff2'); font-weight: 400 600; font-display: swap; }
@font-face { font-family: 'Pixelify Sans'; src: url('fonts/pixelify-sans-700.woff2') format('woff2'); font-weight: 700 900; font-display: swap; }

:root {
  --ink: #1b1020;
  --paper: #fff4d6;
  --paper-2: #f3e2b8;
  --slime: #8fdc3a;
  --slime-d: #4f9a2b;
  --goo: #6cbf3c;
  --pink: #ff86b8;
  --red: #e8344a;
  --gold: #ffd23f;
  --blue: #4fb3ff;
  --purple: #9a6bd1;
  --orange: #ff8a1f;
  --shadow: 0 4px 0 var(--ink);
  --title: 'Press Start 2P', monospace;
  --body: 'Pixelify Sans', 'Trebuchet MS', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2b1d33; color: var(--ink); font-family: var(--body); font-size: 18px; user-select: none; }
canvas#game { position: fixed; inset: 0; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
/* Above #loading, so a dialog shown during startup (like the sync "Two different goblins!" choice) is visible. */
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
#ui > * { pointer-events: auto; }
#ui > #bubble, #ui > #toasts, #ui > #screen { pointer-events: none; }
#screen > * { pointer-events: none; }
#screen > * > * { pointer-events: auto; }
.hidden { display: none !important; }
#loading { position: fixed; inset: 0; z-index: 1; display: grid; place-items: center; color: var(--slime); font-family: var(--title); font-size: 16px; background: #2b1d33; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--title); font-size: 12px; line-height: 1.3; color: var(--ink);
  background: var(--paper); border: 4px solid var(--ink); padding: 10px 14px; cursor: pointer;
  box-shadow: inset -4px -4px 0 rgba(0,0,0,.18), inset 4px 4px 0 rgba(255,255,255,.5), var(--shadow);
  position: relative; transition: transform .05s; white-space: nowrap;
}
@media (hover: hover) { .btn:hover { transform: translateY(-2px); filter: brightness(1.06); } }
.btn:active { transform: translateY(3px); box-shadow: inset -4px -4px 0 rgba(0,0,0,.18), 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.slime { background: var(--slime); }
.btn.pink { background: var(--pink); }
.btn.gold { background: var(--gold); }
.btn.blue { background: var(--blue); }
.btn.red { background: #ff6b6b; }
.btn.purple { background: #c4a0ff; }
.btn.small { font-size: 10px; padding: 6px 9px; border-width: 3px; }
.btn.big { font-size: 16px; padding: 16px 22px; }
.btn.on { background: var(--gold); }
.btn .key { display: inline-block; font-size: 8px; opacity: .6; margin-left: 4px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; gap: 12px; align-items: flex-start; }
.nameplate, .coins { font-family: var(--title); font-size: 14px; background: var(--paper); border: 4px solid var(--ink); padding: 10px 14px; box-shadow: var(--shadow); }
.coins { background: var(--gold); display: flex; align-items: center; gap: 8px; }
.coins .coin-ico { width: 18px; height: 18px; background: #ffe14d; border: 3px solid #a8701c; border-radius: 50%; box-shadow: inset -3px -3px 0 #e0a020; }
.coins.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.18); } }
.spacer { flex: 1; }

.stats { position: absolute; left: 14px; top: 84px; display: flex; flex-direction: column; gap: 8px; width: 230px; }
.stat { background: var(--paper); border: 4px solid var(--ink); padding: 6px 8px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; }
.stat .ico { font-size: 18px; width: 24px; text-align: center; }
.stat .lbl { font-family: var(--title); font-size: 9px; width: 54px; }
.stat .bar { flex: 1; height: 14px; background: #3a2a40; border: 2px solid var(--ink); position: relative; overflow: hidden; }
.stat .fill { position: absolute; inset: 0 auto 0 0; background: var(--slime); transition: width .4s; }
.stat .fill.low { background: var(--red); animation: blink 1s infinite; }
.stat .fill.mid { background: var(--gold); }
@keyframes blink { 50% { filter: brightness(1.5); } }

.actions { position: absolute; left: 0; right: 0; bottom: 16px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 0 14px; pointer-events: none; }
.actions > * { pointer-events: auto; }
.actions .btn { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 96px; padding: 10px 10px; font-size: 10px; }
.actions .btn .emo { font-size: 26px; line-height: 1; font-family: initial; }
.actions .btn.math { background: var(--gold); min-width: 150px; font-size: 12px; }
.actions .btn.math .emo { font-size: 30px; }

.away-banner { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); text-align: center; background: var(--paper); border: 4px solid var(--ink); box-shadow: var(--shadow); padding: 20px 26px; max-width: 460px; }
.away-banner h2 { font-family: var(--title); font-size: 14px; margin: 0 0 10px; line-height: 1.5; }
.away-banner .timer { font-family: var(--title); font-size: 26px; margin: 12px 0; color: #7a3fb5; }

/* ---------- speech bubble ---------- */
.bubble {
  position: fixed; transform: translate(-50%, -100%); max-width: 320px; min-width: 120px;
  background: #fff; border: 4px solid var(--ink); padding: 10px 14px; font-size: 18px; font-weight: 600; line-height: 1.25;
  box-shadow: var(--shadow); text-align: center; z-index: 5;
}
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -16px; width: 16px; height: 12px; background: #fff; border: 4px solid var(--ink); border-top: none; transform: translateX(-50%); clip-path: polygon(0 0, 100% 0, 50% 100%); }

/* ---------- panels & modals ---------- */
.panel {
  position: fixed; right: 14px; top: 14px; bottom: 14px; width: min(460px, 46vw); background: var(--paper);
  border: 4px solid var(--ink); box-shadow: 6px 6px 0 rgba(0,0,0,.35); display: flex; flex-direction: column; z-index: 4;
}
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 4px solid var(--ink); background: var(--paper-2); }
.panel-head h2 { font-family: var(--title); font-size: 14px; margin: 0; flex: 1; }
.panel-body { flex: 1; overflow-y: auto; padding: 14px; }
.panel-foot { border-top: 4px solid var(--ink); padding: 12px 14px; background: var(--paper-2); }
.panel-body::-webkit-scrollbar { width: 14px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--slime-d); border: 3px solid var(--paper); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab { font-family: var(--title); font-size: 9px; padding: 7px 8px; border: 3px solid var(--ink); background: #fff; cursor: pointer; }
.tab.on { background: var(--slime); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.card { background: #fff; border: 4px solid var(--ink); padding: 8px 6px; text-align: center; cursor: pointer; position: relative; box-shadow: 0 3px 0 var(--ink); }
@media (hover: hover) { .card:hover { transform: translateY(-2px); } }
.card.sel { background: #fff9c4; outline: 4px solid var(--gold); }
.card.equipped::before { content: 'WEARING'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-family: var(--title); font-size: 7px; background: var(--slime); border: 2px solid var(--ink); padding: 2px 4px; }
.card img { width: 72px; height: 72px; image-rendering: pixelated; display: block; margin: 0 auto 4px; }
.card .nm { font-size: 15px; font-weight: 700; line-height: 1.1; min-height: 2.2em; display: flex; align-items: center; justify-content: center; }
.card .pr { font-family: var(--title); font-size: 10px; margin-top: 4px; color: #8a5a00; }
.card .pr.owned { color: var(--slime-d); }
.card .count { position: absolute; top: 4px; right: 6px; font-family: var(--title); font-size: 10px; background: var(--gold); border: 2px solid var(--ink); padding: 2px 4px; }
.card .mine { position: absolute; top: 4px; left: 4px; font-size: 14px; }
.detail { display: flex; gap: 12px; align-items: center; }
.detail img { width: 80px; height: 80px; image-rendering: pixelated; background: #fff; border: 3px solid var(--ink); }
.detail .txt { flex: 1; }
.detail h3 { margin: 0 0 4px; font-size: 20px; }
.detail p { margin: 0; font-size: 16px; line-height: 1.25; }
.detail .btns { display: flex; flex-direction: column; gap: 8px; }
.empty { text-align: center; padding: 30px 10px; font-size: 18px; opacity: .8; line-height: 1.4; }

.modal-wrap { position: fixed; inset: 0; background: rgba(20, 8, 30, .6); display: grid; place-items: center; z-index: 10; }
.modal { background: var(--paper); border: 4px solid var(--ink); box-shadow: 8px 8px 0 rgba(0,0,0,.4); padding: 22px 24px; width: min(640px, 94vw); max-height: 92vh; overflow-y: auto; position: relative; }
.modal h2 { font-family: var(--title); font-size: 16px; margin: 0 0 14px; line-height: 1.5; }
.modal p { font-size: 18px; line-height: 1.35; margin: 8px 0; }
.modal .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.modal .x { position: absolute; top: 10px; right: 10px; }
.modal input[type=text], .modal select { font-family: var(--body); font-size: 22px; padding: 8px 10px; border: 4px solid var(--ink); width: 100%; background: #fff; }
.modal label { font-family: var(--title); font-size: 10px; display: block; margin: 14px 0 6px; }
.skins { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.skin { width: 44px; height: 44px; border: 4px solid var(--ink); cursor: pointer; }
.skin.on { outline: 4px solid var(--gold); transform: scale(1.1); }

/* destinations */
.dest { display: flex; gap: 12px; align-items: center; background: #fff; border: 4px solid var(--ink); padding: 10px; margin-bottom: 10px; cursor: pointer; }
@media (hover: hover) { .dest:hover { background: #fff9c4; } }
.dest canvas { width: 120px; height: 75px; image-rendering: pixelated; border: 3px solid var(--ink); }
.dest .info { flex: 1; }
.dest h3 { margin: 0; font-size: 20px; }
.dest p { margin: 2px 0 0; font-size: 15px; }
.dest .meta { font-family: var(--title); font-size: 9px; margin-top: 6px; color: #7a3fb5; }

/* postcards */
.postcard { display: flex; background: #fffdf3; border: 4px solid var(--ink); box-shadow: 6px 6px 0 rgba(0,0,0,.3); }
.postcard canvas { width: 50%; image-rendering: pixelated; border-right: 3px dashed #b8a070; display: block; }
.postcard .back { flex: 1; padding: 14px 16px; font-size: 18px; line-height: 1.3; position: relative; }
.postcard .stamp { position: absolute; top: 10px; right: 10px; width: 44px; height: 52px; border: 3px dotted #b84a3a; display: grid; place-items: center; font-size: 26px; background: #ffe0d0; }
.postcard .from { font-family: var(--title); font-size: 9px; color: #7a3fb5; margin-bottom: 8px; padding-right: 50px; line-height: 1.6; }
.postcard .sig { margin-top: 10px; font-weight: 700; }
.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.album .thumb { cursor: pointer; border: 4px solid var(--ink); background: #fff; }
.album .thumb canvas { width: 100%; image-rendering: pixelated; display: block; }
.album .thumb div { font-family: var(--title); font-size: 8px; padding: 6px; line-height: 1.5; }

/* toasts & floaters */
#toasts { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 20; }
.toast { font-family: var(--title); font-size: 12px; background: var(--gold); border: 4px solid var(--ink); padding: 10px 14px; box-shadow: var(--shadow); animation: toast 2.6s forwards; }
@keyframes toast { 0% { transform: translateY(-20px); opacity: 0; } 10%, 85% { transform: none; opacity: 1; } 100% { opacity: 0; } }
.floater { position: fixed; font-family: var(--title); font-size: 16px; color: var(--gold); text-shadow: 3px 3px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink); pointer-events: none; animation: floatUp 1s forwards; z-index: 15; transform: translate(-50%, -50%); }
@keyframes floatUp { to { transform: translate(-50%, -160%); opacity: 0; } }

/* ---------- gauntlet ---------- */
.gauntlet { position: fixed; inset: 0; pointer-events: none; }
.gauntlet > * { pointer-events: auto; }
.g-top { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; gap: 12px; align-items: center; }
.g-timer { flex: 1; height: 30px; background: #3a2a40; border: 4px solid var(--ink); position: relative; box-shadow: var(--shadow); }
.g-timer .fill { position: absolute; inset: 0 auto 0 0; background: var(--slime); }
.g-timer .fill.hurry { background: var(--red); }
.g-timer .t { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--title); font-size: 12px; color: #fff; text-shadow: 2px 2px 0 var(--ink); }
.g-box { position: absolute; right: 4vw; top: 52%; transform: translateY(-50%); width: min(600px, 50vw); text-align: center; }
.g-card { background: var(--paper); border: 6px solid var(--ink); box-shadow: 8px 8px 0 rgba(0,0,0,.35); padding: 34px 20px 28px; }
.g-prob { font-family: var(--title); font-size: clamp(22px, 3.2vw, 46px); line-height: 1.3; white-space: nowrap; word-spacing: -0.35em; }
.g-ans { display: inline-block; min-width: 2.2em; border-bottom: 6px solid var(--ink); color: #7a3fb5; margin-left: .35em; word-spacing: normal; }
.g-ans.blink::after { content: '_'; animation: blink 1s infinite; opacity: .5; }
.g-card.right { animation: goodflash .3s; }
.g-card.wrong { animation: shake .4s; background: #ffd6d6; }
@keyframes goodflash { 0% { background: #d6ffc0; transform: scale(1.04); } }
@keyframes shake { 20% { transform: translateX(-10px); } 40% { transform: translateX(10px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
.g-hint { font-size: 18px; margin-top: 16px; min-height: 1.4em; font-weight: 700; }
.g-hint.fix { color: #b8203a; }
.g-meta { display: flex; justify-content: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.pill { font-family: var(--title); font-size: 11px; background: #fff; border: 3px solid var(--ink); padding: 8px 10px; }
.pill.combo { background: var(--gold); }
.pill.combo.hot { background: #ff8a1f; animation: bump .3s; }
.g-speed { font-family: var(--title); font-size: 14px; height: 18px; margin-top: 10px; color: #c66a00; }
.countdown { font-family: var(--title); font-size: 90px; color: var(--gold); text-shadow: 6px 6px 0 var(--ink); }
.results h2 { text-align: center; }
.res-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.res-grid div { background: #fff; border: 3px solid var(--ink); padding: 10px; text-align: center; }
.res-grid b { display: block; font-family: var(--title); font-size: 20px; margin-top: 6px; }
.res-best { text-align: center; font-family: var(--title); font-size: 14px; color: #fff; background: var(--red); border: 4px solid var(--ink); padding: 10px; margin: 10px 0; animation: bump .6s infinite; }
.tricky { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 6px; }
.tricky span { font-family: var(--title); font-size: 10px; background: #ffe0e6; border: 3px solid var(--ink); padding: 6px 8px; }

/* ---------- goblin's homework ---------- */
.hw-card { padding: 18px 18px 16px; }
/* lined school paper with a red margin */
.hw-sheet {
  font-family: var(--title); font-size: clamp(14px, 1.7vw, 24px); text-align: left; padding: 4px 10px 6px 44px; position: relative;
  background: #fffdf4 repeating-linear-gradient(transparent 0 calc(2em - 2px), #a9c8f0 calc(2em - 2px) 2em);
  border: 3px solid var(--ink);
}
.hw-sheet::before { content: ''; position: absolute; top: 0; bottom: 0; left: 34px; width: 2px; background: #f08a96; }
.hw-head { display: flex; justify-content: space-between; height: 2em; align-items: center; font-family: var(--body); font-weight: 700; font-size: .8em; color: #555; }
.hw-line { display: flex; align-items: center; height: 2em; white-space: nowrap; word-spacing: -0.35em; }
.hw-line.on { background: rgba(255, 210, 63, .45); margin: 0 -10px 0 -44px; padding: 0 10px 0 44px; }
.hw-line.later { opacity: .45; }
.hw-n { width: 2.4em; margin-left: -2.6em; font-size: .6em; color: #888; text-align: right; padding-right: .5em; }
.hw-expr { flex: 1; }
.hw-gob { color: #3d8a1c; display: inline-block; transform: rotate(-3deg); }
.hw-gob.struck { text-decoration: line-through 3px var(--red); color: #9a8f98; }
.hw-red, .hw-input { color: var(--red); margin-left: .5em; word-spacing: normal; display: inline-block; }
.hw-input { min-width: 1.6em; border-bottom: 4px solid var(--red); }
.hw-input.blink::after { content: '_'; animation: blink 1s infinite; opacity: .5; }
.hw-mark { color: var(--red); min-width: 2.6em; text-align: right; font-family: initial; font-weight: 900; font-size: 1.15em; }
.hw-star { font-size: .7em; margin-left: .15em; }
.hw-ctl .g-hint { margin-top: 10px; }
.hw-btns { display: flex; gap: 14px; justify-content: center; margin-top: 10px; min-height: 52px; }
@media (max-height: 700px) { .hw-card.done .hw-sheet { display: none; } } /* results need the room; the tricky ones are listed anyway */

/* ---------- workshop ---------- */
.ws { position: fixed; inset: 0; pointer-events: none; }
.ws > * { pointer-events: auto; }
.ws-top { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 10px; align-items: center; }
.ws-top input { font-family: var(--body); font-size: 20px; font-weight: 700; padding: 8px 10px; border: 4px solid var(--ink); width: 280px; }
.ws-title { font-family: var(--title); font-size: 13px; background: var(--paper); border: 4px solid var(--ink); padding: 10px 12px; box-shadow: var(--shadow); }
.ws-left { position: absolute; left: 12px; top: 80px; display: flex; flex-direction: column; gap: 8px; width: 150px; }
.ws-left .btn { text-align: left; }
.ws-right { position: absolute; right: 12px; top: 80px; width: 196px; background: var(--paper); border: 4px solid var(--ink); padding: 10px; box-shadow: var(--shadow); }
.ws-right h3 { font-family: var(--title); font-size: 10px; margin: 0 0 8px; }
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.swatch { aspect-ratio: 1; border: 3px solid var(--ink); cursor: pointer; position: relative; }
.swatch.on { outline: 3px solid #fff; box-shadow: 0 0 0 6px var(--ink); z-index: 1; }
.swatch .n { position: absolute; bottom: -1px; right: 1px; font-size: 9px; font-family: var(--title); color: #fff; text-shadow: 1px 1px 0 #000; }
.ws-cur { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 15px; }
.ws-cur input[type=color] { width: 48px; height: 36px; border: 3px solid var(--ink); padding: 0; background: none; cursor: pointer; }
.ws-help { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); background: rgba(255,244,214,.95); border: 4px solid var(--ink); padding: 8px 14px; font-size: 16px; font-weight: 600; text-align: center; box-shadow: var(--shadow); white-space: nowrap; }
.ws-count { font-family: var(--title); font-size: 9px; margin-top: 10px; opacity: .7; }
.ws-pick { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(20,8,30,.55); }
.ws-pick .modal { width: min(860px, 94vw); }
.ws-top { position: sticky; top: -22px; z-index: 2; display: flex; justify-content: space-between; gap: 10px; margin: -22px -24px 12px; padding: 12px 24px; background: var(--paper); border-bottom: 4px solid var(--ink); }
.card.locked { background: #e4e0e8; }
.card.locked img { filter: grayscale(1) brightness(0.85); opacity: 0.6; }
.card.locked .nm { color: #6a6474; }
.card .lock { position: absolute; top: 4px; right: 6px; font-size: 14px; }
.ws-warn { background: #ffe0a0; border: 4px solid var(--ink); padding: 8px 12px; font-size: 17px; font-weight: 700; line-height: 1.3; margin-bottom: 8px; }
.slotpick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.slotpick .btn { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px; font-size: 10px; }
.slotpick .btn .emo { font-size: 32px; font-family: initial; }

/* grown-up stuff */
.heat { display: grid; grid-template-columns: 30px repeat(9, 1fr); gap: 3px; margin: 10px 0; }
.heat div { font-family: var(--title); font-size: 9px; padding: 8px 0; text-align: center; border: 2px solid var(--ink); }
.heat .hd { border: none; background: none; font-weight: bold; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 14px; height: 14px; border: 2px solid var(--ink); display: inline-block; }
table.hist { width: 100%; border-collapse: collapse; font-size: 15px; }
table.hist td, table.hist th { border: 2px solid var(--ink); padding: 4px 6px; text-align: center; }
.holdbtn { position: relative; overflow: hidden; }
.holdbtn .prog { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--red); width: 0; }
.g-fixline { font-size: 24px !important; color: #b8203a; margin-bottom: 12px; }

/* math game picker */
.game-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.game-card { display: flex !important; flex-direction: column; align-items: center; gap: 8px; padding: 16px 10px !important; white-space: normal !important; text-align: center; }
.game-card .emo { font-size: 40px; font-family: initial; }
.game-card .gname { font-size: 13px; }
.game-card .gdesc { font-family: var(--body); font-size: 16px; line-height: 1.2; }
.game-card .gbest { font-size: 9px; color: #7a3fb5; }
.game-card:nth-child(1) { background: var(--gold); }
.game-card:nth-child(2) { background: var(--slime); }
.game-card:nth-child(3) { background: var(--pink); }
.game-card:nth-child(4) { background: var(--blue); }
.game-card:nth-child(5) { background: #c4a0ff; }
.game-card:nth-child(6) { background: var(--orange); }

/* fart rocket */
.g-timer.fuel .fill { background: linear-gradient(90deg, #7fbf3f, #c9e27a); }
.g-timer.fuel .fill.hurry { background: var(--red); animation: blink .5s infinite; }
.alt-pill { font-size: 14px !important; min-width: 110px; text-align: center; background: #c4a0ff !important; }

/* goblin café */
.ticket-card { background: #fffdf3; padding: 22px 20px 20px; }
.ticket { text-align: left; }
.ticket-head { font-family: var(--title); font-size: 11px; color: #7a3fb5; border-bottom: 3px dashed #b8a070; padding-bottom: 8px; margin-bottom: 8px; }
.ticket-row { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin: 6px 0; }
.ticket-row img { width: 48px; height: 48px; image-rendering: pixelated; background: #fff; border: 3px solid var(--ink); }
.ticket-row .q { font-family: var(--title); font-size: 16px; }
.ticket-row .n { flex: 1; }
.ticket-row .p { font-family: var(--title); font-size: 12px; color: #8a5a00; }
.ticket-note { font-size: 19px; font-weight: 600; margin: 6px 0; }
.ticket-note.big { font-size: 22px; font-weight: 700; }
.ticket-q { font-size: clamp(20px, 2.6vw, 34px) !important; margin-top: 12px; border-top: 3px dashed #b8a070; padding-top: 12px; text-align: center; }
.menu-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: left; }
.menu-list div { display: flex; align-items: center; gap: 6px; background: #fff; border: 3px solid var(--ink); padding: 4px 6px; font-size: 15px; font-weight: 700; }
.menu-list img { width: 32px; height: 32px; image-rendering: pixelated; }
.menu-list span { flex: 1; }
.menu-list b { font-family: var(--title); font-size: 10px; color: #8a5a00; }
.cust-bubble { background: #fff6d6; }

/* vacation status */
.away-banner .status { background: #fff; border: 3px solid var(--ink); padding: 10px 12px; margin: 6px 0 4px; }
.away-banner .status-label { font-family: var(--title); font-size: 9px; color: #7a3fb5; margin-bottom: 6px; }
.away-banner .status-text { font-size: 20px; font-weight: 700; line-height: 1.25; min-height: 2.5em; display: grid; place-items: center; }
.away-banner .status-text.pop { animation: statusPop .5s; }
@keyframes statusPop { 0% { opacity: 0; transform: translateY(6px); } 100% { opacity: 1; transform: none; } }
.ws-label { font-family: var(--title); font-size: 8px; color: #fff; margin-top: 8px; text-shadow: 2px 2px 0 var(--ink); }
.ws-brush { display: flex; gap: 4px; }
.ws-brush .btn { flex: 1; padding: 6px 2px; font-size: 9px; text-align: center; }
.ws-help div + div { font-size: 14px; opacity: .85; margin-top: 2px; }
.num { font-family: var(--title); font-size: .78em; letter-spacing: 0; }
.g-fixline { white-space: pre-line; line-height: 1.5; }

/* times-table unlock progress */
.unlock { background: #fff; border: 4px solid var(--ink); padding: 10px 12px; margin-bottom: 14px; }
.unlock-top { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; font-size: 17px; flex-wrap: wrap; }
.unlock-bar { height: 16px; background: #3a2a40; border: 3px solid var(--ink); margin-top: 8px; }
.unlock-bar div { height: 100%; background: linear-gradient(90deg, var(--slime), var(--gold)); }
.unlock-tip { font-size: 14px; margin-top: 6px; opacity: .75; }
.heat .locked { background: #cfc8bc; color: #8a8478; }

/* swamp sprint */
.race-bar { flex: 1; height: 44px; position: relative; background: linear-gradient(#b0814f, #9a6c40); border: 4px solid var(--ink); box-shadow: var(--shadow); margin-right: 26px; }
.race-dot { position: absolute; width: 14px; height: 8px; border: 2px solid var(--ink); }
.race-dot.you { width: 36px; height: 14px; top: 24px !important; font-family: var(--title); font-size: 7px; line-height: 10px; text-align: center; color: #fff; text-shadow: 1px 1px 0 var(--ink); outline: 2px solid var(--gold); z-index: 1; }
.race-flag { position: absolute; right: -26px; top: 4px; font-size: 24px; }
.place-pill { font-size: 16px !important; background: var(--gold) !important; min-width: 60px; text-align: center; }
.race-box { top: auto; bottom: 3vh; transform: none; width: min(560px, 46vw); }
.race-box .g-card { padding: 22px 18px 18px; }
.race-tag { position: fixed; transform: translate(-50%, -100%); font-family: var(--title); font-size: 9px; color: #fff; background: rgba(27,16,32,.75); padding: 4px 6px; pointer-events: none; white-space: nowrap; }

/* squid smackdown */
.g-timer.hp { height: 26px; }
.g-timer.hp.gob .fill { background: linear-gradient(90deg, #4f9a2b, var(--slime)); transition: width .25s; }
.g-timer.hp.gob .fill.hurry { background: var(--red); animation: blink .5s infinite; }
.g-timer.hp.squid .fill { background: linear-gradient(90deg, #b83a62, #ff86b8); transition: width .25s; }
.g-timer.hp .t { font-size: 10px; }
.vs { font-family: var(--title); font-size: 14px; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
.ko-pill { font-size: 16px !important; letter-spacing: 2px; }
.ko-pill span { color: #cfc8bc; }
.ko-pill span.on { color: #e0a020; }
.squid-warn { background: var(--red); border: 4px solid var(--ink); box-shadow: var(--shadow); padding: 8px 10px; margin-bottom: 12px; animation: bump .5s infinite; }
.squid-warn .w-text { font-family: var(--title); font-size: 12px; color: #fff; text-shadow: 2px 2px 0 var(--ink); margin-bottom: 6px; }
.squid-warn .w-bar { height: 12px; background: #3a2a40; border: 2px solid var(--ink); }
.squid-warn .w-bar .fill { height: 100%; background: var(--gold); }
.squid-warn.paused { animation: none; opacity: .75; }
.squid-bubble { background: #ffe0ec; }
.hit-flash { position: fixed; inset: 0; pointer-events: none !important; background: #ff2040; opacity: 0; }
.hit-flash.on { animation: hitflash .35s; }
@keyframes hitflash { 0% { opacity: .45; } 100% { opacity: 0; } }
.card.equipped.placed::before { content: 'IN DEN'; }
.card .pose-emo { font-size: 46px; line-height: 72px; height: 72px; margin-bottom: 4px; font-family: initial; }
.skin-any { font-size: 16px; margin-left: 6px; }
.skin-custom { width: 52px; height: 44px; padding: 0; border: 4px solid var(--ink); background: #fff; cursor: pointer; }

/* device sync */
.sync-code { font-family: var(--title); font-size: 14px; line-height: 1.6; background: #fff; border: 4px solid var(--ink); padding: 10px 12px; text-align: center; word-break: break-word; user-select: all; }
.sync-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.sync-pick > div { border: 4px solid var(--ink); background: #fff; padding: 10px; font-size: 17px; display: flex; flex-direction: column; gap: 4px; }
.sync-pick label { margin-top: 0; }
.sync-pick .btn { margin-top: 8px; }
.sync-wait { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(43, 29, 51, .85); color: var(--slime); font-family: var(--title); font-size: 14px; }
@media (max-width: 520px) { .sync-pick { grid-template-columns: 1fr; } }

/* ======================================================================
   Phones and tablets. Everything below only applies to touch screens
   (html.touch), so the computer layout stays exactly the same.
   ====================================================================== */

/* "Turn sideways" screen when a touch device is held upright */
#rotate { display: none; }
@media (orientation: portrait) {
  html.touch #rotate {
    position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
    background: #2b1d33; color: var(--slime); font-family: var(--title); font-size: 16px; line-height: 1.6; text-align: center; padding: 24px;
  }
  html.touch #rotate p { font-family: var(--body); font-size: 20px; color: var(--paper); margin: 0; }
  html.touch #rotate .rot-phone { font-size: 72px; font-family: initial; animation: rotPhone 2s ease-in-out infinite; }
}
@keyframes rotPhone { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

html.touch, html.touch body { touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-user-select: none; }
html.touch .key { display: none; }
html.touch .holdbtn { touch-action: none; }
html.touch .modal { max-height: 92dvh; }

/* ---------- number pad ---------- */
:root {
  --np-key: min(80px, calc((100vh - 120px) / 4 - 8px));
  --np-key: min(80px, calc((100dvh - 120px) / 4 - 8px));
  --np-w: calc(var(--np-key) * 3 + 44px);
}
.numpad {
  position: fixed; right: 12px; bottom: 12px; z-index: 6; display: grid; gap: 8px; padding: 10px;
  grid-template-columns: repeat(3, var(--np-key)); grid-auto-rows: var(--np-key);
  background: var(--paper-2); border: 4px solid var(--ink); box-shadow: var(--shadow); touch-action: none;
}
.np-key { padding: 0; font-size: calc(var(--np-key) * .4); display: grid; place-items: center; }
.np-key.press { animation: npPress .12s; }
.np-backspace { background: #ffb3b3; font-size: calc(var(--np-key) * .26); }
.np-enter { background: var(--slime); font-size: calc(var(--np-key) * .28); }
@keyframes npPress { 50% { transform: translateY(3px); filter: brightness(.9); } }
/* make room for the pad: the question card sits between the goblin and the pad */
html.numpad-on body .g-box { right: calc(var(--np-w) + 24px); width: min(560px, calc(100vw - var(--np-w) - 36vw)); }

/* ---------- short screens (phones held sideways) ---------- */
@media (max-height: 520px) {
  html.touch body { font-size: 15px; }
  html.touch .btn { font-size: 10px; padding: 8px 10px; }
  html.touch .btn.small { font-size: 9px; padding: 6px 8px; }
  html.touch .btn.big { font-size: 13px; padding: 12px 16px; }

  /* home */
  html.touch .topbar { top: 8px; left: 10px; right: 10px; gap: 8px; }
  html.touch .nameplate, html.touch .coins { font-size: 11px; padding: 6px 10px; border-width: 3px; }
  html.touch .stats { top: 52px; left: 10px; width: 150px; gap: 4px; }
  html.touch .stat { padding: 3px 6px; border-width: 3px; box-shadow: 0 3px 0 var(--ink); }
  html.touch .stat .ico { font-size: 14px; width: 18px; }
  html.touch .stat .lbl { display: none; }
  html.touch .stat .bar { height: 10px; }
  html.touch .actions { bottom: 8px; gap: 6px; padding: 0 8px; }
  html.touch .actions .btn { min-width: 0; padding: 6px 8px; font-size: 8px; gap: 3px; border-width: 3px; }
  html.touch .actions .btn .emo { font-size: 20px; }
  html.touch .actions .btn.math { min-width: 0; font-size: 9px; }
  html.touch .actions .btn.math .emo { font-size: 22px; }
  html.touch .away-banner { top: 45%; padding: 12px 16px; max-width: 70vw; }
  html.touch .away-banner h2 { font-size: 11px; }
  html.touch .away-banner .timer { font-size: 20px; margin: 6px 0; }
  html.touch .away-banner p { margin: 4px 0; }
  html.touch .bubble { font-size: 15px; padding: 6px 10px; max-width: 260px; border-width: 3px; }
  html.touch #toasts { top: 50px; }

  /* side panels (shop, wardrobe, feed, decorate) */
  html.touch .panel { top: 8px; bottom: 8px; right: 8px; width: min(460px, 52vw); }
  html.touch .panel-head { padding: 6px 10px; border-bottom-width: 3px; }
  html.touch .panel-head h2 { font-size: 11px; }
  html.touch .panel-body { padding: 10px; }
  html.touch .panel-foot { padding: 8px 10px; border-top-width: 3px; }
  html.touch .tabs { margin-bottom: 8px; }
  html.touch .grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
  html.touch .card img { width: 56px; height: 56px; }
  html.touch .card .pose-emo { font-size: 36px; line-height: 56px; height: 56px; }
  html.touch .card .nm { font-size: 13px; }
  html.touch .detail img { width: 56px; height: 56px; }
  html.touch .detail h3 { font-size: 16px; }
  html.touch .detail p { font-size: 14px; }
  html.touch .detail .btns { gap: 6px; }

  /* pop-up windows */
  html.touch .modal { padding: 14px 16px; width: min(720px, 94vw); }
  html.touch .ws-top { top: -14px; margin: -14px -16px 10px; padding: 8px 16px; }
  html.touch .modal h2 { font-size: 12px; margin-bottom: 8px; padding-right: 36px; }
  html.touch .modal p { font-size: 15px; margin: 6px 0; }
  html.touch .modal label { margin: 10px 0 4px; }
  html.touch .modal input[type=text], html.touch .modal select { font-size: 17px; padding: 5px 8px; border-width: 3px; }
  html.touch .modal .row { margin-top: 10px; }
  html.touch .modal.onboard { width: min(560px, 62vw); margin-left: 34vw; }
  html.touch .skin { width: 36px; height: 36px; }
  html.touch .game-pick { grid-template-columns: repeat(6, 1fr); gap: 8px; }
  html.touch .game-card { padding: 10px 4px !important; gap: 6px; }
  html.touch .game-card .emo { font-size: 30px; }
  html.touch .game-card .gname { font-size: 9px; line-height: 1.4; }
  html.touch .game-card .gdesc { display: none; }
  html.touch .game-card .gbest { font-size: 7px; line-height: 1.5; }
  html.touch .unlock { padding: 6px 10px; margin-bottom: 10px; }
  html.touch .unlock-top { font-size: 14px; }
  html.touch .unlock-tip { display: none; }
  html.touch .dest { padding: 6px; margin-bottom: 6px; }
  html.touch .dest canvas { width: 96px; height: 60px; }
  html.touch .dest h3 { font-size: 16px; }
  html.touch .dest p { font-size: 13px; }

  /* math games */
  html.touch .g-top { top: 8px; left: 10px; right: 10px; gap: 8px; }
  html.touch .g-timer { height: 26px; border-width: 3px; }
  html.touch .g-timer .t { font-size: 9px; }
  html.touch .pill { font-size: 9px; padding: 5px 7px; border-width: 3px; white-space: nowrap; }
  html.touch .g-top > .pill:first-child { display: none; } /* game name: no room */
  html.touch .g-box { top: calc(50% + 22px); max-height: calc(100dvh - 60px); overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
  html.touch .g-card { padding: 16px 12px 12px; border-width: 4px; box-shadow: 5px 5px 0 rgba(0,0,0,.35); }
  html.touch .g-prob { font-size: clamp(18px, 3.4vw, 34px); }
  html.touch .g-ans { border-bottom-width: 4px; }
  html.touch .g-hint { font-size: 15px; margin-top: 8px; }
  html.touch .g-speed { font-size: 11px; height: 14px; margin-top: 4px; }
  html.touch .g-meta { margin-top: 8px; gap: 6px; }
  html.touch .g-fixline { font-size: 17px !important; margin-bottom: 6px; }
  html.touch .g-card p { font-size: 15px !important; margin: 6px 0; }
  html.touch .countdown { font-size: 60px; }
  html.touch .results h2 { margin-bottom: 4px !important; }
  html.touch .res-grid { gap: 6px; margin: 6px 0; }
  html.touch .res-grid div { padding: 5px; font-size: 13px; }
  html.touch .res-grid b { font-size: 14px; margin-top: 3px; }
  html.touch .res-best { font-size: 11px; padding: 6px; margin: 6px 0; }
  html.touch .tricky span { font-size: 9px; padding: 4px 6px; }
  html.touch .g-box { width: min(640px, 60vw); }
  html.touch .g-card .g-prob[style] { font-size: 20px !important; } /* titles like MATH DASH! */
  html.touch .res-grid { grid-template-columns: repeat(4, 1fr); }
  html.touch .results h2 { font-size: 14px !important; }
  html.touch .results .row { margin-top: 8px !important; }
  html.touch .menu-list { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  html.touch .modal.onboard p { font-size: 14px; margin: 2px 0; }
  html.touch .modal.onboard label { margin: 6px 0 3px; }
  html.touch .hw-card { padding: 10px 10px 8px; }
  html.touch .hw-sheet { font-size: 14px; padding-left: 36px; border-width: 2px; }
  html.touch .hw-sheet::before { left: 28px; }
  html.touch .hw-line.on { margin-left: -36px; padding-left: 36px; }
  html.touch .hw-btns { margin-top: 6px; min-height: 40px; }
  html.touch .race-box { top: auto; bottom: 8px; }
  html.touch .race-bar { height: 34px; border-width: 3px; }
  html.touch .race-dot.you { top: 18px !important; }
  html.touch .race-flag { font-size: 20px; top: 2px; }
  html.touch .ticket-card { padding: 12px 12px 10px; }
  html.touch .ticket-head { font-size: 9px; padding-bottom: 4px; margin-bottom: 4px; }
  html.touch .ticket-row { font-size: 15px; margin: 3px 0; gap: 8px; }
  html.touch .ticket-row img { width: 32px; height: 32px; border-width: 2px; }
  html.touch .ticket-row .q { font-size: 12px; }
  html.touch .ticket-row .p { font-size: 9px; }
  html.touch .ticket-note { font-size: 15px; margin: 3px 0; }
  html.touch .ticket-note.big { font-size: 17px; }
  html.touch .ticket-q { font-size: clamp(16px, 2.8vw, 26px) !important; margin-top: 6px; padding-top: 6px; }
  html.touch .menu-list div { font-size: 13px; padding: 2px 4px; }
  html.touch .menu-list img { width: 24px; height: 24px; }
  html.touch .squid-warn { padding: 5px 8px; margin-bottom: 6px; }
  html.touch .squid-warn .w-text { font-size: 9px; margin-bottom: 4px; }
  html.touch .vs { font-size: 10px; }
  html.touch .ko-pill { font-size: 12px !important; }
  html.touch .place-pill { font-size: 12px !important; min-width: 0; }
  html.touch .alt-pill { font-size: 11px !important; min-width: 80px; }
}

@media (max-height: 400px) {
  html.touch .results > p { display: none; } /* "Super-fast facts" line: Grown-ups has it */
  html.touch .results > h2 { display: none; } /* the timer bar already says TIME! */
  html.touch .results .tricky { margin-top: 2px; }
}
@media (max-height: 320px) {
  html.touch .g-card .menu-list, html.touch .g-card div:has(+ .menu-list) { display: none; } /* Café menu: prices are on each ticket anyway */
  html.touch .results > div:has(.tricky) { display: none; }
}
