:root {
  --ink: #2a1630;
  --paper: #fff8ec;
  --paper2: #fdecd2;
  --gold: #ffcf3f;
  --pink: #ff6fae;
  --blue: #3f8fe0;
  --green: #4fbf5a;
  --purple: #7c4fe0;
  --shadow: 0 5px 0 rgba(42, 22, 48, 0.85);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1b1030; overflow: hidden; font-family: Fredoka, "Trebuchet MS", sans-serif; color: var(--ink); -webkit-user-select: none; user-select: none; }
#frame { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, #3b2266 0%, #140a24 100%); }
#stage { position: absolute; left: 50%; top: 50%; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; border-radius: 14px; box-shadow: 0 0 0 4px var(--ink), 0 20px 60px rgba(0,0,0,.6); background: #000; }
#view { position: absolute; inset: 0; width: 1280px; height: 720px; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- HUD */
#topbar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 10px; align-items: center; pointer-events: none; }
.pill { pointer-events: auto; background: linear-gradient(#fffdf6, #ffe9c2); border: 3px solid var(--ink); border-radius: 999px; padding: 5px 16px 5px 10px; font-weight: 700; font-size: 20px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; }
.roomname { margin: 0 auto; font-family: "Lilita One", Fredoka, sans-serif; font-weight: 400; letter-spacing: .5px; font-size: 22px; background: linear-gradient(#fff6a8, #ffc23a); padding: 4px 22px; }
.dexpill { cursor: pointer; }
.coin-ico { width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff7b0, #ffcf3f 45%, #d99a1a 100%); border: 2.5px solid var(--ink); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); position: relative; }
.coin-ico::after { content: '🦙'; position: absolute; inset: 0; font-size: 11px; display: grid; place-items: center; filter: grayscale(1) brightness(.6); }
#petcard { position: absolute; left: 12px; top: 64px; display: flex; gap: 8px; align-items: center; background: linear-gradient(#fffdf6, #fdecd2); border: 3px solid var(--ink); border-radius: 18px; padding: 4px 12px 4px 4px; box-shadow: var(--shadow); cursor: pointer; }
#petPortrait { width: 64px; height: 64px; background: radial-gradient(circle at 50% 40%, #fff, #cfeaff); border-radius: 12px; border: 2.5px solid var(--ink); }
.petname { font-weight: 700; font-size: 16px; margin-bottom: 3px; }
.meter { display: flex; align-items: center; gap: 4px; font-size: 12px; margin: 2px 0; }
.bar { width: 92px; height: 11px; border: 2px solid var(--ink); border-radius: 6px; background: #fff; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(#9dee7a, #4fbf5a); transition: width .4s; }
.bar.joy i { background: linear-gradient(#ffb0d6, #ff5aa8); }
#hovertip { position: absolute; padding: 5px 12px; background: var(--ink); color: #fff; border-radius: 10px; font-size: 15px; font-weight: 600; pointer-events: none; white-space: nowrap; transform: translate(-50%, -140%); box-shadow: 0 3px 0 rgba(0,0,0,.3); }

#toolbar { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; background: linear-gradient(#6fb8ff, #3a7fe0); border: 3px solid var(--ink); border-radius: 22px; padding: 7px 10px; box-shadow: var(--shadow), inset 0 3px 0 rgba(255,255,255,.4); }
.tb { font-family: inherit; width: 62px; height: 58px; border: 3px solid var(--ink); border-radius: 16px; background: linear-gradient(#ffffff, #ffe7b8); font-size: 24px; cursor: pointer; box-shadow: 0 4px 0 var(--ink), inset 0 -4px 0 rgba(0,0,0,.08); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; transition: transform .08s; color: var(--ink); padding: 0; }
.tb small { font-size: 11px; font-weight: 700; margin-top: 3px; }
.tb:hover { transform: translateY(-2px); background: linear-gradient(#ffffff, #fff1c8); }
.tb:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tb.small { width: 44px; height: 44px; font-size: 20px; border-radius: 13px; }
#chatwrap { display: flex; gap: 6px; align-items: center; background: rgba(255,255,255,.25); border-radius: 16px; padding: 4px; }
#chat { font-family: inherit; width: 170px; height: 44px; border: 3px solid var(--ink); border-radius: 13px; padding: 0 14px; font-size: 16px; font-weight: 500; outline: none; background: #fff; }
#chat:focus { box-shadow: 0 0 0 3px #ffe066; }
#emotes { position: absolute; bottom: 92px; left: 50%; transform: translateX(-95px); display: grid; grid-template-columns: repeat(5, 48px); gap: 6px; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 10px; box-shadow: var(--shadow); }
#emotes button { width: 48px; height: 48px; font-size: 24px; border: 2.5px solid var(--ink); border-radius: 12px; background: #fff; cursor: pointer; }
#emotes button:hover { background: #fff1c8; transform: scale(1.08); }

/* ---------- panels (Neopets-style windows) */
#panels { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
#toasts { z-index: 30; }
#fade { z-index: 40; }
.scrim.under > .win { visibility: hidden; }
.scrim.under { background: transparent; }
.scrim { isolation: isolate; z-index: 1; position: absolute; inset: 0; background: rgba(30, 12, 50, .45); pointer-events: auto; display: grid; place-items: center; animation: fadein .15s; }
@keyframes fadein { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.win { position: relative; background: linear-gradient(var(--paper), var(--paper2)); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 8px 0 var(--ink), 0 20px 50px rgba(0,0,0,.45); animation: pop .22s cubic-bezier(.3,1.5,.6,1); max-height: 660px; display: flex; flex-direction: column; overflow: hidden; }
.win > header { position: relative; padding: 12px 64px 12px 22px; background: linear-gradient(#b48cff, #7c4fe0); border-bottom: 4px solid var(--ink); color: #fff; font-family: "Lilita One", Fredoka, sans-serif; font-size: 30px; letter-spacing: .5px; text-shadow: 0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink); }
.win > header::after { content: ''; position: absolute; left: 14px; right: 14px; top: 6px; height: 12px; border-radius: 8px; background: rgba(255,255,255,.28); }
.win.green > header { background: linear-gradient(#8ff08a, #3fb54f); }
.win.pink > header { background: linear-gradient(#ffb0d8, #ff5aa8); }
.win.blue > header { background: linear-gradient(#8fd0ff, #3a7fe0); }
.win.orange > header { background: linear-gradient(#ffc27a, #ff7a2a); }
.win.gold > header { background: linear-gradient(#fff08a, #ffb321); }
.win .x { position: absolute; right: 12px; top: 10px; width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--ink); background: linear-gradient(#ff8a8a, #e0453a); color: #fff; font-weight: 700; font-size: 22px; cursor: pointer; box-shadow: 0 3px 0 var(--ink); z-index: 2; font-family: inherit; }
.win .x:hover { filter: brightness(1.1); }
.win .body { padding: 16px 20px 20px; overflow: auto; }
.btn { font-family: inherit; font-weight: 700; font-size: 18px; padding: 10px 22px; border: 3px solid var(--ink); border-radius: 16px; background: linear-gradient(#9dee7a, #3fb54f); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.35); cursor: pointer; box-shadow: 0 4px 0 var(--ink), inset 0 3px 0 rgba(255,255,255,.35); transition: transform .08s; }
.btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.blue { background: linear-gradient(#8fd0ff, #3a7fe0); }
.btn.pink { background: linear-gradient(#ffb0d8, #ff5aa8); }
.btn.gold { background: linear-gradient(#fff08a, #ffb321); color: var(--ink); text-shadow: 0 1px 0 rgba(255,255,255,.6); }
.btn.gray { background: linear-gradient(#f2f2f2, #c9c4d2); color: var(--ink); text-shadow: none; }
.btn[disabled] { filter: grayscale(.8) opacity(.6); cursor: not-allowed; }
.row { display: flex; gap: 12px; align-items: center; }
.grid { display: grid; gap: 10px; }
.grid > * { min-width: 0; }
.body > * { min-width: 0; }
.card { background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 8px; text-align: center; position: relative; box-shadow: 0 3px 0 rgba(42,22,48,.6); cursor: pointer; transition: transform .1s; }
.card:hover { transform: translateY(-3px); }
.card.sel { background: linear-gradient(#fff9d8, #ffe58a); box-shadow: 0 0 0 3px var(--gold), 0 3px 0 rgba(42,22,48,.6); }
.card canvas { display: block; margin: 0 auto; }
.card .nm { font-weight: 700; font-size: 14px; line-height: 1.1; margin-top: 2px; }
.card .sub { font-size: 12px; opacity: .75; }
.card.locked { background: #ece6f2; cursor: default; }
.card.locked:hover { transform: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; color: #fff; border: 2px solid var(--ink); text-shadow: 0 1px 0 rgba(0,0,0,.4); }
.price { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.price::before { content: ''; width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff7b0, #ffcf3f 45%, #d99a1a); border: 2px solid var(--ink); }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { font-family: inherit; font-weight: 700; font-size: 15px; padding: 7px 14px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; cursor: pointer; box-shadow: 0 3px 0 var(--ink); color: var(--ink); }
.tab.on { background: linear-gradient(#fff08a, #ffb321); }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--ink); cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0,0,0,.18), inset 0 3px 0 rgba(255,255,255,.4); }
.swatch.on { outline: 3px solid var(--gold); outline-offset: 2px; }
.bigview { background: radial-gradient(circle at 50% 35%, #ffffff, #cfeaff 60%, #9fd0ff); border: 3px solid var(--ink); border-radius: 22px; position: relative; overflow: hidden; }
.bigview::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 26%; background: linear-gradient(#9fdc7a, #6fbf52); border-top: 3px solid var(--ink); z-index: 0; }
.bigview canvas { position: relative; z-index: 1; }
input.txt { font-family: inherit; font-size: 20px; font-weight: 600; border: 3px solid var(--ink); border-radius: 14px; padding: 8px 14px; outline: none; }
input.txt:focus { box-shadow: 0 0 0 3px #ffe066; }
h3 { margin: 6px 0 8px; font-family: "Lilita One", Fredoka, sans-serif; font-weight: 400; font-size: 22px; letter-spacing: .3px; }
p { margin: 6px 0; }

/* ---------- toasts / fx */
#toasts { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; max-width: 520px; }
.toast { font-size: 15px !important; }
.toast { background: linear-gradient(#fffdf6, #ffe9c2); border: 3px solid var(--ink); border-radius: 16px; padding: 8px 18px; font-weight: 700; font-size: 17px; box-shadow: var(--shadow); animation: toast 3.2s forwards; }
@keyframes toast { 0% { transform: translateY(-20px) scale(.8); opacity: 0; } 8% { transform: none; opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
#fade { position: absolute; inset: 0; background: #1b1030; opacity: 0; pointer-events: none; transition: opacity .28s; }
#fade.on { opacity: 1; pointer-events: auto; }
#gamehost { position: absolute; inset: 0; background: #000; z-index: 10; }
#gamehost canvas { position: absolute; inset: 0; width: 1280px; height: 720px; }
.gamequit { position: absolute; right: 12px; top: 12px; z-index: 5; }

/* ---------- title */
#title { position: absolute; inset: 0; pointer-events: auto; display: flex; flex-direction: column; align-items: center; background: radial-gradient(ellipse 60% 45% at 50% 28%, rgba(40,15,70,.55), rgba(40,15,70,0) 70%); }
.logo { margin-top: 26px; font-family: "Lilita One", Fredoka, sans-serif; font-size: 108px; line-height: 1; color: #fff; letter-spacing: 2px; text-shadow: 0 6px 0 var(--ink), 4px 0 0 var(--ink), -4px 0 0 var(--ink), 0 -4px 0 var(--ink), 4px 4px 0 var(--ink), -4px 4px 0 var(--ink), 4px -4px 0 var(--ink), -4px -4px 0 var(--ink), 0 14px 0 rgba(42,22,48,.35); background: none; }
.logo span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-2deg); } }
.tagline { font-size: 22px; font-weight: 700; color: #fff; text-shadow: 0 3px 0 var(--ink); margin-top: 6px; }
.dedication { font-size: 16px; font-weight: 600; color: #ffd6ea; text-shadow: 0 2px 0 var(--ink); margin-top: 8px; font-style: italic; }

.keeper { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.keeper .bigview { cursor: pointer; }
.kbubble { position: relative; flex: 1; background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 10px 16px; font-size: 16px; box-shadow: 0 3px 0 rgba(42,22,48,.6); }
.kbubble::before { content: ''; position: absolute; left: -14px; top: 50%; margin-top: -9px; border: 9px solid transparent; border-right: 12px solid var(--ink); border-left: 0; }
.kbubble::after { content: ''; position: absolute; left: -9px; top: 50%; margin-top: -6px; border: 6px solid transparent; border-right: 9px solid #fff; border-left: 0; }
/* preview backdrops follow the current room */
#stage[data-room="cove"] .bigview { background: radial-gradient(circle at 50% 35%, #fff, #bff0ff 55%, #5fd0f0); }
#stage[data-room="cove"] .bigview::after { background: linear-gradient(#ffe9b0, #f2c97a); }
#stage[data-room="peaks"] .bigview { background: radial-gradient(circle at 50% 35%, #fff, #dbe8ff 60%, #a9c0f0); }
#stage[data-room="peaks"] .bigview::after { background: linear-gradient(#ffffff, #dbe8f6); }
#stage[data-room="grove"] .bigview { background: radial-gradient(circle at 50% 35%, #ffe9f6, #c9a6f0 55%, #6a4aa8); }
#stage[data-room="grove"] .bigview::after { background: linear-gradient(#6fbf7a, #3f8a5a); }
#stage[data-room="caverns"] .bigview { background: radial-gradient(circle at 50% 35%, #f3e9ff, #a98ae0 55%, #4a3a7a); }
#stage[data-room="caverns"] .bigview::after { background: linear-gradient(#8a7aa8, #5a4a78); }
#stage[data-room="sky"] .bigview { background: radial-gradient(circle at 50% 35%, #fff6e0, #ffc9e6 55%, #b8a0f0); }
#stage[data-room="sky"] .bigview::after { background: linear-gradient(#ffffff, #efe6ff); }
#stage[data-room="farm"] .bigview::after { background: linear-gradient(#b8e07a, #7fc052); }

#quest { position: absolute; right: 12px; top: 64px; width: 270px; background: linear-gradient(#fffdf6, #fdecd2); border: 3px solid var(--ink); border-radius: 18px; padding: 8px 12px 10px; box-shadow: var(--shadow); animation: pop .3s; }
#quest .qh { font-family: "Lilita One", Fredoka, sans-serif; font-size: 17px; display: flex; align-items: center; gap: 6px; }
#quest .qh span { margin-left: auto; font-family: Fredoka, sans-serif; font-weight: 700; font-size: 13px; background: #ffe066; border: 2px solid var(--ink); border-radius: 999px; padding: 0 8px; }
#quest .qh button { border: none; background: none; cursor: pointer; font-size: 14px; color: var(--ink); opacity: .6; }
#quest .qt { font-weight: 600; font-size: 15px; margin: 4px 0 2px; }
#quest .qr { font-size: 13px; opacity: .8; }

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate { display: grid; place-items: center; position: fixed; inset: 0; z-index: 99; background: radial-gradient(ellipse at center, #3b2266, #140a24); color: #fff; font-family: "Lilita One", Fredoka, sans-serif; font-size: 26px; text-align: center; padding: 24px; }
  #rotate span { display: block; font-size: 64px; animation: bob 2s ease-in-out infinite; }
}
.badge { position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; border-radius: 11px; background: #e0453a; color: #fff; border: 2.5px solid var(--ink); font: 700 12px Fredoka, sans-serif; display: grid; place-items: center; }
.badge:empty { display: none; }
#chat { width: 120px !important; }

/* starter/dex/shop cards: names wrap and stay centered */
.card .nm { text-align: center; overflow-wrap: break-word; font-size: 13px; line-height: 1.15; width: 100%; }
.card { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; overflow: hidden; }
.card > canvas { flex: none; }
.card.hcard { flex-direction: row; gap: 6px; padding: 4px 8px; align-items: center; }
.card.hcard .nm { text-align: left; font-size: 14px; }

#stage.playing #toasts { display: none; }
