:root {
  --green: #008751;
  --green-deep: #0b3d2a;
  --green-ink: #062419;
  --cream: #fff6e3;
  --gold: #f6b80f;
  --orange: #ea5b1c;
  --ink: #1d1407;
  --wood-light: #e8c48e;
  --wood-dark: #6b3a1c;
  --wood-frame: #3b1d0b;
  /* cap colours; overwritten from JS when the start.ng character has a colour */
  --p1: #17a34a;
  --p1d: #0a5a28;
  --p2: #d7261e;
  --p2d: #7c100c;
  --font-display: 'Lilita One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--cream);
  background-color: var(--green-deep);
  /* Ankara-style wax print: concentric rings + diamonds */
  background-image:
    radial-gradient(circle at 50% 50%, transparent 0 9px, rgba(246, 184, 15, .16) 9px 12px, transparent 12px 18px, rgba(234, 91, 28, .14) 18px 21px, transparent 21px),
    radial-gradient(circle at 0 0, rgba(255, 255, 255, .05) 0 6px, transparent 7px),
    linear-gradient(45deg, rgba(0, 0, 0, .12) 25%, transparent 25% 75%, rgba(0, 0, 0, .12) 75%),
    linear-gradient(-45deg, rgba(0, 0, 0, .12) 25%, transparent 25% 75%, rgba(0, 0, 0, .12) 75%);
  background-size: 56px 56px, 28px 28px, 56px 56px, 56px 56px;
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: linear-gradient(180deg, rgba(6, 36, 25, .95), rgba(6, 36, 25, .75));
  border-bottom: 4px solid var(--green);
  box-shadow: 0 4px 0 #fff, 0 8px 0 var(--green);
  margin-bottom: 8px;
}

.startng-card {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px; border-radius: 999px;
  background: #292a23; color: #fffefa; min-width: 0;
}
.startng-card img { width: 44px; height: 44px; border-radius: 50%; background: #d8fd71; object-fit: cover; flex: none; }
.startng-card .who { min-width: 0; }
.startng-card b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.startng-card span { font-size: 12px; opacity: .7; }
.startng-card button {
  margin-left: 4px; border: 0; border-radius: 999px; padding: 6px 12px;
  background: #d8fd71; color: #1b1b14; font-weight: 800; cursor: pointer;
}

.brand { text-align: center; }
.brand h1 {
  margin: 0; font-family: var(--font-display); font-weight: 400;
  font-size: clamp(28px, 4vw, 44px); letter-spacing: 1px; line-height: 1;
  color: #fff; text-shadow: 3px 3px 0 var(--green), 6px 6px 0 rgba(0, 0, 0, .35);
}
.brand h1 span { color: var(--gold); }
.brand p { margin: 4px 0 0; font-size: 13px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; opacity: .75; }

.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }

