:root {
  --bg-1: #2a5a96;
  --bg-2: #3a7ec1;
  --ice-1: #d6f1ff;
  --ice-2: #8ad2f5;
  --accent: #ffd84d;
  --danger: #ff5b6e;
  --text: #f3f8ff;
  --muted: #cfe1f5;
  --card: #1f4982;
  --card-hi: #2c629c;
  --line: #4f7eb5;
  --p-red: #ff4d5e;
  --p-yellow: #ffd84d;
  --p-blue: #4ec3ff;
  --p-green: #6cdc6c;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 50% -10%, #2c5fa3 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 100%, #143062 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  min-height: 100%;
  user-select: none;
}

#app { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }

.screen { display: none; width: 100%; max-width: 920px; }
.screen.visible { display: block; }

/* In-game: kill the centering/padding/maxwidth so the board fills the
   whole viewport without page scroll. */
body.in-game { overflow: hidden; }
body.in-game #app { padding: 0; align-items: stretch; justify-content: stretch; min-height: 100vh; height: 100vh; }
body.in-game #screen-game { max-width: none; height: 100vh; }
body.in-game #screen-game.visible { display: flex; }

.card {
  background: linear-gradient(180deg, var(--card-hi), var(--card));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
  max-width: 520px;
  margin: 0 auto;
}

.title {
  text-align: center;
  font-size: clamp(36px, 6vw, 56px);
  font-weight: 900;
  letter-spacing: 2px;
  margin: 0 0 4px;
  background: linear-gradient(180deg, #fff, #b6e7ff 60%, #66b7e7);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 0 rgba(0,0,0,0.2);
  line-height: 0.95;
}
.title-sub { font-size: 0.55em; letter-spacing: 6px; color: var(--accent); -webkit-text-fill-color: var(--accent); }
.subtitle { text-align: center; color: var(--muted); margin: 8px 0 24px; }

label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 14px; }
input[type=text], select {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: #0a1c34; color: var(--text);
  border: 1px solid var(--line); font-size: 16px;
  outline: none;
}
input:focus, select:focus { border-color: var(--ice-2); box-shadow: 0 0 0 3px rgba(102,183,231,0.2); }

.row { display: flex; gap: 10px; margin-top: 16px; }
button {
  flex: 1; padding: 12px 16px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer;
  font-size: 15px; font-weight: 700; letter-spacing: 0.3px;
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.primary { background: linear-gradient(180deg, #ffe27a, #f0b400); color: #2a1f00; border-color: #c89400; }
.primary:hover:not(:disabled) { background: linear-gradient(180deg, #fff0a0, #ffc724); }
.secondary { background: #1f4070; color: var(--text); border-color: #335f9a; }
.secondary:hover:not(:disabled) { background: #285591; }
.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--ice-2); }

.hint { color: var(--muted); font-size: 13px; text-align: center; margin: 18px 0 0; }
.error { color: var(--danger); margin: 12px 0 0; min-height: 18px; font-size: 14px; text-align: center; }

/* ---------- Lobby ---------- */
.lobby { max-width: 760px; }
.lobby-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 36px; font-weight: 800; letter-spacing: 6px;
  color: var(--accent);
}
.invite { display: flex; align-items: center; gap: 10px; position: relative; }
.copied { color: #6cdc6c; font-size: 13px; opacity: 0; transition: opacity 0.3s ease; }
.copied.show { opacity: 1; }

.lobby-body { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin: 22px 0; }
@media (max-width: 640px) { .lobby-body { grid-template-columns: 1fr; } }

.lobby-players ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.lobby-players li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 10px;
  background: #0e2444; border: 1px solid var(--line);
}
.dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0,0,0,0.4) inset; }
.dot.red { background: var(--p-red); }
.dot.yellow { background: var(--p-yellow); }
.dot.blue { background: var(--p-blue); }
.dot.green { background: var(--p-green); }
.host-tag {
  margin-left: auto; font-size: 11px; padding: 2px 6px;
  border-radius: 999px; background: #c89400; color: #2a1f00; font-weight: 800;
}

.lobby-footer { display: flex; gap: 10px; }

/* ---------- Game ---------- */
.game-wrap { width: 100%; max-width: none; margin: 0; display: flex; flex-direction: column; gap: 8px; padding: 8px; box-sizing: border-box; height: 100vh; min-height: 0; flex: 1 1 auto; }

.hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--card-hi), var(--card));
  border: 1px solid var(--line); border-radius: 12px;
}
.hud-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin-right: 6px; }
.hud-val { font-weight: 800; }
.hud-mid { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.hud-player {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 8px;
  background: #0a1c34; border: 1px solid var(--line);
  font-size: 12px;
}
.hud-player.dead { opacity: 0.4; text-decoration: line-through; }
.hud-stats { color: var(--muted); font-size: 11px; }

.canvas-wrap {
  position: relative;
  background: #2a5a96;
  border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  flex: 1 1 auto; min-height: 0;
  /* Force full available width so JS can measure something real instead of
     collapsing to canvas content width. */
  width: 100%;
  display: flex; align-items: center; justify-content: center;
}
canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }

.overlay {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55); color: #fff; font-weight: 800;
  font-size: 28px; text-align: center;
  padding: 20px; flex-direction: column; gap: 8px;
}
.overlay.show { display: flex; }
.overlay small { font-size: 14px; color: var(--muted); font-weight: 600; }

.hint-bar {
  text-align: center; color: var(--muted); font-size: 13px;
  padding: 6px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #11294a; color: var(--text);
  padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--line);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
