/* The realistic option changes materials, never the rules or fitted geometry. */
#board .board-appearance {
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  width: 100%;
  max-width: 940px;
  margin: 0 auto 18px;
  padding: 10px 12px;
  border: 1px solid #cbb991;
  border-radius: 12px;
  background: #fffaf0;
  color: #263d48;
}
#board .board-appearance label { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: .82rem; font-weight: 650; }
#board .board-appearance .select { min-height: 44px; max-width: 100%; background: #fffdf7; border-color: #b8ac92; }
#board .board-appearance .btn { min-height: 44px; padding: 8px 12px; font-size: .8rem; }
#board #board-art-status { flex: 1 1 260px; margin: 0; font-size: .78rem; line-height: 1.5; overflow-wrap: anywhere; }
#board .board-appearance [hidden] { display: none !important; }
#board .board-appearance :focus-visible { outline: 3px solid #075a8c; outline-offset: 3px; }
html.km-playing #board .board-appearance { flex: none; margin: 0; padding: 7px 10px; gap: 6px 10px; }

#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) {
  --board-walnut: #493329;
  --board-ivory: #f6e7c5;
  --board-brass: #c49b52;
  --board-blue: #075b8c;
}
/* Absolute photo layers do not provide a grid's intrinsic width. The viewport
   fitter owns width and height in playing mode; only ordinary pages need this. */
html:not(.km-playing) #board[data-board-style=living][data-board-ready=true] .game-grid-board { width: 100%; box-sizing: border-box; }
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) :is(.chess-grid, .checkers-grid) {
  border-color: #61412c;
  box-shadow: 0 3px 0 #33261e, 0 8px 18px #33261e33, inset 0 0 0 1px #dab174;
}
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) :is(.chess-grid, .checkers-grid) .cell {
  background-color: #eed8ae;
  background-image: linear-gradient(125deg, #fff8d64d, #bd91501c), var(--board-living-wood, linear-gradient(90deg, #efd8af, #e6cba0));
  background-size: cover, 280px 280px;
  color: #263a43;
}
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) :is(.chess-grid, .checkers-grid) .cell.dark {
  background-color: #75513d;
  background-image: linear-gradient(#4e2d258c, #4e2d258c), var(--board-living-wood, linear-gradient(110deg, #98734f, #754d38));
}
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) :is(.chess-grid, .checkers-grid) .cell:hover:not(:disabled) {
  background-image: linear-gradient(#fff4c94d, #fff4c94d), var(--board-living-wood, linear-gradient(110deg, #d5bc94, #a68862));
}
#board[data-chess-style=living] .chess-grid .coordinate { background: #fff9e7eb; color: #18354b; }
#board[data-chess-style=living] .chess-grid .cell.last-move {
  background-image: linear-gradient(#d6e9acb3, #d6e9acb3), var(--board-living-wood, linear-gradient(#d6e9ac, #bad39a));
}
#board[data-chess-style=living] .chess-grid .cell.dark.last-move {
  background-image: linear-gradient(#739261c7, #739261c7), var(--board-living-wood, linear-gradient(#87a66f, #739261));
}
#board[data-chess-style=living] .chess-grid .cell.in-check {
  background-image: linear-gradient(#eb948ad9, #eb948ad9), var(--board-living-wood, linear-gradient(#eb948a, #d57d72));
}
#board[data-chess-style=living] .chess-grid .cell.coach-from { box-shadow: inset 0 0 0 4px #075b8c; }
#board[data-chess-style=living] .chess-grid .cell.coach-to { box-shadow: inset 0 0 0 4px #c38214; }

#board[data-board-style=living][data-board-ready=true] :is(.checker, .four-disc, .bg-checker, .domino-tile, .domino-back, .dice-button) { position: relative; isolation: isolate; }
#board .board-living-object, #board .board-living-ships { display: none; pointer-events: none; }
#board[data-board-style=living][data-board-ready=true] .board-living-object {
  position: absolute;
  display: block;
  z-index: 1;
  left: 50%;
  top: 50%;
  /* Runtime registers the actual source rectangle and sets a uniform contain
     size in pixels. Portrait domino views rotate after this calculation. */
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  transform: translate(-50%, -50%);
  background-image: var(--board-living-atlas);
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: auto;
  overflow: hidden;
}
#board[data-board-style=living][data-board-ready=true] .checker {
  box-sizing: border-box;
  border: 2px solid #a17a4f;
  background: radial-gradient(ellipse at 35% 20%, #98704d, #463029 68%, #281e1c);
  box-shadow: 0 3px 0 #271b15, 0 5px 7px #271b1540, inset 0 0 0 3px #cead735e;
}
#board[data-board-style=living][data-board-ready=true] .checker.white {
  border-color: #c7b286;
  background: radial-gradient(ellipse at 35% 20%, #fff9df, #e4d0aa 76%, #baa177);
  box-shadow: 0 3px 0 #ad8d5f, 0 5px 7px #271b1540, inset 0 0 0 3px #fffae18c;
}
#board[data-board-style=living][data-board-ready=true] .checker:has(.checker-crown) {
  border-bottom-width: 4px;
  box-shadow: 0 4px 0 #271b15, 0 6px 0 #b18a54, 0 8px 7px #271b1540;
}
#board[data-board-style=living][data-board-ready=true] .checker.white:has(.checker-crown) { box-shadow: 0 4px 0 #ad8d5f, 0 6px 0 #f4e2b8, 0 8px 7px #271b1540; }
#board[data-board-style=living][data-board-ready=true] .checker-crown { position: relative; z-index: 3; filter: drop-shadow(0 1px 1px #24140b99); }
#board[data-board-style=living][data-board-ready=true] .reversi-grid {
  border: 5px solid #48382b;
  background: #153f33;
  border-radius: 11px;
  box-shadow: 0 3px 0 #2a231e, 0 8px 18px #1b2b2533;
}
#board[data-board-style=living][data-board-ready=true] .reversi-grid .cell {
  background: radial-gradient(ellipse at 0 0, #285e47, #1d4b3a);
  border-color: #72867466;
  border-radius: 1px;
}
#board[data-board-style=living][data-board-ready=true] .reversi-grid .cell:hover:not(:disabled) { background: #346651; }
#board[data-board-style=living][data-board-ready=true] .reversi-grid .checker { border-color: #242629; background: radial-gradient(ellipse at 35% 20%, #52575b, #141a1d 80%); }
#board[data-board-style=living][data-board-ready=true] .reversi-grid .checker.white { border-color: #e4d6b7; background: radial-gradient(ellipse at 35% 20%, #fffdf0, #e7d9bd 80%); }
#board .reversi-grid .cell[data-board-last-move=true]::before { content: ''; position: absolute; z-index: 4; width: 84%; height: 84%; box-sizing: border-box; border: 2px solid #ffdc78; border-radius: 50%; box-shadow: 0 0 0 1px #193c31; pointer-events: none; }

