* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #1b1f3a, #0a0b14 70%);
  color: #e6e8f2;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 12px 16px;
  min-height: 100vh;
}

.back {
  position: absolute;
  top: 12px;
  left: 16px;
  font-size: 13px;
  color: #8a90b8;
}
.back a { color: #aab0d4; text-decoration: none; }
.back a:hover { color: #fff; }

.arena {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.player header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #8a90b8;
}
.player header h2 {
  margin: 0 auto 0 0;
  font-size: 16px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #e6e8f2;
}
.player header h2 small { font-size: 11px; color: #8a90b8; letter-spacing: 1px; }
.player header b { color: #e6e8f2; font-variant-numeric: tabular-nums; }

.field { display: flex; gap: 6px; align-items: stretch; }

.board {
  display: block;
  width: min(260px, 26vw);
  height: auto;
  border: 2px solid #3a4078;
  border-radius: 6px;
  box-shadow: 0 0 30px rgba(90, 110, 255, 0.2);
  background: #07080f;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 84px;
}
.side canvas {
  width: 84px;
  height: auto;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}
.side.denied canvas:first-of-type { animation: shake 0.3s; }

h3 {
  margin: 4px 0 0;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #8a90b8;
}

.meter {
  position: relative;
  width: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}
.meter div {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0;
  background: linear-gradient(#ff6a6a, #f03838);
  transition: height 0.15s;
}

.vs {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: #8a90b8;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.vs div { display: flex; flex-direction: column; align-items: center; }
.vs b { font-size: 20px; color: #e6e8f2; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.vs-label {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(90deg, #00f0f0, #a000f0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay {
  position: absolute;
  inset: -8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
  background: rgba(7, 8, 15, 0.88);
  border-radius: 10px;
  z-index: 2;
}
.overlay.hidden { display: none; }
.overlay h1 {
  margin: 0;
  font-size: 40px;
  letter-spacing: 5px;
  background: linear-gradient(90deg, #00f0f0, #a000f0, #f0a000);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay h1 span { font-size: 24px; }
.overlay p { margin: 0; max-width: 420px; color: #aab0d4; }
.overlay .hint { font-size: 12px; color: #6b7088; }

button {
  font: inherit;
  cursor: pointer;
  color: #fff;
  background: #2a2f55;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
}
button:hover { background: #3a4078; }
button.primary { background: #4c55c9; padding: 10px 28px; }
button.primary:hover { background: #5d66de; }
.difficulty { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.difficulty button.selected { border-color: #8c94ff; background: #3a4078; }

.help { margin: 0; font-size: 12px; color: #8a90b8; text-align: center; }
kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  background: #2a2f55;
  font-size: 11px;
  font-family: inherit;
  color: #e6e8f2;
}

.touch {
  display: none;
  grid-template-columns: repeat(3, 72px);
  gap: 10px;
}
.touch button { padding: 16px 0; font-size: 20px; }
.touch button:active { background: #4c55c9; }

@keyframes shake {
  0%, 100% { transform: translateX(0); border-color: #f03838; }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (max-width: 760px), (pointer: coarse) {
  .touch { display: grid; }
  .help, .ai-side, .vs { display: none; }
  body { padding-left: 6px; padding-right: 6px; }
  .arena { gap: 8px; }
  .field { gap: 4px; }
  .board { width: 36vw; }
  .side { width: 12vw; }
  .side canvas { width: 12vw; }
  .player header { gap: 6px; font-size: 11px; }
  .player header h2 { font-size: 13px; }
  .overlay h1 { font-size: 28px; }
}
