:root {
  --ink: #f7f7f2;
  --muted: #969ba6;
  --panel: rgba(18, 21, 28, 0.94);
  --panel-2: #1b1f29;
  --line: rgba(255, 255, 255, 0.11);
  --blue: #6da8ff;
  --blue-soft: #9ac4ff;
  --orange: #ff884d;
  --orange-soft: #ffb184;
  --acid: #dfff57;
  --danger: #ff6f78;
  --black: #080a0f;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--black);
}

body {
  min-height: 100dvh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Noto Sans TC", sans-serif;
}

button,
input {
  color: inherit;
  font: inherit;
}

button {
  touch-action: manipulation;
}

a {
  color: inherit;
}

.loading-screen,
.page {
  min-height: 100dvh;
}

.loading-screen {
  display: grid;
  place-content: center;
  gap: 14px;
  text-align: center;
  color: var(--muted);
}

.loading-orb {
  width: 44px;
  height: 44px;
  margin: auto;
  border: 2px solid rgba(109, 168, 255, 0.25);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.page {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top)) 16px
    max(18px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 14% 8%, rgba(109, 168, 255, 0.16), transparent 34%),
    radial-gradient(circle at 86% 90%, rgba(255, 136, 77, 0.13), transparent 36%),
    #080a0f;
}

