:root {
  --ink: #34233f;
  --ink-soft: #6b5a78;
  --paper: #fff8e8;
  --cream: #ffeec8;
  --broth: #f4b942;
  --broth-deep: #d9951c;
  --chili: #e4572e;
  --teal: #2fa4b5;
  --teal-light: #8fe0ea;
  --matcha: #8cbf5a;
  --plum-glass: rgba(52, 35, 63, 0.55);
  --display: "Bagel Fat One", "Baloo 2", system-ui, sans-serif;
  --body: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --pop: 0 4px 0 var(--ink);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #2b1f36;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
body { -webkit-touch-callout: none; }
button:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 0;
  gap: 12px;
}
.hud-left { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; }
.hud-right { display: flex; gap: 8px; }
.pill {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: var(--pop);
  padding: 2px 14px 0; height: 38px;
  font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.clock-icon { width: 20px; height: 20px; border-radius: 50%; background: var(--broth); border: 2.5px solid var(--ink); flex: none; }
.clock-icon.moon { background: #d9d4ff; box-shadow: inset -5px -2px 0 #9d94d8; }
.meters { display: flex; gap: 8px; align-items: center; }
.meter {
  display: flex; align-items: center; gap: 6px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 999px; box-shadow: var(--pop);
  padding: 0 10px 0 6px; height: 38px;
}
.meter-icon { width: 24px; height: 24px; }
.bar { width: 96px; height: 14px; border: 2.5px solid var(--ink); border-radius: 999px; background: #e7dcc6; overflow: hidden; }
.bar-fill { height: 100%; width: 70%; border-radius: 999px; transition: width .2s linear; }
.bar-fill.water { background: linear-gradient(180deg, var(--teal-light), var(--teal)); }
.bar-fill.low { background: linear-gradient(180deg, #ffab8f, var(--chili)); animation: throb .6s ease-in-out infinite alternate; }
@keyframes throb { to { opacity: .55; } }
.coin { width: 18px; height: 18px; border-radius: 50%; background: var(--broth); border: 2.5px solid var(--ink); box-shadow: inset 0 -3px 0 var(--broth-deep); }
.goal {
  height: auto; min-height: 38px; padding: 6px 14px 4px 6px; border-radius: 16px;
  white-space: normal; text-align: left; max-width: min(360px, calc(100vw - 150px));
  font-size: 15px; line-height: 1.2; font-weight: 700; gap: 8px;
}
.goal-label {
  flex: none; background: var(--chili); color: var(--paper); border-radius: 10px;
  padding: 3px 8px 1px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; font-weight: 800;
}
.goal.flash { animation: goalflash .9s ease; }
@keyframes goalflash { 0%,100% { transform: none; } 30% { transform: scale(1.08) rotate(-1.5deg); background: #fff1a8; } }

.icon-btn {
  pointer-events: auto; position: relative;
  width: 54px; height: 54px; border-radius: 18px;
  background: var(--paper); border: 3px solid var(--ink); box-shadow: var(--pop);
  display: grid; place-items: center; font-size: 22px;
  transition: transform .08s;
}
.icon-btn.small { width: 44px; height: 44px; border-radius: 14px; font-size: 18px; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.badge {
  position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%);
  background: var(--broth); border: 2.5px solid var(--ink); border-radius: 999px;
  font-size: 12px; font-weight: 800; padding: 1px 6px 0; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.badge.dot { width: 16px; height: 16px; padding: 0; background: var(--chili); top: -6px; right: -6px; bottom: auto; left: auto; transform: none; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.25); } }
.icon-fs { width: 22px; height: 22px; display: block; background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2334233f' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 9V3h6M15 3h6v6M21 15v6h-6M9 21H3v-6'/%3E%3C/svg%3E"); }
#fsBtn.on .icon-fs { transform: scale(.7); }
.touch-how { display: none; margin: 8px 0 0; font-weight: 800; font-size: 15px; max-width: 28ch; text-wrap: balance; }
body.touch .touch-how { display: block; }
.icon-bowl, .icon-book { width: 30px; height: 30px; display: block; background-size: contain; background-repeat: no-repeat; background-position: center; }
.icon-bowl { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 4c0 4 3 4 3 8M16 3c0 4 3 4 3 8' fill='none' stroke='%2334233f' stroke-width='2.4' stroke-linecap='round'/%3E%3Cpath d='M3 14h26c0 8-5 13-13 13S3 22 3 14z' fill='%23e4572e' stroke='%2334233f' stroke-width='2.6' stroke-linejoin='round'/%3E%3Cpath d='M7 18c3-2 5 2 8 0s5 2 8 0' fill='none' stroke='%23fff3d6' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E"); }
.icon-book { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect x='5' y='4' width='22' height='25' rx='3' fill='%232fa4b5' stroke='%2334233f' stroke-width='2.6'/%3E%3Cpath d='M10 4v25' stroke='%2334233f' stroke-width='2.4'/%3E%3Ccircle cx='19' cy='14' r='4.5' fill='none' stroke='%23fff3d6' stroke-width='2.4'/%3E%3Cpath d='M22 17l3 3' stroke='%23fff3d6' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E"); }

.buff {
  position: absolute; left: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  background: #1f1a2e; color: #9ff3ff; border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 14px 2px; font-weight: 800; font-size: 14px; box-shadow: var(--pop); pointer-events: none;
}
body.touch .buff { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 200px); }

.combo {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%);
  font-family: var(--display); font-size: 44px; color: var(--broth);
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink); pointer-events: none; white-space: nowrap;
  animation: comboPop .35s cubic-bezier(.2, 1.8, .4, 1);
}
@keyframes comboPop { from { transform: translateX(-50%) scale(.3) rotate(-10deg); } }

/* ---------- toasts ---------- */
#toasts {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(env(safe-area-inset-top, 0px) + 140px);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(92vw, 380px);
}
.toast {
  display: flex; align-items: center; gap: 12px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; box-shadow: var(--pop);
  padding: 8px 16px 6px 8px; font-weight: 700; line-height: 1.2;
  animation: toastIn .4s cubic-bezier(.2, 1.5, .4, 1), toastOut .35s ease-in forwards;
  animation-delay: 0s, var(--life, 2.6s);
}
.toast canvas { width: 48px; height: 48px; flex: none; }
.toast .t-small { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--chili); font-weight: 800; }
.toast.big { padding: 10px 20px 8px 10px; background: #fff1a8; }
.toast.big canvas { width: 64px; height: 64px; }
@keyframes toastIn { from { transform: translateY(-20px) scale(.7); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-14px); opacity: 0; } }

/* ---------- touch controls ---------- */
#stick {
  position: absolute; width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255, 248, 232, .22); border: 3px solid rgba(255, 248, 232, .6);
  pointer-events: none; transform: translate(-50%, -50%);
}
#stick.rest { opacity: .55; transition: opacity .3s; }
.stick-label {
  position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%);
  font-weight: 800; font-size: 12px; letter-spacing: .12em; color: var(--paper);
  text-shadow: 0 2px 0 var(--ink); white-space: nowrap;
}
#stick:not(.rest) .stick-label { display: none; }
#stickKnob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); box-shadow: var(--pop);
}
#action {
  position: absolute; right: 22px; bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  width: 108px; height: 108px; border-radius: 50%;
  background: var(--broth); border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink);
  font-family: var(--display); font-size: 19px; letter-spacing: .02em;
  display: grid; place-items: center; transition: transform .08s, box-shadow .08s;
}
#flyBtn {
  position: absolute; right: 140px; bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  width: 76px; height: 76px; border-radius: 50%;
  background: #d9f4ff; border: 4px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  font-family: var(--display); font-size: 16px; touch-action: none;
}
#flyBtn.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
body:not(.touch) #flyBtn { display: none !important; }
#action.pressed, #action:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
#action.water { background: var(--teal-light); }
#action.talk { background: #ffc6d9; }
#action.swim { background: #9ff3ff; }
#action.look { background: #d9d4ff; }
#action.pop { animation: actPop .3s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes actPop { from { scale: .6; } }
#action.idle { opacity: .45; }
body:not(.touch) #action { width: auto; height: auto; min-width: 0; border-radius: 999px; padding: 10px 22px 6px; font-size: 20px; right: 50%; transform: translateX(50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 22px); }
body:not(.touch) #action::after { content: "Space"; font-family: var(--body); font-size: 12px; font-weight: 800; margin-left: 10px; background: var(--ink); color: var(--paper); border-radius: 6px; padding: 2px 6px 0; vertical-align: 3px; }
body:not(.touch) #action { display: block; }
body:not(.touch) #action[hidden] { display: none !important; }
body:not(.touch) #action.pressed, body:not(.touch) #action:active { transform: translateX(50%) translateY(4px); }