#board[data-board-style=living][data-board-ready=true] .domino-chain {
  border: 1px solid #b09c7e;
  background-color: #8a6850;
  background-image: linear-gradient(#563a2559, #563a2559), var(--board-living-wood, linear-gradient(95deg, #9e7957, #7b5c44));
  background-size: cover, 420px 420px;
  box-shadow: inset 0 2px 4px #2d211833;
}
#board[data-board-style=living][data-board-ready=true] .domino-empty { color: #fff9e8; background: #382a22ba; border-radius: 5px; padding: 5px 8px; }
#board[data-board-style=living][data-board-ready=true] .domino-tile {
  overflow: hidden;
  border-color: #c4af8b;
  background: linear-gradient(155deg, #fffcf1, #f5e9cf 60%, #d3be98);
  box-shadow: 0 3px 0 #b59e77, 0 5px 7px #271b1533, inset 0 0 0 1px #fffcf1;
}
#board[data-board-style=living][data-board-ready=true] .domino-face { position: relative; z-index: 3; }
#board[data-board-style=living][data-board-ready=true] .board-living-object[data-board-object=domino-front] { transform: translate(-50%, -50%) rotate(90deg); }
#board[data-board-style=living][data-board-ready=true] .domino-face + .domino-face { border-left-color: #72593f; }
/* Rectangular face tracks keep their spacing; actual pips stay round. */
#board .domino-face .pip { width: 100%; height: auto; aspect-ratio: 1; place-self: center; }
#board[data-board-style=living][data-board-ready=true] .pip { background: #172b36; box-shadow: inset 0 1px 1px #0009; }
#board[data-board-style=living][data-board-ready=true] .domino-back {
  overflow: hidden;
  background: linear-gradient(120deg, #4f3b30, #886b49);
  border-color: #d4ba88;
  box-shadow: 0 2px 0 #443127;
}
#board[data-board-style=living][data-board-ready=true] .domino-hand button.playable .domino-tile { border-color: #a5650b; }
#board[data-board-style=living][data-board-ready=true] .domino-hand button.selected { border-color: #075b8c; background: #fff7daba; box-shadow: 0 0 0 1px #fffaf0; }

