.game-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.app {
  max-height: 946px;
  width: 100%;
  max-width: var(--container-max);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-head {
  width: 100%;
  max-width: min(90vw, 960px);
  margin: 0 auto var(--space-6);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-8);
}
.game-head-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}
.game-head-point {
  flex: 1 1 24ch;
  max-width: 42ch;
  margin: 0;
  text-align: right;
  font-size: var(--type-sm);
  line-height: var(--leading-snug);
  color: var(--muted);
}

.game-title {
  font-size: var(--type-h2);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
  text-align: left;
}

.layout-middle {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.action-bar {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-12);
  justify-content: center;
}

.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  width: 100%;
  max-width: min(90vw, 960px);
  margin: var(--space-6) auto 0;
}

.game-bar-slot {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  min-width: 0;
}

.game-bar-right { justify-content: flex-end; }

.game-bar .controls-hint { flex: 0 0 auto; margin: 0; }

.cta-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.game-screen {
  width: 100%;
  height: auto;
  max-width: 90vw;
  max-height: min(600px, 80vh);
  aspect-ratio: 16 / 10;
  border: 1px solid var(--border);
  border-radius: var(--space-2);
  background: var(--bg);
  box-shadow: 0 20px 40px -20px color-mix(in oklch, var(--fg), transparent 90%);
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}
.game-screen.dark { background: oklch(20% 0 0); }

.app[data-state="idle"] .game-screen { cursor: pointer; }
.app[data-state="idle"] .game-screen:hover {
  box-shadow: 0 6px var(--space-8) color-mix(in oklch, var(--fg), transparent 90.0%);
}

.game-screen > canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.game-screen > canvas.pixelated {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.screen-idle {
  position: absolute;
  inset: 0;
  color: oklch(0% 0 0);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8% 12%;
  box-sizing: border-box;
}
.screen-idle > svg {
  width: 100%;
  height: 100%;
  max-width: min(calc(var(--space-5) * 7), 60%);
  max-height: 60%;
  object-fit: contain;
  position: relative;
  z-index: 0;
}

.cta {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-4);
  background: color-mix(in oklch, oklch(100% 0 0), transparent 10%);
  color: oklch(0% 0 0);
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: background 0.2s ease, color 0.2s ease;
}

.cta-solo { border-right: 1px solid color-mix(in oklch, oklch(0% 0 0), transparent 88%); }

.cta:hover,
.cta:focus-visible {
  background: oklch(0% 0 0);
  color: oklch(100% 0 0);
  outline: none;
}

.cta-num {
  position: relative;
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-weight: 900;
  line-height: 0.85;
  letter-spacing: -0.03em;
}

.cta-label {
  font-size: var(--type-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-stretch: semi-condensed;
}

.cta-badge {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(85%, -45%);
  padding: 3px var(--space-2);
  background: oklch(0% 0 0);
  color: oklch(100% 0 0);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.cta:hover .cta-badge,
.cta:focus-visible .cta-badge {
  background: oklch(100% 0 0);
  color: oklch(0% 0 0);
}

.screen-idle .illust-bg { fill: oklch(98.5% 0 0); }
.game-screen.dark .screen-idle .illust-bg { fill: oklch(20% 0 0); }

#game-mount {
  width: 100%;
  height: 100%;
}
.game-screen.dark .screen-idle { color: oklch(100% 0 0); }

.app[data-state="idle"]    .screen-play { display: none !important; }
.app[data-state="playing"] .screen-idle { display: none !important; }

.app:not([data-state="idle"])    .state-idle    { display: none !important; }
.app:not([data-state="invite"])  .state-invite  { display: none !important; }
.app:not([data-state="playing"]) .state-playing { display: none !important; }
.app:not([data-state="over"])    .state-over    { display: none !important; }

.game-screen { view-transition-name: game-portal; }

.game-screen .grid {
  margin-inline: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklch, var(--fg), transparent 30.0%);
  color: oklch(100% 0 0);
  font-size: calc(var(--space-2) * 2);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  pointer-events: none;
}
.overlay.show { display: flex; }

.demo-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  background: oklch(100% 0 0);
  color: oklch(0% 0 0);
  padding: 2px 7px;
  z-index: 5;
}

.screen-info {
  position: absolute;
  top: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: clamp(var(--space-2), 3vh, calc(var(--space-2) * 2));
  font-weight: 700;
  letter-spacing: 0.18em;
  color: oklch(0% 0 0);
  pointer-events: none;
  z-index: 3;
}
.game-screen.dark .screen-info { color: oklch(100% 0 0); }

.fx-result {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: oklch(0% 0 0);
  z-index: 200;
  overflow: hidden;
  animation: fx-result-slide-down 0.5s cubic-bezier(0.23, 1, 0.32, 1) forwards;
  transition: background 700ms ease;
}

.fx-result-settling {
  background: transparent !important;
}
.fx-result-settling .fx-result-particles {
  opacity: 0;
  transition: opacity 700ms ease;
}
.fx-result-settling .fx-result-text {
  animation: fx-result-settle 700ms cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
}
@keyframes fx-result-settle {
  to {
    transform: translate(var(--settle-dx, 0), var(--settle-dy, 0)) scale(var(--settle-scale, 0.3));
  }
}

.fx-result-text {
  font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;
  font-size: clamp(calc(var(--space-2) * 4), 12vmin, var(--space-5));
  font-weight: 900;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: oklch(100% 0 0);
  text-align: center;
  white-space: nowrap;
  z-index: 2;
}

.fx-result-particles {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.fx-result-win .fx-result-text {
  animation: fx-win-anim 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.fx-result-lose .fx-result-text {
  animation: fx-lose-anim 0.6s cubic-bezier(0.47, 0, 0.745, 0.715) forwards,
             fx-lose-impact 0.4s 0.6s ease-out forwards;
}

.fx-result-draw .fx-result-text,
.fx-result-info .fx-result-text {
  animation: fx-result-fade 0.5s ease forwards;
}

@keyframes fx-result-slide-down {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

@keyframes fx-win-anim {
  0% { transform: translateX(100%) rotate(10deg); opacity: 0; }
  100% { transform: translateX(0) rotate(0deg); opacity: 1; }
}

@keyframes fx-lose-anim {
  0% { transform: translateY(-200%); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

@keyframes fx-lose-impact {
  0% { transform: translateY(0); }
  25% { transform: translateY(-15px); }
  50% { transform: translateY(0); }
  75% { transform: translateY(-5px); }
  100% { transform: translateY(0); }
}

@keyframes fx-result-fade {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.controls-hint {
  text-align: center;
  font-size: 11px;
  color: oklch(62.3% 0 0);
  margin-top: 10px;
  letter-spacing: 0.05em;
}
.controls-hint kbd {
  font-family: inherit;
  display: inline-block;
  border: 1px solid oklch(0% 0 0);
  padding: 1px 5px;
  margin: 0 1px;
  font-size: 10px;
  background: oklch(100% 0 0);
  color: oklch(0% 0 0);
}
.controls-hint .sep { color: oklch(84.4% 0 0); margin: 0 6px; }