/* ---------- dialogue ---------- */
#dialog {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 16px calc(env(safe-area-inset-bottom, 0px) + 18px);
  display: flex; justify-content: center; cursor: pointer;
}
.dialog-card {
  width: min(640px, 100%);
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink);
  padding: 14px 18px 12px 14px;
  animation: toastIn .3s cubic-bezier(.2, 1.4, .4, 1);
}
#portrait { width: 84px; height: 84px; flex: none; border-radius: 16px; background: var(--cream); border: 3px solid var(--ink); }
.dialog-body { flex: 1; min-width: 0; }
.dialog-name { font-family: var(--display); font-size: 20px; color: var(--chili); line-height: 1; margin-bottom: 4px; }
.dialog-text { font-size: 18px; font-weight: 600; line-height: 1.35; min-height: 50px; white-space: pre-line; }
.dialog-text em { font-style: normal; color: var(--teal); font-weight: 800; }
.dialog-next { text-align: right; font-size: 13px; font-weight: 800; color: var(--ink-soft); margin-top: 2px; animation: nudge .9s ease-in-out infinite alternate; }
@keyframes nudge { from { opacity: .55; } to { opacity: 1; } }
.dialog-choices { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.choice {
  background: var(--broth); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink);
  font-weight: 800; font-size: 15px; padding: 6px 14px 3px;
}
.choice.alt { background: var(--cream); }
.choice:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- sheet ---------- */
#sheet {
  position: absolute; inset: 0; background: var(--plum-glass);
  display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet-card {
  width: min(760px, 100%); max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink);
  animation: toastIn .3s cubic-bezier(.2, 1.3, .4, 1);
  overflow: hidden;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px 10px 22px; border-bottom: 3px dashed #e4d2a8;
}
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1; color: var(--ink); text-wrap: balance; }
.close { width: 42px; height: 42px; border-radius: 14px; border: 3px solid var(--ink); background: var(--cream); font-size: 18px; font-weight: 800; box-shadow: 0 3px 0 var(--ink); flex: none; }
.sheet-body { overflow-y: auto; padding: 16px 22px 24px; -webkit-overflow-scrolling: touch; touch-action: pan-y; user-select: text; }
.sheet-sub { margin: 0 0 14px; color: var(--ink-soft); font-weight: 600; }
.progress { height: 16px; border: 3px solid var(--ink); border-radius: 999px; background: #efe3c9; overflow: hidden; margin-bottom: 16px; }
.progress > div { height: 100%; background: repeating-linear-gradient(-45deg, var(--broth) 0 10px, #f7ca66 10px 20px); }

.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.dex-card {
  border: 3px solid var(--ink); border-radius: 18px; background: #fff; padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
}
.dex-card canvas { width: 72px; height: 72px; align-self: center; }
.dex-card .num { font-size: 12px; font-weight: 800; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.dex-card h3 { margin: 0; font-size: 16px; line-height: 1.15; font-weight: 800; }
.dex-card p { margin: 0; font-size: 13px; line-height: 1.3; color: var(--ink-soft); font-weight: 600; }
.dex-card.locked { background: #f1e6cf; border-style: dashed; }
.dex-card.locked h3 { color: var(--ink-soft); }
.rarity { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; border-radius: 8px; padding: 2px 7px 0; border: 2px solid var(--ink); }
.r-common { background: #eee; }
.r-rare { background: #bfe9ff; }
.r-legendary { background: #e2c9ff; }
.r-secret { background: #ffe07a; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { border: 3px solid var(--ink); border-radius: 12px; background: var(--cream); font-weight: 800; padding: 5px 14px 2px; font-size: 15px; }
.tab.on { background: var(--ink); color: var(--paper); }

.clue {
  border: 3px solid var(--ink); border-radius: 18px; background: #fff; padding: 14px 16px; margin-bottom: 12px;
}
.clue h3 { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.clue .where { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--chili); }
.clue blockquote { margin: 8px 0 0; font-size: 18px; line-height: 1.4; font-weight: 600; font-style: italic; color: var(--ink); max-width: 60ch; }
.clue.solved { background: #f2fbe8; }
.clue .solved-tag { display: inline-block; margin-top: 8px; font-size: 13px; font-weight: 800; color: #3e7d22; }
.reflection { display: block; width: 100%; max-width: 420px; height: auto; border: 3px solid var(--ink); border-radius: 14px; margin: 10px 0 4px; }
.faces { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.faces canvas { width: 56px; height: 48px; }
.cipher { display: flex; flex-wrap: wrap; gap: 4px 2px; margin: 10px 0; }
.cipher canvas { width: 30px; height: 36px; }
.cipher .gap { width: 16px; }
.answer-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.answer-row input {
  flex: 1; min-width: 160px; font: inherit; font-size: 17px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  border: 3px solid var(--ink); border-radius: 12px; padding: 7px 12px 4px; background: var(--paper); color: var(--ink);
}
.answer-row input:focus { outline: 3px solid var(--teal); }
.answer-msg { font-weight: 700; font-size: 14px; margin-top: 6px; min-height: 1.2em; }
.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.piece { border: 3px solid var(--ink); border-radius: 16px; background: #fff; padding: 8px; text-align: center; font-weight: 800; font-size: 14px; }
.piece canvas { width: 100%; height: auto; aspect-ratio: 1; max-width: 100%; display: block; border-radius: 10px; }
.piece.locked { background: #f1e6cf; border-style: dashed; color: var(--ink-soft); }
.alpha { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; margin-top: 10px; }
.alpha div { border: 2px solid var(--ink); border-radius: 10px; background: var(--paper); text-align: center; font-weight: 800; padding: 2px 0; }
.alpha canvas { width: 30px; height: 36px; display: block; margin: 0 auto; }
.empty { color: var(--ink-soft); font-weight: 600; }
.oracle-btn { margin-top: 10px; }

/* ---------- more menu ---------- */
.hud-right { position: relative; }
#menuBtn { font-size: 26px; font-weight: 800; line-height: 1; }
#menuPop {
  position: absolute; right: 0; top: calc(100% + 12px); z-index: 5; pointer-events: auto;
  display: flex; flex-direction: column; gap: 4px; min-width: 190px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; box-shadow: var(--pop); padding: 6px;
}
#menuPop button { text-align: left; border: 0; background: none; font-weight: 800; font-size: 16px; padding: 9px 12px 6px; border-radius: 12px; }
#menuPop button:active { background: var(--cream); }
@media (hover: hover) { #menuPop button:hover { background: var(--cream); } }
#menuPop button[hidden] { display: none; }

/* ---------- food ---------- */
.needs { display: flex; flex-wrap: wrap; gap: 6px; }
.need { display: inline-flex; align-items: center; gap: 4px; border: 2.5px solid var(--ink); border-radius: 999px; padding: 2px 10px 0 2px; font-weight: 700; font-size: 13px; background: #fbe3dc; }
.need.ok { background: #e3f4d3; }
.need canvas { width: 26px; height: 26px; }
.recipe h3 small { font-size: 13px; color: var(--ink-soft); }
.choice:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---------- skills ---------- */
.lesson { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0 6px; border-top: 2px dashed #eadcbc; font-size: 15px; line-height: 1.3; }
.lesson small { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.lesson .mark { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 50%; border: 2.5px solid var(--ink); font-weight: 800; font-size: 13px; background: #fff; }
.lesson.done .mark { background: #8cbf5a; color: #fff; }
.lesson.next .mark { background: var(--broth); }
.lesson.locked { opacity: .6; }

/* ---------- multiplayer ---------- */
.room { gap: 6px; font-size: 14px; background: #1f1a2e; color: #9ff3ff; }
.room-dot { width: 10px; height: 10px; border-radius: 50%; background: #8cbf5a; box-shadow: 0 0 0 3px rgba(140,191,90,.3); }
.room.off .room-dot { background: var(--chili); }
.icon-star { font-size: 24px; line-height: 1; }
#emoteBar {
  position: absolute; z-index: 6; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 80px); flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px);
  display: flex; gap: 6px; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; box-shadow: var(--pop); padding: 6px;
}
#emoteBar button { width: 50px; height: 46px; border: 0; background: none; font-size: 26px; border-radius: 12px; padding: 0; display: grid; place-items: center; }
#emoteBar canvas { width: 46px; height: 40px; }
#emoteBar[hidden] { display: none; }
body.touch #emoteBar { right: calc(env(safe-area-inset-right, 0px) + 12px); bottom: calc(env(safe-area-inset-bottom, 0px) + 206px); }
@media (max-height: 500px) { body.touch #emoteBar { bottom: calc(env(safe-area-inset-bottom, 0px) + 90px); right: calc(env(safe-area-inset-right, 0px) + 236px); } }
#faceBtn { font-size: 22px; }
#faceBtn.on { background: var(--broth); }
#emoteBtn, #emoteMenuBtn { display: none !important; }
#emoteBar button:active { background: var(--cream); }
.big-btn.friends { background: var(--teal); font-size: 22px; padding: 9px 26px 6px; }
.big-btn.small { font-size: 20px; padding: 8px 24px 5px; }
.mp-panel {
  width: min(440px, 100%); background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink);
  padding: 16px; display: flex; flex-direction: column; gap: 12px; text-align: left;
}
.mp-row { display: flex; flex-direction: column; gap: 4px; }
.mp-row label, .mp-label { font-weight: 800; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.mp-panel input {
  font: inherit; font-size: 18px; font-weight: 700; border: 3px solid var(--ink); border-radius: 12px; padding: 6px 12px 3px; background: #fff; color: var(--ink); width: 100%;
}
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--ink); }
.swatches button.on { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); }
.mp-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-card { text-align: left; border: 3px solid var(--ink); border-radius: 16px; background: #fff; padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.mode-card strong { font-size: 17px; }
.mode-card span { font-size: 13px; font-weight: 600; line-height: 1.3; color: var(--ink-soft); }
.mode-card.on { background: #fff1a8; box-shadow: 0 3px 0 var(--ink); }
.mp-or { text-align: center; font-weight: 800; font-size: 13px; color: var(--ink-soft); }
.mp-join { display: flex; gap: 8px; }
.mp-join input { text-transform: uppercase; letter-spacing: .3em; text-align: center; }
.mp-msg { margin: 0; font-weight: 700; font-size: 14px; min-height: 1.2em; }
.mp-msg.err { color: var(--chili); }
.players { display: flex; flex-direction: column; gap: 8px; }
.player-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; padding: 6px 12px 4px; font-weight: 700; }
.player-row.me { background: #fff1a8; }
.player-row .rank { font-family: var(--display); font-size: 20px; width: 26px; }
.player-row .dot { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--ink); flex: none; }
.player-row .who { flex: 1 1 110px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-row .stats { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-left: auto; justify-content: flex-end; }
.player-row .stat { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.code-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.code-box .code { font-family: var(--display); font-size: 40px; letter-spacing: .12em; line-height: 1; }

/* ---------- title ---------- */
#title {
  position: absolute; inset: 0; overflow-y: auto;
  display: grid; place-items: center; text-align: center;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background:
    radial-gradient(ellipse at 50% 120%, #ffb38a 0%, transparent 60%),
    radial-gradient(circle at 50% 36%, #fff3c4 0 120px, transparent 260px),
    linear-gradient(180deg, #7ecbe0 0%, #b7e3d9 45%, #ffd9a8 100%);
  touch-action: pan-y;
}
.title-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 520px; }
#titleHero { width: 200px; height: 200px; }
#title h1 {
  margin: 0; font-family: var(--display); font-weight: 400; line-height: .9;
  font-size: clamp(54px, 13vw, 96px); color: var(--broth);
  -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; text-shadow: 0 7px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center;
}
#title h1 span:last-child { color: var(--paper); transform: rotate(-3deg); }
.tagline { margin: 6px 0 8px; font-size: 19px; font-weight: 700; color: var(--ink); max-width: 30ch; text-wrap: balance; }
.big-btn {
  font-family: var(--display); font-size: 28px; background: var(--chili); color: var(--paper);
  border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink);
  padding: 12px 38px 8px; transition: transform .08s;
}
@media (hover: hover) { .big-btn:hover { transform: translateY(-2px) rotate(-1deg); } }
.big-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.link-btn { background: none; border: 0; font-weight: 800; text-decoration: underline; font-size: 15px; }
.how { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: center; margin-top: 12px; font-weight: 700; font-size: 14px; }
.how div { display: flex; gap: 6px; align-items: center; }
kbd { background: var(--paper); border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 8px; padding: 1px 7px 0; font-family: var(--body); font-weight: 800; font-size: 13px; }
body.touch .how { display: none; }

/* ---------- phones & tablets ---------- */
/* Toasts sit near the bottom on touch screens so they never cover Squareface Guy. */
body.touch #toasts { top: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 150px); }
body.touch .toast { font-size: 15px; }

@media (max-width: 600px) {
  #hud { padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 0; gap: 8px; }
  .hud-left { gap: 6px; }
  .pill { font-size: 13px; height: 32px; padding: 2px 10px 0; gap: 6px; box-shadow: 0 3px 0 var(--ink); border-width: 2.5px; }
  .clock-icon { width: 16px; height: 16px; }
  .meter { height: 32px; padding: 0 8px 0 4px; box-shadow: 0 3px 0 var(--ink); border-width: 2.5px; }
  .meter-icon { width: 20px; height: 20px; }
  .bar { width: 64px; height: 12px; }
  .coin { width: 15px; height: 15px; }
  .goal { font-size: 13px; padding: 5px 10px 3px 5px; max-width: calc(100vw - 24px); }
  .goal-label { font-size: 10px; padding: 2px 6px 0; }
  .hud-right { gap: 6px; align-items: flex-start; }
  .icon-btn { width: 42px; height: 42px; border-radius: 13px; box-shadow: 0 3px 0 var(--ink); border-width: 2.5px; }
  .icon-btn.small { width: 42px; height: 42px; font-size: 16px; }
  .icon-bowl, .icon-book { width: 24px; height: 24px; }
  .badge { font-size: 10px; bottom: -9px; }
  .dialog-text { font-size: 16px; }
  #portrait { width: 60px; height: 60px; }
  .combo { font-size: 32px; }
  .sheet-head h2 { font-size: 24px; }
  .dex-grid, .pieces { grid-template-columns: repeat(2, 1fr); }
  .dex-card canvas { width: 56px; height: 56px; }
  #action { width: 96px; height: 96px; font-size: 17px; right: 16px; }
  #titleHero { width: 150px; height: 150px; }
}
/* narrow phones: goal gets its own row under the stats */
@media (max-width: 420px) {
  .hud-right { flex-wrap: wrap; justify-content: flex-end; max-width: 144px; }
  .icon-btn { width: 42px; height: 42px; }
}
/* phones in landscape: short screen, keep everything slim */
@media (max-height: 500px) {
  #hud { padding: calc(env(safe-area-inset-top, 0px) + 8px) calc(env(safe-area-inset-right, 0px) + 12px) 0 calc(env(safe-area-inset-left, 0px) + 12px); }
  .hud-left { gap: 5px; }
  .pill, .meter { height: 30px; font-size: 13px; box-shadow: 0 3px 0 var(--ink); }
  .bar { width: 70px; }
  .goal { font-size: 13px; max-width: 46vw; }
  .icon-btn, .icon-btn.small { width: 40px; height: 40px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }
  .icon-bowl, .icon-book { width: 22px; height: 22px; }
  body.touch #toasts { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 58px); left: auto; right: calc(env(safe-area-inset-right, 0px) + 12px); transform: none; width: min(300px, 36vw); align-items: flex-end; }
  .toast { font-size: 13px; padding: 6px 12px 4px 6px; }
  .toast canvas, .toast.big canvas { width: 38px; height: 38px; }
  #action { width: 88px; height: 88px; font-size: 16px; right: calc(env(safe-area-inset-right, 0px) + 18px); bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); }
  .dialog-card { padding: 10px 14px 8px 10px; }
  .dialog-text { font-size: 15px; min-height: 0; }
  #portrait { width: 52px; height: 52px; }
  .combo { font-size: 30px; top: 16%; }
  #titleHero { width: 110px; height: 110px; }
  #title h1 { font-size: 52px; flex-direction: row; gap: 14px; }
  .tagline { font-size: 16px; margin: 0; }
  .big-btn { font-size: 22px; padding: 8px 28px 5px; }
  .title-inner { gap: 6px; }
}
/* tablets: roomier buttons, bigger action button */
@media (min-width: 700px) and (min-height: 700px) {
  body.touch #action { width: 124px; height: 124px; font-size: 21px; right: 32px; bottom: calc(env(safe-area-inset-bottom, 0px) + 36px); }
  body.touch #stick { width: 140px; height: 140px; }
  body.touch #stickKnob { width: 60px; height: 60px; margin: -30px 0 0 -30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
#boardName { text-transform: none; letter-spacing: normal; }
.locked-chapter { opacity: .65; }

/* ---------- UI audit fixes ---------- */
/* 1: the goal pill always grows to fit its text */
.pill.goal { height: auto; }
/* 7: desktop toasts sit top-right, clear of Squareface and the combo text */
body:not(.touch) #toasts { top: calc(env(safe-area-inset-top, 0px) + 92px); left: auto; right: 16px; transform: none; width: min(360px, 40vw); align-items: flex-end; }
/* 5: phone toasts sit above the joystick and action button */
body.touch #toasts { bottom: calc(env(safe-area-inset-bottom, 0px) + 212px); }
/* 8: long dialogue scrolls inside its card */
.dialog-card { max-height: calc(100% - 120px); }
.dialog-body { display: flex; flex-direction: column; min-height: 0; max-height: calc(100vh - 170px); }
.dialog-text { overflow-y: auto; min-height: 0; }
/* 9: comfortable tap targets on touch screens */
body.touch .tab, body.touch .choice { min-height: 42px; }
body.touch #menuPop button { min-height: 46px; }
body.touch .swatches button { width: 42px; height: 42px; }
body.touch #roomPill { min-height: 38px; }
.link-btn { padding: 10px 12px; }
/* 13: leaderboard name field stays on one line */
#nameForm { flex-wrap: nowrap; }
#nameForm input { min-width: 0; }
/* 14: even noodle cards */
.dex-card h3 { min-height: 2.3em; }
@media (max-width: 600px) {
  .combo { top: 32%; }
  /* 6: goal pill may use the full width under the buttons */
  .hud-left { flex: 1 1 auto; }
  .goal { width: max-content; max-width: calc(100vw - 24px); }
}
@media (max-width: 420px) {
  /* 6: one row of four buttons; emotes move into the menu */
  .hud-right { flex-wrap: nowrap; max-width: none; gap: 5px; }
  .icon-btn, .icon-btn.small { width: 40px; height: 40px; }
  #emoteBtn { display: none !important; }
}
@media (min-width: 421px) { #emoteMenuBtn { display: none !important; } }
/* 4: landscape phones keep toasts above the touch buttons */
@media (max-height: 500px) {
  body.touch #toasts { max-height: calc(100vh - 58px - 140px); overflow: hidden; }
}
:root { --sal: env(safe-area-inset-left, 0px); --sab: env(safe-area-inset-bottom, 0px); }
/* smallest phones: keep the clock short so it never runs under the buttons */
@media (max-width: 360px) { .clock-day { display: none; } }
/* long dialogue: only the text scrolls; name, hint and choices keep their size */
.dialog-name, .dialog-next, .dialog-choices { flex-shrink: 0; }
.goal { flex-wrap: wrap; }
#goalText { flex: 1 1 60%; min-width: 0; }
.goal-hint { flex-basis: 100%; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); line-height: 1.25; padding: 2px 0 0 2px; }
.decoder { display: flex; flex-wrap: wrap; gap: 10px 18px; margin: 10px 0 4px; }
.dword { display: flex; gap: 4px; }
.dcell { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dcell canvas { width: 30px; height: 36px; }
.dcell select { font: inherit; font-weight: 800; font-size: 16px; width: 40px; min-height: 36px; text-align: center; border: 2.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink); padding: 0; appearance: none; -webkit-appearance: none; text-align-last: center; }
.dcell select.ok { background: #d8f0c4; }
.dcell select.bad { background: #fbd6cc; }
.code-box { justify-content: space-between; }
.code-box .mp-label { display: block; }
.link-line { user-select: text; word-break: break-all; font-size: 13px; background: #fff; border: 2px dashed #e4d2a8; border-radius: 10px; padding: 6px 10px 4px; }
.mp-help { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); line-height: 1.3; }
.dice { font-size: 20px; padding: 4px 12px 2px; }
.mp-join input { letter-spacing: .2em; }
.player-row .rank:empty { display: none; }
.dex-card.shiny { border-color: #d99a00; background: linear-gradient(160deg, #fffbe6, #fff1a8); box-shadow: 0 0 0 3px #ffd23f inset; }
.shop-card canvas { width: 96px; height: 96px; }
.shop-card .choice { margin-top: auto; width: 100%; }
.shop-card .answer-row { width: 100%; margin-top: auto; }
.goodie-icon { font-size: 44px; line-height: 1.2; align-self: center; }
.shop-coins b { color: var(--ink); }
/* ---------- world map ---------- */
.map-wrap { width: 100%; border: 3px solid var(--ink); border-radius: 16px; overflow: hidden; background: #e9dcc0; }
.map-canvas { display: block; width: 100%; cursor: crosshair; }
.map-legend { font-size: 13px; margin-top: 10px; }
#minimap {
  position: absolute; left: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  width: 220px; height: 159px; border: 3px solid var(--ink); border-radius: 14px; box-shadow: var(--pop);
  background: #e9dcc0; cursor: pointer; display: none;
}
/* the live map is always on screen while playing: bottom-left on computers, top-right under the buttons on touch screens */
body.show-mini #minimap { display: block; }
@media (max-width: 899px), (max-height: 599px) { body:not(.touch) #minimap { width: 160px; height: 116px; } }
body.touch #minimap { left: auto; bottom: auto; right: calc(env(safe-area-inset-right, 0px) + 12px); top: var(--mm-top, 120px); width: 132px; height: 96px; border-width: 2.5px; border-radius: 12px; box-shadow: 0 3px 0 var(--ink); }
@media (min-width: 700px) and (min-height: 700px) { body.touch #minimap { width: 190px; height: 138px; } }
@media (max-height: 500px) { body.touch #minimap { width: 120px; height: 87px; } body.touch #toasts { top: calc(var(--mm-top, 58px) + 96px); max-height: calc(100vh - var(--mm-top, 58px) - 96px - 120px); } }
body:not(.touch) .buff { left: 250px; }
#skillsMenuBtn { display: none; }
@media (max-width: 420px) {
  #skillsBtn { display: none !important; }
  #skillsMenuBtn { display: block; }
}
/* ---------- healthy play: breaks and bedtime ---------- */
#care {
  position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; overflow-y: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: radial-gradient(circle at 50% 30%, #3b2f63 0%, #1f1a2e 70%);
}
.care-card {
  width: min(460px, 100%); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink); padding: 18px 20px 20px;
}
#careHero { width: 160px; height: 145px; }
.care-card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 32px; line-height: 1.05; text-wrap: balance; }
.care-text { margin: 0; font-weight: 700; font-size: 17px; line-height: 1.35; max-width: 34ch; }
.care-tip { margin: 0; font-weight: 800; font-size: 16px; color: var(--teal); min-height: 2.6em; max-width: 32ch; }
.care-count { font-family: var(--display); font-size: 28px; color: var(--chili); font-variant-numeric: tabular-nums; }
.care-actions { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.care-gate, .care-settings { width: 100%; text-align: left; border-top: 3px dashed #e4d2a8; padding-top: 12px; }
.care-gate label { font-weight: 800; }
.care-settings h3 { margin: 0 0 8px; }
.care-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 8px; }
.care-row select { font: inherit; font-weight: 800; border: 2.5px solid var(--ink); border-radius: 10px; padding: 4px 8px 2px; background: #fff; color: var(--ink); min-height: 40px; }
/* ---------- Brain Noodle quiz ---------- */
.quiz-q { margin: 4px 0 14px; font-size: 21px; line-height: 1.3; text-wrap: balance; }
.quiz-opts { display: grid; gap: 10px; margin-bottom: 12px; }
.quiz-opt { text-align: left; font-weight: 800; font-size: 18px; min-height: 52px; padding: 10px 16px 7px; border: 3px solid var(--ink); border-radius: 16px; background: #fff; box-shadow: 0 3px 0 var(--ink); }
.quiz-opt:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.quiz-opt.right { background: #d8f0c4; }
.quiz-opt.wrong { background: #fbd6cc; }
.quiz-opt:disabled { cursor: default; }
.quiz-why { font-weight: 700; font-size: 16px; line-height: 1.4; background: #fbe3dc; border-radius: 12px; padding: 10px 14px 8px; margin: 0 0 12px; }
.quiz-why.ok { background: #e3f4d3; }
/* readable small text on touch screens */
body.touch .goal-label, body.touch .badge, body.touch .rarity { font-size: 13px; }
body.touch .badge.dot { font-size: 0; }
.go-pin { display: block; margin: 12px auto 0; }

/* ---------- room chat & voice ---------- */
#talkBar { position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 22px); display: flex; gap: 8px; z-index: 4; }
#talkBar[hidden] { display: none; }
body.touch #talkBar { right: calc(env(safe-area-inset-right, 0px) + 22px); bottom: calc(env(safe-area-inset-bottom, 0px) + 150px); }
#talkBar .icon-btn { font-size: 22px; position: relative; }
#chatBtn.on { background: var(--broth); }
#micBtn { background: #c9f0b4; }
#micBtn.muted { background: #f1e6cf; }
#chatBadge { background: var(--chili); color: #fff; }
/* a compact panel in the corner: the game stays visible next to it */
#chat {
  position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 80px); z-index: 6;
  width: min(360px, calc(100vw - 24px)); max-height: min(440px, calc(100% - 110px));
  display: flex; flex-direction: column; gap: 6px; padding: 10px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 20px; box-shadow: var(--pop);
}
#chat[hidden] { display: none; }
body.touch #chat { right: calc(env(safe-area-inset-right, 0px) + 12px); bottom: calc(var(--kb, 0px) + env(safe-area-inset-bottom, 0px) + 12px); max-height: calc(100% - var(--kb, 0px) - env(safe-area-inset-top, 0px) - 70px); }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 20px; }
.chat-head .close { width: 36px; height: 36px; font-size: 16px; }
.chat-people { display: flex; gap: 5px; align-items: center; overflow-x: auto; flex: none; scrollbar-width: none; }
.chat-people button { flex: none; display: inline-flex; align-items: center; gap: 4px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; font-weight: 800; font-size: 12px; padding: 2px 8px 0 5px; min-height: 28px; white-space: nowrap; }
.chat-people button.off { opacity: .55; text-decoration: line-through; }
.chat-people .dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink); }
.chat-people small, .chat-note { color: var(--ink-soft); font-size: 12px; font-weight: 700; margin: 0; white-space: nowrap; }
.chat-note { white-space: normal; }
.chat-note:empty { display: none; }
.chat-voice { flex: none; display: flex; align-items: center; gap: 6px; background: #e3f4d3; border: 2px solid var(--ink); border-radius: 12px; padding: 4px 6px 4px 10px; font-weight: 800; font-size: 13px; }
.chat-voice:empty { display: none; }
.chat-voice span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-voice .choice { flex: none; padding: 3px 10px 1px; font-size: 13px; min-height: 32px; box-shadow: 0 2px 0 var(--ink); }
.chat-log { flex: 1 1 auto; min-height: 48px; max-height: 150px; overflow-y: auto; background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 4px 8px; }
.chat-log[hidden], .chat-phrases[hidden], .chat-form[hidden] { display: none; }
.chat-line { margin: 2px 0; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
.chat-line b { color: var(--ink); border-left: 4px solid var(--c); padding-left: 5px; margin-right: 2px; }
.chat-line.me b { opacity: .7; }
.chat-sys { margin: 2px 0; font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.chat-phrases { flex: none; display: flex; gap: 5px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: thin; }
.chat-phrases button { flex: none; border: 2px solid var(--ink); border-radius: 999px; background: var(--cream); font-weight: 800; font-size: 13px; padding: 3px 10px 1px; min-height: 32px; white-space: nowrap; }
.chat-phrases button:active { background: var(--broth); }
.chat-form { flex: none; display: flex; gap: 6px; }
.chat-form input { flex: 1 1 auto; min-width: 0; font: inherit; font-size: 16px; font-weight: 700; border: 2px solid var(--ink); border-radius: 12px; padding: 4px 10px; }
.chat-form .choice { min-height: 36px; padding: 4px 14px 2px; }
@media (max-height: 500px) {
  body.touch #talkBar { bottom: calc(env(safe-area-inset-bottom, 0px) + 34px); right: calc(env(safe-area-inset-right, 0px) + 236px); }
  #chat { width: min(360px, 52vw); }
  .chat-log { max-height: 84px; }
}
.care-row select { font: inherit; }
.map-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.map-nav b { text-align: center; font-size: 15px; }
.map-nav .choice { font-size: 13px; padding: 4px 10px 2px; min-height: 36px; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* quiet pass: stars live in the Skills sheet and the journal, not on the HUD */
#starCount { display: none; }
@media (max-width: 420px) {
  #emoteBar { gap: 4px; padding: 5px; flex-wrap: nowrap; }
  #emoteBar button { width: 44px; height: 42px; }
  #emoteBar canvas { width: 42px; height: 36px; }
}
