:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", Arial, sans-serif;
  color: #fff;
  background: #101033;
  --panel: #111139ee;
  --rim: #a1aaff75;
  --gap: clamp(10px, 2.3vw, 29px);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
main { position: relative; height: 100vh; height: 100dvh; width: 100%; overflow: hidden; isolation: isolate; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
button, a { -webkit-tap-highlight-color: transparent; }
button, dialog {
  font: inherit; color: inherit; background: var(--panel);
  border: 1px solid var(--rim); border-radius: 14px;
}
button { cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid #fff390; outline-offset: 3px; }
button:disabled { cursor: default; }
header {
  position: absolute; z-index: 2; pointer-events: none;
  top: max(var(--gap), env(safe-area-inset-top)); left: max(var(--gap), env(safe-area-inset-left));
  text-shadow: 0 2px 4px #140d44, 0 0 22px #100935;
}
.brand { color: #d2eaff; font-size: clamp(.67rem, 1.3vw, .88rem); font-weight: 800; letter-spacing: .17em; text-transform: uppercase; }
h1 { font-size: clamp(1.95rem, 4.5vw, 4.5rem); letter-spacing: -.045em; line-height: .92; margin: .14em 0 0; }
h1 span { display: block; margin-top: .23em; font-size: .47em; letter-spacing: 0; color: #efd4ff; }
.tools { position: absolute; z-index: 4; top: max(var(--gap), env(safe-area-inset-top)); right: max(var(--gap), env(safe-area-inset-right)); display: flex; align-items: start; gap: 8px; }
.tools button { min-height: 42px; padding: 6px 12px; font-weight: 800; }
#fullscreen { font-size: 1.35rem; }
#pac-button { position: absolute; z-index: 1; background: transparent; border: none; touch-action: manipulation; transform: translate(-50%, -50%); }
.scene-message {
  position: absolute; z-index: 3; left: 50%; top: 25%; transform: translateX(-50%);
  width: max-content; max-width: 83vw; padding: .7em 1em; margin: 0; border: 2px solid #ffd982;
  border-radius: 14px; background: #221547f5; text-align: center; pointer-events: none;
  font-size: clamp(.9rem, 2.1vw, 1.55rem); font-weight: 800; box-shadow: 0 5px 22px #140d5580;
}
.win { top: 23%; color: #fff6a6; border-color: #f0acf9; font-size: clamp(1.3rem, 3.5vw, 2.9rem); }
.play {
  position: absolute; z-index: 4; left: 50%; bottom: max(var(--gap), env(safe-area-inset-bottom));
  width: min(620px, calc(100% - 230px)); transform: translateX(-50%); text-align: center;
}
#game-status {
  display: inline-block; max-width: 100%; margin: 0 0 8px; padding: 5px 10px; border-radius: 9px;
  background: #13103ce8; font-size: clamp(.72rem, 1.5vw, .98rem); font-weight: 800;
}
.resources { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(4px, 1.1vw, 12px); }
.resources button { min-width: 0; min-height: 95px; padding: 6px 3px; display: grid; justify-items: center; align-content: center; gap: 4px; font-size: clamp(.67rem, 1.45vw, .94rem); font-weight: 800; line-height: 1.05; touch-action: manipulation; }
.resources img { height: clamp(31px, 6vw, 62px); width: auto; }
.resources output { color: #fff0a7; font-variant-numeric: tabular-nums; }
.resources button.done { border-color: #96edaa; }
.resources button.done output { color: #a7f6b7; }
@media (hover: hover) { .resources button:enabled:hover { background: #35205e; border-color: #dfc1ff; } }
.resources button:enabled:active { transform: translateY(2px); }
.join { position: absolute; z-index: 4; right: max(var(--gap), env(safe-area-inset-right)); bottom: max(var(--gap), env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 5px; }
.join a, #join-large { display: inline-flex; background: white; border-radius: 8px; padding: 3px; }
.join img { width: clamp(60px, 7vw, 105px); }
.join button { padding: 5px 7px; font-size: .72rem; }
dialog { width: min(460px, calc(100% - 24px)); text-align: center; padding: 22px; box-shadow: 0 12px 60px #080724; }
dialog::backdrop { background: #0c082cbb; }
dialog h2 { margin: 4px 34px 14px; }
dialog > form:first-child { position: absolute; right: 10px; top: 10px; }
dialog button { min-height: 38px; padding: 7px 12px; }
dialog p { margin-bottom: .7em; }
#qr-large { width: min(69vw, 54dvh, 330px); }
.host-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
@media (max-width: 690px) {
  .play { width: calc(100% - var(--gap) * 2); }
  .join { bottom: calc(max(var(--gap), env(safe-area-inset-bottom)) + 119px); }
  .join img { width: 52px; }
  .resources button { min-height: 78px; }
  .tools:has(#host-button:not([hidden])) { top: 75px; }
}
@media (max-height: 470px) and (min-width: 600px) {
  .play { width: min(540px, calc(100% - 185px)); }
  .resources button { min-height: 65px; }
  .resources img { height: 31px; }
  .join { bottom: var(--gap); }
  h1 { font-size: clamp(1.6rem, 3.6vw, 2.9rem); }
}
