:root {
  color-scheme: dark;
  --ink: #e4ece4;
  --muted: #8b9a90;
  --faint: #6b7a70;
  --panel: #18201ce8;
  --line: #ffffff14;
  --green: #b7e5aa;
  --red: #f08c7a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  overflow: hidden;
  background: #151c18;
  color: var(--ink);
  font: 13px Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas { display: block; width: 100vw; height: 100dvh; touch-action: none; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
[hidden] { display: none !important; }

.panel, #standings, footer, #selection, #promote, .corner, #toast {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.brand {
  position: fixed; top: 20px; left: 22px;
  font-size: 14px; font-weight: 600; letter-spacing: -.3px; color: #ffffff8c;
  pointer-events: none;
}

#standings {
  position: fixed; top: 16px; right: 16px; min-width: 116px;
  padding: 8px 10px 6px; border-radius: 12px;
}
#standings:has(#connection[hidden]):has(#leaderList:empty) { display: none; }
#connection { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted); padding: 2px 0; }
#connection i { width: 6px; height: 6px; border-radius: 50%; background: var(--red); }
#connection:not([hidden]) + #leaderList:not(:empty) { margin-top: 4px; }
#leaderList { list-style: none; margin: 0; padding: 0; }
#leaderList:empty { display: none; }
#leaderList li {
  display: grid; grid-template-columns: 16px 9px 1fr auto; align-items: center; gap: 7px;
  padding: 2px 4px; margin: 0 -4px; border-radius: 6px; cursor: pointer;
  font-size: 12px; font-variant-numeric: tabular-nums; color: #c9d4ca;
}
#leaderList li:hover { background: #ffffff0d; }
#leaderList li span { color: var(--faint); font-size: 10px; text-align: right; }
#leaderList li i { width: 8px; height: 8px; border-radius: 50%; }
#leaderList li em { font-style: normal; font-size: 10px; color: var(--muted); }
#leaderList li b { font-weight: 500; text-align: right; }
#leaderList li.you { color: #fff; }
#leaderList li.you i { box-shadow: 0 0 0 2px #ffffffb0; }
#leaderList li.gap { margin-top: 3px; border-top: 1px solid var(--line); border-radius: 0; padding-top: 4px; }

#danger {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 7px 14px; border-radius: 20px; border: 1px solid #f08c7a66;
  background: #3a1d19e6; color: #ffd5cc; font-size: 12px; pointer-events: none;
  animation: pulse .9s ease-in-out infinite alternate;
}
@keyframes pulse { from { box-shadow: 0 0 0 0 #f08c7a00; } to { box-shadow: 0 0 20px 2px #f08c7a50; } }

#toast {
  position: fixed; left: 50%; top: 58px; transform: translate(-50%, -6px);
  padding: 8px 14px; border-radius: 20px; font-size: 12px;
  opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

footer {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: stretch; gap: 2px; padding: 5px; border-radius: 14px;
  box-shadow: 0 10px 40px #0004; overflow: hidden;
}
#moveBar {
  position: absolute; left: 0; top: 0; height: 2px; width: 100%;
  background: var(--green); transform-origin: left; transform: scaleX(1); opacity: 0;
  transition: opacity .2s;
}
#moveBar.waiting { opacity: .8; }
.wallet {
  display: flex; align-items: center; justify-content: center; min-width: 58px; padding: 0 10px 0 8px;
  font-size: 22px; font-weight: 500; letter-spacing: -.8px; font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--line); margin-right: 3px;
}
.pieces { display: flex; gap: 2px; }
.pieceButton {
  width: 48px; height: 54px; border-radius: 9px; border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: background .1s, opacity .15s;
}
.pieceButton:hover { background: #ffffff0b; }
.pieceButton .glyph { width: 32px; height: 32px; margin-bottom: 1px; }
.pieceButton .price { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pieceButton.active { background: #b7e5aa1a; border-color: #b7e5aa70; }
.pieceButton.poor { opacity: .38; }

#selection {
  position: fixed; left: 50%; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 76px); transform: translateX(-50%);
  display: flex; gap: 2px; padding: 4px; border-radius: 11px;
}
#selection button { padding: 7px 11px; border-radius: 8px; font-size: 12px; }
#selection button:hover { background: #ffffff0d; }
#rotate { font-size: 15px; line-height: 1; }

#promote {
  position: fixed; left: 0; top: 0; z-index: 2;
  display: flex; gap: 2px; padding: 4px; border-radius: 11px;
  box-shadow: 0 8px 30px #0006;
}
#promote:not([hidden]) { animation: rise .16s ease-out .1s both; }
@keyframes rise { from { opacity: 0; margin-top: 6px; } }
#promote button { width: 42px; height: 42px; border-radius: 8px; display: grid; place-items: center; }
#promote button img { width: 34px; height: 34px; }
#promote button:hover { background: #b7e5aa1a; }

