/* Backgammon — dark terminal/wood aesthetic */
:root {
  --bg: #1a0e0a;
  --surface: #2a1810;
  --surface2: #34201484;
  --text: #f5f0e8;
  --muted: #9e8a78;
  --border: #3e2723;
  --accent: #ffb300;
  --brass: #c9a96e;
  --danger: #e0645a;
  --good: #7fc97f;
  --ivory: #f3ead6;
  --felt-a: #5d3a1e;
  --felt-b: #4a2c16;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
}
h1, h2, h3, .brand { font-family: Georgia, "Times New Roman", serif; letter-spacing: 0.01em; }
h2 { color: var(--accent); margin: 0 0 0.6em; font-size: 1.6rem; }
h3 { color: var(--brass); margin: 1.6em 0 0.5em; font-size: 1.15rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }

/* ---------- top bar + tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
  background: #140906f2; border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
}
.brand { font-size: 1.25rem; color: var(--ivory); white-space: nowrap; }
.brand-mark { color: var(--accent); }
.tabs { display: flex; gap: 6px; }
.tabs button {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 0.95rem; cursor: pointer;
}
.tabs button.on { color: #1a0e0a; background: var(--accent); border-color: var(--accent); font-weight: 700; }

main { max-width: 1080px; margin: 0 auto; padding: 18px 14px 60px; }
.tab-panel[hidden] { display: none; }

/* ---------- panels, setup ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; max-width: 640px; margin: 0 auto;
}
.setup-grid { display: grid; gap: 18px; margin: 18px 0; }
.field label { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.field .hint { font-size: 0.82rem; color: var(--muted); margin: 6px 0 0; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  background: #1f120b; color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 10px 16px; font-size: 0.95rem; cursor: pointer; min-height: 44px;
}
.seg button.on { border-color: var(--accent); color: var(--accent); background: #2c1a0e; font-weight: 700; }
.setup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 18px; }

.btn-brass {
  background: linear-gradient(180deg, #d8b878, #b98f4e); color: #241207;
  border: 1px solid #8a6a35; border-radius: 10px;
  padding: 10px 18px; font-size: 0.95rem; font-weight: 700; cursor: pointer; min-height: 44px;
}
.btn-brass:disabled { opacity: 0.35; cursor: default; }
.btn-brass:not(:disabled):hover { filter: brightness(1.08); }
.btn-lg { font-size: 1.05rem; padding: 12px 26px; }
.btn-sm { padding: 6px 12px; min-height: 36px; font-size: 0.85rem; }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; font-size: 0.9rem; cursor: pointer; min-height: 44px;
}
.btn-ghost:disabled { opacity: 0.3; cursor: default; }
.btn-ghost:not(:disabled):hover { color: var(--text); border-color: var(--muted); }

.stats { border-top: 1px solid var(--border); padding-top: 14px; }
.stats h3 { margin-top: 0.8em; }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: #1f120b; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; flex: 1; min-width: 120px; }
.stat-d { display: block; text-transform: capitalize; color: var(--muted); font-size: 0.8rem; }
.stat-v { font-size: 1.15rem; font-weight: 700; color: var(--ivory); }
.match-list { display: grid; gap: 6px; }
.match-item { display: flex; justify-content: space-between; gap: 10px; font-size: 0.88rem; color: var(--muted); background: #1f120b; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }

button:focus-visible,
.seg button:focus-visible,
.pt:focus-visible,
.bar-slot:focus-visible,
#offTray:focus-visible,
.hint:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- game layout ---------- */
.game { display: flex; flex-direction: column; gap: 12px; }
.g-top { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.pcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.pcard .pc-name { font-family: Georgia, serif; font-size: 1.05rem; }
.pcard .pc-pip { color: var(--muted); font-size: 0.85rem; }
.pcard.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 18px #ffb30033; }
.pcard.active .pc-name::before { content: "▸ "; color: var(--accent); }
.cube-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; justify-content: center; }
.cube {
  width: 56px; height: 56px; border-radius: 10px;
  background: linear-gradient(145deg, #3a2417, #241209);
  border: 2px solid var(--brass); color: var(--ivory);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 800; font-family: Georgia, serif;
}
.cube.mine { border-color: var(--accent); box-shadow: 0 0 12px #ffb30055; }
.cube-owner { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.g-main { display: grid; grid-template-columns: 1fr 300px; gap: 14px; align-items: start; }
.board-wrap { min-width: 0; }
.board-tip { color: var(--muted); font-size: 0.82rem; margin: 8px 2px 0; }

/* ---------- board ---------- */
.board {
  display: flex; width: 100%; aspect-ratio: 16 / 10.2;
  background: linear-gradient(160deg, #6b421f, #4a2a12 60%, #3a2010);
  border: 10px solid #241309; border-radius: 12px;
  box-shadow: inset 0 0 40px #00000088, 0 8px 30px #00000066;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.b-half { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.b-row { flex: 1; display: flex; min-height: 0; }
.pt { flex: 1; position: relative; min-width: 0; cursor: pointer; }
.tri { position: absolute; inset: 3px 2px; opacity: 0.5; }
.pt-a .tri { background: #d9b98a; }
.pt-b .tri { background: #7a4f28; }
.pt-top .tri { clip-path: polygon(0 0, 100% 0, 50% 100%); }
.pt-bot .tri { clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.pt.lm .tri { opacity: 0.85; filter: brightness(1.25); }
.pt.sel .tri { opacity: 0.95; filter: brightness(1.5) sepia(0.4); }
.cks { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }
.pt-top .cks { justify-content: flex-start; padding-top: 5px; }
.pt-bot .cks { justify-content: flex-end; padding-bottom: 5px; }
.ck {
  width: 92%; aspect-ratio: 1; border-radius: 50%;
  box-shadow: 0 2px 4px #00000088, inset 0 -2px 4px #00000044;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 800; color: #1a0e0a;
  margin: -1px 0;
}
.ck-w { background: radial-gradient(circle at 35% 30%, #fffdf4, #e9dcc0 70%, #cbb488); border: 2px solid #7d5f31; }
.ck-b { background: radial-gradient(circle at 35% 30%, #5a5a5a, #232323 70%, #0c0c0c); border: 2px solid #000; color: #f5f0e8; }
.ck-mini { width: 30px; margin: 1px 0; }
.ck-count { font-size: 0.8rem; }
.destm {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 26%; aspect-ratio: 1; border-radius: 50%;
  background: var(--accent); opacity: 0.9; box-shadow: 0 0 10px var(--accent);
  pointer-events: none; animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.25); opacity: 0.6; } }
.plab {
  position: absolute; font-size: 9px; color: #f5f0e8aa; pointer-events: none;
  left: 50%; transform: translateX(-50%);
}
.pt-top .plab { top: 1px; }
.pt-bot .plab { bottom: 1px; }
.b-bar {
  flex: 0 0 46px; display: flex; flex-direction: column;
  background: #1d0f08; border-left: 1px solid #00000066; border-right: 1px solid #00000066;
}
.bar-slot { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; cursor: pointer; border-radius: 6px; }
.bar-slot.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.bar-label { text-align: center; font-size: 9px; letter-spacing: 0.2em; color: var(--muted); padding: 2px 0; }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.dice-box { display: flex; gap: 8px; align-items: center; min-height: 56px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
.dice-hint { color: var(--muted); font-size: 0.88rem; }
.die {
  width: 46px; height: 46px; border-radius: 9px; padding: 7px;
  background: linear-gradient(145deg, #fffdf4, #e6d7b8);
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  box-shadow: 0 3px 8px #00000066; animation: diein 0.25s ease-out;
}
@keyframes diein { from { transform: translateY(-8px) rotate(-12deg); opacity: 0; } }
.die-used { opacity: 0.28; filter: grayscale(0.7); animation: none; }
.pip { border-radius: 50%; }
.pip.on { background: #241207; }
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.controls #rollBtn { grid-column: 1 / -1; }
.ai-note { color: var(--accent); font-size: 0.9rem; animation: pulse 1.4s infinite; }

.hints { background: #1e2a1400; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.hints[hidden] { display: none; }
.hints-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.hint { background: #241309; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; cursor: pointer; }
.hint:hover { border-color: var(--accent); }
.hint-top { border-color: var(--brass); }
.hint-move { font-weight: 700; color: var(--ivory); font-family: Georgia, serif; }
.hint-why { font-size: 0.83rem; color: var(--muted); margin-top: 2px; }

.match-score { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; font-size: 0.9rem; }
.match-score[hidden] { display: none; }
.match-score .craw { color: var(--accent); }

.trays .tray {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 12px; cursor: pointer;
}
.tray.dest-tray { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 16px #ffb30044; animation: pulse 1.2s infinite; }
.tray-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 4px; }
.tray-row { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.tray-who { font-size: 0.82rem; color: var(--muted); width: 74px; }
.tray-slot { display: flex; align-items: center; gap: 2px; flex: 1; }
.tray-count { font-size: 0.8rem; color: var(--muted); }

.log {
  background: #160b06; border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; height: 220px; overflow-y: auto; font-size: 0.83rem;
  display: flex; flex-direction: column; gap: 3px;
}
.log-line { color: var(--muted); }
.log-line:last-child { color: var(--text); }

/* ---------- modal ---------- */
#overlay {
  position: fixed; inset: 0; background: #000000bb; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
#overlay[hidden] { display: none; }
.modal {
  background: var(--surface); border: 1px solid var(--brass); border-radius: 16px;
  padding: 24px; max-width: 440px; width: 100%; box-shadow: 0 20px 60px #000;
}
.modal h3 { margin-top: 0; color: var(--accent); }
.modal .score-line { font-size: 1.05rem; }
.modal-btns { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-btns button { flex: 1; }

/* ---------- article pages ---------- */
.article { max-width: 760px; margin: 0 auto; }
.article .lede { font-size: 1.08rem; color: var(--ivory); border-left: 3px solid var(--accent); padding-left: 14px; }
.article ul, .article ol { padding-left: 1.3em; }
.article li { margin-bottom: 0.45em; }
.odds { border-collapse: collapse; margin: 12px 0; font-size: 0.92rem; }
.odds th, .odds td { border: 1px solid var(--border); padding: 7px 12px; text-align: center; }
.odds th { background: #241309; color: var(--brass); font-weight: 600; }
.odds td { background: #1f120b; }
.back-link { margin-top: 2em; }

/* ---------- mini board diagrams ---------- */
.mini-board { margin: 14px 0; max-width: 520px; }
.mb-caption { font-size: 0.85rem; color: var(--brass); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.mb-board {
  display: grid; grid-template-columns: repeat(13, 1fr);
  background: #3a2412; border: 6px solid #241309; border-radius: 8px; overflow: hidden;
}
.mb-point { aspect-ratio: 5 / 7; position: relative; display: flex; flex-direction: column; align-items: center; }
.mb-a { background: #6b421f55; }
.mb-b { background: #2c1a0c55; }
.mb-top { justify-content: flex-start; }
.mb-bot { justify-content: flex-end; }
.mb-checker {
  width: 78%; aspect-ratio: 1; border-radius: 50%; margin: 1px 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 800; color: #1a0e0a;
}
.mb-w { background: radial-gradient(circle at 35% 30%, #fffdf4, #d9c9a4); border: 1px solid #7d5f31; }
.mb-b { background: radial-gradient(circle at 35% 30%, #5a5a5a, #141414); border: 1px solid #000; color: #f5f0e8; }
.mb-badge { font-size: 10px; font-weight: 800; color: var(--accent); }
.mb-bar { grid-row: 1 / 3; grid-column: 13; background: #1d0f08; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 2px; }
.mb-bar-c { width: 90%; }
.mb-plabel { font-size: 8px; color: #f5f0e866; line-height: 1; padding: 1px 0; }
.mb-note { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }

/* ---------- responsive ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 900px) {
  .g-main { grid-template-columns: 1fr; }
  .side { display: grid; grid-template-columns: 1fr 1fr; }
  .dice-box, .controls, .ai-note { grid-column: 1 / -1; }
  .log { height: 160px; }
}
@media (max-width: 560px) {
  .topbar { flex-direction: column; gap: 8px; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; padding: 10px 6px; }
  main { padding: 12px 8px 48px; }
  .board { border-width: 6px; }
  .b-bar { flex-basis: 34px; }
  .plab { display: none; }
  .side { grid-template-columns: 1fr; }
  .ck { font-size: 0.6rem; }
}
