/* Backgammon: game styles. Colors and fonts come from ../shared/eg-theme.css */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 20px;
  line-height: 1.45;
}
[hidden] { display: none !important; }

.noscript { margin: 16px; padding: 16px; border: 2px solid var(--ink); border-radius: 12px; background: #FBF6EA; color: #1F3246; }

:focus-visible { outline: 4px solid var(--mid); outline-offset: 2px; }
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; }

/* ---------- extra colors used only by this game ---------- */
:root {
  --board: #FBF6EA;
  --ptA: #D2BB8C;
  --ptB: #9C7C4E;
  --you-fill: #FFFDF6;
  --you-mark: #E0792B;
  --cpu-fill: #1F3246;
  --cpu-mark: #F4EBD9;
  --checker-edge: #1F3246;
  --hint: #1F5FA8;
  --die: #FFFFFF;
}
:root[data-contrast="high"] {
  --board: #FFFFFF;
  --ptA: #D4D4D4;
  --ptB: #7A7A7A;
  --you-fill: #FFFFFF;
  --you-mark: #000000;
  --cpu-fill: #000000;
  --cpu-mark: #FFFFFF;
  --checker-edge: #000000;
  --hint: #0B5394;
  --die: #FFFFFF;
}

/* ---------- header and settings ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px 4px;
}
.name-block { min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 12px; }
.name { margin: 0; font-family: var(--font-head); font-weight: 800; font-size: 30px; line-height: 1.15; }
.kind { margin: 0; white-space: nowrap; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.kind::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--dot); border: 2px solid var(--ink); flex: none; }

.textlink {
  color: var(--ink); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 4px;
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; white-space: nowrap;
}
.linkbtn { background: none; border: 0; cursor: pointer; }

.settings {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 4px 16px 10px; border-bottom: 2px solid var(--rule);
}
.settings-label { font-size: 18px; margin-right: 2px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 52px; padding: 8px 16px;
  font: inherit; font-weight: 700; font-size: 20px; line-height: 1.2;
  color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: 12px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn.small { min-height: 46px; font-size: 18px; padding: 6px 14px; }
.btn.primary { background: var(--ink); color: var(--card); }
.btn[aria-disabled="true"] { opacity: 0.5; border-style: dashed; cursor: default; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--card); }
.btn.attn { outline: 5px solid var(--dot); outline-offset: 2px; }
.btn.bigact { min-height: 64px; font-size: 24px; padding: 8px 28px; font-family: var(--font-head); font-weight: 800; }

/* ---------- layout ---------- */
main { padding: 12px 6px 40px; max-width: 1180px; margin: 0 auto; }
.h2 { margin: 8px 0 12px; font-family: var(--font-head); font-weight: 800; font-size: 30px; line-height: 1.15; }
.titlerow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.titlerow .h2 { font-size: 26px; margin: 4px 0; }
.panel { background: var(--card); border: 2px solid var(--rule); border-radius: 20px; padding: 4px 18px; margin: 0 0 12px; max-width: 760px; }
.howto { margin: 14px 0; font-size: 20px; }
.note { margin: 10px 0 0; font-size: 18px; }
.legend { margin-top: 8px; }
.pips { margin-top: 4px; }
.turn-note { padding: 8px 12px; border: 2px solid var(--ink); border-radius: 12px; background: var(--card); max-width: 760px; }

details.howto-panel { padding: 0 18px; }
details.howto-panel summary {
  min-height: 52px; display: flex; align-items: center; cursor: pointer;
  font-family: var(--font-head); font-weight: 800; font-size: 24px;
}
details.howto-panel[open] summary { border-bottom: 2px solid var(--rule); margin-bottom: 4px; }

