:root {
  --bg: #0b0e1a;
  --panel: #141a2e;
  --panel-border: #1f2742;
  --panel-hover: #1b223a;
  --ink: #e8ecf7;
  --ink-dim: #8b94b2;
  --accent: #5b8cff;
  --accent-dim: #2a3e7a;
  --red: #ff4d5e;
  --yellow: #ffce3a;
  --board: #253ba8;
  --board-dark: #1a2b80;
  --board-cell: #0b0e1a;
  --win: #43e08a;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(ellipse at top, #182144 0%, var(--bg) 60%) fixed;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

button, input { font-family: inherit; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 36px;
  border-bottom: 1px solid var(--panel-border);
  flex-wrap: wrap;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand .logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--board) 0%, var(--accent) 100%);
  position: relative;
  box-shadow: var(--shadow);
}
.brand .logo::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--yellow);
  top: 13px;
  left: 13px;
  box-shadow: 0 0 12px rgba(255, 206, 58, .6);
}

h1 {
  font-size: 22px;
  margin: 0;
  letter-spacing: -.01em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--ink-dim);
  font-size: 13px;
}

.stats {
  display: flex;
  gap: 28px;
}
.stats > div {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.stat-num {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 20px;
  color: var(--ink);
}
.stat-label {
  color: var(--ink-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

main {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 24px;
  padding: 24px 36px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
}

aside { display: flex; flex-direction: column; gap: 16px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel.mini { padding: 12px 14px; }
.panel h2 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-dim);
}
.hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.5;
}
.panel ol, .panel p { font-size: 13px; line-height: 1.55; }
.panel ol { padding-left: 18px; margin: 8px 0 0; }
.panel p:last-child { margin-bottom: 0; }

.btn {
  display: block;
  width: 100%;
  border: none;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
  transition: transform .08s ease, background .15s ease;
}
.btn.primary { background: var(--red); color: white; }
.btn.primary:hover { background: #ff6172; }
.btn.ghost { background: var(--yellow); color: #2a1f00; }
.btn.ghost:hover { background: #ffd757; }
.btn:active { transform: translateY(1px); }

input[type=text] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--ink);
  font-size: 14px;
  margin-top: 4px;
}
input[type=text]:focus {
  outline: none;
  border-color: var(--accent);
}

#games {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 360px;
  overflow-y: auto;
}
.game-card {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.game-card:hover { background: var(--panel-hover); border-color: var(--accent-dim); }
.game-card.active { border-color: var(--accent); background: var(--panel-hover); }
.game-card .title { font-size: 13px; font-weight: 600; }
.game-card .meta { font-size: 11px; color: var(--ink-dim); margin-top: 2px; display: flex; justify-content: space-between; }
.game-card .badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--ink);
  margin-right: 4px;
}
.game-card.demo .badge { background: var(--win); color: #0b0e1a; }

.board-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  font-size: 14px;
}
.turn { font-size: 13px; color: var(--ink-dim); }
.turn.you { color: var(--win); }
.turn.win { color: var(--win); font-weight: 600; }

.board {
  background: var(--board);
  border-radius: 18px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  aspect-ratio: 7 / 6;
  box-shadow: var(--shadow), inset 0 -6px 20px var(--board-dark);
  position: relative;
}
.board.locked { cursor: not-allowed; }

