/* ============================================================
   POD BAY CHESS — 2001-inspired control-deck aesthetic
   ============================================================ */

:root {
  --bg: #06080d;
  --panel: #0c111c;
  --panel-2: #101726;
  --line: rgba(214, 224, 245, 0.13);
  --line-soft: rgba(214, 224, 245, 0.07);
  --ink: #e8ecf5;
  --muted: #76819b;
  --red: #e8392e;
  --red-glow: rgba(232, 57, 46, 0.55);
  --amber: #fbbf24;
  --ok: #5fe0a8;
  --sq-light: #aeb9d4;
  --sq-dark: #3a4259;
  --sq-sel: rgba(251, 191, 36, 0.45);
  --sq-last: rgba(251, 191, 36, 0.22);
  --sq-check: rgba(232, 57, 46, 0.55);
  --display: "Michroma", "Eurostile", sans-serif;
  --mono: "Space Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
}

body {
  background:
    radial-gradient(1100px 500px at 70% -10%, rgba(232, 57, 46, 0.07), transparent 60%),
    radial-gradient(900px 600px at 10% 110%, rgba(125, 211, 252, 0.05), transparent 60%),
    var(--bg);
  overflow-x: hidden;
}

/* --- atmosphere --- */
.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    radial-gradient(1px 1px at 12% 24%, rgba(232,236,245,.55) 50%, transparent 51%),
    radial-gradient(1px 1px at 38% 67%, rgba(232,236,245,.35) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 61% 14%, rgba(232,236,245,.45) 50%, transparent 51%),
    radial-gradient(1px 1px at 83% 41%, rgba(232,236,245,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 27% 88%, rgba(232,236,245,.3) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 92% 79%, rgba(232,236,245,.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 49% 38%, rgba(232,236,245,.25) 50%, transparent 51%),
    radial-gradient(1px 1px at 71% 92%, rgba(232,236,245,.3) 50%, transparent 51%);
}
.grain {
  position: fixed; inset: -50%; pointer-events: none; z-index: 50; opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 7s steps(8) infinite;
}
@keyframes grain {
  0%,100% { transform: translate(0,0); } 25% { transform: translate(-2%,3%); }
  50% { transform: translate(3%,-2%); } 75% { transform: translate(-3%,-3%); }
}

/* --- masthead --- */
.masthead {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 26px;
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--ink); }
.brand-text { font-family: var(--display); font-size: 15px; letter-spacing: .22em; }
.brand-text em { font-style: normal; color: var(--red); }
.sys { font-size: 11px; letter-spacing: .18em; color: var(--muted); }

/* HAL eye */
.hal {
  position: relative; width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #3a0b08, #120406 70%, #000);
  box-shadow: 0 0 0 2px rgba(214,224,245,.18), 0 0 18px var(--red-glow);
  display: inline-grid; place-items: center;
}
.hal-core {
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #ffd9a8, var(--red) 55%, #7a100a);
  box-shadow: 0 0 10px var(--red), 0 0 22px var(--red-glow);
  animation: halPulse 3.2s ease-in-out infinite;
}
@keyframes halPulse {
  0%, 100% { transform: scale(1); opacity: .92; }
  50% { transform: scale(1.18); opacity: 1; }
}
.hal.thinking .hal-core { animation: halPulse .9s ease-in-out infinite; }

/* ============================================================
   LOBBY
   ============================================================ */
.lobby { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; padding: 56px 24px 40px; }

.hero h1 {
  font-family: var(--display);
  font-size: clamp(30px, 6vw, 58px);
  line-height: 1.12;
  letter-spacing: .06em;
  margin: 0 0 18px;
  text-shadow: 0 0 40px rgba(232, 57, 46, .25);
  animation: rise .7s ease both;
}
.hero .accent { color: var(--red); }
.tagline { color: var(--muted); margin: 0 0 44px; max-width: 56ch; animation: rise .7s .08s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; animation: rise .7s .16s ease both; }
@media (max-width: 720px) { .panels { grid-template-columns: 1fr; } }

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 22px;
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
}
.panel-title {
  font-family: var(--display); font-size: 12px; letter-spacing: .3em;
  color: var(--muted); margin: 0 0 18px;
}
.panel-title .blink { color: var(--red); animation: blink 1.2s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block; font-size: 10px; letter-spacing: .25em; color: var(--muted); margin-bottom: 7px;
}
.field input {
  width: 100%; padding: 11px 13px;
  background: rgba(0,0,0,.4);
  border: 1px solid var(--line); border-radius: 6px;
  color: var(--ink); font-family: var(--mono); font-size: 15px;
  letter-spacing: .08em; outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.field input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(232,57,46,.15); }
