/* Chess with friends - the board is the only ornate thing; everything else stays quiet. */

:root {
  --mist: #dde6e2;
  --spruce: #22403b;
  --bone: #f4f0e4;
  --lichen: #6f8f84;
  --mulberry: #8c2f52;
  --brass: #e8c25a;
  --ink: #1c2a27;
  --muted: #46605a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --symbols: "Noto Sans Symbols 2", "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", "Arial Unicode MS", sans-serif;
  --bs: min(calc(100vw - 420px), calc(100vh - 200px), 680px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--mist);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  min-height: 100vh;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 14px 24px;
}
.top-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.top-right { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.home-link {
  font: 600 13px/1.2 var(--sans);
  color: var(--spruce);
  background: rgba(34, 64, 59, 0.1);
  padding: 6px 14px;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}
.acct { display: flex; align-items: center; gap: 2px; min-width: 0; }
.acct-name {
  font: 600 14px/1.2 var(--sans);
  color: var(--spruce);
  padding: 6px 8px;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quiet.strong { color: var(--mulberry); font-weight: 600; }
a.quiet { text-decoration: none; }
.brand {
  font: 600 22px/1 var(--serif);
  color: var(--spruce);
  text-decoration: none;
  letter-spacing: 0.01em;
}
.quiet {
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.quiet:hover { color: var(--spruce); background: rgba(34, 64, 59, 0.08); }

main { padding: 0 24px 96px; } /* room for the floating voice buttons */

/* ---------- buttons & fields ---------- */
.btn {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1.5px solid var(--spruce);
  background: transparent;
  color: var(--spruce);
  font: 600 15px/1 var(--sans);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover:not(:disabled) { background: rgba(34, 64, 59, 0.08); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--mulberry); border-color: var(--mulberry); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #742645; }
.btn.danger { color: var(--mulberry); border-color: var(--mulberry); }
.btn.danger:hover:not(:disabled) { background: rgba(140, 47, 82, 0.09); }

:where(button, input, a):focus-visible { outline: 3px solid var(--mulberry); outline-offset: 2px; }

label.field { display: grid; gap: 6px; font-weight: 600; font-size: 15px; }
input[type="text"],
input[type="password"] {
  height: 46px;
  padding: 0 12px;
  border: 1.5px solid #8fa8a0;
  border-radius: 8px;
  background: #fbfaf5;
  font: 400 16px var(--sans);
  color: var(--ink);
  width: 100%;
}

/* segmented colour choice */
fieldset.seg { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
fieldset.seg legend { padding: 0; font-weight: 600; font-size: 15px; margin-bottom: 6px; }
.seg .opts { display: flex; gap: 8px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  border: 1.5px solid var(--spruce);
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: var(--spruce);
}
.seg input:checked + span { background: var(--spruce); color: var(--bone); }
.seg input:focus-visible + span { outline: 3px solid var(--mulberry); outline-offset: 2px; }

/* ---------- lobby ---------- */
.lobby {
  --bs: min(520px, calc(100vw - 600px), calc(100vh - 140px));
  display: grid;
  grid-template-columns: minmax(280px, 440px) auto;
  gap: 64px;
  align-items: start;
  justify-content: center;
  padding-top: 24px;
}
.lobby h1 {
  font: 600 46px/1.08 var(--serif);
  letter-spacing: -0.01em;
  color: var(--spruce);
  margin: 0 0 12px;
  text-wrap: balance;
}
.lede { margin: 0 0 28px; color: var(--muted); max-width: 34ch; font-size: 17px; }
.stack { display: grid; gap: 18px; }
.joinrow { display: grid; gap: 6px; margin-top: 28px; padding-top: 22px; border-top: 1.5px solid #b5c7c0; }
.joinrow .row { display: flex; gap: 8px; }
.joinrow .btn { white-space: nowrap; flex: none; }
.codebox { text-transform: uppercase; letter-spacing: 0.14em; font-weight: 600; }
.codebox::placeholder { letter-spacing: 0.04em; font-weight: 400; text-transform: none; }
.resume { display: inline-block; margin-top: 18px; color: var(--spruce); font-weight: 600; }
.boardwrap.hero { position: sticky; top: 24px; }

/* ---------- account: login / sign-up ---------- */
.card { background: rgba(255, 255, 255, 0.55); border-radius: 14px; padding: 20px; }
h2.sub { font: 600 21px/1.2 var(--serif); color: var(--spruce); margin: 0; }
.authp { display: grid; gap: 14px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: rgba(34, 64, 59, 0.08); border-radius: 10px; }
.tabs button {
  flex: 1;
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: 600 15px/1.2 var(--sans);
  cursor: pointer;
}
.tabs button.on { background: #fff; color: var(--spruce); box-shadow: 0 1px 3px rgba(20, 40, 36, 0.18); }
.opt { font-weight: 400; color: var(--muted); font-size: 14px; }
.hint { margin: 0; font-size: 14px; color: var(--muted); font-weight: 400; line-height: 1.45; }
.err {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(140, 47, 82, 0.1);
  color: var(--mulberry);
  font-size: 14px;
  font-weight: 600;
}

/* pop-up (game page) */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 40, 36, 0.55);
}
.modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--mist);
  border-radius: 14px;
  padding: 22px 20px 20px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.5);
}
.modal-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
.modal-x:hover { background: rgba(34, 64, 59, 0.08); color: var(--spruce); }

/* ---------- my games ---------- */
#lobbyIn { display: grid; gap: 24px; }
#lobbyIn[hidden] { display: none; }
.create { padding-top: 22px; border-top: 1.5px solid #b5c7c0; }
.mygames { display: grid; gap: 10px; }
.mg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mg-head h2 { font: 600 23px/1.2 var(--serif); color: var(--spruce); margin: 0; }
.mg-list { display: grid; gap: 8px; }
.mg-empty { margin: 0; padding: 14px; border-radius: 10px; background: rgba(255, 255, 255, 0.5); color: var(--muted); font-size: 15px; }
.mg-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  border-radius: 10px;
  background: var(--bone);
  border-left: 4px solid #b5c7c0;
}
.mg-row.mine { border-left-color: var(--mulberry); background: #fbf6ea; }
.mg-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.mg-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mg-opp { font: 600 17px/1.25 var(--serif); color: var(--spruce); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-row.wait .mg-opp { font-style: italic; font-weight: 400; color: var(--muted); }
.chip { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--spruce); flex: none; display: inline-block; }
.chip.w { background: #fbf8ee; }
.chip.b { background: #1b2422; }
.mg-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 13.5px; color: var(--ink); }
.mg-meta.soft { color: var(--muted); }
.mg-code { font-weight: 700; letter-spacing: 0.1em; }
.mg-turn.on { color: var(--mulberry); font-weight: 700; }
.mg-draw { color: var(--mulberry); font-weight: 600; }
.mg-row .btn { flex: none; min-height: 40px; padding: 0 12px; font-size: 14px; }

/* other games, inside the game panel */
.others { border-top: 1.5px solid #b5c7c0; padding-top: 12px; }
.others summary { cursor: pointer; font-weight: 600; color: var(--spruce); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.others[open] summary { margin-bottom: 10px; }
.badge { background: var(--mulberry); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 12.5px; font-weight: 600; }
.mg-list.compact .mg-row { padding: 9px 10px 9px 12px; gap: 8px; }
.mg-list.compact .mg-opp { font-size: 15.5px; }
.mg-list.compact .mg-meta { font-size: 12.5px; }

/* ---------- board ---------- */
.boardwrap {
  position: relative;
  padding: 10px;
  width: calc(var(--bs) + 20px);
  background: var(--spruce);
  border-radius: 10px;
  box-shadow: 0 22px 44px -22px rgba(20, 40, 36, 0.6);
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: var(--bs);
  height: var(--bs);
  border-radius: 3px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.board.still { pointer-events: none; }
.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--bs) / 8 * 0.8);
  line-height: 1;
  min-width: 0;
  min-height: 0;
}
.sq.light { background: var(--bone); }
.sq.dark { background: var(--lichen); }
.sq.go { cursor: pointer; }
.sq::before { content: ""; position: absolute; inset: 0; pointer-events: none; }
.sq.last::before { background: rgba(232, 194, 90, 0.5); }
.sq.sel::before { background: rgba(232, 194, 90, 0.85); }
.sq.check::before {
  background: radial-gradient(circle, rgba(140, 47, 82, 0.95) 0%, rgba(140, 47, 82, 0.55) 45%, rgba(140, 47, 82, 0) 72%);
}
.sq.hint::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(34, 64, 59, 0.42);
  pointer-events: none;
}
.sq.cap::after {
  content: "";
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  border: calc(var(--bs) / 8 * 0.09) solid rgba(34, 64, 59, 0.45);
  pointer-events: none;
}
.sq.go:hover::before { background: rgba(255, 255, 255, 0.22); }

.pc {
  position: relative;
  z-index: 1;
  font-family: var(--symbols);
  pointer-events: none;
}
.pc.w {
  color: #fbf8ee;
  -webkit-text-stroke: calc(var(--bs) / 8 * 0.035) #1d2a27;
  paint-order: stroke fill;
  text-shadow: 0 0.03em 0.05em rgba(0, 0, 0, 0.35);
}
.pc.b {
  color: #1b2422;
  text-shadow: 0 0.025em 0 rgba(255, 255, 255, 0.25), 0 0.03em 0.05em rgba(0, 0, 0, 0.3);
}
.coord {
  position: absolute;
  font: 600 calc(var(--bs) / 8 * 0.16) / 1 var(--sans);
  pointer-events: none;
  z-index: 0;
}
.coord.r { top: 5%; left: 6%; }
.coord.f { bottom: 5%; right: 6%; }
.sq.light .coord { color: var(--lichen); }
.sq.dark .coord { color: var(--bone); }

/* promotion picker */
.promo {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(20, 40, 36, 0.62);
  border-radius: 10px;
}
.promo .pick {
  width: calc(var(--bs) / 8 * 1.25);
  height: calc(var(--bs) / 8 * 1.25);
  border-radius: 10px;
  border: 0;
  background: var(--bone);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--bs) / 8 * 0.95);
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.promo .pick:hover { background: #fff; }

/* ---------- game layout ---------- */
.game {
  display: grid;
  grid-template-columns: auto 320px;
  gap: 32px;
  justify-content: center;
  align-items: start;
}
.pbar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(var(--bs) + 20px);
  padding: 8px 2px;
  font: 600 18px/1.2 var(--serif);
  color: var(--spruce);
  min-height: 44px;
}
.pbar .chip { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--spruce); flex: none; }
.pbar .chip.w { background: #fbf8ee; }
.pbar .chip.b { background: #1b2422; }
.pbar .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pbar .pname.empty { font-weight: 400; font-style: italic; color: var(--muted); }
.pbar .turn {
  margin-left: auto;
  font: 600 13px/1 var(--sans);
  color: var(--mulberry);
  display: none;
  align-items: center;
  gap: 6px;
}
.pbar .turn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--mulberry); }
.pbar.on .turn { display: inline-flex; }

.panel {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 14px;
  padding: 20px;
  display: grid;
  gap: 16px;
  align-content: start;
}
.status { font: 600 25px/1.2 var(--serif); color: var(--spruce); }
.status small { display: block; margin-top: 6px; font: 400 15px/1.4 var(--sans); color: var(--muted); }

.box { display: grid; gap: 10px; padding: 14px; border-radius: 10px; background: var(--bone); border-left: 4px solid var(--mulberry); }
.box p { margin: 0; font-size: 15px; }
.box strong { letter-spacing: 0.12em; }
.box .row { display: flex; gap: 8px; flex-wrap: wrap; }
.box input[type="text"] { height: 42px; font-size: 14px; }

.moves {
  list-style: none;
  margin: 0;
  padding: 6px 4px;
  max-height: 280px;
  overflow: auto;
  background: var(--bone);
  border-radius: 10px;
  font: 400 17px/1.55 var(--serif);
  font-variant-numeric: tabular-nums;
}
.moves:empty::before { content: "No moves yet"; display: block; padding: 6px 10px; color: var(--muted); font: italic 15px var(--sans); }
.moves li { display: grid; grid-template-columns: 2.6em 1fr 1fr; padding: 0 8px; }
.moves .n { color: var(--muted); }
.moves .m.cur { background: rgba(232, 194, 90, 0.55); border-radius: 4px; padding: 0 4px; margin-left: -4px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--spruce);
  color: var(--bone);
  padding: 11px 18px;
  border-radius: 8px;
  font-size: 15px;
  max-width: calc(100vw - 32px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}
#toast.show { opacity: 1; }

.notfound { max-width: 440px; margin: 60px auto; text-align: center; }
.notfound h2 { font: 600 28px/1.2 var(--serif); color: var(--spruce); }

/* ---------- viewers + room list ---------- */
.watchbtn { margin-top: 8px; width: 100%; }
.joinrow .hint { margin-top: 2px; }
.board.gated { filter: grayscale(0.5) blur(1.5px); opacity: 0.55; pointer-events: none; }

.room { display: grid; gap: 10px; border-top: 1.5px solid #b5c7c0; padding-top: 14px; }
.room-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.room-head h3 { margin: 0; font: 600 19px/1.2 var(--serif); color: var(--spruce); }
.room-count { font-size: 13.5px; color: var(--muted); font-weight: 600; }
.room-group { display: grid; gap: 4px; }
.rg-title { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
#viewerCount.full { color: var(--mulberry); }
.rlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.rp {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--bone);
  border: 1.5px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}
.rp.me { background: #fbf6ea; }
.rp.empty { background: transparent; color: var(--muted); font-size: 14px; font-style: italic; padding-left: 2px; min-height: 28px; }
.rp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 15px; }
.rp.away .rp-name { color: var(--muted); }
.rp-tags { display: flex; align-items: center; gap: 8px; flex: none; }
.dot { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #9db0aa; }
.dot.on::before { background: #2f9e62; }
.rp-voice { font-size: 15px; opacity: 0.18; filter: grayscale(1); transition: opacity 0.15s; }
.rp.speaking { border-color: #2f9e62; background: #eef8f1; }
.rp.speaking .rp-voice { opacity: 1; filter: none; animation: talk 0.6s ease-in-out infinite alternate; }
@keyframes talk { from { transform: scale(1); } to { transform: scale(1.25); } }
.room .row { display: flex; gap: 8px; flex-wrap: wrap; }
.room .row .btn { flex: 1 1 auto; font-size: 14px; }

.speak-now {
  position: fixed;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  z-index: 25;
  max-width: min(320px, calc(100vw - 24px));
  padding: 7px 12px;
  border-radius: 999px;
  background: #1f6b45;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 6px 18px -6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* ---------- room code field ---------- */
.err.small { font-size: 13.5px; padding: 7px 10px; font-weight: 600; }
#roomIn[aria-invalid="true"] { border-color: var(--mulberry); }

/* ---------- share: like Ludo King's waiting room (code box + one button) ---------- */
.room-code-box {
  background: var(--bone);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: center;
  font: 800 26px/1.2 var(--sans);
  letter-spacing: 4px;
  color: var(--spruce);
  word-break: break-all;
}
.room-code-box span:first-child {
  display: block;
  margin-bottom: 4px;
  font: 600 12.5px/1.3 var(--sans);
  letter-spacing: normal;
  color: var(--muted);
}
.btn.sharebtn { width: 100%; min-height: 46px; font-size: 15px; }
#leaveWatch { width: 100%; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  :root { --bs: min(calc(100vw - 44px), 640px); }
  main { padding: 0 12px 96px; }
  .top { padding: 12px 16px; }
  .lobby { grid-template-columns: 1fr; gap: 32px; --bs: min(calc(100vw - 44px), 420px); justify-items: center; }
  .boardwrap.hero { position: static; }
  .lobby-copy { width: 100%; max-width: 480px; }
  .lobby h1 { font-size: 36px; }
  .game { grid-template-columns: 1fr; justify-items: center; gap: 16px; }
  .panel { width: calc(var(--bs) + 20px); }
}

@media (max-width: 520px) {
  .top { padding: 10px 12px; }
  .brand { font-size: 19px; }
  .top-left { gap: 10px; }
  .top-right { width: 100%; justify-content: space-between; }
  .acct-name { max-width: 12ch; }
  .card { padding: 16px; }
  .mg-row { flex-wrap: wrap; }
  .mg-row .btn { width: 100%; }
  .mg-list.compact .mg-row .btn { width: auto; }
  .lobby h1 { font-size: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
  .rp.speaking .rp-voice { animation: none; }
}
