/* Steelyard - game page */

body.play {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px var(--gutter);
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  flex-wrap: wrap;
}

.top-info {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-right: auto;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.chip {
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  background: var(--surface);
  white-space: nowrap;
}

.chip[hidden] {
  display: none;
}

.chip:empty {
  display: none;
}

.chip b {
  letter-spacing: 0.1em;
}

.stage-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
}

.stage {
  position: relative;
  width: min(100%, calc((100dvh - 64px) * 1.4));
  aspect-ratio: 28 / 20;
  max-height: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0c1016;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- HUD ---- */

.hud-top {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 13, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
  font-size: 0.8rem;
  white-space: nowrap;
}

.base {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lbl {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.cyan {
  color: var(--cyan);
}

.amber {
  color: var(--amber);
}

.bar {
  width: clamp(60px, 12vw, 140px);
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.base.right .bar {
  transform: scaleX(-1);
}

.fill {
  height: 100%;
  width: 100%;
  border-radius: 4px;
  transition: width 0.2s;
}

.fill.cyan {
  background: var(--cyan);
}

.fill.amber {
  background: var(--amber);
}

.num {
  min-width: 1.6em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.timer {
  font: 700 1rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  min-width: 3.4em;
  text-align: center;
}

.feed {
  position: absolute;
  top: 52px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
  max-width: 55%;
}

.feed-item {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  background: rgba(10, 13, 18, 0.7);
  animation: feed-in 0.2s ease-out;
}

.feed-item .dim {
  color: var(--muted);
}

@keyframes feed-in {
  from {
    opacity: 0;
    transform: translateX(12px);
  }
}

.hud-me {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(10, 13, 18, 0.72);
  font-size: 0.8rem;
  pointer-events: none;
}

.hud-me #me-fx:empty {
  display: none;
}

.pips {
  display: flex;
  gap: 4px;
}

.pips i {
  width: 18px;
  height: 8px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.16);
}

.pips i.on {
  background: var(--ok);
}

.respawn {
  position: absolute;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 10px;
  background: rgba(10, 13, 18, 0.82);
  border: 1px solid rgba(255, 90, 77, 0.5);
  font-weight: 600;
  display: none;
  pointer-events: none;
}

.respawn.show {
  display: block;
}

.toast {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -8px);
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(10, 13, 18, 0.88);
  border: 1px solid var(--border);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
  overflow-wrap: anywhere;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- Scoreboard ---- */

.scoreboard-wrap {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(8, 10, 14, 0.6);
  pointer-events: none;
}

.scoreboard-wrap.show {
  display: grid;
}

.sb {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  width: min(92%, 640px);
  text-align: left;
}

.scoreboard-wrap .sb {
  background: rgba(16, 21, 28, 0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.sb h3 {
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.sb table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.sb th,
.sb td {
  padding: 4px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.sb th {
  color: var(--muted);
  font-weight: 600;
}

.sb th:not(:first-child),
.sb td:not(:first-child) {
  text-align: right;
  width: 2.5em;
}

.sb tr.me td {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
}

.sb .tag {
  margin-left: 6px;
  padding: 0 5px;
  font-size: 0.68rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
}

/* ---- Overlays ---- */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(8, 10, 14, 0.82);
  backdrop-filter: blur(4px);
  padding: 12px;
  overflow: auto;
}

.overlay.show {
  display: grid;
}

/* Join and connection dialogs cover the whole viewport so that they fit on phones. */
#overlay-join,
#overlay-conn {
  position: fixed;
  z-index: 50;
}

.overlay.banner {
  background: rgba(8, 10, 14, 0.7);
}

.panel {
  width: min(100%, 460px);
  text-align: center;
  padding: 22px 22px 18px;
  border-radius: 14px;
  background: rgba(22, 29, 39, 0.96);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.banner .panel {
  width: min(100%, 680px);
}

.panel h1,
.panel h2 {
  font-size: clamp(1.5rem, 4vw, 2.3rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel label {
  display: block;
  text-align: left;
  margin: 12px 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.panel input[type='text'] {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  user-select: text;
  -webkit-user-select: text;
}

.panel input[type='text']:focus {
  border-color: var(--cyan);
  outline: none;
}

.panel .row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.panel .row.tight {
  margin-top: 0;
  flex-wrap: nowrap;
}

.panel .row .btn.large {
  flex: 1 1 150px;
}

.invite {
  color: var(--amber);
  font-weight: 600;
  margin: 0 0 6px;
}

.hint {
  margin: 16px 0 0;
  font-size: 0.82rem;
  line-height: 2;
}

.hint kbd {
  margin: 0 2px;
  min-width: 22px;
  padding: 0 6px;
}

/* ---- Touch controls ---- */

.touch {
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 6px 16px calc(14px + env(safe-area-inset-bottom));
  gap: 16px;
}

.touch.show {
  display: flex;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 58px);
  gap: 4px;
}

.touch button {
  border: 1px solid #34445c;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.2rem;
  touch-action: none;
}

.touch button.active {
  background: var(--amber);
  color: #1a1204;
}

.dpad .up {
  grid-column: 2;
  grid-row: 1;
}

.dpad .left {
  grid-column: 1;
  grid-row: 2;
}

.dpad .right {
  grid-column: 3;
  grid-row: 2;
}

.dpad .down {
  grid-column: 2;
  grid-row: 3;
}

.touch .fire {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  font-weight: 800;
  letter-spacing: 0.08em;
  border-color: var(--danger);
  color: var(--danger);
}

.touch .fire.active {
  background: var(--danger);
  color: #fff;
}

@media (max-width: 700px) {
  .topbar {
    gap: 8px;
  }

  .top-actions .btn.small {
    padding: 5px 9px;
  }

  .stage {
    width: min(100%, calc((100dvh - 190px) * 1.4));
  }

  .sb {
    grid-template-columns: minmax(0, 1fr);
  }

  .hud-top {
    gap: 8px;
    padding: 4px 10px;
  }

  .hud-top .lbl {
    display: none;
  }
}