/* ---------- dice, messages ---------- */
.status { padding: 10px 14px; max-width: none; }
.statusline { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.statusbtns { display: flex; gap: 8px; }
.dice { display: flex; align-items: center; gap: 10px; min-height: 64px; }
.dice .who { font-size: 18px; font-weight: 700; margin-right: 2px; }
.die { width: 60px; height: 60px; flex: none; display: block; }
.die rect { fill: var(--die); stroke: var(--ink); stroke-width: 3; }
.die circle { fill: var(--ink); }
.die.used { opacity: 0.35; }
.die.used rect { stroke-dasharray: 6 5; }
.msg { margin: 8px 0 2px; font-size: 20px; line-height: 1.35; min-height: 1.35em; }

/* ---------- the board ---------- */
.board-wrap {
  background: var(--iconbg); border: 2px solid var(--ink); border-radius: 16px;
  padding: 3px; overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom;
}
.board { position: relative; margin: 0 auto; background: var(--board); border-radius: 10px; }

.lbl {
  position: absolute; margin: 0; font-size: 16px; line-height: 1.1; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: clip;
}
.lbl.right { text-align: right; }

.pt {
  position: absolute; margin: 0; padding: 0; border: 0; background: transparent;
  font: inherit; color: var(--ink); cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.pt::before {
  content: ""; position: absolute; left: 6%; right: 6%; top: 0; bottom: 0;
  background: var(--tri); pointer-events: none;
}
.pt.up::before { clip-path: polygon(0 0, 100% 0, 50% 100%); }
.pt.down::before { clip-path: polygon(0 100%, 100% 100%, 50% 0); }
.pt.a { --tri: var(--ptA); }
.pt.b { --tri: var(--ptB); }

.bar-col, .tray {
  position: absolute; margin: 0; padding: 0; border: 2px solid var(--ink); border-radius: 8px;
  background: var(--iconbg); font: inherit; color: var(--ink);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.bar-col { border-radius: 0; border-top: 0; border-bottom: 0; }
button.bar-col, button.tray { cursor: pointer; }
.tray { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-align: center; line-height: 1.1; font-weight: 700; }
.tray .tn { font-family: var(--font-head); font-weight: 800; font-size: 30px; }
.tray .tl { font-size: 16px; }

/* a checker: light with an orange ring is yours, dark with a light diamond is the computer's */
.ck {
  position: absolute; border-radius: 50%; pointer-events: none;
  border: 3px solid var(--checker-edge);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-weight: 800; line-height: 1;
}
.ck.you { background: var(--you-fill); color: var(--checker-edge); }
.ck.you::after {
  content: ""; width: 52%; height: 52%; border-radius: 50%; border: 4px solid var(--you-mark); box-sizing: border-box;
}
.ck.cpu { background: var(--cpu-fill); color: var(--cpu-mark); }
.ck.cpu::after {
  content: ""; width: 34%; height: 34%; background: var(--cpu-mark); transform: rotate(45deg);
}
.ck.has-n::after { display: none; }
.ck .n { font-size: 0.5em; }
.ck.ghost { background: transparent; border: 3px dashed var(--accent-text); }
.ck.ghost::after { display: none; }

.pt.plain::before { display: none; }
.pt.can::after {
  content: ""; position: absolute; left: 28%; right: 28%; height: 7px; border-radius: 4px;
  background: var(--dot); pointer-events: none;
}
.pt.up.can::after { bottom: 4px; }
.pt.down.can::after { top: 4px; }
.pt.plain.can::after { top: auto; bottom: 4px; left: 20%; right: 20%; }
.pt.sel { outline: 5px solid var(--dot); outline-offset: -2px; border-radius: 6px; }
.bar-col.sel, .tray.sel { outline: 5px solid var(--dot); outline-offset: -2px; }
.pt.dest, .tray.dest { outline: 5px dashed var(--accent-text); outline-offset: -2px; border-radius: 6px; }
.pt.hint, .tray.hint, .bar-col.hint { outline: 6px solid var(--hint); outline-offset: -2px; border-radius: 6px; }
.pt.hintto, .tray.hintto { outline: 6px dashed var(--hint); outline-offset: -2px; border-radius: 6px; }
.pt.last, .tray.last { box-shadow: inset 0 0 0 4px var(--hint); border-radius: 6px; }
.nudge { animation: nudge 0.35s ease-in-out; }
@keyframes nudge { 0%, 100% { translate: 0 0; } 25% { translate: -5px 0; } 75% { translate: 5px 0; } }

/* ---------- buttons under the board ---------- */
.dock { margin-top: 10px; padding: 8px 0 max(8px, env(safe-area-inset-bottom)); border-top: 2px solid var(--rule); }
.controls { display: grid; gap: 8px; margin-top: 0; }
.controls.three-up { grid-template-columns: repeat(3, 1fr); }
.controls.two { grid-template-columns: 1fr 1fr; margin-top: 8px; }
.controls .btn { min-height: 56px; font-size: 19px; }
.levelrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.confirm { margin-top: 12px; }
.confirm-text { margin: 0 0 4px; font-size: 19px; }

/* ---------- game over ---------- */
.winp { margin-top: 16px; padding: 18px; }
.win-title { margin: 0 0 6px; font-family: var(--font-head); font-weight: 800; font-size: 36px; line-height: 1.1; }
.winp p { margin: 0 0 14px; }
.win-buttons { display: grid; gap: 8px; }
.win-buttons .btn { min-height: 56px; }

@media (max-height: 480px) {
  .bar { padding-top: 2px; padding-bottom: 0; }
  .name { font-size: 24px; }
  .settings { padding-bottom: 4px; }
  .titlerow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .nudge { animation: none; }
}

/* ---------- phone held sideways: everything fits on one screen ---------- */
.cells { position: absolute; left: 0; top: 0; right: 0; bottom: 0; }
.midctl { display: none; }
.midgrp { position: absolute; display: flex; align-items: center; gap: 6px; }
.compact .midctl { display: block; }
.compact .topbars { display: flex; align-items: center; gap: 6px; border-bottom: 2px solid var(--rule); padding: 0 8px; }
.compact .bar { padding: 0; flex: none; gap: 10px; }
.compact .kind { display: none; }
.compact .name { font-size: 22px; }
.compact .textlink { font-size: 17px; }
.compact .settings { border: 0; padding: 2px 0; flex: 1; flex-wrap: nowrap; justify-content: flex-end; gap: 6px; }
.compact .settings .btn.small { font-size: 16px; padding: 4px 10px; }
.compact .settings-label { font-size: 16px; }
.compact main { padding: 4px 4px 20px; }
.compact #screen-play { display: flex; flex-direction: column; }
.compact .titlerow, .compact #turn-note, .compact .statusline { display: none; }
.compact .howto-panel { order: 10; }
.compact #win-panel { display: none !important; }
.compact .status { padding: 2px 10px; margin: 0 0 4px; border-radius: 12px; }
.compact .msg { margin: 0; font-size: 16px; line-height: 1.3; min-height: 2.6em; }
.compact .dock { order: 1; margin-top: 6px; padding: 6px 0 4px; border-top: 0; }
.compact .legend, .compact .pips { order: 2; }
.compact .midctl .btn { min-height: 44px; font-size: 15px; padding: 2px 4px; white-space: nowrap; }
.compact #mid-right .btn { flex: none; padding: 2px 12px; font-size: 17px; }
.compact #mid-right .dice { flex: 1 1 auto; min-width: 0; min-height: 0; gap: 3px; }
.compact .dice .who { display: none; }
.compact .dice { overflow: hidden; }
.compact .die { width: 34px; height: 34px; }