.cell {
  background: var(--board-cell);
  border-radius: 50%;
  aspect-ratio: 1;
  box-shadow: inset 0 6px 14px rgba(0, 0, 0, .55);
  position: relative;
  cursor: pointer;
}
.cell .disc {
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  transform: translateY(-200%);
  transition: transform .35s cubic-bezier(.4, .9, .25, 1.4);
}
.cell .disc.p1 { background: radial-gradient(circle at 30% 30%, #ff7d8a, var(--red) 60%, #c33545 100%); }
.cell .disc.p2 { background: radial-gradient(circle at 30% 30%, #ffe787, var(--yellow) 60%, #d3a300 100%); }
.cell .disc.placed { transform: translateY(0); }
.cell.last .disc {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .25), 0 0 18px rgba(91, 140, 255, .5);
}
.cell.col-hover {
  background: rgba(91, 140, 255, .12);
}
.board.your-turn .cell:hover {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.result {
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 15px;
}
.result.hidden { display: none; }
.result.win { border-color: var(--win); color: var(--win); }
.result.loss { border-color: var(--red); color: var(--red); }
.result.draw { color: var(--ink-dim); }

.moves-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-dim);
}
.player { display: flex; align-items: center; gap: 8px; }
.player .dot { width: 14px; height: 14px; border-radius: 50%; }
.player.p1 .dot { background: var(--red); }
.player.p2 .dot { background: var(--yellow); }
.player.active .name { color: var(--ink); font-weight: 600; }

.moves-count { font-variant-numeric: tabular-nums; }

.kvp {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-dim);
  padding: 3px 0;
}
.kvp > span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }

footer {
  text-align: center;
  padding: 24px;
  color: var(--ink-dim);
  font-size: 12px;
  border-top: 1px solid var(--panel-border);
  margin-top: 24px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}
.connecting { animation: pulse 1.4s ease-in-out infinite; }

.hidden { display: none !important; }

/* Game switcher tabs */
.game-tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 4px;
}
.tab {
  background: transparent;
  border: none;
  color: var(--ink-dim);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.tab:hover { color: var(--ink); }
.tab.active {
  background: var(--accent-dim);
  color: var(--ink);
}

.btn.blue { background: var(--accent); color: white; }
.btn.blue:hover { background: #6e9aff; }

/* ----- Pig view ----- */
.pig-board {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
  min-height: 380px;
  align-items: stretch;
}

.pig-side {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: border-color .2s, box-shadow .2s;
}
.pig-side.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 140, 255, .25);
}
.pig-side.p1 .pig-name::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--red);
  margin-right: 6px;
  vertical-align: middle;
}
.pig-side.p2 .pig-name::before {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
  vertical-align: middle;
}
.pig-name {
  font-size: 13px;
  color: var(--ink-dim);
  font-weight: 600;
}
.pig-side.active .pig-name { color: var(--ink); }
.pig-score {
  font-size: 64px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: 1;
}
.pig-bar {
  width: 100%;
  height: 6px;
  background: var(--panel-border);
  border-radius: 3px;
  overflow: hidden;
}
.pig-side.p1 .pig-fill { background: var(--red); }
.pig-side.p2 .pig-fill { background: var(--accent); }
.pig-fill {
  height: 100%;
  width: 0;
  transition: width .4s cubic-bezier(.3, .8, .3, 1);
}

.pig-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
}

.pig-dice {
  display: flex;
  gap: 14px;
}

