:root {
  --paper: #0f1420;
  --panel: #18202f;
  --panel2: #202b3d;
  --ink: #eaf0f7;
  --dim: #8fa0b5;
  --p1: #5aa2f0;
  --p1d: #2b6fc0;
  --p2: #f07eb0;
  --p2d: #c04d84;
  --gold: #e2c391;
  --line: #2c3852;
  --good: #46d17a;
  --bad: #f0685f;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: radial-gradient(1200px 700px at 50% -10%, #1b2436, #0f1420 60%);
  color: var(--ink);
  font:
    16px/1.5 "Segoe UI",
    system-ui,
    sans-serif;
  overflow-x: hidden;
}
.hidden {
  display: none !important;
}

.gbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.gbar h1 {
  font:
    700 20px/1 Georgia,
    serif;
  margin: 0 auto 0 0;
  letter-spacing: 0.5px;
}
.gbar .back {
  color: var(--p1);
  text-decoration: none;
  font-weight: 600;
}
.conn {
  font-size: 12px;
  color: var(--dim);
}
.conn.ok {
  color: var(--good);
}
.conn.bad {
  color: var(--bad);
}

.screen {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.card.centre {
  text-align: center;
}
.lead {
  color: var(--dim);
  text-align: center;
  margin: 0 0 18px;
}
.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 14px;
}
.half {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.half h3 {
  margin: 0 0 12px;
  font-size: 16px;
}
.fld {
  display: block;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 12px;
}
.fld input,
.fld select {
  display: block;
  width: 100%;
  margin-top: 5px;
  background: #0f1626;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
.fld.small {
  display: inline-block;
  width: 48%;
}
.fld.small:first-of-type {
  margin-right: 4%;
}
#code {
  letter-spacing: 6px;
  font-size: 22px;
  text-align: center;
  font-weight: 700;
}

.gbtn {
  background: linear-gradient(var(--p1), var(--p1d));
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 12px 20px;
  font: 700 15px/1 inherit;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(43, 111, 192, 0.35);
}
.gbtn:hover {
  filter: brightness(1.08);
}
.gbtn:active {
  transform: translateY(1px);
}
.gbtn.big {
  width: 100%;
  padding: 14px;
  font-size: 16px;
}
.gbtn.alt {
  background: linear-gradient(var(--p2), var(--p2d));
  box-shadow: 0 6px 16px rgba(192, 77, 132, 0.35);
}
.err {
  color: var(--bad);
  font-size: 13px;
  min-height: 18px;
  text-align: center;
  margin: 8px 0 0;
}

.roomcode {
  font:
    800 54px/1 Georgia,
    serif;
  letter-spacing: 12px;
  color: var(--gold);
  margin: 14px 0 10px;
  text-shadow: 0 3px 12px rgba(226, 195, 145, 0.3);
}
.spinner {
  width: 34px;
  height: 34px;
  margin: 16px auto 0;
  border: 4px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* game */
.tops {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}
.pcard {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  text-align: center;
}
.pcard.p1 {
  border-color: var(--p1d);
}
.pcard.p2 {
  border-color: var(--p2d);
}
.pcard.turn {
  box-shadow: 0 0 0 3px var(--gold);
}
.pn {
  font-weight: 700;
  margin-bottom: 8px;
  font-size: 15px;
}
.p1 .pn {
  color: var(--p1);
}
.p2 .pn {
  color: var(--p2);
}
.pg {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}
.cell {
  aspect-ratio: 1;
  border-radius: 4px;
  background: #0e1626;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
}
.p1 .cell.on {
  background: var(--p1d);
  color: #fff;
  animation: pop 0.3s;
}
.p2 .cell.on {
  background: var(--p2d);
  color: #fff;
  animation: pop 0.3s;
}
@keyframes pop {
  0% {
    transform: scale(0.3);
  }
  70% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}
.ps {
  margin-top: 8px;
  color: var(--dim);
  font-size: 13px;
}
.ps b {
  color: var(--ink);
  font-size: 18px;
}

.centre-col {
  text-align: center;
  min-width: 190px;
}
.turnline {
  font-size: 14px;
  color: var(--dim);
  min-height: 20px;
  margin-bottom: 6px;
}
.targwrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 8px;
}
.findlbl {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--dim);
}
.target {
  font:
    800 56px/1 Georgia,
    serif;
  color: var(--gold);
  margin-top: 2px;
}
.timerwrap {
  height: 10px;
  background: var(--panel2);
  border-radius: 6px;
  overflow: hidden;
  margin: 12px 0 6px;
}
.timerbar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--good), var(--gold));
  transform-origin: left;
}
.timerbar.run {
  animation: drain linear forwards;
}
@keyframes drain {
  from {
    transform: scaleX(1);
  }
  to {
    transform: scaleX(0);
  }
}
.stampbtn {
  width: 100%;
  margin-top: 4px;
  padding: 26px 10px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(var(--p2), var(--p2d));
  color: #fff;
  cursor: pointer;
  font:
    800 30px/1 Georgia,
    serif;
  letter-spacing: 2px;
  user-select: none;
  box-shadow: 0 8px 20px rgba(192, 77, 132, 0.4);
  touch-action: manipulation;
}
.stampbtn:active {
  transform: translateY(2px);
}
.stampbtn.pulse {
  animation: stamppulse 0.12s;
}
@keyframes stamppulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.94);
  }
  100% {
    transform: scale(1);
  }
}
.pcard.marking {
  box-shadow: 0 0 0 3px var(--gold);
  cursor: pointer;
}
.pcard.marking::after {
  content: "tap to stamp ✗";
  display: block;
  font-size: 11px;
  color: var(--gold);
  margin-top: 6px;
}
.play.searching {
  box-shadow: inset 0 0 0 2px rgba(90, 162, 240, 0.5);
}
.play:not(.searching) .tile {
  cursor: default;
  opacity: 0.92;
}
.msg {
  min-height: 22px;
  font-weight: 700;
  font-size: 15px;
}
.msg.good {
  color: var(--good);
}
.msg.bad {
  color: var(--bad);
}

