/* Pixel game UI. Mobile-first; desktop gets a centred 720px column.
   Pixel borders = stepped box-shadows (square corners notched out), no border-radius anywhere. */
:root {
  --ink: #3b2a33;
  --ink-2: #5a4652;
  --paper: #fff6e6;
  --paper-2: #ffe9c9;
  --shade: #ecd2b0;
  --muted: #7d6a70;
  --primary: #e8663d;
  --primary-d: #b8472a;
  --mint: #3f9e8f;
  --mint-d: #2d7266;
  --gold: #ffd35a;
  --warn: #c0392b;
  --good: #3f8f4f;
  --box: #2b2040;
  --bg: #2e2230;
  --px: 3px;
  --font: "DotGothic16", "Mali", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); font: 500 15px/1.45 var(--font);
  background-color: var(--bg);
  background-image: linear-gradient(45deg, #342736 25%, transparent 25%, transparent 75%, #342736 75%),
                    linear-gradient(45deg, #342736 25%, transparent 25%, transparent 75%, #342736 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px;
}
[hidden] { display: none !important; }
#app { max-width: 720px; margin: 0 auto; padding: 0 12px calc(88px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; display: flex; align-items: center; gap: 6px; }
p { margin: 0 0 10px; }
.center { text-align: center; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; flex-wrap: nowrap; }
.center-row { justify-content: center; margin: 8px 0; }
.muted { color: var(--muted); }
.small-text { font-size: .82rem; }
.lead { font-size: 1.05rem; }
.warn { color: var(--warn); font-weight: 700; }
.pixel { image-rendering: pixelated; image-rendering: crisp-edges; display: block; margin: 0 auto; }

/* ---------- pixel frames ---------- */
.px-window, .px-panel, .px-mini, input, .list li, .px-dialog {
  --b: var(--px);
  box-shadow:
    0 calc(-1 * var(--b)) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink),
    calc(-1 * var(--b)) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink),
    inset calc(-1 * var(--b)) calc(-1 * var(--b)) 0 0 var(--shade), inset var(--b) var(--b) 0 0 #fff;
}
.px-window { background: var(--paper); padding: 14px; margin: 14px 3px; }
.px-panel { --b: 2px; background: rgba(255, 246, 230, .94); padding: 5px 7px; font-size: 12px; line-height: 1.3; }
.px-tag {
  display: inline-block; background: var(--ink); color: var(--gold); padding: 1px 7px; font-size: 12px;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
}
.px-textbox {
  background: var(--box); color: #fff; padding: 6px 10px; font-size: 13px;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 0 0 2px #fff;
}

