:root {
  --page: #2b2d30;
  --panel: #3a3d41;
  --panel-line: #565a60;
  --text: #f0f0ee;
  --muted: #a9adb3;
  --accent: #e0a23b;
  --accent-text: #1e1f21;
  --bad: #e07a6a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--page); color: var(--text); font: 16px/1.35 system-ui, sans-serif; overscroll-behavior: none; }
#app { position: relative; display: flex; flex-direction: column; height: 100dvh; max-width: 1400px; margin: 0 auto; user-select: none; -webkit-user-select: none; }
#hud { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 8px 12px; font-weight: 600; }
#hud-boss { color: var(--bad); }
#hud-gold { color: var(--accent); }
#hud-shop { margin-left: auto; }
#gains { margin: 0; padding: 0 12px 6px; min-height: 1.6em; color: var(--muted); font-size: 14px; }
#stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 8px; touch-action: none; }
#desk, #mini { display: block; touch-action: none; border-radius: 4px; }
#mini { cursor: ns-resize; }
#status { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 18px; padding: 8px; font-size: 14px; }
#status-caps { font-weight: 700; }
#status-boss { color: var(--bad); }
button { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--panel-line); border-radius: 8px; padding: 8px 14px; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.35; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
button.on { outline: 3px solid var(--accent); }
button.off { opacity: 0.5; text-decoration: line-through; }
#overlay { position: absolute; inset: 0; background: rgba(30, 31, 33, 0.9); display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
#overlay[hidden], #tune[hidden] { display: none; }
.panel { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px; margin: auto; }
.panel h1, .panel h2 { margin: 0; }
.panel p { margin: 0; color: var(--muted); }
.panel input { font: inherit; padding: 8px; border-radius: 8px; border: 1px solid var(--panel-line); background: var(--page); color: var(--text); width: 100%; text-transform: uppercase; }
.row { display: flex; flex-wrap: wrap; gap: 8px; }
.error { color: var(--bad); min-height: 1.35em; }
.code { font-family: ui-monospace, monospace; color: var(--text); user-select: all; -webkit-user-select: all; }
.panel h3 { margin: 4px 0 0; font-size: 15px; }
.panel .stats { color: var(--text); font-weight: 600; }
.warn { color: var(--bad) !important; }
.note { min-height: 1.35em; }
.muted { color: var(--muted); }
/* Kit: round tokens with a rarity ring, like loot on the board. */
.tabs { display: flex; gap: 4px; padding: 3px; background: var(--page); border-radius: 10px; }
.tabs .tab { flex: 1; border: 0; background: transparent; padding: 8px; color: var(--muted); }
.tabs .tab.on { background: var(--panel-line); color: var(--text); font-weight: 700; outline: 0; }
.tab-body { display: flex; flex-direction: column; gap: 10px; }
.gold { color: var(--accent) !important; font-weight: 700; }
.token { --ring: var(--panel-line); position: relative; width: 56px; height: 56px; padding: 0; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #4a4e55, #2a2c30 70%); border: 3px solid var(--ring); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.35); }
.token canvas { width: 40px; height: 40px; image-rendering: pixelated; pointer-events: none; }
.token.empty { border-style: dashed; background: var(--page); }
.token .ghost { opacity: 0.18; filter: grayscale(1); }
.token.has-item { touch-action: none; cursor: grab; }
.token.better::after { content: '▲'; position: absolute; top: -4px; right: -4px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; line-height: 1; color: #10301a; background: #7be08a; border: 2px solid var(--panel); }
.token.dragging { opacity: 0.3; }
.drag-ghost { position: fixed; z-index: 10; pointer-events: none; transform: translate(-50%, -60%) scale(1.15); box-shadow: 0 8px 18px rgba(0, 0, 0, 0.5); }
.doll-hero.fits, .bag.fits { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 12px; }
.fits.hover { outline-style: solid; background-color: rgba(224, 162, 59, 0.12); }
.token.fits.hover { box-shadow: 0 0 0 6px rgba(224, 162, 59, 0.5); animation: none; }
.better-hint { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: rgba(123, 224, 138, 0.12); border: 1px solid #7be08a; font-size: 14px; font-weight: 600; }
.better-hint[hidden] { display: none; }
.better-hint span { flex: 1; }
.token.picked { outline: 3px solid var(--text); outline-offset: 2px; }
.token.fits { border-color: var(--accent); border-style: solid; animation: fits 1s ease-in-out infinite alternate; }
@keyframes fits { from { box-shadow: 0 0 0 0 rgba(224, 162, 59, 0.7); } to { box-shadow: 0 0 0 6px rgba(224, 162, 59, 0); } }
.offer { flex: 1 1 150px; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; font-size: 14px; }
.offer b.price { color: var(--accent); }
.fight-bars { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.fighter { display: flex; flex-direction: column; gap: 4px; }
.fighter:last-child { text-align: right; }
.bar { position: relative; height: 26px; background: var(--page); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 100%; background: #5fa36a; transition: width 0.2s; }
.fighter:last-child .bar-fill { background: var(--bad); margin-left: auto; }
.bar-text { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.arena { width: 100%; height: auto; border-radius: 8px; image-rendering: pixelated; }
.fight-log { list-style: none; margin: 0; padding: 0; height: 84px; overflow: hidden; color: var(--muted); font-size: 14px; }
.fight-log li:first-child { color: var(--text); font-weight: 600; }
#tune { position: absolute; right: 8px; top: 48px; width: 250px; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 8px; padding: 10px; font-size: 13px; display: flex; flex-direction: column; gap: 6px; }
#tune label { display: flex; flex-direction: column; }
@media (max-width: 500px) {
  .token { width: 48px; height: 48px; }
  .token canvas { width: 34px; height: 34px; }
  .panel { padding: 14px; }
  #hud { font-size: 13px; gap: 2px 10px; padding: 6px 8px; }
  #hud button { padding: 6px 8px; }
  #status { font-size: 12px; padding: 6px; }
  #tune { top: auto; bottom: 90px; }
}
.panel input.plain { text-transform: none; }
.panel .note { color: var(--text); }
.own-code { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.qr { width: 168px; height: 168px; image-rendering: pixelated; border-radius: 4px; }
.code-row { display: flex; align-items: center; gap: 10px; }
.big-code { font-size: 28px; font-weight: 700; letter-spacing: 4px; color: var(--accent); user-select: all; -webkit-user-select: all; }
.icon-copy { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; }
.icon-copy svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.panel .copy-note { min-height: 1.4em; font-size: 13px; }
.panel .add-friend input::placeholder { text-transform: none; }
.add-friend .row input { flex: 1; width: auto; }
.friends { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.friends li { background: var(--page); border-radius: 8px; padding: 8px 10px; }
.friends .code { color: var(--muted); font-size: 13px; }
#hud-friends.alert, .friends li.waiting { border-color: var(--accent); }
#hud-friends.alert { color: var(--accent); }
.friends li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.friends li > button { margin-left: auto; padding: 6px 10px; }
.friends li > .row { margin-left: auto; }
.friends li.waiting { border: 1px solid var(--accent); }
.inbox .friends li > span { flex: 1 1 60%; }
/* The text spans stretch, the online dot does not: it stays a 10 px circle. */
.inbox .friends li > .dot { flex: none; }
/* GAM-25: presence dot, differs by shape as well as colour. */
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--muted); }
.dot.on { background: #5cc16b; border-color: #5cc16b; }
/* GAM-11: items offered when refusing a duel or picking loot. */
.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-list button { text-align: left; font-size: 14px; }
.item-list button.chosen { border-color: var(--accent); outline: 2px solid var(--accent); }
/* GAM-13: helpers' health bars under the main pair. */
.fight-bars.allies { grid-template-columns: repeat(3, 1fr); font-size: 13px; }
/* Allies are heroes: the boss colour rule for the last bar does not apply to them. */
.fight-bars.allies .fighter .bar-fill { background: #5fa36a; margin-left: 0; }
/* GAM-18: the victory screen. --v-main and --v-glow come from the variant's row in src/ui/victory.js. */
.victory { position: relative; overflow: hidden; text-align: center; border-color: var(--v-main); box-shadow: 0 0 var(--v-glow) var(--v-main);
  animation: victory-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.victory-sky { position: absolute; left: 0; top: 0; width: 100%; height: 220px; pointer-events: none; }
.victory-head { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 26px 0 8px; }
.victory-head h1 { color: var(--v-main); font-size: 34px; letter-spacing: 0.02em; text-shadow: 0 3px 0 #17171d, 0 0 var(--v-glow) var(--v-main);
  animation: victory-title 0.6s 0.1s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
.victory-head p { color: var(--text) !important; font-weight: 600; }
.victory-rewards { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 60px; }
.panel .victory-gold { color: var(--accent); font-size: 30px; font-weight: 800; text-shadow: 0 2px 0 #17171d; animation: pop 0.35s ease-out both; }
.loot-cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; }
.loot-card { --ring: var(--panel-line); flex: 1 1 150px; max-width: 240px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px;
  border: 2px solid var(--ring); background: var(--page); font-size: 13px; animation: pop 0.4s ease-out backwards; }
.loot-card .token { --ring: inherit; border-color: var(--ring); flex: none; aspect-ratio: 1; }
.loot-text { display: flex; flex-direction: column; gap: 2px; }
.loot-card.taken { cursor: default; }
.loot-card.chosen { outline: 3px solid var(--accent); outline-offset: 2px; transform: translateY(-4px); box-shadow: 0 0 16px var(--ring); }
.victory .row { justify-content: center; }
.victory-flash { position: absolute; inset: 0; background: #fff; pointer-events: none; animation: flash 0.5s ease-out both; }
@keyframes flash { from { opacity: 0.85; } to { opacity: 0; visibility: hidden; } }
@keyframes victory-in { from { transform: scale(0.7); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes victory-title { from { transform: scale(2.2); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-width: 500px) {
  .victory-head h1 { font-size: 26px; }
  .loot-card { flex-basis: 100%; max-width: none; flex-direction: row; text-align: left; }
}
/* GAM-37: rewards are one column, or one row on a screen wide enough for four cards. Never a wrapped mix. */
.victory .loot-cards { flex-direction: column; flex-wrap: nowrap; align-items: center; }
.victory .loot-card { flex: none; width: 100%; max-width: 440px; flex-direction: row; text-align: left; }
@media (prefers-reduced-motion: reduce) {
  .victory, .victory-head h1, .loot-card, .victory-gold, .victory-flash { animation-duration: 0.01s; }
}
/* GAM-15: waiting invitations on the HUD and a toast that slides in above every screen. */
#hud-friends { position: relative; }
#hud-friends .icon { margin-right: 6px; }
#hud-friends .badge { position: absolute; top: -7px; right: -7px; min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box;
  border-radius: 10px; background: #e5484d; color: #fff; font-size: 12px; line-height: 20px; text-align: center; }
#hud-friends .badge[hidden] { display: none; }
#toast { position: fixed; z-index: 20; top: 8px; left: 50%; width: min(440px, calc(100% - 32px)); box-sizing: border-box;
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--accent);
  border-radius: 10px; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45); transform: translate(-50%, calc(-100% - 16px));
  transition: transform 0.25s ease-out; }
#toast.in { transform: translate(-50%, 0); }
#toast[hidden] { display: none; }
#toast span { flex: 1; }
#toast button { padding: 6px 12px; }
/* GAM-16: asking friends for help on the boss screen. */
.ask-help { display: flex; flex-direction: column; gap: 6px; }
.ask-help .friends { max-height: 172px; overflow-y: auto; }
.ask-help li { flex-wrap: nowrap; padding: 4px 6px 4px 10px; }
.ask-help li > span { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ask-help li > button { padding: 5px 12px; }
.ask-help .error:empty { display: none; }
.ask-help > button { align-self: flex-start; }
/* GAM-20: loot bags that drop in, shake, burst in the item's rarity colour and turn into the item card. */
.panel.fight-out { animation: fight-out 0.32s ease-in both; }
@keyframes fight-out { to { transform: scale(1.08); opacity: 0; filter: brightness(2); } }
.loot-cards.bags { align-items: center; }
.loot-bag { --ring: var(--v-main, var(--accent)); position: relative; width: 84px; height: 84px; padding: 0; display: grid; place-items: center;
  border-radius: 50%; border: 2px solid transparent; background: radial-gradient(circle, rgba(255, 255, 255, 0.12), transparent 70%);
  animation: bag-drop 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) backwards; }
.loot-bag canvas { width: 60px; height: 60px; image-rendering: pixelated; pointer-events: none; animation: bag-idle 1.4s ease-in-out infinite; }
.loot-bag.opening canvas { animation: bag-shake 0.42s linear both; }
.loot-bag.opening::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 4px solid var(--ring);
  box-shadow: 0 0 24px var(--ring); animation: bag-burst 0.42s ease-out both; }
.loot-card.revealed { animation: reveal 0.5s cubic-bezier(0.2, 1.5, 0.4, 1) backwards; box-shadow: 0 0 18px var(--ring); }
@keyframes bag-drop { from { transform: translateY(-120px) scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bag-idle { 50% { transform: translateY(-3px); } }
@keyframes bag-shake { 0%, 100% { transform: none; } 20% { transform: rotate(-12deg); } 40% { transform: rotate(10deg) scale(1.08); }
  60% { transform: rotate(-8deg) scale(1.15); } 80% { transform: rotate(6deg) scale(1.25); } }
@keyframes bag-burst { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
@keyframes reveal { from { transform: scale(0.3) rotate(-6deg); opacity: 0; filter: brightness(2.5); } to { transform: none; opacity: 1; filter: none; } }
/* A chosen card keeps its glow after its bag opened. */
.loot-card.revealed.chosen { box-shadow: 0 0 22px var(--accent); }
/* A bag takes the slot its card will fill, so little moves under the finger or mouse when it opens. */
.victory .loot-bag { flex: none; width: 100%; max-width: 440px; height: 72px; border-radius: 10px;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.12), transparent 40px); }
.victory .loot-cards.bags .loot-card { min-height: 72px; }
.victory .loot-bag.opening::after { inset: -6px calc(50% - 42px); }
@media (min-width: 960px) {
  .panel.victory:has(.loot-cards) { width: min(1000px, 100%); }
  .victory .loot-cards { flex-direction: row; justify-content: center; align-items: stretch; }
  .victory .loot-card, .victory .loot-bag { flex: 1 1 0; min-width: 0; width: auto; max-width: 240px; }
  .victory .loot-card { flex-direction: column; text-align: center; }
  .victory .loot-bag { height: auto; min-height: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .loot-bag, .loot-bag canvas, .loot-bag.opening::after, .loot-card.revealed, .panel.fight-out { animation-duration: 0.01s; }
}
/* GAM-21: the loser's screen of a fight between friends. --d-main comes from src/ui/defeat.js. */
.defeat { text-align: center; border-color: var(--d-main); background: radial-gradient(circle at 50% 0%, rgba(224, 82, 74, 0.18), var(--panel) 70%);
  animation: defeat-in 0.5s ease-out both; }
.defeat-head { display: flex; flex-direction: column; gap: 4px; padding: 18px 0 4px; }
.defeat-head h1 { color: var(--d-main); font-size: 32px; text-shadow: 0 3px 0 #17171d; }
.defeat-head p { color: var(--text) !important; font-weight: 600; }
.panel .defeat-gold { color: var(--bad); font-size: 26px; font-weight: 800; }
.panel .defeat-ends { color: var(--text); }
.defeat .row { justify-content: center; }
@keyframes defeat-in { 0% { transform: translateY(-30px); opacity: 0; } 60% { transform: translateY(6px); opacity: 1; } 75% { transform: translateX(-6px); }
  90% { transform: translateX(4px); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .defeat { animation-duration: 0.01s; } }

/* GAM-22: the item compare card, its verdict chip, the popover and the gains-line item buttons. */
.cmp { display: flex; flex-direction: column; gap: 4px; min-width: 0; text-align: left; font-size: 13px; }
.cmp-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.cmp-sub { font-size: 12px; }
.cmp-rows { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.cmp-row { display: flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.cmp-stat { color: var(--muted); }
.cmp-delta { font-weight: 700; font-size: 12px; }
.cmp-delta.up, .v-better { color: #7be08a; }
.cmp-delta.down, .v-worse { color: var(--bad); }
.v-mixed { color: var(--accent); }
.v-same, .v-worn { color: var(--muted); }
.cmp-chip { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.loot-card .loot-text { width: 100%; align-items: stretch; }
.kit-card .kit-text { min-width: 0; }
.cmp-pop { position: fixed; z-index: 50; width: min(280px, calc(100vw - 16px)); padding: 10px; border-radius: 10px; background: var(--panel); border: 1px solid var(--panel-line); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); }
#gains { display: flex; flex-wrap: wrap; align-items: center; white-space: pre-wrap; }
.gain-item { min-height: 40px; padding: 4px 8px; background: transparent; border: 1px dashed currentColor; font-size: 14px; text-align: left; }
/* The 40px touch target must not grow the gains line: #stage would shrink and the board rescale on every stored item. */
#gains .gain-item { margin: -9px 0; }
.victory .row { position: sticky; bottom: -14px; padding: 8px 0 2px; background: var(--panel); z-index: 2; }

/* Shop shelf (GAM-26): two planks with three item tokens standing on each. */
.shelf { display: flex; flex-direction: column; gap: 14px; padding: 10px 8px 0; border-radius: 10px; background: var(--page); }
.plank { display: grid; grid-template-columns: repeat(3, 1fr); justify-items: center; padding: 0 0 8px; border-bottom: 8px solid #6b4a2b; box-shadow: 0 3px 0 #3d2a18; }
.shelf-spot { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: -4px; }
.shelf-spot .price { color: var(--accent); font-size: 13px; min-height: 1.2em; }
.shelf-card .row { align-items: center; }
.shelf-card .row button { flex: 0 0 auto; }

/* Leaderboard (GAM-23) */
.lb-tabs { display: flex; gap: 6px; }
.lb-tab { flex: 1; min-height: 44px; padding: 8px 6px; }
.lb-tab[aria-selected="true"] { border-color: var(--accent); background: var(--page); font-weight: 700; }
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: min(52vh, 440px); overflow-y: auto; }
.lb-row { background: var(--page); border: 1px solid transparent; border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.lb-row.me { border-color: var(--accent); }
.lb-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.lb-rank { min-width: 2ch; color: var(--muted); font-weight: 700; }
.lb-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-you { flex: none; font-size: 12px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 6px; padding: 1px 6px; }
.lb-score { flex: none; font-variant-numeric: tabular-nums; }
.lb-detail { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.lb-gap, .lb-hint { text-align: center; color: var(--muted); font-size: 14px; padding: 4px; }
