:root {
  --bg: #060913;
  --card: rgba(17, 24, 45, 0.78);
  --line: rgba(125, 160, 255, 0.14);
  --text: #e9efff;
  --muted: #8291b8;
  --cyan: #22d3ee;
  --purple: #a855f7;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px 12px 24px;
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(900px 500px at 50% -12%, rgba(46, 85, 190, 0.35), transparent 65%),
    radial-gradient(600px 400px at 100% 100%, rgba(168, 85, 247, 0.14), transparent 60%),
    var(--bg);
}

.app {
  width: 480px;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

h1 span {
  margin-left: 6px;
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  font-size: 10.5px;
  color: var(--muted);
  background: rgba(10, 16, 32, 0.6);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.conn i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 8px #f59e0b;
}

.conn.online i {
  background: #34d399;
  box-shadow: 0 0 8px #34d399;
}

.conn.offline i {
  background: #f43f5e;
  box-shadow: 0 0 8px #f43f5e;
}

.game {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.08), rgba(168, 85, 247, 0.06));
  box-shadow: 0 18px 42px -20px rgba(34, 211, 238, 0.45);
}

#board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 2;
  border-radius: 9px;
  background: #05080f;
}

.panel {
  flex: 0 0 132px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.card h2 {
  margin: 0 0 5px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.card canvas {
  display: block;
  width: 100%;
  height: auto;
}

.stats {
  padding: 7px 10px;
}

.stats div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 3px 0;
}

.stats span {
  font-size: 11px;
  color: var(--muted);
}

.stats b {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

#score {
  color: var(--cyan);
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
}

.controls button {
  height: 40px;
  color: #cfe0ff;
  font-family: inherit;
  font-size: 14px;
  background: rgba(20, 28, 52, 0.9);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.controls button:hover {
  border-color: rgba(34, 211, 238, 0.4);
  color: #fff;
}

.controls button:active {
  transform: translateY(1px);
  background: rgba(34, 211, 238, 0.14);
  border-color: rgba(34, 211, 238, 0.55);
}

.hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.7;
  text-align: center;
}

.overlay {
  position: absolute;
  inset: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  background: rgba(4, 8, 18, 0.78);
  border-radius: 9px;
  backdrop-filter: blur(3px);
  cursor: pointer;
}

.overlay[hidden] {
  display: none !important;
}

.overlay-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.overlay-tip {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #a5f3fc;
  background: rgba(34, 211, 238, 0.16);
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

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

@media (max-width: 420px) {
  .panel {
    flex-basis: 112px;
  }

  .controls button {
    height: 38px;
    font-size: 13px;
  }

  .hint {
    font-size: 10px;
  }
}
