:root{
  --bg:#faf8f6;
  --panel:#fff9f6;
  --muted:#6b7280;
  --accent:#8b5cf6;
  --accent-2:#f97316;
  --card:#fff;
  --board-bg:#fff6f8;
  --cell:#ffeef6;
  --castle:#d946ef;
  --belly:#fff1e6;
  --black:#111827;
  --yellow:#d97706;
  --red:#dc2626;
  --green:#15803d;
  --shadow: 0 8px 24px rgba(11,15,40,0.08);
  --grid-size:19;
  --cell-size:36px;
}
*{box-sizing:border-box}
body{
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  margin:0;
  background: linear-gradient(180deg, #fffaf9 0%, #fbfbff 100%);
  color:var(--black);
  -webkit-font-smoothing:antialiased;
}
.screen{display:none;min-height:100vh;align-items:center;justify-content:center;padding:28px}
.screen.active{display:flex}
.card{background:var(--card);border-radius:14px;padding:22px;box-shadow:var(--shadow);max-width:720px}

/* Splash */
.splash-card{width:420px;text-align:center}
.brand{font-size:38px;margin:4px 0;color:var(--accent)}
.tagline{color:var(--muted);margin-bottom:18px}
.field{display:flex;flex-direction:column;align-items:flex-start;gap:6px;margin:10px 0}
.field select{padding:10px;border-radius:8px;border:1px solid #eee;width:100%}
.actions{display:flex;gap:12px;justify-content:center;margin-top:18px}
.primary{background:linear-gradient(90deg,var(--accent),#7c3aed);color:white;border:0;padding:10px 14px;border-radius:12px;font-weight:700}
.link{background:transparent;border:0;color:var(--accent);text-decoration:underline;padding:6px}
.ghost{background:transparent;border:1px solid #eef2f7;padding:8px;border-radius:8px}

/* Game layout */
.topbar{display:flex;justify-content:space-between;align-items:center;padding:16px 28px;border-bottom:1px solid rgba(14,20,30,0.06);background:linear-gradient(180deg,#fff 0%, #fffaf6 100%)}
.brand-left{display:flex;flex-direction:column}
.logo{font-weight:800;color:var(--accent);font-size:20px}
.subtitle{font-size:12px;color:var(--muted)}
.controls-top{display:flex;gap:14px;align-items:center}
.player-status{font-weight:700;padding:8px 12px;border-radius:10px;background:linear-gradient(90deg,#fff,#fff7);border:1px solid #f1e6ff}
.throw-area{display:flex;flex-direction:column;gap:6px;align-items:center}
.cowrie-row{display:flex;gap:6px}
.cowrie{width:36px;height:36px;display:flex;align-items:center;justify-content:center;font-weight:700;border:1px solid rgba(11,16,40,0.06);background:white;border-radius:6px}
.cowrie.toss{ animation: toss 420ms ease; }
@keyframes toss { 0%{ transform: translateY(-6px) rotate(-12deg) scale(0.96) } 50%{ transform: translateY(0) rotate(6deg) scale(1.02) } 100%{ transform: translateY(0) rotate(0) scale(1) } }
.face-up{background:linear-gradient(180deg,#fff6e6,#fff1d6);border-color:#fde68a}
.face-down{background:linear-gradient(180deg,#eef2ff,#e6f0ff);border-color:#c7d2fe}
.throw-controls{display:flex;gap:10px;align-items:center}
.turn-badge{padding:8px 10px;border-radius:10px;background:linear-gradient(90deg,#fff,#fff9);border:1px solid #f1e6ff;font-weight:700}
.throwResult{margin-top:6px}
.guide{margin-top:6px;padding:8px;border-radius:8px;background:linear-gradient(90deg,#fff,#fff7);border:1px solid #f6f0ff;width:320px;text-align:center}

/* Main layout */
.main{display:flex;gap:16px;padding:20px;align-items:flex-start}
.board-area{flex:1;display:flex;align-items:center;justify-content:center}
.sidebar{width:320px}
.panel{background:var(--panel);padding:12px;border-radius:12px;border:1px solid rgba(14,20,30,0.03);margin-bottom:12px}
.turnInfo{padding:8px;background:linear-gradient(90deg,#fff,#fffbf7);border-radius:8px;border:1px solid #f3e9f6}

/* Board grid 19x19 to represent 3x8 arms with 3x3 center */
#board{
  width: calc(var(--cell-size) * var(--grid-size));
  height: calc(var(--cell-size) * var(--grid-size));
  display:grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0,1fr));
  grid-template-rows: repeat(var(--grid-size), minmax(0,1fr));
  gap:6px;
  background: linear-gradient(180deg,#fff,#fff8f7);
  padding:10px;border-radius:12px;border:2px solid rgba(14,20,30,0.04); /* stronger outer border */
  box-shadow: var(--shadow);
}

/* Generic cell */
.cell{
  background:var(--board-bg);
  border-radius:6px;
  display:flex;align-items:center;justify-content:center;
  position:relative;font-size:12px;height:var(--cell-size);
  box-shadow: inset 0 -2px 0 rgba(11,15,40,0.02);
  border: 1.5px solid rgba(17,24,39,0.06); /* increased contrast on each box */
}
.cell.empty{background:transparent;box-shadow:none;border-radius:0}

/* CHARKONI: emphasized, cleaner, with visible internal slots (center 3x3 already separate cells) */
.cell.charkoni{
  background: linear-gradient(180deg,#fff6fb,#fff);
  border: 4px solid rgba(139,92,246,0.10);
  box-shadow: 0 10px 24px rgba(139,92,246,0.05);
}

/* Roles */
.cell.castle{background:linear-gradient(180deg,#fff0f7,#fff);border:2px solid rgba(217,70,239,0.18)}
.cell.belly{background:var(--belly);border:1px dashed rgba(249,115,22,0.08)}
.cell.outer{background:linear-gradient(180deg,#fff,#fff6f6)}

.cell .cross{position:absolute;top:6px;left:6px;color:var(--castle);font-weight:800}
.cell .stack{position:absolute;right:6px;bottom:6px;background:rgba(0,0,0,0.06);padding:4px 6px;border-radius:6px;font-size:11px}

/* Pawn visuals: CLEAR SQUARES with visible color borders */
.pawn{
  width:28px;height:28px;border-radius:6px; /* subtle radius but square look */
  display:flex;align-items:center;justify-content:center;font-weight:700;
  background:#ffffff;
  box-shadow:0 6px 14px rgba(11,15,40,0.06);
  border:2px solid rgba(0,0,0,0.06);
  color:var(--black);
}
.pawn.small{width:20px;height:20px;font-size:11px;border-radius:4px}

/* strong colored borders for contrast */
.pawn-black{ border-color:var(--black); color:var(--black); background: #fff; }
.pawn-yellow{ border-color:var(--yellow); color:var(--yellow); background: #fff; }
.pawn-red{ border-color:var(--red); color:var(--red); background: #fff; }
.pawn-green{ border-color:var(--green); color:var(--green); background: #fff; }

.highlight{outline:4px solid rgba(139,92,246,0.14);transform:translateY(-2px);z-index:3}
.bad{opacity:0.45}

/* Turn highlight next to throw button */
.turn-badge{ display:flex;align-items:center;gap:8px; }
.turn-chip{width:18px;height:18px;border-radius:6px;box-shadow:0 2px 6px rgba(11,15,40,0.06)}
.turn-text{font-weight:700}

/* Legend swatches */
.legend{display:flex;flex-direction:column;gap:6px;margin-top:8px}
.legend-swatch{display:inline-block;width:16px;height:12px;border-radius:3px;margin-right:8px;vertical-align:middle}
.sw-black{background:var(--black)}
.sw-yellow{background:var(--yellow)}
.sw-red{background:var(--red)}
.sw-green{background:var(--green)}
.sw-castle{background:linear-gradient(90deg,var(--castle),#f3c2ff)}
.sw-belly{background:linear-gradient(90deg,#fff1e6,#fff6f0)}

/* small helpers */
.log{height:260px;overflow:auto;padding:8px;background:linear-gradient(180deg,#fff,#fffbf7);border-radius:8px;border:1px dashed rgba(14,20,30,0.03)}
.small{font-size:12px}
.muted{color:var(--muted)}
.tiny{font-size:12px}

/* Modal how to */
.modal{display:none;position:fixed;inset:0;align-items:center;justify-content:center;background:rgba(10,12,20,0.38)}
.modal .how-card{max-width:680px}
.modal.active{display:flex}

/* Responsive */
@media(max-width:980px){
  .main{flex-direction:column}
  .sidebar{width:100%}
  #board{width:100%;height:auto}
}