.corner {
  position: fixed; right: 16px; bottom: max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; border-radius: 11px; overflow: hidden;
}
.corner button { width: 38px; height: 38px; font-size: 17px; color: #c9d4ca; display: grid; place-items: center; }
#home img { width: 24px; height: 24px; }
.corner button:hover { background: #ffffff0d; }
.corner button + button { border-top: 1px solid var(--line); font-size: 13px; }

#defeat {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: #08110bb8; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  animation: fade .3s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal { max-width: 360px; padding: 32px; text-align: center; }
h1 { font-weight: 500; font-size: 34px; letter-spacing: -1.2px; margin: 0 0 10px; }
.modal p { margin: 0; line-height: 1.6; color: #a6b6a9; }
.run { display: flex; justify-content: center; gap: 28px; margin: 26px 0 28px; }
.run div { display: flex; flex-direction: column-reverse; gap: 2px; }
.run dt { font-size: 10px; color: var(--faint); }
.run dd { margin: 0; font-size: 22px; font-variant-numeric: tabular-nums; }
#respawn { background: var(--green); color: #172218; border-radius: 10px; padding: 12px 26px; font-weight: 600; }
#respawn:hover { background: #c9f0be; }

dialog {
  max-width: 420px; width: calc(100% - 32px);
  border: 1px solid var(--line); background: #19221e; color: var(--ink); border-radius: 16px;
  padding: 26px 28px; box-shadow: 0 20px 80px #0008;
}
dialog::backdrop { background: #06100988; }
#closeHelp { position: absolute; right: 12px; top: 10px; width: 30px; height: 30px; border-radius: 8px; font-size: 22px; line-height: 1; color: var(--muted); }
#closeHelp:hover { background: #ffffff0d; color: var(--ink); }
/* Opening the dialog focuses the close button; only show a ring when the keyboard put it there. */
#closeHelp:focus-visible { outline: none; background: #ffffff0d; }
h2 { font-size: 18px; font-weight: 550; letter-spacing: -.3px; margin: 0 0 18px; }
dialog dl { display: grid; grid-template-columns: 66px 1fr; gap: 12px 12px; margin: 0; font-size: 13px; line-height: 1.5; }
dialog dt { color: var(--green); }
dialog dd { margin: 0; color: #b3c1b5; }

@media (max-width: 560px) {
  .brand { display: none; }
  #standings { top: 10px; right: 10px; }
  #leaderList li:nth-child(n+4):not(.you) { display: none; }
  #danger { top: 12px; }
  footer { bottom: max(12px, env(safe-area-inset-bottom)); }
  .wallet { min-width: 46px; font-size: 19px; padding: 0 7px 0 5px; }
  .pieceButton { width: 42px; height: 50px; }
  .pieceButton .glyph { width: 28px; height: 28px; }
  #selection { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 70px); }
  .corner { right: 10px; bottom: auto; top: 50%; transform: translateY(-50%); }
}
