:root {
  --bg: #15121c;
  --panel: #211c2b;
  --panel-2: #2b2538;
  --text: #ece8f4;
  --muted: #9a93aa;
  --accent: #e0469b;
  --accent-2: #8b5cf6;
  --danger: #ef4444;
  --sq-light: #ecd9b9;
  --sq-dark: #ae8a68;
  --last: rgba(255, 214, 0, 0.42);
  --selected: rgba(139, 92, 246, 0.55);
  --hint: rgba(36, 24, 60, 0.42);
  --hint-enemy: rgba(224, 70, 155, 0.6);
  --check: radial-gradient(circle, rgba(255, 30, 30, 0.95) 0%, rgba(255, 30, 30, 0.5) 45%, transparent 75%);
  --radius: 12px;
  --board: min(94vw, calc(100dvh - 190px), 640px);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #2d1f45 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- landing ---------- */

.hero { text-align: center; margin: 8vh 0 28px; }
.title {
  font-size: clamp(2.4rem, 8vw, 4rem); font-weight: 800; letter-spacing: -0.02em; text-decoration: none;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text;
  background-clip: text; color: transparent;
}
.tagline { color: var(--muted); margin: 4px 0 0; }

.card {
  background: var(--panel); border: 1px solid #ffffff14; border-radius: var(--radius);
  padding: 20px; max-width: 420px; margin: 0 auto 16px;
}
.choice { display: grid; gap: 12px; }
.form label { display: grid; gap: 8px; font-weight: 600; margin-bottom: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .btn { flex: none; }
.form .row { justify-content: flex-end; }

input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid #ffffff22;
  background: var(--panel-2); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }

.btn {
  display: inline-block; padding: 10px 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; font: inherit;
  font-weight: 600; text-decoration: none; text-align: center;
}
.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; }
.btn.ghost { background: var(--panel-2); border: 1px solid #ffffff22; }
.btn.danger { background: transparent; border: 1px solid var(--danger); color: #fca5a5; }
.btn.big { padding: 16px; font-size: 1.1rem; }

.muted { color: var(--muted); }
.error { color: #fca5a5; text-align: center; min-height: 1.4em; }

/* ---------- game ---------- */

.game {
  display: grid; gap: 12px 24px; justify-content: center;
  grid-template-columns: var(--board) minmax(240px, 320px);
  grid-template-areas: "banner banner" "notice notice" "board side";
}
.banner {
  grid-area: banner; text-align: center; padding: 8px 12px; border-radius: var(--radius);
  background: linear-gradient(90deg, #e0469b33, #8b5cf633); border: 1px solid #ffffff1a;
  font-weight: 700; letter-spacing: 0.04em;
}
.notice { grid-area: notice; text-align: center; color: #fcd34d; min-height: 0; }
.notice:empty { display: none; }
.board-col { grid-area: board; display: grid; gap: 8px; }
.side { grid-area: side; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side .card { margin: 0; max-width: none; }

.player { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; min-height: 44px; }
.player.to-move { background: var(--panel); box-shadow: inset 3px 0 0 var(--accent); }
.player-icon { width: 28px; height: 28px; }
.player-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.75rem; padding: 2px 8px; border-radius: 99px; }
.tag.offline { background: #ffffff14; color: var(--muted); }

.share p { margin: 0 0 8px; }
.share .muted { margin: 8px 0 0; font-size: 0.9rem; }
.link { font-size: 0.9rem; padding: 8px 10px; }

.status { font-weight: 600; font-size: 1.05rem; }
.offer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.offer:empty { display: none; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.controls .btn { flex: 1; }

/* ---------- board ---------- */

.board-wrap { position: relative; width: var(--board); aspect-ratio: 1; }
.board {
  /* fixed 8×8 tracks: squares never resize to fit (or lack) their pieces */
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  width: 100%; height: 100%;
  border-radius: 6px; overflow: hidden; touch-action: none; user-select: none;
  -webkit-user-select: none; box-shadow: 0 10px 40px #0008;
}
.sq { position: relative; min-width: 0; min-height: 0; cursor: pointer; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before, .sq.selected::before, .sq.check::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.sq.last::before { background: var(--last); }
.sq.selected::before { background: var(--selected); }
.sq.check::before { background: var(--check); }
.sq img { position: absolute; inset: 4%; width: 92%; height: 92%; pointer-events: none; z-index: 1; }
.sq img.lifted { opacity: 0.3; }

/* hints: a dot for a move, a ring for a capture; enemy pieces use the accent colour */
.sq.target::after, .sq.target-capture::after {
  content: ""; position: absolute; pointer-events: none; z-index: 2; border-radius: 50%;
}
.sq.target::after { width: 30%; height: 30%; background: var(--hint); }
.sq.target-capture::after { inset: 4%; border: 6px solid var(--hint); }
.sq.enemy.target::after { background: var(--hint-enemy); }
.sq.enemy.target-capture::after { border-color: var(--hint-enemy); }

.coord {
  position: absolute; font-size: clamp(9px, 1.6vw, 12px); font-weight: 700; pointer-events: none; z-index: 1;
}
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 4px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }

.drag-ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50; }

.picker {
  position: absolute; z-index: 20; transform: translate(-50%, -50%); display: flex; gap: 4px; padding: 6px;
  background: var(--panel); border: 1px solid #ffffff33; border-radius: 12px; box-shadow: 0 8px 30px #000a;
}
.picker button {
  width: calc(var(--board) / 8); height: calc(var(--board) / 8); border: 0; border-radius: 8px;
  background: var(--sq-light); cursor: pointer; padding: 4px; color: #222; font-weight: 700;
}
.picker button:hover { background: #fff; }
.picker img { width: 100%; height: 100%; }
.picker .picker-cancel { width: 32px; background: var(--panel-2); color: var(--text); }

@media (max-width: 860px) {
  #app { padding: 10px 16px; }
  .game {
    grid-template-columns: var(--board);
    grid-template-areas: "banner" "notice" "board" "side";
  }
  .hero { margin-top: 5vh; }
}