.code-input { text-transform: uppercase; letter-spacing: .35em !important; }

.side-pick { display: flex; gap: 8px; }
.side-btn {
  flex: 1; padding: 9px 0; cursor: pointer;
  background: rgba(0,0,0,.35); color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
  font-family: var(--display); font-size: 10px; letter-spacing: .14em;
  transition: all .15s;
}
.side-btn:hover { color: var(--ink); }
.side-btn.active { color: var(--ink); border-color: var(--red); box-shadow: 0 0 14px rgba(232,57,46,.25) inset; }

.btn {
  cursor: pointer; padding: 13px 22px;
  background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  font-family: var(--display); font-size: 12px; letter-spacing: .2em;
  transition: all .16s;
  width: 100%;
}
.btn:hover { border-color: rgba(214,224,245,.4); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn-primary {
  background: linear-gradient(180deg, #c4291f, #8f1812);
  border-color: rgba(255,255,255,.18);
  box-shadow: 0 6px 24px rgba(232,57,46,.35);
}
.btn-primary:hover { box-shadow: 0 8px 30px rgba(232,57,46,.5); border-color: rgba(255,255,255,.34); }
.btn-small { padding: 8px 14px; font-size: 10px; width: auto; }
.btn-danger:hover { border-color: var(--red); color: #ff8a80; }

/* open rooms */
.open-rooms { margin-top: 22px; animation: rise .7s .24s ease both; }
.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-row {
  display: flex; align-items: center; gap: 16px;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 8px;
  padding: 12px 16px; cursor: pointer;
  transition: border-color .15s, transform .15s;
}
.room-row:hover { border-color: var(--red); transform: translateX(4px); }
.room-row .rr-code { font-weight: 700; letter-spacing: .25em; color: var(--amber); }
.room-row .rr-host { color: var(--ink); }
.room-row .rr-side { margin-left: auto; font-size: 11px; color: var(--muted); letter-spacing: .12em; }
.room-empty { color: var(--muted); font-size: 13px; padding: 10px 2px; font-style: italic; }

.foot {
  margin-top: 70px; padding-top: 22px; border-top: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 6px;
  color: var(--muted); font-size: 12px; font-style: italic;
}
.foot-meta { font-style: normal; font-size: 11px; }
.foot a { color: var(--muted); }

/* ============================================================
   GAME
   ============================================================ */
.hidden { display: none !important; }

.game {
  position: relative; z-index: 1;
  display: flex; gap: 30px; justify-content: center; align-items: flex-start;
  padding: 28px 24px 60px;
  max-width: 1200px; margin: 0 auto;
}
@media (max-width: 900px) { .game { flex-direction: column; align-items: center; } }

.board-wrap { display: flex; flex-direction: column; gap: 10px; }

.player-tag {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; letter-spacing: .12em; min-height: 22px;
}
.player-tag .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #3a4259; box-shadow: none; flex: none;
  transition: all .3s;
}
.player-tag .dot.on { background: var(--ok); box-shadow: 0 0 8px rgba(95,224,168,.7); }
.player-tag .dot.turn { background: var(--amber); box-shadow: 0 0 8px rgba(251,191,36,.8); animation: halPulse 1.6s infinite; }
.tag-name { font-weight: 700; }
.tag-mat { color: var(--muted); font-size: 12px; letter-spacing: 0; }

/* board */
.board {
  --cell: min(11.5vw, 76px);
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  border: 1px solid rgba(214,224,245,.25);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0,0,0,.6), 0 0 0 6px rgba(12,17,28,.9), 0 0 0 7px var(--line-soft);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
@media (max-width: 900px) { .board { --cell: min(11.8vw, 60px); } }

.sq { position: relative; display: grid; place-items: center; cursor: pointer; }
.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: var(--sq-last); }
.sq.sel::before  { content: ""; position: absolute; inset: 0; background: var(--sq-sel); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, var(--sq-check), transparent 75%); }
.sq .piece { width: 88%; height: 88%; position: relative; z-index: 1; pointer-events: none; }
.sq .piece svg { width: 100%; height: 100%; display: block; }
.sq.movable:hover { filter: brightness(1.12); }