#board[data-board-style=living][data-board-ready=true] .four-grid {
  background-color: #795138;
  background-image: linear-gradient(#6c422a33, #6c422a33), var(--board-living-wood, linear-gradient(110deg, #b48050, #69452f));
  background-size: cover, 320px 320px;
  border-color: #553c2c;
  border-radius: 14px;
  box-shadow: 0 5px 0 #3a2a22, 0 9px 16px #1d2d3533;
}
#board[data-board-style=living][data-board-ready=true] .four-grid .cell {
  background: #24343b;
  border-color: #4a3020;
  box-shadow: inset 0 3px 5px #0a1418bb, 0 1px 0 #e8c38488;
}
#board[data-board-style=living][data-board-ready=true] .four-grid .cell:hover:not(:disabled) { background: #46616b; }
#board[data-board-style=living][data-board-ready=true] .four-disc { width: 94%; height: 94%; box-sizing: border-box; border: 2px solid #c28817; background: radial-gradient(ellipse at 35% 20%, #ffe88e, #e6ae26 70%, #b57d0c); box-shadow: inset 0 0 0 3px #fff4c95c, 0 2px 3px #14222955; }
#board[data-board-style=living][data-board-ready=true] .four-disc.second { border-color: #a84260; background: radial-gradient(ellipse at 35% 20%, #ffc5d4, #d9668d 70%, #a13c60); }
/* A winning line is readable in either appearance and never relies on colour. */
#board .four-grid .cell[data-board-winning=true]::after { content: '✓'; position: absolute; z-index: 5; right: 3%; bottom: 3%; display: grid; place-items: center; width: 35%; height: 35%; border-radius: 50%; background: #fff9e4; border: 1px solid #213d48; color: #173c2d; font: 800 .65em system-ui; pointer-events: none; }
#board .four-grid .cell[data-board-winning=true] { outline: 3px solid #fff4b3; outline-offset: -4px; }

#board[data-board-style=living][data-board-ready=true] .bg-board {
  border-color: #59402d;
  background-color: #8d6748;
  background-image: linear-gradient(#3c281c33, #3c281c33), var(--board-living-wood, linear-gradient(90deg, #b0885d, #775336));
  background-size: cover, 340px 340px;
  box-shadow: 0 3px 0 #39291d, 0 8px 18px #33261e33, inset 0 0 0 1px #dabb80;
}
#board[data-board-style=living][data-board-ready=true] .bg-point { background: linear-gradient(90deg, #eedbb2, #f5e5c5 45%, #e8cea6); }
#board[data-board-style=living][data-board-ready=true] .bg-point::before { background: linear-gradient(90deg, #774637, #a36850 50%, #704133); }
#board[data-board-style=living][data-board-ready=true] .bg-point:nth-child(even)::before { background: linear-gradient(90deg, #244843, #426959 50%, #20443e); }
#board[data-board-style=living][data-board-ready=true] .bg-point:nth-child(6), #board[data-board-style=living][data-board-ready=true] .bg-point:nth-child(18) { border-right-color: #715135; }
#board[data-board-style=living][data-board-ready=true] .bg-checker { box-sizing: border-box; border-color: #b49a73; background: radial-gradient(ellipse at 35% 20%, #fff7df, #dcc7a2 80%); box-shadow: 0 2px 0 #a88b63, 0 3px 4px #241c1b55; }
#board[data-board-style=living][data-board-ready=true] .bg-checker.second { border-color: #9b7750; background: radial-gradient(ellipse at 35% 20%, #916e4e, #422c25 80%); box-shadow: 0 2px 0 #38281e, 0 3px 4px #241c1b55; }
/* A crowded stack must not push its count onto the point-number strip. Keep
   the count at the stack's outer end, opposite the point number, in either
   appearance. The badge overlays a disc without consuming stack height. */