.btn {
  border: 0; cursor: pointer; border-radius: 12px;
  padding: 9px 14px; font-weight: 900; font-size: 14px;
  background: var(--gold); color: var(--ink);
  box-shadow: 0 4px 0 #9b6c00;
  transition: transform .08s, box-shadow .08s, opacity .2s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #9b6c00; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.ghost { background: rgba(255, 255, 255, .1); color: var(--cream); box-shadow: 0 4px 0 rgba(0, 0, 0, .35); }
.btn.icon { padding: 9px 11px; }
.btn.big { font-size: 18px; padding: 14px 22px; border-radius: 14px; }

/* ---------- arena ---------- */
.arena {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 20px;
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 20px 32px;
  align-items: start;
}

.table { --bw: min(100%, 640px, max(300px, calc(100svh - 290px))); display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; }

.seat {
  position: relative;
  width: var(--bw);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-radius: 16px;
  background: rgba(6, 36, 25, .78);
  border: 2px solid rgba(255, 255, 255, .08);
  transition: border-color .25s, box-shadow .25s;
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(246, 184, 15, .25); }
.avatar {
  width: 48px; height: 48px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px;
  background: var(--cream); overflow: hidden;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .15);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.seat-info { min-width: 0; flex: 1; }
.seat-info b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-info span { font-size: 12px; opacity: .7; font-weight: 700; }

.pile { display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; gap: 2px; max-width: 46%; }
.pile .mini {
  width: 14px; height: 14px; border-radius: 50%;
  background: repeating-conic-gradient(var(--c) 0 15deg, var(--cd) 15deg 30deg);
  box-shadow: inset 0 0 0 3px var(--c);
}
.pile .count { font-family: var(--font-display); font-size: 18px; margin-left: 6px; color: var(--gold); align-self: center; }

.bubble {
  position: absolute; left: 70px; top: calc(100% + 6px); z-index: 30;
  max-width: min(340px, 78%);
  padding: 10px 14px; border-radius: 14px 14px 14px 4px;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 15px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .25);
  animation: pop .25s ease-out;
  pointer-events: none;
}
.bubble::before {
  content: ''; position: absolute; left: 14px; top: -8px;
  border: 8px solid transparent; border-top: 0; border-bottom-color: #fff;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.status {
  margin: 4px 0 0; min-height: 26px; text-align: center;
  font-weight: 900; font-size: 17px; color: #fff;
}
.status.warn { color: var(--gold); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- board ---------- */
.board-wrap {
  width: var(--bw);
  padding: clamp(8px, 2vw, 16px);
  border-radius: 14px;
  background:
    repeating-linear-gradient(92deg, rgba(0, 0, 0, .18) 0 2px, transparent 2px 9px),
    linear-gradient(135deg, #5a2c10, var(--wood-frame));
  box-shadow: 0 14px 0 #220f04, 0 22px 40px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .15);
}
.board { position: relative; aspect-ratio: 1; width: 100%; border-radius: 4px; overflow: hidden; box-shadow: 0 0 0 3px #2a1406; }
.squares { position: absolute; inset: 0; display: grid; }
.sq { position: relative; }
.sq.light {
  background: linear-gradient(135deg, #f1d7a8, var(--wood-light));
}
.sq.dark {
  background:
    repeating-linear-gradient(80deg, rgba(0, 0, 0, .1) 0 1px, transparent 1px 6px),
    linear-gradient(135deg, #7d4522, var(--wood-dark));
  cursor: pointer;
}
.sq.last::after { content: ''; position: absolute; inset: 0; background: rgba(246, 184, 15, .28); }
.sq.movable::before {
  content: ''; position: absolute; inset: 6%; border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(246, 184, 15, .9);
  animation: pulse 1.1s ease-in-out infinite;
}
.sq.must::before { box-shadow: 0 0 0 3px #ff4d2e; }
.sq.selected::before { content: ''; position: absolute; inset: 4%; border-radius: 50%; box-shadow: 0 0 0 4px #fff, 0 0 18px 4px rgba(255, 255, 255, .6); animation: none; }
.sq.target::after {
  content: ''; position: absolute; inset: 32%; border-radius: 50%;
  background: rgba(246, 184, 15, .95); box-shadow: 0 0 0 4px rgba(246, 184, 15, .35);
  animation: pulse 1s ease-in-out infinite;
}
.sq.final::after { background: #fff; box-shadow: 0 0 0 4px rgba(255, 255, 255, .35); }
.sq.path::after { content: ''; position: absolute; inset: 38%; border-radius: 50%; background: rgba(255, 255, 255, .6); }
.sq.hint::before { content: ''; position: absolute; inset: 4%; border-radius: 50%; box-shadow: 0 0 0 4px #4ade80, 0 0 20px #4ade80; }
@keyframes pulse { 50% { transform: scale(.88); opacity: .65; } }

.pieces { position: absolute; inset: 0; pointer-events: none; }

/* bottle caps */
.cap {
  position: absolute;
  width: calc(var(--cell) * .84); height: calc(var(--cell) * .84);
  margin: calc(var(--cell) * .08);
  border-radius: 50%;
  transition: left .2s ease-in-out, top .2s ease-in-out, transform .2s, opacity .3s;
  /* crimped edge */
  background: repeating-conic-gradient(var(--c) 0 7.5deg, var(--cd) 7.5deg 15deg);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .45), 0 5px 8px rgba(0, 0, 0, .35);
  z-index: 2;
}
.cap::before {
  content: ''; position: absolute; inset: 10%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .55), transparent 38%), var(--c);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35), inset 0 -3px 4px rgba(0, 0, 0, .3);
}
.cap::after {
  content: attr(data-label); position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--font-display); color: #fff; font-size: calc(var(--cell) * .2);
  letter-spacing: .5px; text-shadow: 0 1px 0 rgba(0, 0, 0, .45);
}
.cap.a { --c: var(--p1); --cd: var(--p1d); }
.cap.b { --c: var(--p2); --cd: var(--p2d); }
/* king = two caps stacked */
.cap.king { box-shadow: 0 4px 0 var(--cd), 0 7px 0 rgba(0, 0, 0, .45), 0 10px 10px rgba(0, 0, 0, .35); transform: translateY(-3px); }
.cap.king::after { content: '♛'; font-family: serif; font-size: calc(var(--cell) * .42); color: var(--gold); text-shadow: 0 2px 0 rgba(0, 0, 0, .5); }
.cap.lifted { z-index: 10; transform: translateY(-6px) scale(1.12); box-shadow: 0 12px 14px rgba(0, 0, 0, .45); }
.cap.chopped { transform: scale(.2) rotate(200deg); opacity: 0; }
.cap.crowned { animation: crown .6s ease-out; }
@keyframes crown { 40% { transform: translateY(-14px) scale(1.25); } }

/* ---------- side panel ---------- */
.gist {
  background: rgba(6, 36, 25, .82); border-radius: 18px; padding: 16px;
  border: 2px solid rgba(255, 255, 255, .08);
  position: sticky; top: 12px;
}
.gist h2 { margin: 0 0 8px; font-family: var(--font-display); font-weight: 400; font-size: 22px; color: var(--gold); }
#log { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; display: flex; flex-direction: column-reverse; gap: 6px; }
#log li { font-size: 14px; line-height: 1.35; padding: 7px 10px; border-radius: 10px; background: rgba(255, 255, 255, .06); }
#log li.me { border-left: 4px solid var(--p1); }
#log li.them { border-left: 4px solid var(--p2); }
#log li.sys { border-left: 4px solid var(--gold); }
.record { margin-top: 12px; padding-top: 12px; border-top: 1px dashed rgba(255, 255, 255, .2); font-size: 13px; font-weight: 700; opacity: .85; }
.record b { color: var(--gold); }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(3, 18, 12, .72); backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.sheet {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--cream); color: var(--ink);
  border-radius: 22px; padding: 22px;
  box-shadow: 0 10px 0 var(--green), 0 10px 0 4px #fff, 0 30px 60px rgba(0, 0, 0, .5);
  animation: pop .25s ease-out;
}
.sheet.center { text-align: center; }
.sheet h2 { margin: 0 0 14px; font-family: var(--font-display); font-weight: 400; font-size: 30px; color: var(--green-deep); }
.sheet .btn.big { width: 100%; margin-top: 14px; }
.sheet .btn.ghost { background: #e9dcc0; color: var(--ink); box-shadow: 0 4px 0 #b9a77f; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.seg { display: flex; background: #eadfc6; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 10px; border-radius: 9px; font-weight: 800; cursor: pointer; color: #6a5a3c; }
.seg button.on { background: var(--green); color: #fff; box-shadow: 0 3px 0 #005434; }

.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.levels[hidden] { display: none; }
.level {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px;
  border: 3px solid transparent; background: #f3e8cf; border-radius: 14px; padding: 12px 8px; cursor: pointer;
}
.level .lv-ico { font-size: 34px; }
.level b { font-family: var(--font-display); font-weight: 400; font-size: 19px; color: var(--green-deep); }
.level small { font-size: 12px; color: #6a5a3c; font-weight: 700; }
.level.on { border-color: var(--green); background: #fff; box-shadow: 0 4px 0 var(--green); }

.row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.row label { width: 110px; font-weight: 900; color: var(--green-deep); flex: none; }
.row .seg { flex: 1; }
.row[hidden] { display: none; }

.rules { padding-left: 18px; margin: 0; line-height: 1.5; }
.rules li { margin-bottom: 8px; }
.over-ico { font-size: 64px; line-height: 1; }
#over-text { font-weight: 700; font-size: 17px; }
.over-score { font-family: var(--font-display); font-size: 22px; color: var(--green); min-height: 1em; }
.muted { color: #7a6a4c; }

.lb { width: 100%; border-collapse: collapse; font-size: 15px; }
.lb th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: #7a6a4c; padding: 6px; }
.lb td { padding: 8px 6px; border-top: 1px solid #eadfc6; font-weight: 700; }
.lb tr.me td { background: #e2f5e9; }
.lb .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .arena { grid-template-columns: 1fr; }
  .gist { position: static; }
  #log { max-height: 180px; }
}
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr auto; padding: 10px 16px; gap: 10px; }
  .brand { order: -1; grid-column: 1 / -1; }
  .actions { grid-column: 1 / -1; justify-content: center; }
  .startng-card { grid-column: 1 / -1; justify-self: center; }
  .arena { padding: 10px 16px 24px; }
  .btn { padding: 8px 11px; font-size: 13px; }
  .levels { grid-template-columns: 1fr; }
  .level { flex-direction: row; text-align: left; gap: 10px; }
  .level .lv-ico { font-size: 28px; }
  .row { flex-direction: column; align-items: stretch; gap: 6px; }
  .row label { width: auto; }
  .btn-row { flex-direction: column; }
}