/* ---------- controls ---------- */
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible { outline: 3px solid #7fb7ff; outline-offset: 4px; }
button:disabled { cursor: not-allowed; }
.px-btn {
  --edge: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink);
  min-height: 44px; padding: 8px 16px; background: var(--paper); font-weight: 700; margin: 3px;
  box-shadow: var(--edge), inset -3px -4px 0 0 var(--shade), inset 3px 3px 0 0 #fff;
}
.px-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: var(--edge), inset 3px 3px 0 0 var(--shade); }
.px-btn.primary { background: var(--primary); color: #fff; box-shadow: var(--edge), inset -3px -4px 0 0 var(--primary-d), inset 3px 3px 0 0 #ffa27f; }
.px-btn.danger { background: var(--warn); color: #fff; box-shadow: var(--edge), inset -3px -4px 0 0 #8e2a20, inset 3px 3px 0 0 #e8766a; }
.px-btn.ghost { background: var(--paper-2); }
.px-btn.small { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.px-btn.big { font-size: 1.25rem; padding: 12px 36px; margin-top: 14px; }
.px-btn.icon-only { min-height: 36px; min-width: 36px; padding: 4px; display: inline-grid; place-items: center; }
.px-btn:disabled { background: #d9ccc0; color: #7d6a70; box-shadow: 0 -3px 0 0 var(--ink-2), 0 3px 0 0 var(--ink-2), -3px 0 0 0 var(--ink-2), 3px 0 0 0 var(--ink-2); }
.px-mini {
  --b: 2px; min-width: 22px; height: 22px; padding: 0 5px; margin-left: 4px; background: var(--paper-2); color: var(--ink);
  font-size: 12px; font-weight: 700; line-height: 22px; pointer-events: auto; vertical-align: middle;
}
.px-mini.info { font-family: Georgia, serif; font-style: italic; }
.px-mini.wide { padding: 0 8px; height: 24px; line-height: 24px; }
label { display: grid; gap: 6px; font-weight: 700; }
input { --b: 3px; min-height: 44px; padding: 8px 12px; border: 0; background: #fffdf9; font-weight: 500; margin: 3px; }

.px-tabs { display: flex; background: var(--ink); margin: 10px 3px 14px; padding: 3px; }
.px-tabs button { flex: 1; min-height: 40px; color: #d9c9d2; font-weight: 700; padding: 4px 6px; }
.px-tabs button .ico { --size: 24px; margin-right: 2px; }
.px-tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: inset -3px -3px 0 0 var(--shade); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 3px 12px; }
.chips button { min-height: 34px; padding: 2px 10px; }
.chips button[aria-pressed="true"] { background: var(--mint); color: #fff; box-shadow: var(--edge), inset -3px -4px 0 0 var(--mint-d); }

/* ---------- icons (strip from /art/icons.png, wired up in app.js) ---------- */
.ico {
  --size: 16px; display: inline-block; width: var(--size); height: var(--size); flex: none; vertical-align: middle;
  background-image: var(--icons-url); background-repeat: no-repeat; image-rendering: pixelated;
  background-size: calc(var(--icons-n, 16) * var(--size)) var(--size);
  background-position: calc(var(--i, 0) * -1 * var(--size)) 0;
}
.tabbar .ico, .dock .ico, h2 .ico { --size: 32px; }
.ico.big { --size: 64px; }

/* ---------- top bar + logo ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 3px 8px; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.logo { font-family: "Pixelify Sans", sans-serif; font-weight: 700; color: var(--gold); letter-spacing: 1px; text-shadow: 3px 3px 0 var(--primary-d); font-size: 2.2rem; }
.logo.small { font-size: 1.1rem; text-shadow: 2px 2px 0 var(--primary-d); margin-right: auto; }
.logo-block { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 0 6px; }

/* ---------- game screen + HUD overlay ---------- */
.screen-wrap { position: relative; margin: 6px -12px 10px; background: var(--ink); overflow: hidden; }
.screen-wrap canvas { margin: 0 auto; }
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { position: absolute; pointer-events: auto; }
.hud-tl { top: 8px; left: 8px; max-width: calc(52% - 12px); }
.hud-tr { top: 8px; right: 8px; max-width: calc(48% - 12px); }
.hud-bottom { left: 8px; right: 8px; bottom: 7px; min-height: 30px; display: flex; align-items: center; gap: 8px; }
.hud-title { font-weight: 700; font-size: 14px; display: flex; align-items: center; white-space: nowrap; }
.hud-title #mon-name { overflow: hidden; text-overflow: ellipsis; }
.hud-sub { color: var(--muted); font-size: 11px; }
.hud-care { display: flex; gap: 2px; align-items: flex-start; }
#mon-activity:not([hidden]) + #mon-evolve { display: none; }
#mon-activity { color: var(--gold); }

.bars { display: grid; gap: 3px; min-width: 120px; }
.bar { display: grid; grid-template-columns: 16px 1fr 22px; gap: 4px; align-items: center; }
.bar .track { height: 8px; background: var(--ink-2); box-shadow: 0 0 0 1px var(--ink); }
.bar .fill { height: 100%; background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 6px); transition: width .4s steps(5); }
.bar .val { text-align: right; font-weight: 700; font-size: 11px; }
.lv-good { --c: #6cc07a; color: var(--good); }
.lv-mid { --c: #f0b640; color: #9a6a0a; }
.lv-low { --c: #e06a6a; color: var(--warn); }

/* battle HUD */
.hud .side { width: calc(50% - 40px); font-size: 12px; color: var(--ink); background: #fff6e6; } /* opaque = sharper text; leaves the top-centre for the round tag */
.hud .side.right { text-align: right; }
.hud-round { top: 8px; left: 50%; transform: translateX(-50%); z-index: 1; white-space: nowrap; }
.hud .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .stage { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .hp, .hud .gauge { height: 7px; background: var(--ink-2); margin: 3px 0; box-shadow: 0 0 0 1px var(--ink); display: flex; }
.hud .side.right .hp, .hud .side.right .gauge { justify-content: flex-end; }
.hud .hp i, .hud .gauge i { display: block; height: 100%; transition: width .3s steps(6); }
.hud .hp i { background: repeating-linear-gradient(90deg, #6cc07a 0 5px, transparent 5px 6px); }
.hud .gauge i { background: repeating-linear-gradient(90deg, #f0b640 0 5px, transparent 5px 6px); }
.hud .move { font-weight: 700; color: var(--primary); min-height: 1.2em; }
.hud .meta, .hud .gmeta { white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud .gmeta { color: #9a6a10; }
.battle-box { justify-content: space-between; }
.battle-box #battle-log { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.box-btns { display: flex; gap: 4px; flex: none; }
.flash { animation: flash .35s steps(3); }
@keyframes flash { 30% { filter: brightness(2.2) saturate(1.4); } }

/* ---------- care action dock ---------- */
.dock { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 8px 0 4px; }
.dock button { display: grid; grid-template-columns: 32px 1fr; column-gap: 8px; text-align: left; align-items: center; padding: 8px 10px; min-height: 66px; }
.dock .ico { grid-row: 1 / 4; }
.dock .label { font-size: 1rem; }
.dock .effect { font-weight: 500; font-size: .72rem; color: var(--muted); }
.dock .cd { font-size: .75rem; color: var(--primary-d); font-variant-numeric: tabular-nums; }
.dock button:disabled .ico { opacity: .55; }
/* Care dock timers: every button shows its own countdown (state set in renderTimers). */
.dock button { position: relative; }
.dock .meter { grid-column: 1 / -1; display: none; height: 6px; margin-top: 5px; background: rgba(59, 42, 51, .18); box-shadow: 0 0 0 2px var(--ink-2); }
.dock .meter i { display: block; height: 100%; width: calc(var(--fill, 0) * 100%); background: repeating-linear-gradient(90deg, var(--c, var(--mint)) 0 5px, transparent 5px 6px); transition: width 1s linear; }
.dock button[data-state="doing"], .dock button[data-state="cooldown"] { grid-template-rows: auto auto auto auto; }
.dock button[data-state="doing"] .meter, .dock button[data-state="cooldown"] .meter { display: block; }
.dock button[data-state="doing"] .cd, .dock button[data-state="cooldown"] .cd { font-size: 1rem; font-weight: 700; }
.dock button[data-state="doing"], .dock button[data-state="sending"]:disabled {
  background: var(--gold); color: var(--ink); --c: var(--primary);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset -3px -4px 0 0 #e0a830, inset 3px 3px 0 0 #fff4a8, 0 0 0 6px rgba(255, 211, 90, .45);
  animation: dock-glow 1.4s steps(2) infinite;
}
.dock button[data-state="doing"] .ico, .dock button[data-state="sending"] .ico { opacity: 1; }
.dock button[data-state="doing"] .cd { color: var(--primary-d); }
.dock button[data-state="cooldown"]:disabled { background: #e7f2ee; color: var(--mint-d); }
.dock button[data-state="cooldown"] .cd { color: var(--mint-d); }
.dock button[data-state="waiting"]:disabled { opacity: .7; }
.dock button[data-state="waiting"] .cd, .dock button[data-state="locked"] .cd, .dock button[data-state="capped"] .cd, .dock button[data-state="full"] .cd { color: var(--muted); }
.dock button[data-state="full"]:disabled { background: #eef0e6; opacity: .85; }
.dock button.suggest { box-shadow: var(--edge), inset -3px -4px 0 0 var(--shade), inset 3px 3px 0 0 #fff, 0 0 0 5px rgba(255, 211, 90, .6); animation: dock-glow 1.6s steps(2) infinite; }
.dock button[data-state="ready"] .cd { color: var(--good); }
.dock button.just-ready { animation: dock-ready .9s steps(3) 1; }
@keyframes dock-glow { 50% { box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset -3px -4px 0 0 #e0a830, inset 3px 3px 0 0 #fff4a8, 0 0 0 9px rgba(255, 211, 90, .25); } }
@keyframes dock-ready { 0%, 66% { background: #c8f0d8; box-shadow: var(--edge), inset -3px -4px 0 0 var(--shade), inset 3px 3px 0 0 #fff, 0 0 0 6px rgba(63, 158, 143, .5); } }
@media (prefers-reduced-motion: reduce) { .dock button { animation: none !important; } .dock .meter i { transition: none; } }
#train-lock { margin: 10px 3px 0; background: var(--paper); padding: 6px 10px; box-shadow: 0 0 0 3px var(--warn); }
.stat-grid { display: grid; grid-template-columns: repeat(2, auto 1fr); gap: 6px 10px; margin: 8px 0 0; align-items: baseline; }
.stat-grid dt { color: var(--muted); font-size: .8rem; }
.stat-grid dd { margin: 0; font-weight: 700; }
@media (min-width: 720px) { .stat-grid { grid-template-columns: repeat(3, auto 1fr); } }

/* ---------- status screen ---------- */
.stats-head { display: flex; gap: 14px; align-items: center; margin: 4px 0 8px; }
.stats-portrait { margin: 0; padding: 4px 8px; flex: none; }
.stats-portrait canvas { width: 96px; height: 96px; }
#stats-body .stat-grid dd { font-size: 1.05rem; white-space: nowrap; }
.stat-grid .trained { color: var(--good); font-size: .75rem; }
.stats-id { display: grid; gap: 6px; min-width: 0; }
.stage-stars { display: flex; align-items: center; gap: 2px; }
.stage-stars .ico { --size: 24px; }
.stage-stars .ico.off { filter: grayscale(1) brightness(.75); opacity: .35; }
.stage-stars .label { margin-left: 6px; font-size: .8rem; color: var(--muted); }
.element-chip {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 6px; font-weight: 700; font-size: .9rem;
  background: var(--el-core); color: var(--el-rim);
  box-shadow: 0 -2px 0 0 var(--el-rim), 0 2px 0 0 var(--el-rim), -2px 0 0 0 var(--el-rim), 2px 0 0 0 var(--el-rim);
}
.element-chip .ico { --size: 24px; }
/* Compact versions for the home HUD panel */
.hud-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }
.stage-stars.small { gap: 1px; }
.stage-stars.small .ico { --size: 14px; }
.stage-stars.small .label { display: none; } /* stars + aria-label carry the stage here */
.element-chip.small { font-size: 11px; padding: 1px 6px 1px 3px; gap: 3px; }
.element-chip.small .ico { --size: 14px; }

.mode-row { align-items: flex-start; gap: 8px; }
.mode-row p { margin: 0; }
.reset-line { font-size: .82rem; color: var(--mint-d); margin: 6px 0 0; font-weight: 700; }

.evo-path { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 6px 0 8px; }
.evo-step { background: #fffdf8; padding: 2px 8px; font-size: .8rem; box-shadow: 0 0 0 2px var(--ink); }
.evo-step.now { background: var(--gold); font-weight: 700; }
.evo-step.next { background: var(--paper-2); color: var(--muted); }
.evo-arrow { color: var(--primary-d); font-weight: 700; }
.lean-chip { display: inline-block; padding: 0 6px; margin: 2px 4px 2px 0; color: #fff; font-weight: 700; }
.lean-attack { background: #d9542f; } .lean-defense { background: #3a7fc0; } .lean-speed { background: #3f9a70; } .lean-balanced { background: #9a6ae0; }

/* ---------- skills ---------- */
.skill-cards { display: grid; gap: 12px; margin-top: 6px; }
.skill-card { background: #fffdf8; padding: 8px 10px; margin: 3px; box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink); text-align: left; }
.skill-card .tag { display: inline-block; font-size: .7rem; padding: 0 6px; margin-right: 6px; color: #fff; background: var(--primary); }
.skill-card.passive .tag { background: var(--mint); }
.skill-card strong { font-size: 1rem; }
.skill-card p { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.skill-cards.compact { gap: 8px; }
.skill-line { font-size: .75rem; color: var(--primary-d); }
.fx-chips { display: flex; flex-wrap: wrap; gap: 2px; min-height: 0; }
.hud .side.right .fx-chips { justify-content: flex-end; }
.fx-chip { font-size: 10px; padding: 0 4px; color: #fff; }
.fx-chip.good { background: var(--good); }
.fx-chip.bad { background: var(--warn); }

/* ---------- gacha / egg ---------- */
.stage-box { background: linear-gradient(#bfe6ff 0 62%, #9ad67e 62%); padding: 18px 0; margin: 12px 0; box-shadow: 0 0 0 3px var(--ink); }
.egg-btn { padding: 8px; display: block; margin: 0 auto; }
.egg-btn canvas { width: 128px; height: 160px; }
/* Egg light show (docs/04): brighter and shakier the closer it is to hatching. */
.egg-stage { position: relative; overflow: hidden; }
.egg-fx { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; pointer-events: none; }
.egg-btn { position: relative; }
.egg-btn[data-charge="2"] canvas { animation: quiver .9s steps(2) infinite; }
.egg-btn[data-charge="3"] canvas { animation: quiver .35s steps(2) infinite; }
.egg-btn.hatching canvas { animation: quiver .08s steps(2) infinite; }
.egg-btn.wobble canvas { animation: wobble .25s steps(4); }
@keyframes quiver { 50% { transform: translateX(2px) rotate(2deg); } }
.hatch-flash { position: fixed; inset: 0; background: #fffbe8; z-index: 50; pointer-events: none; animation: hatch-flash .9s steps(6) forwards; }
@keyframes hatch-flash { 0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .egg-btn canvas { animation: none !important; } .hatch-flash { animation-duration: .3s; } }
@keyframes wobble { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
#gacha-canvas { width: 192px; height: 264px; }
#gacha-canvas.spin { animation: wobble .3s steps(4) 3; }

/* ---------- lists ---------- */
.list { list-style: none; padding: 0; margin: 12px 3px 0; display: grid; gap: 14px; }
.list li { background: #fffdf8; padding: 8px 10px; display: flex; gap: 10px; align-items: center; }
.list li.incoming { background: #fff1ea; }
.list li .grow { flex: 1; min-width: 0; }
.list canvas { width: 96px; height: 96px; flex: none; margin: -8px -4px; }
.list .who-line { font-weight: 700; }
.stage-line { font-weight: 700; font-size: .85rem; }
.badge { display: inline-block; padding: 0 6px; font-size: .75rem; font-weight: 700; color: #fff; }
.badge.win { background: var(--good); }
.badge.loss { background: var(--warn); }
.badge.draw { background: var(--muted); }
.msg { margin: 6px 0 0; padding: 6px 10px; background: var(--paper-2); white-space: pre-wrap; word-break: break-word; box-shadow: inset 3px 0 0 0 var(--primary); }
.reroll-row { margin-top: 14px; }

.rank-list { padding: 0; list-style: none; margin: 0; }
.rank-list li { display: grid; grid-template-columns: 3em 1fr auto; gap: 8px; padding: 6px 4px; border-bottom: 2px dashed var(--shade); }
.rank-list li.mine { background: #fff1c2; }
.me-rank { font-weight: 700; background: var(--box); color: #fff; padding: 8px 12px; }

/* ---------- battle result ---------- */
.result-head { font-size: 1.35rem; }
.rounds { width: 100%; border-collapse: collapse; font-size: .78rem; }
.rounds th { background: var(--ink); color: var(--paper); font-weight: 600; position: sticky; top: 0; }
.rounds th, .rounds td { padding: 4px; text-align: center; border-bottom: 2px dashed var(--shade); }
.table-wrap { max-height: 280px; overflow: auto; box-shadow: 0 0 0 2px var(--ink); margin: 8px 2px; }
.msg-card { background: var(--paper-2); padding: 12px; margin: 10px 3px; box-shadow: 0 0 0 3px var(--ink); }
.msg-card textarea { width: 100%; min-height: 64px; border: 0; padding: 8px; resize: vertical; box-shadow: 0 0 0 2px var(--ink); background: #fffdf9; }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--ink); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -3px 0 0 #1f1620;
}
.tabbar button { flex: 1; max-width: 150px; min-width: 0; display: grid; justify-items: center; gap: 2px; color: #cdbac5; font-size: .78rem; font-weight: 700; padding: 4px 0; position: relative; min-height: 56px; }
.tabbar button[aria-current="page"] { color: var(--gold); background: #4d3a47; box-shadow: inset 0 -3px 0 0 var(--gold); }
.dot { position: absolute; top: 4px; right: calc(50% - 22px); width: 9px; height: 9px; background: var(--primary); box-shadow: 0 0 0 2px var(--ink); }

/* ---------- dialogs ---------- */
.px-dialog { --b: 4px; border: 0; background: var(--paper); color: var(--ink); max-width: min(440px, calc(100vw - 32px)); padding: 18px; }
.px-dialog::backdrop { background: rgba(30, 20, 30, .6); }
.creds { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 1.05rem; }
.creds dt { color: var(--muted); }
.creds dd { margin: 0; font-family: ui-monospace, monospace; font-weight: 700; word-break: break-all; }
.info-list { display: grid; gap: 4px; margin: 0; }
.info-list dt, .info-list h3 { font-weight: 700; margin: 6px 0 0; font-size: 1rem; }
.info-list dd, .info-list p { margin: 0; color: var(--muted); }
.info-list .low { color: var(--warn); }
.switch { display: flex; gap: 10px; align-items: center; }
.switch input { width: 22px; height: 22px; min-height: 0; margin: 0; }
.celebrate { text-align: center; overflow: hidden; }
.evo-stage { background: linear-gradient(#fff6d8, #ffe3ee); padding: 8px 0; box-shadow: 0 0 0 3px var(--ink); }
.evo-stats { margin: 0 auto; border-collapse: collapse; }
.evo-stats td { padding: 2px 10px; text-align: left; }
.evo-stats .up { color: var(--good); font-weight: 700; }
.textbox-window h1 { font-size: 1.3rem; }
.hud .hud-tl.px-tag { top: 10px; left: 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--box); color: #fff; padding: 10px 16px; max-width: calc(100vw - 32px);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 0 0 2px #fff;
}

/* ---------- desktop ---------- */
@media (min-width: 720px) {
  #app { padding-left: 24px; padding-right: 24px; }
  .screen-wrap { margin: 6px 3px 14px; box-shadow: 0 0 0 4px var(--ink); }
  .dock { grid-template-columns: repeat(4, 1fr); }
  .px-panel { font-size: 13px; }
  .hud-title { font-size: 15px; }
  .bars { min-width: 170px; }
  .bar .track { height: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
#onboarding, #setup { padding-top: 14px; }

/* Four small milestones make the companion journey visible at a glance. */
.ob-progress { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; list-style: none; padding: 0; margin: 0 0 18px; font-size: .8rem; }
.ob-progress li { text-align: center; padding: 6px 2px; border-bottom: 3px solid var(--shade, #dbc6a5); }
.ob-progress li[aria-current="step"] { background: #ffe5a0; border-color: #bf7040; font-weight: 700; }
.ob-progress li.done { border-color: #739b68; }
.ob-hook { color: #8b4939; font-weight: 700; margin-top: 10px; }
.ob-tip { background: #fff5df; border-left: 3px solid #d0a560; padding: 10px 12px; font-size: .9rem; }
#onboarding .row.end { flex-wrap: wrap; gap: 8px; }
@media (max-width: 480px) {
  #onboarding h1 { font-size: 1.35rem; }
  #ob-next { flex-basis: 100%; }
}

#farewell-dialog { width: min(680px, calc(100vw - 32px)); }
#farewell-canvas { display: block; width: 100%; height: auto; background: #53394f; }
#farewell-note { color: #826050; font-size: .9rem; }
#farewell-caption { text-align: center; color: #82576b; }

/* Passcode hand-off: one clear call to action. */
#credentials .creds dd { font-size: 1.3rem; letter-spacing: .06em; user-select: all; }
.cred-note { background: #fff5df; border-left: 3px solid #d0a560; padding: 8px 10px; font-size: .9rem; }
.cred-go { display: block; width: calc(100% - 6px); margin-top: 10px; padding: 12px 10px; font-size: 1.1rem; }

/* Training result popup */
#train-dialog h2 { text-align: center; }
.train-stage { display: grid; place-items: center; }
#train-canvas { width: 192px; height: 192px; }
.train-gain { font-size: 1.6rem; margin: 4px 0 0; }
.train-gain strong { color: var(--good); font-size: 2rem; }
#train-dialog.rare h2, #train-dialog.rare .train-gain strong { color: #c88a10; }
#train-dialog.rare .train-stage { background: linear-gradient(#fff3a8, #ffd6a0); }

/* Cancel-activity confirmation */
.dock button[data-state="doing"] .effect { color: var(--primary-d); font-weight: 700; }
.cancel-lose { background: #fff1ea; box-shadow: 0 0 0 2px var(--warn); padding: 10px 12px; margin: 4px 2px; }
.cancel-lose p { margin: 4px 0; font-size: 1.15rem; font-weight: 700; color: var(--warn); }
.cancel-lose small { color: var(--muted); }

/* Battle floating text: HTML over the canvas so it stays sharp at 2× zoom and on desktop. */
.pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.pop {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap; color: #fff;
  font: 700 17px/1 "Pixelify Sans", "DotGothic16", "Mali", sans-serif; letter-spacing: .02em;
  text-shadow: 2px 0 #3b2a33, -2px 0 #3b2a33, 0 2px #3b2a33, 0 -2px #3b2a33, 2px 2px #3b2a33, -2px 2px #3b2a33, 2px -2px #3b2a33, -2px -2px #3b2a33, 0 4px 0 rgba(59, 42, 51, .35);
}
.pop.dmg { font-size: 22px; }
.pop.big { font-size: 30px; color: #ffe07a; }
.pop.guard { color: #9fe0ff; }
.pop.skill { color: #ffd35a; font-size: 18px; }
.pop.good { color: #8ff0a0; }
.pop.bad { color: #ff9a8a; }
@media (min-width: 720px) { .pop { font-size: 20px; } .pop.dmg { font-size: 26px; } .pop.big { font-size: 36px; } .pop.skill { font-size: 21px; } .hud .side { font-size: 13px; } .hud .name { font-size: 15px; } }

/* Version tag after the logo + release notes */
.brand { display: flex; align-items: center; gap: 6px; margin-right: auto; min-width: 0; }
.brand .logo.small { margin-right: 0; }
.version-tag { position: relative; font: 700 11px/1 "DotGothic16", "Mali", monospace; color: var(--gold); background: #3b2a33; padding: 4px 6px; box-shadow: 0 0 0 2px var(--primary-d); cursor: pointer; }
.version-tag:hover { color: #fff3a8; }
.version-tag.unread::after { content: ""; position: absolute; top: -4px; right: -4px; width: 7px; height: 7px; background: #ff5a6a; box-shadow: 0 0 0 2px var(--bg); }
#notes-dialog { width: min(560px, calc(100vw - 32px)); }
.release-list { max-height: min(60vh, 520px); overflow-y: auto; padding-right: 4px; display: grid; gap: 14px; }
.release h3 { margin: 0 0 4px; font-size: 1.15rem; }
.release h3 small { display: block; font-size: .8rem; font-weight: 500; color: var(--muted); }
.release h4 { margin: 10px 0 2px; font-size: .9rem; color: var(--primary-d); }
.release ul { margin: 0; padding-left: 18px; display: grid; gap: 3px; font-size: .92rem; }

/* Inventory bag */
.bag-btn { position: relative; }
.bag-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; font: 700 11px/18px "DotGothic16", "Mali", sans-serif; color: #fff; background: var(--primary); box-shadow: 0 0 0 2px var(--bg); text-align: center; }
#bag-dialog { width: min(460px, calc(100vw - 32px)); }
#bag-dialog h2 .ico { --size: 32px; }
.bag-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.bag-slot { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: #f3e4cf; box-shadow: inset 0 0 0 2px var(--shade), 0 0 0 2px var(--ink-2); }
.bag-slot:disabled { cursor: default; background: #eadbc6; }
.bag-slot[aria-selected="true"] { background: #fff3c8; box-shadow: inset 0 0 0 2px #e0a830, 0 0 0 3px var(--ink); }
.bag-slot img { width: 64%; height: auto; image-rendering: pixelated; }
.bag-n { position: absolute; right: 4px; bottom: 2px; font: 700 12px/1 "Pixelify Sans", monospace; color: var(--ink); }
.bag-detail { display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: start; background: #fffdf8; padding: 10px; box-shadow: 0 0 0 2px var(--ink-2); }
.bag-detail img { width: 64px; height: 64px; image-rendering: pixelated; }
.bag-detail p { margin: 4px 0 0; font-size: .92rem; }

/* Players online badge (bottom-right, above the tab bar) */
.online-badge { position: fixed; right: 10px; bottom: calc(var(--tabbar-h, 76px) + 8px); z-index: 6; font: 700 11px/1 "DotGothic16", "Mali", sans-serif; color: #d9f5d0; background: rgba(43, 32, 64, .9); padding: 5px 8px 5px 18px; box-shadow: 0 0 0 2px #3b2a33; pointer-events: auto; }
.online-badge::before { content: ""; position: absolute; left: 7px; top: 50%; width: 6px; height: 6px; margin-top: -3px; background: #5ce07a; box-shadow: 0 0 0 1px #1e4a28; }
/* Keep the top bar on one line at phone width now that it also holds the version tag and the bag. */
.topbar .logo.small { white-space: nowrap; }
#who { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
@media (max-width: 420px) { .topbar { gap: 6px; } .topbar .logo.small { font-size: 1rem; } .version-tag { font-size: 10px; padding: 3px 4px; } }
.version-tag.update { color: #1e4a28; background: #8ff0a0; box-shadow: 0 0 0 2px #3f8f4f; animation: dock-ready 1.2s steps(2) infinite; }

/* Item use effect: big item in the middle, spinning rays, pulsing glow, sparkles, then float up and fade. */
.item-fx { position: fixed; inset: 0; z-index: 60; pointer-events: none; display: grid; place-items: center; }
.item-fx > * { grid-area: 1 / 1; }
.item-fx img { width: 128px; height: 128px; image-rendering: pixelated; animation: item-pop 1.65s steps(12) forwards; }
.item-fx .glow { width: 220px; height: 220px; background: radial-gradient(circle, rgba(255, 246, 200, .95) 0 22%, rgba(255, 211, 90, .6) 23% 40%, rgba(255, 211, 90, .25) 41% 58%, transparent 59%); animation: item-glow 1.65s steps(10) forwards; }
.item-fx .rays { width: 340px; height: 340px; background: repeating-conic-gradient(rgba(255, 240, 180, .55) 0 10deg, transparent 10deg 30deg); -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%); mask: radial-gradient(circle, #000 30%, transparent 70%); animation: item-rays 1.65s steps(16) forwards; }
.item-fx i { width: 8px; height: 8px; background: #fff3a8; box-shadow: 0 0 0 2px #ffd35a; animation: item-spark 1.3s steps(8) forwards; }
.item-fx i:nth-of-type(1) { --x: -90px; --y: -70px; } .item-fx i:nth-of-type(2) { --x: 95px; --y: -60px; } .item-fx i:nth-of-type(3) { --x: -110px; --y: 30px; }
.item-fx i:nth-of-type(4) { --x: 105px; --y: 45px; } .item-fx i:nth-of-type(5) { --x: -30px; --y: -120px; } .item-fx i:nth-of-type(6) { --x: 40px; --y: 110px; animation-delay: .15s; }
@keyframes item-pop { 0% { transform: scale(0); } 18% { transform: scale(1.35); } 30%, 70% { transform: scale(1) translateY(0); opacity: 1; } 100% { transform: scale(.8) translateY(-60px); opacity: 0; } }
@keyframes item-glow { 0% { transform: scale(0); opacity: 0; } 25% { transform: scale(1.1); opacity: 1; } 45% { transform: scale(.95); } 65% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
@keyframes item-rays { 0% { transform: rotate(0) scale(.2); opacity: 0; } 25% { opacity: 1; transform: rotate(40deg) scale(1); } 75% { opacity: 1; } 100% { transform: rotate(160deg) scale(1.2); opacity: 0; } }
@keyframes item-spark { 0% { transform: translate(0, 0) scale(0); opacity: 0; } 30% { opacity: 1; transform: translate(calc(var(--x) * .6), calc(var(--y) * .6)) scale(1); } 100% { transform: translate(var(--x), var(--y)) scale(.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .item-fx .rays, .item-fx i { display: none; } .item-fx img, .item-fx .glow { animation: item-fade .5s forwards; } }
@keyframes item-fade { from { opacity: 1; } to { opacity: 0; } }