#board .bg-point .bg-count { position: absolute; top: 2px; right: 1px; bottom: auto; z-index: 4; box-sizing: border-box; max-width: 100%; margin: 0; padding: 1px 3px; line-height: 1.15; pointer-events: none; }
#board .bg-point.bottom .bg-count { top: auto; bottom: 2px; }
#board[data-board-style=living][data-board-ready=true] .bg-number { background: #fff7e3eb; color: #183443; }
#board[data-board-style=living][data-board-ready=true] .bg-count { background: #163b47; color: #fffdf0; box-shadow: 0 0 0 1px #fff8e1; }
#board[data-board-style=living][data-board-ready=true] .bg-details { color: inherit; }
#board[data-board-style=living][data-board-ready=true] .dice-button { overflow: hidden; background: linear-gradient(145deg, #fffdf3, #e4d2ad); border-color: #ad9469; box-shadow: 0 2px 0 #99825d, 0 4px 5px #33261e33; }
#board[data-board-style=living][data-board-ready=true] .dice-button .board-living-mark { position: relative; z-index: 3; color: #163745; font-weight: 800; text-shadow: 0 1px 0 #fffaf0; }
#board[data-board-style=living][data-board-ready=true] .dice-button.selected { border-color: #075b8c; box-shadow: 0 0 0 2px #075b8c, 0 0 0 4px #fffaf0; }