.sq.dot::after {
  content: ""; position: absolute; z-index: 2;
  width: 26%; height: 26%; border-radius: 50%;
  background: rgba(10, 14, 22, .45);
  box-shadow: 0 0 0 2px rgba(232, 236, 245, .25);
}
.sq.dot.capture::after {
  width: 86%; height: 86%; background: transparent;
  border: 3px solid rgba(232, 57, 46, .75); box-shadow: none;
}

/* square labels */
.sq .lbl {
  position: absolute; font-size: calc(var(--cell) * 0.17); font-weight: 700;
  z-index: 0; opacity: .65; letter-spacing: 0;
}
.sq .lbl.file { right: 5%; bottom: 3%; }
.sq .lbl.rank { left: 6%; top: 4%; }
.sq.light .lbl { color: var(--sq-dark); }
.sq.dark .lbl { color: var(--sq-light); }

@keyframes boardShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-7px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}
.board.shake { animation: boardShake .35s ease; }

/* side panel */
.side {
  width: 320px; max-width: 94vw;
  display: flex; flex-direction: column; gap: 14px;
}
.room-id-row { display: flex; align-items: center; gap: 12px; }
.room-id {
  flex: 1;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px;
  display: flex; align-items: baseline; gap: 12px;
}
.room-id-label { font-size: 10px; letter-spacing: .25em; color: var(--muted); }
.room-code {
  font-family: var(--display); font-size: 18px; letter-spacing: .3em; color: var(--amber);
  text-shadow: 0 0 16px rgba(251,191,36,.4);
}

.status {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-left: 3px solid var(--red);
  border-radius: 8px; padding: 13px 16px;
  font-size: 13px; letter-spacing: .1em; min-height: 48px;
  display: flex; align-items: center;
}
.status.good { border-left-color: var(--ok); }
.status.warn { border-left-color: var(--amber); }

.moves-box {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 8px;
  height: 300px; overflow-y: auto; padding: 10px 14px;
}
@media (max-width: 900px) { .moves-box { height: 170px; } }
.moves { margin: 0; padding: 0; list-style: none; columns: 1; font-size: 13.5px; }
.moves li {
  display: flex; gap: 14px; padding: 3px 4px; border-radius: 4px;
}
.moves li:nth-child(odd) { background: rgba(214,224,245,.03); }
.moves .num { color: var(--muted); width: 28px; flex: none; text-align: right; }
.moves .mv { width: 72px; }
.moves .mv.latest { color: var(--amber); font-weight: 700; }

.controls { display: flex; gap: 8px; }
.controls .btn { flex: 1; }

/* modal */
.modal {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(4, 6, 10, .75); backdrop-filter: blur(4px);
  display: grid; place-items: center;
}
.modal-card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 24px 28px; box-shadow: 0 30px 80px rgba(0,0,0,.7);
  animation: rise .25s ease both;
}
.modal-title { font-family: var(--display); font-size: 11px; letter-spacing: .3em; color: var(--muted); margin-bottom: 16px; text-align: center; }
.promo-row { display: flex; gap: 10px; }
.promo-row button {
  width: 72px; height: 72px; cursor: pointer;
  background: rgba(0,0,0,.35); border: 1px solid var(--line); border-radius: 8px;
  transition: all .15s;
}
.promo-row button:hover { border-color: var(--amber); transform: translateY(-3px); }
.promo-row .promo-piece { width: 100%; height: 100%; display: block; }
.promo-row svg { width: 100%; height: 100%; display: block; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px);
  z-index: 95; pointer-events: none;
  background: #1a0c0b; border: 1px solid rgba(232,57,46,.5); border-radius: 8px;
  color: #ffb4ad; padding: 12px 22px;
  font-size: 13px; letter-spacing: .08em; font-style: italic;
  opacity: 0; transition: all .25s ease;
  box-shadow: 0 10px 40px rgba(232,57,46,.25);
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.info { background: #0d141f; border-color: rgba(125,211,252,.4); color: #bfe3ff; }

/* scrollbars */
.moves-box::-webkit-scrollbar { width: 8px; }
.moves-box::-webkit-scrollbar-thumb { background: var(--sq-dark); border-radius: 4px; }