/* play area */
.play {
  position: relative;
  height: 62vh;
  min-height: 380px;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0 27px,
      rgba(255, 255, 255, 0.03) 27px 28px
    ),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.tile {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--r));
  background: #f6efe0;
  color: #23324a;
  border-radius: 8px;
  padding: 6px 12px;
  font:
    800 26px/1 Georgia,
    serif;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  animation: drift var(--dur) ease-in-out var(--delay) infinite alternate;
  will-change: transform;
}
.tile:hover {
  filter: brightness(1.05);
}
.tile.hit {
  animation: none;
  background: var(--good);
  color: #05230f;
  box-shadow: 0 0 0 5px rgba(70, 209, 122, 0.4);
}
.tile.miss {
  animation: shake 0.35s;
  background: #f2c4c0;
}
@keyframes drift {
  from {
    transform: translate(calc(-50% - 7px), calc(-50% - 5px)) rotate(var(--r));
  }
  to {
    transform: translate(calc(-50% + 7px), calc(-50% + 6px))
      rotate(calc(var(--r) + 8deg));
  }
}
@keyframes shake {
  0%,
  100% {
    margin-left: 0;
  }
  25% {
    margin-left: -6px;
  }
  75% {
    margin-left: 6px;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.wincard {
  background: var(--panel);
  border: 1px solid var(--gold);
  border-radius: 20px;
  padding: 34px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
#wintext {
  font:
    800 30px/1.2 Georgia,
    serif;
  color: var(--gold);
  margin-bottom: 20px;
}

@media (max-width: 720px) {
  .two {
    grid-template-columns: 1fr;
  }
  .tops {
    grid-template-columns: 1fr;
  }
  .pcard {
    order: 2;
  }
  .centre-col {
    order: 1;
  }
  .target {
    font-size: 44px;
  }
  .roomcode {
    font-size: 40px;
    letter-spacing: 8px;
  }
  .tile {
    font-size: 21px;
    padding: 5px 9px;
  }
}
