:root {
  --bg: #161512;
  --panel: #262421;
  --panel-2: #302e2b;
  --line: #3d3b37;
  --text: #ddd8d0;
  --muted: #9a948a;
  --accent: #6a9a3f;
  --accent-2: #7fa650;
  --white-tile: #efe7d2;
  --white-edge: #b8a878;
  --black-tile: #3a3027;
  --black-edge: #0c0a08;
  --target: rgba(120, 190, 90, 0.55);
  --select: #f2c14e;
  --throw: #4ba3e3;
  --lastmove: rgba(242, 193, 78, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 20px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand span { color: var(--accent-2); font-weight: 400; margin-left: 6px; font-size: 14px; }
.topnav a { color: var(--muted); text-decoration: none; margin-left: 16px; }
.topnav a:hover { color: var(--text); }

.account { display: inline-flex; align-items: center; gap: 14px; margin-left: 16px; }
.account .signin {
  background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 5px;
  font-size: 13px; font-weight: 600;
}
.account .signin:hover { background: var(--accent-2); color: #fff; }
.account .me { color: var(--text); font-weight: 600; }
.account .me .rec { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
.account .signout { font-size: 12px; }

/* Player seats in the game sidebar */
.players { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.pseat { font-size: 13px; color: var(--text); }
.pname.link { color: var(--accent-2); text-decoration: none; }
.pname.link:hover { text-decoration: underline; }

/* Login page */
.login { max-width: 380px; margin: 60px auto; padding: 0 20px; text-align: center; }
.login h1 { font-size: 30px; margin: 0 0 6px; }
.login .sub { color: var(--muted); margin: 0 0 26px; }
.login .btn.provider {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; margin: 10px 0; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); font-size: 15px;
}
.login .btn.provider:hover { background: var(--line); }
.login .btn.provider .pico { font-size: 18px; }
.login .provider-steam:hover { border-color: #66c0f4; }
.login .provider-google:hover { border-color: #4285f4; }
.login .provider-github:hover { border-color: #8b949e; }
.login .provider-microsoft:hover { border-color: #00a4ef; }
.login .provider-gitlab:hover { border-color: #fc6d26; }
.login .provider-discord:hover { border-color: #5865f2; }
.login .anon { display: inline-block; margin-top: 16px; color: var(--muted); font-size: 13px; text-decoration: none; }
.login .anon:hover { color: var(--text); text-decoration: underline; }

/* Profile page */
.profile { max-width: 620px; margin: 40px auto; padding: 0 20px; text-align: center; }
.profile h1 { font-size: 32px; margin: 0 0 4px; }
.profile .sub { color: var(--muted); margin: 0 0 26px; }
.profile .stats { display: flex; justify-content: center; gap: 14px; margin-bottom: 28px; }
.statbox {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px 22px; min-width: 78px;
}
.statn { font-size: 28px; font-weight: 700; }
.statl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.gamehist { text-align: left; margin: 8px 0 28px; }
.gamehist h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 0 0 8px; }
.gamehist .empty { color: var(--muted); }
.ghtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ghrow { cursor: pointer; border-top: 1px solid var(--line); }
.ghrow:hover { background: #ffffff08; }
.ghtable td { padding: 9px 8px; vertical-align: middle; }
.ghbadge {
  display: inline-block; width: 22px; height: 22px; line-height: 22px; text-align: center;
  border-radius: 5px; font-weight: 800; font-size: 12px; color: #fff;
}
.ghbadge.win { background: var(--accent); }
.ghbadge.loss { background: #b4513f; }
.ghbadge.draw { background: #7a756c; }
.ghbadge.ongoing { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.ghopp { font-weight: 600; }
.ghopp a { color: var(--accent-2); text-decoration: none; }
.ghopp a:hover { text-decoration: underline; }
.ghreason { color: var(--muted); }
.ghexp { color: var(--accent-2); font-variant-numeric: tabular-nums; }
.ghmoves, .ghdate { color: var(--muted); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

#app { flex: 1; min-height: 0; display: flex; }

/* ---- Lobby ---- */
.lobby {
  margin: auto;
  text-align: center;
  padding: 40px 20px;
  max-width: 560px;
}
.lobby h1 { font-size: 34px; margin: 0 0 6px; }
.lobby p { color: var(--muted); margin: 0 0 28px; }
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: var(--accent-2); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--line); }
.btn:disabled { opacity: 0.5; cursor: default; }
.lobby .pieces { font-size: 40px; letter-spacing: 6px; margin: 26px 0; }
.lobby .hint { font-size: 13px; color: var(--muted); margin-top: 22px; }

.expansions {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px; margin: 0 auto 24px; max-width: 380px; text-align: left;
}
.expansions h3 {
  margin: 0 0 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted);
}
.expansions .exp {
  display: flex; align-items: center; gap: 10px; padding: 7px 4px; cursor: pointer;
}
.expansions .exp input { width: 17px; height: 17px; cursor: pointer; }
.expansions .exp .em { font-size: 22px; width: 26px; text-align: center; }
.expansions .exp b { display: block; }
.expansions .exp small { color: var(--muted); }

/* ---- Game layout ---- */
.game {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 0;
  width: 100%;
  min-height: 0;
}
.boardwrap {
  position: relative;
  min-width: 0;
  background: radial-gradient(circle at 50% 40%, #211f1c, #161512 70%);
  overflow: hidden;
}
#board { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#board.dragging { cursor: grabbing; }

.stackpop {
  position: absolute;
  z-index: 30;
  transform: translate(-50%, -100%);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  min-width: 150px;
  box-shadow: 0 6px 20px #0008;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}
.stackpop.show { opacity: 1; }
.stackpop::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: var(--panel-2);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
.sp-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 5px;
}
.sp-row { display: flex; align-items: center; gap: 7px; padding: 2px 0; font-size: 13px; }
.sp-em { font-size: 18px; width: 20px; text-align: center; }
.sp-name { flex: 1; }
.sp-tag {
  font-size: 10px; color: var(--bg); background: var(--accent-2);
  border-radius: 4px; padding: 0 5px; font-weight: 700;
}
.board-controls button {
  background: rgba(38, 36, 33, 0.9);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
}
.board-controls button:hover { background: var(--panel-2); }

.sidebar {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.statusbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.statusbar .turn { font-size: 17px; font-weight: 600; }
.statusbar .you { font-size: 13px; color: var(--muted); margin-top: 2px; }
.statusbar .result { font-size: 17px; font-weight: 700; color: var(--accent-2); }
.statusbar .dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; border: 1px solid #0008; }
.dot.white { background: var(--white-tile); }
.dot.black { background: var(--black-tile); }

.reserve { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.reserve h3 {
  margin: 0 0 6px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.tile {
  position: relative;
  width: 46px; height: 50px;
  border: none; background: none; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tile .hex {
  position: absolute; inset: 0;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--white-tile); border: 0;
}
.tile.black .hex { background: var(--black-tile); }
.tile .emoji { position: relative; font-size: 22px; }
.tile .count {
  position: absolute; right: 1px; bottom: 0;
  font-size: 11px; font-weight: 700; color: #111;
  background: #fffd; border-radius: 8px; padding: 0 4px; line-height: 15px;
}
.tile.black .count { color: #111; }
.tile.selectable { outline: 2px solid var(--accent-2); outline-offset: -2px; border-radius: 4px; }
.tile.selected .hex { box-shadow: 0 0 0 3px var(--select); }
.tile[disabled] { cursor: default; opacity: 0.55; }
.tile.empty { opacity: 0.28; cursor: default; }

.history { flex: 1; overflow-y: auto; padding: 8px 0; }
.history h3 { margin: 4px 14px 6px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.5px; }
.movelist { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.movelist td { padding: 3px 8px; }
.movelist td.num { color: var(--muted); width: 34px; text-align: right; }
.movelist td.mv { cursor: default; }
.movelist tr:nth-child(even) { background: #ffffff06; }

.actions { padding: 12px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { padding: 9px 14px; font-size: 14px; flex: 1; }

.invite {
  margin: 10px 12px; padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
}
.invite p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.invite .row { display: flex; gap: 6px; }
.invite input {
  flex: 1; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 4px; padding: 7px 8px; font-size: 12px;
}

/* ---- Game-over modal ---- */
.result-modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0); transition: background 0.25s ease;
}
.result-modal.show { background: rgba(0, 0, 0, 0.58); }
.result-modal.hide { background: rgba(0, 0, 0, 0); }
.result-card {
  position: relative; z-index: 2;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 42px 26px; text-align: center; min-width: 290px; max-width: 90vw;
  box-shadow: 0 24px 70px #000b;
  transform: scale(0.85) translateY(8px); opacity: 0;
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.45), opacity 0.25s ease;
}
.result-modal.show .result-card { transform: scale(1) translateY(0); opacity: 1; }
.rm-emoji { font-size: 66px; line-height: 1; }
.result-modal.show .rm-emoji { animation: rm-emoji-pop 0.55s 0.08s both; }
.rm-title { font-size: 30px; font-weight: 800; margin-top: 10px; }
.tone-win .rm-title { color: var(--accent-2); }
.tone-loss .rm-title { color: #e7917f; }
.tone-draw .rm-title { color: var(--text); }
.rm-sub { color: var(--muted); margin-top: 6px; font-size: 14px; }
.rm-actions { display: flex; gap: 10px; justify-content: center; margin-top: 24px; }
.rm-actions .btn { flex: 1; padding: 10px 16px; font-size: 14px; }

@keyframes rm-emoji-pop {
  0% { transform: scale(0) rotate(-25deg); }
  70% { transform: scale(1.25) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}

.confetti { position: fixed; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute; top: -8vh;
  animation-name: confetti-fall; animation-timing-function: linear; animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-10vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(112vh) rotate(560deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .result-modal, .result-card { transition: none; }
  .result-modal.show .rm-emoji { animation: none; }
  .confetti { display: none; }
}

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 6px; opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; }

@media (max-width: 820px) {
  .game { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .boardwrap { min-height: 52vh; }
  .sidebar { border-left: none; border-top: 1px solid var(--line); max-height: 48vh; }
}
