:root {
  --bg: #081326;
  --text: #eaf3ff;
  --muted: #8fb0d8;
  --accent: #4fc3f7;
  --accent-dim: #1c6f96;
  --panel: rgba(8, 18, 38, 0.94);
  --grid: #244062;
}

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

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}

.wrap {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.wrap:fullscreen, .wrap:-webkit-full-screen { width: 100vw; height: 100vh; }

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 8px;
}
.bar h1 { font-size: 16px; font-weight: 800; letter-spacing: 0.2px; }
.scores { display: flex; align-items: center; gap: 12px; }
.score { font-size: 14px; color: var(--muted); }
.score strong { color: var(--text); margin-left: 2px; }
#stage { color: var(--accent); font-weight: 700; }

.icon {
  background: transparent;
  border: 1px solid var(--grid);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  width: 34px;
  height: 30px;
  cursor: pointer;
}
.icon:active { background: var(--grid); }
.icon.home { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 8px 6px;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--grid);
  background: #0a1830;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; }

/* Overlays ------------------------------------------------------------------ */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 10px;
  padding: 18px;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  z-index: 5;
}
.overlay.hidden { display: none; }
.big {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0,0,0,0.5);
}
.sub { font-size: 14px; color: var(--muted); max-width: 420px; line-height: 1.35; }
.section { font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-top: 4px; }

.extra { font-size: 14px; color: var(--text); max-width: 420px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Pick grids ---------------------------------------------------------------- */
.grid { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 440px; }
.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.05);
  border: 2px solid var(--grid);
  border-radius: 14px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--text);
  transition: transform .08s, border-color .12s, background .12s;
  position: relative;
}
.cell:hover, .cell:active { transform: translateY(-2px); border-color: var(--accent); }
.cell.sel { border-color: var(--accent); background: rgba(79,195,247,0.16); }
.cell.locked { opacity: 0.55; cursor: not-allowed; }
.cell.locked::after {
  content: "🔒";
  position: absolute;
  top: 2px; right: 4px;
  font-size: 13px;
}
.cell canvas { image-rendering: auto; }
.cell .label { font-size: 11px; font-weight: 700; }
.colours .cell { padding: 6px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); }

.name-input {
  background: rgba(255,255,255,0.08);
  border: 2px solid var(--grid);
  border-radius: 12px;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  padding: 10px 16px;
  width: 220px;
  outline: none;
}
.name-input:focus { border-color: var(--accent); }

.play {
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #042033;
  font-size: 17px;
  font-weight: 800;
  padding: 12px 30px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dim);
  transition: transform .08s;
  margin-top: 6px;
}
.play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dim); }
.play.ghost {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--grid);
  box-shadow: none;
}
.play.ghost:active { transform: translateY(0); background: var(--grid); }

/* Touch controls ------------------------------------------------------------ */
.touch { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.touch.hidden { display: none; }
.dpad {
  position: absolute;
  left: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vh, 28px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(4px, 1vw, 8px);
  width: clamp(150px, 38vmin, 220px);
  height: clamp(150px, 38vmin, 220px);
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(12, 24, 48, 0.5);
  color: #fff;
  font-size: clamp(20px, 5vmin, 32px);
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  backdrop-filter: blur(2px);
}
.tbtn:active { background: rgba(79, 195, 247, 0.6); }
.tbtn.up    { grid-column: 2; grid-row: 1; }
.tbtn.left  { grid-column: 1; grid-row: 2; }
.tbtn.right { grid-column: 3; grid-row: 2; }
.tbtn.down  { grid-column: 2; grid-row: 3; }
.tbtn.slide {
  position: absolute;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vh, 28px);
  width: clamp(80px, 18vmin, 116px);
  height: clamp(80px, 18vmin, 116px);
  border-radius: 50%;
  font-size: clamp(30px, 7vmin, 46px);
  background: rgba(79, 195, 247, 0.34);
}

.hint {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 2px 8px 4px;
}
.foot { flex: 0 0 auto; text-align: center; font-size: 10px; color: var(--muted); padding-bottom: 4px; }
