:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  background: #070a10;
  font-synthesis: none;
  --ink: #090d17;
  --panel: #121827;
  --pale: #ecf6f3;
  --turquoise: #51e6cf;
  --coral: #ff6f7f;
  --lavender: #b997ff;
  --gold: #ffd166;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 280px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 10%, #24324a 0, transparent 25%),
    radial-gradient(circle at 85% 80%, #352247 0, transparent 28%),
    #070a10;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  -webkit-user-select: none;
  user-select: none;
}

button,
a { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  width: min(100%, 430px);
  height: 100%;
  min-height: 440px;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 10px;
  min-height: 54px;
}

.brand-block { min-width: 0; }

.eyebrow {
  display: block;
  margin-bottom: 1px;
  color: var(--turquoise);
  font-size: 7px;
  font-weight: 950;
  letter-spacing: .24em;
}

h1 {
  margin: 0;
  color: var(--pale);
  font-size: clamp(23px, 8vw, 34px);
  line-height: .86;
  letter-spacing: -.055em;
  text-shadow: 2px 3px 0 #6e3bab;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(48px, 1fr));
  gap: 5px;
}

.stat {
  display: grid;
  min-width: 51px;
  height: 46px;
  place-items: center;
  align-content: center;
  border: 1px solid #fff2;
  border-radius: 11px;
  background: #111725dd;
  box-shadow: inset 0 1px #fff1, 0 6px 18px #0004;
}

.stat span {
  color: #aeb9c1;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .14em;
}

.stat strong {
  color: var(--pale);
  font-size: 18px;
  line-height: 1;
}

.balls-stat { border-color: #51e6cf55; }
.balls-stat strong { color: var(--turquoise); }
.balls-stat.is-empty { border-color: #ff6f7f77; animation: empty-pulse 1.1s ease-in-out infinite; }
.balls-stat.is-empty strong { color: var(--coral); }

.machine {
  position: relative;
  justify-self: center;
  width: min(100%, calc((100dvh - 150px) * .5625));
  height: 100%;
  max-height: 720px;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 1px solid #ffffff24;
  border-radius: 20px;
  background: #101624;
  box-shadow: inset 0 0 0 5px #0508105c, 0 20px 60px #0009, 0 0 38px #65408c2a;
  isolation: isolate;
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.drop-hint {
  position: absolute;
  z-index: 3;
  top: 11.5%;
  left: 50%;
  width: max-content;
  max-width: 82%;
  margin: 0;
  padding: 6px 10px;
  translate: -50% 0;
  border: 1px solid #51e6cf55;
  border-radius: 99px;
  color: var(--pale);
  background: #070b13cf;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .04em;
  pointer-events: none;
  transition: opacity .4s, translate .4s;
}

.drop-hint.is-hidden { opacity: 0; translate: -50% -7px; }

.toast {
  position: absolute;
  z-index: 7;
  top: 18%;
  left: 50%;
  min-width: 120px;
  padding: 8px 12px;
  translate: -50% -8px;
  border: 1px solid #fff4;
  border-radius: 99px;
  color: #fff;
  background: #070a12e8;
  box-shadow: 0 7px 22px #0008;
  font-size: 9px;
  font-weight: 950;
  letter-spacing: .1em;
  text-align: center;
  opacity: 0;
  pointer-events: none;
}

.toast.is-visible { animation: toast 1.15s ease both; }

.pap-stage {
  position: absolute;
  z-index: 6;
  top: 19%;
  right: -7%;
  width: 45%;
  aspect-ratio: 180 / 195;
  opacity: 0;
  pointer-events: none;
  transform-origin: right center;
}

.pap-art,
.pap-art svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pap-speech {
  position: absolute;
  z-index: 2;
  right: 72%;
  top: 6%;
  width: max-content;
  max-width: 140px;
  padding: 7px 10px;
  border: 2px solid var(--coral);
  border-radius: 13px 13px 3px 13px;
  color: var(--pale);
  background: #090d17ee;
  box-shadow: 3px 4px 0 #552f65;
  font-size: 8px;
  font-weight: 950;
  letter-spacing: .09em;
}

.pap-stage.is-nose-mode {
  top: 27%;
  right: 25%;
  width: 52%;
  pointer-events: auto;
}

.nose-button {
  position: absolute;
  z-index: 5;
  top: 37%;
  left: 36%;
  width: 31%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.nose-button:focus-visible { outline: 4px solid #fff; outline-offset: 2px; }

.pap-prompt {
  position: absolute;
  top: 93%;
  left: 50%;
  width: max-content;
  translate: -50% 0;
  padding: 8px 13px;
  border: 1px solid #ffd16699;
  border-radius: 12px;
  color: var(--pale);
  background: #070a12ed;
  box-shadow: 0 8px 24px #000a;
  text-align: center;
}

.pap-prompt strong,
.pap-prompt span { display: block; }
.pap-prompt strong { color: var(--gold); font-size: 10px; letter-spacing: .12em; }
.pap-prompt span { margin-top: 2px; color: #b9c2c9; font-size: 7px; font-weight: 850; letter-spacing: .1em; }

.loading {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--pale);
  background: #090d17;
  font-size: 10px;
  letter-spacing: .17em;
  transition: opacity .35s, visibility .35s;
}

.loading span:not(.loading-dot) { letter-spacing: normal; }
.loading.is-hidden { visibility: hidden; opacity: 0; }

.loading-dot {
  width: 24px;
  height: 24px;
  border: 5px solid #ffffff22;
  border-top-color: var(--turquoise);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.controls {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
}

.controls button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid #fff3;
  border-radius: 10px;
  color: var(--pale);
  background: #151c2c;
  box-shadow: inset 0 1px #fff1, 0 4px 12px #0004;
  font-size: 8px;
  font-weight: 950;
  letter-spacing: .1em;
  cursor: pointer;
}

.controls button:first-child { border-color: #51e6cf66; color: var(--turquoise); }
.controls button:active { translate: 0 2px; }

.seed {
  min-width: 0;
  overflow: hidden;
  color: #77838d;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .11em;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seed b { color: #aeb8c0; }

footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 19px;
  color: #78838b;
  font-size: 8px;
  font-weight: 750;
  letter-spacing: .05em;
}

footer a { color: #c8d4d4; text-decoration: none; }
footer a:hover { color: var(--turquoise); }

@keyframes spin { to { rotate: 360deg; } }
@keyframes empty-pulse { 50% { box-shadow: inset 0 0 15px #ff6f7f33, 0 0 12px #ff6f7f22; } }
@keyframes toast {
  0% { opacity: 0; translate: -50% -8px; scale: .9; }
  15%, 70% { opacity: 1; translate: -50% 0; scale: 1; }
  100% { opacity: 0; translate: -50% 4px; scale: .98; }
}

@media (max-height: 620px) {
  .app-shell { grid-template-rows: auto minmax(0, 1fr) auto; }
  .hud { min-height: 42px; }
  .eyebrow { display: none; }
  .stat { height: 38px; }
  .stat strong { font-size: 15px; }
  footer { display: none; }
  .machine { width: min(100%, calc((100dvh - 103px) * .5625)); }
}

@media (max-width: 345px) {
  .app-shell { gap: 5px; }
  .hud { grid-template-columns: auto 1fr; gap: 5px; }
  h1 { font-size: 22px; }
  .stats { gap: 3px; }
  .stat { min-width: 44px; }
  .controls button { padding-inline: 8px; }
  .seed { display: none; }
  .controls { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .balls-stat.is-empty,
  .loading-dot { animation-duration: 2s; }
  .toast.is-visible { animation-duration: 1.6s; }
}