.die {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #fff 0%, #d0d4e0 100%);
  border-radius: 12px;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35), inset 0 -3px 6px rgba(0, 0, 0, .15);
  transition: transform .2s;
}
.die.rolling { animation: roll .5s ease-out; }
.die.danger { background: linear-gradient(135deg, #ffb1b9 0%, #ff4d5e 100%); }
.die.double { background: linear-gradient(135deg, #fff4b1 0%, #ffce3a 100%); }

@keyframes roll {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(180deg) scale(.85); }
  100% { transform: rotate(360deg) scale(1); }
}

.die::before {
  content: attr(data-value);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 32px;
  font-weight: 700;
  color: #2a3050;
}

.pig-turn-total {
  text-align: center;
}
.pig-turn-label {
  font-size: 11px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: .1em;
}
.pig-turn-num {
  font-size: 38px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  color: var(--win);
}

.pig-event {
  font-size: 13px;
  min-height: 18px;
  color: var(--ink-dim);
  text-align: center;
}
.pig-event.danger { color: var(--red); font-weight: 600; }
.pig-event.double { color: var(--yellow); font-weight: 600; }

.pig-actions {
  display: flex;
  gap: 8px;
  width: 100%;
}
.pig-actions .btn {
  margin-bottom: 0;
  flex: 1;
}
.pig-actions .btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .pig-board { grid-template-columns: 1fr; }
  .pig-side { flex-direction: row; justify-content: space-between; }
  .pig-score { font-size: 36px; }
}

/* ----- Diamant view ----- */
.diamant-players {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.diamant-player {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  transition: border-color .2s, box-shadow .2s;
  position: relative;
}
.diamant-player.in { border-color: var(--accent-dim); }
.diamant-player.home {
  background: rgba(67, 224, 138, .08);
  border-color: rgba(67, 224, 138, .4);
}
.diamant-player.lost {
  background: rgba(255, 77, 94, .08);
  border-color: rgba(255, 77, 94, .4);
  opacity: .7;
}
.diamant-player.deciding {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 140, 255, .25);
}
.diamant-player.is-me { border-color: var(--win); }
.diamant-pname {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.diamant-pname.me { color: var(--win); }
.diamant-tent {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 4px;
}
.diamant-run {
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.diamant-run.gain { color: var(--win); }
.diamant-status {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 2px 6px;
  border-radius: 5px;
  margin-top: 6px;
  display: inline-block;
}
.diamant-player.in .diamant-status { background: var(--accent-dim); color: var(--ink); }
.diamant-player.home .diamant-status { background: rgba(67, 224, 138, .25); color: var(--win); }
.diamant-player.lost .diamant-status { background: rgba(255, 77, 94, .25); color: var(--red); }
.diamant-pchose {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 16px;
}

.diamant-path-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
  min-height: 110px;
  box-shadow: var(--shadow);
}
.diamant-deck {
  flex-shrink: 0;
  width: 70px;
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
}
.diamant-deck-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-dim);
}
.diamant-deck-num {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.diamant-path {
  flex: 1;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  min-height: 80px;
}
.diamant-card {
  width: 56px;
  height: 80px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  padding: 4px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
  animation: card-in .4s ease-out;
}
@keyframes card-in {
  from { transform: scale(.4) rotateY(180deg); opacity: 0; }
  to { transform: scale(1) rotateY(0); opacity: 1; }
}
.diamant-card.treasure {
  background: linear-gradient(135deg, #2c7d4f 0%, #43e08a 100%);
  color: #082014;
}
.diamant-card.treasure .val {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}
.diamant-card.treasure .rem {
  font-size: 9px;
  margin-top: 2px;
  opacity: .8;
}
.diamant-card.hazard {
  background: linear-gradient(135deg, #6d1f29 0%, #ff4d5e 100%);
  color: #fff;
}
.diamant-card.hazard.double {
  animation: card-in .4s ease-out, pulse-danger 1.2s ease-in-out infinite .4s;
}
@keyframes pulse-danger {
  0%, 100% { box-shadow: 0 3px 8px rgba(0, 0, 0, .35), 0 0 0 0 rgba(255, 77, 94, .6); }
  50% { box-shadow: 0 3px 8px rgba(0, 0, 0, .35), 0 0 0 8px rgba(255, 77, 94, 0); }
}
.diamant-card .icon { font-size: 22px; line-height: 1; }
.diamant-card .label { font-size: 10px; margin-top: 2px; text-transform: uppercase; letter-spacing: .05em; }

.diamant-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
}
.diamant-event {
  flex: 1;
  font-size: 13px;
  color: var(--ink-dim);
  min-height: 18px;
}
.diamant-event.gain { color: var(--win); }
.diamant-event.danger { color: var(--red); font-weight: 600; }
.diamant-buttons {
  display: flex;
  gap: 8px;
}
.diamant-buttons .btn {
  margin-bottom: 0;
  min-width: 130px;
}
.diamant-buttons .btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

@media (max-width: 700px) {
  .diamant-players { grid-template-columns: repeat(2, 1fr); }
  .diamant-card { width: 44px; height: 64px; }
}