#board[data-board-style=living][data-board-ready=true] .battle-grid {
  position: relative;
  isolation: isolate;
  background: radial-gradient(ellipse at 30% 10%, #b8e3de88, transparent 65%), linear-gradient(145deg, #2d7380, #285568);
  border: 2px solid #547884;
  border-radius: 5px;
  box-shadow: 0 3px 0 #244553, 0 7px 14px #183a4633;
  overflow: hidden;
}
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell { z-index: 2; border-color: #7199a78c; color: #112f3b; border-radius: 1px; background: linear-gradient(150deg, #cce6e45c, #467c942b); }
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell:hover:not(:disabled) { background: #ffebb3c9; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .fleet { background: linear-gradient(145deg, #ccddde, #738d96); color: #294451; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .fleet:not(.hit):not(.sunk) { background: #b8dce31a; border-color: #244e65b3; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .fleet:not(.hit) > .board-living-mark { opacity: 0; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .board-living-mark { position: relative; z-index: 3; pointer-events: none; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .hit { background: #ffc2bccc; color: #721c26; font-weight: 850; text-shadow: 0 1px 0 #ffebe2; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .miss { background: #deedf0d4; color: #234b5c; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .sunk { background: #983a4bea; color: #fff8e8; text-shadow: none; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell.chosen-ship { outline: 3px solid #ffcf65; outline-offset: -4px; }
#board[data-board-style=living][data-board-ready=true] .sea-columns span, #board[data-board-style=living][data-board-ready=true] .sea-rows span { color: inherit; font-weight: 800; }
#board[data-board-style=living][data-board-ready=true] .fleet-setup { background: #fff9eae8; color: #23404e; border-color: #9cabac; }
#board[data-board-style=living][data-board-ready=true] .board-living-ships { position: absolute; display: block; z-index: 1; inset: 0; }
#board[data-board-style=living][data-board-ready=true] .board-living-ship { position: absolute; width: var(--board-ship-long); height: var(--board-ship-short); pointer-events: none; }
#board[data-board-style=living][data-board-ready=true] .board-living-ship[data-ship-axis=v] { width: var(--board-ship-short); height: var(--board-ship-long); }
#board[data-board-style=living][data-board-ready=true] .board-living-ship::before { content: ''; position: absolute; inset: 28% 3%; border: 1px solid #bbced183; border-radius: 42% 22% 22% 42%; background: linear-gradient(#c0cfd06b, #47707b8c); box-shadow: 0 1px 2px #0d293c55; pointer-events: none; }
#board[data-board-style=living][data-board-ready=true] .board-living-ship[data-ship-axis=v]::before { inset: 3% 28%; border-radius: 42% 42% 22% 22%; background: linear-gradient(90deg, #c0cfd06b, #47707b8c); }
#board[data-board-style=living][data-board-ready=true] .board-living-ship[data-ship-axis=v] .board-living-object { transform: translate(-50%, -50%) rotate(90deg); }

/* Put interaction evidence above material layers. */
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) .cell.selected { box-shadow: inset 0 0 0 3px #075b8c, inset 0 0 0 5px #fff9e7; }
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) .cell.legal::after { z-index: 5; background: #075b8c; box-shadow: 0 0 0 2px #fff9e7; }
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) .cell.legal:has(:is(.checker, .chess-piece))::after { background: transparent; border: 3px solid #ffd46f; box-shadow: 0 0 0 1px #654515; }
#board[data-board-style=living][data-board-ready=true] .reversi-grid .cell.legal::after { background: #ffe09a; box-shadow: 0 0 0 2px #163e31; }
#board[data-board-style=living][data-board-ready=true] .bg-point.selected { outline: 3px solid #075b8c; outline-offset: -3px; }
#board[data-board-style=living][data-board-ready=true] .bg-point.legal { box-shadow: inset 0 0 0 3px #ffdb76, inset 0 0 0 5px #715011; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell.fleet-preview-valid, #board[data-board-style=living][data-board-ready=true] .battle-grid .cell.fleet-preview-valid:hover:not(:disabled) { background: #c6efd4e8; color: #174629; box-shadow: inset 0 0 0 3px #247642; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell.fleet-preview-invalid, #board[data-board-style=living][data-board-ready=true] .battle-grid .cell.fleet-preview-invalid:hover:not(:disabled) { background: #fbd3d5ed; color: #7d1728; box-shadow: inset 0 0 0 3px #b1283e; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell[data-preview=valid]::after, #board[data-board-style=living][data-board-ready=true] .battle-grid .cell[data-preview=invalid]::after { z-index: 4; }
#board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) :is(.cell, .bg-point, .domino-hand button):focus-visible { outline: 3px solid #075b8c; outline-offset: -3px; box-shadow: inset 0 0 0 5px #fff9e7; }
#board[data-board-style=living][data-board-ready=true] .battle-grid .cell[data-preview]:focus-visible { outline: 3px solid #075b8c; outline-offset: -3px; z-index: 4; }

html[data-km-contrast=high] #board .board-appearance { border: 2px solid #162e3a; background: #fffdf4; color: #142f3d; }
html[data-km-contrast=high] #board:is([data-board-style=living][data-board-ready=true], [data-chess-style=living]) .cell { border: 1px solid #12303a; }
html[data-km-contrast=high] #board[data-board-style=living][data-board-ready=true] .reversi-grid .cell { border-color: #d2ddc6; }
html[data-km-contrast=high] #board[data-board-style=living][data-board-ready=true] :is(.checker, .four-disc, .bg-checker) { outline: 1px solid #18323f; }
html[data-km-contrast=high] #board[data-board-style=living][data-board-ready=true] .battle-grid .hit { background: #ffb5b5; color: #650616; }
html[data-km-contrast=high] #board[data-board-style=living][data-board-ready=true] .battle-grid .miss { background: #edf6f8; color: #153b4a; }
html[data-km-contrast=high] #board[data-board-style=living][data-board-ready=true] .battle-grid .sunk { background: #75172e; color: #fff; }
html[data-km-contrast=high] #board[data-board-style=living][data-board-ready=true] .fleet-setup { background: #fffdf4; border: 2px solid #18323f; }
html[data-km-contrast=high] #board[data-chess-style=living] .chess-grid .coordinate { background: #fff; color: #102837; }
html[data-km-size=largest] #board .board-appearance label { font-size: .95rem; }
html[data-km-size=largest] #board #board-art-status { font-size: .85rem; }
@media (max-width: 540px) {
  #board .board-appearance { padding: 9px; gap: 7px; margin-bottom: 14px; }
  #board .board-appearance label { flex: 0 1 auto; }
  #board .board-appearance .select { flex: 1 1 130px; min-width: 0; }
  #board #board-art-status { flex-basis: 100%; }
  #board[data-board-style=living][data-board-ready=true] .reversi-grid { border-width: 4px; padding: 4px; }
}
@media (max-height: 500px) and (min-width: 540px) {
  html.km-playing #board .board-appearance { padding: 5px 8px; gap: 5px 10px; }
  html.km-playing #board #board-art-status { flex-basis: 220px; font-size: .72rem; }
}
@media (prefers-reduced-motion: reduce) { #board .board-living-object { animation: none !important; transition: none !important; } }
