:root {
  --bg: #0a0a1e;
  --panel: #131325;
  --accent: #ff3366;
  --accent2: #00ccff;
  --gold: #ffcc00;
  --text: #e8e8f0;
  --muted: #6a6a8a;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  color: var(--text);
}

.wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.board {
  position: relative;
  width: min(96vw, calc(82vh * 3 / 4));
  aspect-ratio: 3 / 4;
  background: var(--bg);
  overflow: hidden;
  border: 1px solid #222240;
  box-shadow: 0 0 40px #0006;
}

.wrap:fullscreen .board,
.wrap:-webkit-full-screen .board,
.wrap:-moz-full-screen .board {
  width: 100vw;
  height: 100vh;
  aspect-ratio: unset;
  border: none;
}

canvas#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* HUD bar */
.bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
  pointer-events: none;
}

.bar h1 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold);
  text-shadow: 0 0 8px #ffcc0066;
}

.scores {
  display: flex;
  gap: 6px;
  pointer-events: all;
}

.icon-btn {
  background: rgba(0,0,0,0.5);
  border: 1px solid #333360;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  padding: 3px 6px;
  text-decoration: none;
  line-height: 1;
  display: flex;
  align-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); }

/* Touch controls */
.touch {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  padding: 6px 10px 10px;
  pointer-events: none;
}

.tgroup {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  pointer-events: all;
}

.tbtn {
  width: 48px; height: 48px;
  background: rgba(0,0,40,0.7);
  border: 2px solid #3344aa66;
  border-radius: 10px;
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.1s;
}

.tbtn:active, .tbtn.pressed {
  background: rgba(0,80,200,0.5);
}

.tbtn.action {
  width: 56px; height: 56px;
  background: rgba(180, 0, 50, 0.7);
  border-color: var(--accent);
  font-size: 22px;
  border-radius: 50%;
}
.tbtn.action:active, .tbtn.action.pressed {
  background: var(--accent);
}

.tbtn.small {
  width: 40px; height: 40px;
  font-size: 14px;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
  background: rgba(5, 5, 20, 0.92);
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.ov-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 0 20px #ffcc0066, 0 0 40px #ffcc0033;
  text-align: center;
}

.ov-sub {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  max-width: 260px;
}

.ov-score {
  font-size: 18px;
  color: var(--accent2);
  font-weight: 700;
}

/* Name input */
.name-input {
  background: var(--panel);
  border: 2px solid #3344aa;
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  padding: 10px 16px;
  width: 200px;
  text-align: center;
  outline: none;
}
.name-input:focus { border-color: var(--accent2); }
.name-input::placeholder { color: var(--muted); }

/* Play button */
.play-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 24px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, transform 0.1s;
  text-transform: uppercase;
}
.play-btn:hover:not(:disabled) { background: #ff5588; transform: scale(1.03); }
.play-btn:active:not(:disabled) { transform: scale(0.97); }
.play-btn:disabled { background: #443; color: #888; cursor: not-allowed; }
.play-btn.small { font-size: 12px; padding: 8px 14px; }
.play-btn.ghost {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}
.play-btn.ghost:hover { background: rgba(255,51,102,0.15); }

/* Character grid */
.char-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 300px;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--panel);
  border: 2px solid #333360;
  border-radius: 8px;
  padding: 6px 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.char-card:hover { border-color: var(--accent2); background: #1a1a35; }
.char-card.selected { border-color: var(--gold); background: #1e1a00; }

.char-card canvas {
  border-radius: 4px;
  background: #0d0d20;
  display: block;
}

.char-card .char-name {
  font-size: 9px;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
}

/* Chat */
.chat-box {
  width: 100%;
  max-width: 300px;
  height: 120px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid #333360;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg {
  max-width: 80%;
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 8px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.player {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.chat-msg.comp {
  align-self: flex-start;
  background: #1e2040;
  color: var(--text);
  border-bottom-left-radius: 2px;
}

.chat-input-row {
  display: flex;
  gap: 6px;
  width: 100%;
  max-width: 300px;
}

.chat-input {
  flex: 1;
  background: var(--panel);
  border: 2px solid #3344aa;
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
}
.chat-input:focus { border-color: var(--accent2); }

.chat-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.foot {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
}
.foot.muted { opacity: 0.5; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333360; border-radius: 2px; }
