:root {
  --bg: #0f1220;
  --fg: #e9eef5;
  --muted: #a8b3c7;
  --accent: #7dd3fc;
  --accent2: #a78bfa;
  --panel: #14182b;
  --good: #6ee7b7;
  --bad: #fb7185;
  --tile: #1f2540;
  --grid: #2b315a;
  --btn: #1c2240;
  --btn-hover: #28306a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
}

/* No page scrolling during gameplay */
body,
html {
  overflow: hidden;
  touch-action: none;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: linear-gradient(180deg, #0c1020, #0f1220);
  border-bottom: 1px solid #1f2340;
}

h1 {
  font-size: 1.1rem;
  margin: 0;
}
h2,
h3 {
  margin: 0.4rem 0;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  background: #22284a;
  border-radius: 0.4rem;
}

.conn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.volume {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.volume input {
  width: 100px;
}

.menu {
  padding: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--panel);
  border: 1px solid #20264a;
  border-radius: 0.6rem;
  padding: 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.row {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0;
}
input[type="text"] {
  flex: 1;
  padding: 0.6rem 0.7rem;
  border-radius: 0.5rem;
  border: 1px solid #2a2f56;
  background: #0c1025;
  color: var(--fg);
}
button,
.link {
  background: var(--btn);
  color: var(--fg);
  border: 1px solid #2a2f56;
  padding: 0.6rem 0.8rem;
  border-radius: 0.5rem;
  cursor: pointer;
}
button:hover,
.link:hover {
  background: var(--btn-hover);
}
.link {
  display: inline-block;
}

.small {
  color: var(--muted);
  font-size: 0.9rem;
}
.share {
  color: var(--accent);
  min-height: 1.2rem;
}

.hidden {
  display: none !important;
}

.arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.6rem;
  gap: 0.6rem;
  padding-bottom: 7.5rem;
}

.boards {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 1rem;
  align-items: start;
}

.board-col {
  background: var(--panel);
  border: 1px solid #20264a;
  border-radius: 0.6rem;
  padding: 0.6rem;
}
.board-stack {
  position: relative;
  z-index: 0; /* create stacking context so negative z child stays within */
  width: 100%;
  aspect-ratio: 1 / 2;
}
.board-stack canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: auto;
  display: block;
  background: transparent; /* allow overlay to show through */
  border: 1px solid #1f2340;
}
.board-stack .op-layer {
  z-index: -1; /* requested: negative z so it sits behind */
  opacity: 0.35; /* lighter overlay */
  pointer-events: none; /* never block input */
  filter: saturate(0.7);
}
.board-stack .me-layer {
  position: relative;
  z-index: 1;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: transparent;
  border: 1px solid #1f2340;
}

.panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.panel {
  background: #111634;
  border: 1px solid #242a54;
  border-radius: 0.4rem;
  padding: 0.5rem;
  display: grid;
  place-items: center;
}
.panel span {
  color: var(--muted);
  font-size: 0.9rem;
}
.panel strong {
  font-size: 1.1rem;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 0px);
  z-index: 10;
  padding: 0.6rem;
  background: linear-gradient(
    180deg,
    rgba(15, 18, 32, 0),
    rgba(15, 18, 32, 0.85)
  );
  backdrop-filter: blur(6px);
}
.dpad,
.actions {
  background: rgba(20, 24, 43, 0.8);
  border: 1px solid #20264a;
  border-radius: 0.6rem;
  padding: 0.6rem;
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.controls button {
  min-width: clamp(52px, 10vw, 80px);
  min-height: clamp(52px, 10vw, 80px);
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  border-radius: 0.8rem;
  cursor: pointer;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 34, 0.8);
  display: grid;
  place-items: center;
}
.overlay-content {
  background: var(--panel);
  border: 1px solid #20264a;
  border-radius: 0.6rem;
  padding: 1rem 1.2rem;
  text-align: center;
}

.toasts {
  position: fixed;
  right: 0.6rem;
  bottom: 0.6rem;
  display: grid;
  gap: 0.4rem;
  z-index: 50;
}
.toast {
  background: #111634;
  border: 1px solid #242a54;
  padding: 0.6rem 0.8rem;
  border-radius: 0.5rem;
}

@media (max-width: 860px) {
  .boards {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .board-col h3 {
    margin-bottom: 0.25rem;
  }
}

@media (min-width: 861px) {
  /* Desktop: keep controls anchored in layout, not fixed */
  .controls {
    position: static;
    padding: 0;
    background: none;
    backdrop-filter: none;
  }
  .arena {
    padding-bottom: 0;
  }
}

/* Extra space on very small phones so fixed controls don't overlap boards */
@media (max-width: 600px) {
  .arena {
    padding-bottom: 30vh;
  }
}
/* Short landscape phones: make controls inline to keep more vertical play area */
@media (orientation: landscape) and (max-height: 500px) {
  .controls {
    position: static;
    padding: 0.4rem 0;
    background: none;
    backdrop-filter: none;
  }
  .arena {
    padding-bottom: 0;
  }
}
/* Very wide screens: center boards and constrain max width */
@media (min-width: 1200px) {
  .boards {
    grid-template-columns: 1fr 1fr;
    max-width: 1100px;
    margin: 0 auto;
  }
}