.page::before,
.page::after {
  position: fixed;
  z-index: 0;
  width: 22rem;
  height: 22rem;
  border: 1px solid rgba(255, 255, 255, 0.035);
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.page::before {
  top: -10rem;
  left: -10rem;
}

.page::after {
  right: -10rem;
  bottom: -10rem;
}

.card,
.game-frame {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(20px);
}

.card {
  padding: clamp(24px, 6vw, 38px);
  border-radius: 28px;
}

.brand {
  text-align: center;
}

.eyebrow {
  color: var(--acid);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 22px 0 14px;
}

.brand-mark span {
  display: block;
}

.brand-mark .piece-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.brand-mark .blue {
  background: var(--blue);
  box-shadow: 0 0 20px rgba(109, 168, 255, 0.6);
}

.brand-mark .orange {
  background: var(--orange);
  box-shadow: 0 0 20px rgba(255, 136, 77, 0.55);
}

.brand-mark .core-dot {
  width: 14px;
  height: 14px;
  border: 3px solid var(--acid);
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(223, 255, 87, 0.55);
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: clamp(38px, 10vw, 58px);
  letter-spacing: 0.08em;
}

.brand p {
  max-width: 390px;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.primary,
.join button,
.share-button,
.lock-button,
.result-card button {
  border: 0;
  border-radius: 14px;
  color: #0b0d10;
  background: var(--acid);
  font-weight: 900;
  cursor: pointer;
}

.primary {
  width: 100%;
  margin-top: 30px;
  padding: 17px 20px;
  font-size: 17px;
  letter-spacing: 0.04em;
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.divider {
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 22px 0;
  color: #676d78;
  font-size: 11px;
  letter-spacing: 0.1em;
}

.divider::before,
.divider::after {
  height: 1px;
  flex: 1;
  background: var(--line);
  content: "";
}

.join label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.join input {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.045);
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.join input:focus {
  border-color: rgba(109, 168, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(109, 168, 255, 0.1);
}

.join button {
  padding: 0 20px;
}

.error {
  margin-top: 14px;
  color: #ff9198;
  font-size: 13px;
  line-height: 1.55;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #6bea8e;
  box-shadow: 0 0 9px rgba(107, 234, 142, 0.7);
}

.store-link {
  display: block;
  margin-top: 24px;
  color: #b8bdc7;
  font-size: 12px;
  text-align: center;
  text-decoration: none;
}

.store-link:hover {
  color: white;
}

.game-page {
  padding: 0;
}

.game-frame {
  display: grid;
  grid-template-rows: auto auto minmax(310px, 1fr) auto;
  min-height: 100dvh;
  max-height: 1000px;
  overflow: hidden;
  border-width: 0 1px;
}

.room-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
}

.room-brand b {
  display: block;
  font-size: 14px;
  letter-spacing: 0.08em;
}

.room-brand small,
.room-code span {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.room-code {
  padding: 7px 14px;
  border: 1px solid rgba(223, 255, 87, 0.3);
  border-radius: 12px;
  color: var(--ink);
  background: rgba(223, 255, 87, 0.07);
  cursor: pointer;
}

.room-code span,
.room-code strong {
  display: block;
}

.room-code strong {
  color: var(--acid);
  font-size: 17px;
  letter-spacing: 0.14em;
}

.leave {
  justify-self: end;
  padding: 8px 9px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}

.connection {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
}

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

.player-id:last-child {
  justify-content: flex-end;
  text-align: right;
}

.avatar {
  width: 17px;
  height: 17px;
  border-radius: 50%;
}

.avatar.p1 {
  background: var(--blue);
  box-shadow: 0 0 12px rgba(109, 168, 255, 0.55);
}

.avatar.p2 {
  background: var(--orange);
  box-shadow: 0 0 12px rgba(255, 136, 77, 0.5);
}

.avatar.offline {
  filter: grayscale(1);
  opacity: 0.28;
}

.player-id small {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.player-id strong {
  font-size: 12px;
}

.versus {
  color: #656a74;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.board-wrap {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 0;
  padding: 13px 18px;
}

.scorebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 9px;
}

.score {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.score:last-child {
  justify-content: flex-end;
}

.score span {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

.score strong {
  font-size: 21px;
}

.score.p1 strong {
  color: var(--blue-soft);
}

.score.p2 strong {
  color: var(--orange-soft);
}

.round {
  text-align: center;
}

.round span,
.round small {
  display: block;
  color: var(--muted);
  font-size: 8px;
}

.round strong {
  display: block;
  margin: 2px 0;
  font-size: 12px;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  aspect-ratio: 1;
  width: min(100%, 370px);
  margin: auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  background: #11141a;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid rgba(255, 255, 255, 0.075);
  border-bottom: 1px solid rgba(255, 255, 255, 0.075);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent),
    #11141a;
}

.cell:nth-child(5n) {
  border-right: 0;
}

.cell:nth-last-child(-n + 5) {
  border-bottom: 0;
}

.cell.core-cell {
  background: radial-gradient(circle, rgba(223, 255, 87, 0.1), transparent 65%), #11141a;
}

.cell.wear-1::after {
  position: absolute;
  width: 40%;
  height: 1px;
  background: rgba(255, 255, 255, 0.2);
  content: "";
  transform: rotate(-34deg);
}

.cell.broken {
  background: #07090d;
}

.cell.broken::before,
.cell.broken::after {
  position: absolute;
  width: 65%;
  height: 1px;
  background: rgba(255, 111, 120, 0.32);
  content: "";
}

.cell.broken::before {
  transform: rotate(36deg);
}

.cell.broken::after {
  transform: rotate(-36deg);
}

.base-mark {
  position: absolute;
  color: rgba(255, 255, 255, 0.13);
  font-size: 12px;
}

.piece {
  z-index: 2;
  display: grid;
  width: 48%;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  color: #0b0d10;
  font-size: 9px;
  font-weight: 900;
}

.piece.p1 {
  background: var(--blue);
  box-shadow: 0 0 16px rgba(109, 168, 255, 0.58);
}

.piece.p2 {
  background: var(--orange);
  box-shadow: 0 0 16px rgba(255, 136, 77, 0.54);
}

.core {
  z-index: 1;
  width: 24%;
  aspect-ratio: 1;
  border: 3px solid var(--acid);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(223, 255, 87, 0.65);
}

.trap {
  position: absolute;
  z-index: 1;
  font-size: clamp(12px, 4vw, 20px);
}

.trap.p1 {
  color: var(--blue-soft);
}

.trap.p2 {
  color: var(--orange-soft);
}

.game-message {
  min-height: 28px;
  padding: 8px 3px 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  text-align: center;
}

.waiting {
  position: absolute;
  inset: 58px 26px 18px;
  z-index: 5;
  display: grid;
  align-content: center;
  padding: 20px;
  border: 1px solid rgba(109, 168, 255, 0.25);
  border-radius: 20px;
  text-align: center;
  background: rgba(10, 13, 18, 0.94);
  backdrop-filter: blur(10px);
}

.waiting .radar {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border: 1px solid rgba(109, 168, 255, 0.4);
  border-radius: 50%;
  box-shadow: 0 0 0 10px rgba(109, 168, 255, 0.05);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    transform: scale(0.86);
    opacity: 0.55;
  }
}

.waiting h2 {
  margin: 7px 0;
  font-size: 22px;
}

.waiting p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.share-button {
  margin: 14px auto 0;
  padding: 12px 18px;
}

.controls {
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(12, 14, 18, 0.98);
}

.control-head,
.control-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.control-head {
  margin-bottom: 9px;
}

.control-title small {
  display: block;
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.control-title strong {
  font-size: 14px;
}

.plan {
  display: flex;
  gap: 6px;
}

.plan span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #666c76;
  font-size: 12px;
  font-weight: 900;
}

.plan span.filled {
  border-color: rgba(223, 255, 87, 0.35);
  color: var(--acid);
  background: rgba(223, 255, 87, 0.08);
}

.actions {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.action {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 54px;
  padding: 5px 2px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.035);
  cursor: pointer;
}

.action span {
  font-size: 17px;
}

.action b {
  font-size: 9px;
}

.action em {
  position: absolute;
  top: 4px;
  right: 5px;
  color: var(--acid);
  font-size: 8px;
  font-style: normal;
}

.control-foot {
  margin-top: 9px;
}

.undo {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  cursor: pointer;
}

.control-foot > span {
  flex: 1;
  color: var(--muted);
  font-size: 9px;
  text-align: center;
}

.lock-button {
  padding: 9px 14px;
}

.locked {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 92px;
  color: var(--muted);
  text-align: left;
}

.locked > span {
  font-size: 25px;
}

.locked strong,
.locked small {
  display: block;
}

.locked strong {
  color: var(--ink);
  font-size: 13px;
}

.locked small {
  margin-top: 3px;
  font-size: 10px;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: 16px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #202530;
  font-size: 11px;
}

.result {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 5, 8, 0.8);
  backdrop-filter: blur(12px);
}

.result-card {
  width: min(100%, 380px);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  text-align: center;
  background: #151923;
}

.result-card .winner {
  display: grid;
  width: 70px;
  height: 70px;
  margin: 17px auto;
  place-items: center;
  border-radius: 50%;
  color: #0b0d10;
  font-size: 30px;
  font-weight: 900;
}

.result-card .winner.p1 {
  background: var(--blue);
}

.result-card .winner.p2 {
  background: var(--orange);
}

.result-card p {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.result-card button {
  width: 100%;
  padding: 13px;
}

.result-card button.secondary {
  margin-top: 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}

@media (min-width: 600px) {
  .game-page {
    padding: 18px;
  }

  .game-frame {
    min-height: min(960px, calc(100dvh - 36px));
    border: 1px solid var(--line);
    border-radius: 26px;
  }
}

@media (max-height: 700px) {
  .board {
    width: min(100%, 290px);
  }

  .board-wrap {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .actions {
    gap: 4px;
  }

  .action {
    min-height: 45px;
  }
}
