/*
 * Hnefatafl board (game 27), Copenhagen rules on an 11 by 11 board.
 *
 * Pure CSS plus the inline SVG sprite in views/play/27/_sprite.tt: no raster
 * image. MyMOO::Games::Hnefatafl::board_for_template hands the template one
 * record per square in reading order (rank 11 first) and the stylesheet turns
 * those records into a grid, so the browser never measures anything to place
 * a square or a piece.
 *
 * Grid geometry: the first track is the rank gutter and the first row the file
 * gutter. The other 11 tracks are equal (1fr) and aspect-ratio: 1 keeps the
 * board square, so every cell is square whatever width the panel hands it and
 * the board can never overflow a phone.
 */

/* --- the panel --- */

.bg-27-panel {
  /* One wood wash over the whole box, panel body and footer together, so the
   * two cannot drift apart at the join. Bootstrap's #f5f5f5 would paint over
   * it on the footer alone. */
  background-image:
    linear-gradient(180deg, rgba(58, 41, 25, .96), rgba(38, 26, 16, .98));
  border-color: rgba(24, 16, 9, .7);
  color: #e8dcc4;
}

.game27 {
  color: #e8dcc4;
}

.bg-27-top {
  padding-bottom: 12px;
}

.bg-27-title {
  font-size: 26px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 10px;
  color: #f2e6cc;
  letter-spacing: 2px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .85);
}

.bg-27-footer {
  margin-top: 12px;
  background-color: transparent;
  border-top-color: rgba(24, 16, 9, .55);
  color: #e8dcc4;
}

/* The seat list is a card per player, so its text goes back to dark. */
.bg-27-panel .list-group-item {
  color: #333;
}

/* --- the seat list --- */

.bg-27-dim {
  color: #7a7a7a;
  font-size: 12px;
}

.bg-27-flag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 3px;
  background: #d4a017;
  color: #2b1d12;
  font-size: 11px;
  font-weight: bold;
}

.list-group-item.bg-27-me {
  border-left: 4px solid #d4a017;
}

.list-group-item.bg-27-turn {
  background-color: #fdf6e3;
}

.list-group-item.bg-27-out s {
  color: #999;
}

/* The side swatch repeats the piece shape from the board, so the list and
 * the board can never disagree about which colour is which side. Seat 0 is
 * the shield, seat 1 the disc the king's side plays with. */
.bg-27-side {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  vertical-align: -3px;
}

.bg-27-side0 {
  background: radial-gradient(circle at 38% 30%, #5a5650, #2a2724 55%, #0f0d0c);
  clip-path: polygon(50% 2%, 97% 22%, 97% 56%, 50% 98%, 3% 56%, 3% 22%);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .5));
}

.bg-27-side1 {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fdf6e6, #e8d9b6 70%, #cbb98f);
  box-shadow: inset 0 0 0 2px rgba(120, 95, 55, .55);
}

/* --- the board (hnefatafl visual layer) --- */

/* ---------- tokens ---------- */
.hf {
  --hf-frame-a: #4a3520;
  --hf-frame-b: #1e140b;
  --hf-slate-a: #5d6166;
  --hf-slate-b: #3d4044;
  --hf-slate-c: #2c2f33;
  --hf-groove: rgba(8, 8, 10, .62);
  --hf-bevel: rgba(255, 255, 255, .07);
  --hf-brass: #b98a2e;
  --hf-verdigris: #4f8f7c;
  --hf-ember: #e0702f;
  --hf-gold-glow: 246, 223, 148;
  --hf-size: min(100%, 680px);
  --hf-piece: 84%;
  --hf-king: 94%;
  --hf-rune-corner: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' fill='none' stroke-linejoin='miter'><g stroke='%23c99a2e' stroke-width='6' stroke-linecap='square'><path d='M50 24 L68 42 L50 60 L32 42 Z'/><path d='M41 51 L32 74 M59 51 L68 74'/></g><g stroke='%236fb3a0' stroke-width='3.4' stroke-linecap='square'><path d='M50 17 V5 M43 11 L50 4 L57 11'/><path d='M46 83 V96 M46 88 L56 81 M46 94 L56 87'/><path d='M9 64 V38 M9 52 L3 43 M9 52 L15 43'/><path d='M91 40 L97 50 L91 60 L85 50 Z'/></g></svg>");
  --hf-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- board ---------- */
.hf-board {
  box-sizing: border-box;
  width: var(--hf-size);
  aspect-ratio: 1 / 1;
  margin-inline: auto;
  display: grid;
  grid-template-columns: var(--hf-gutter, 18px) repeat(11, 1fr);
  grid-template-rows: var(--hf-gutter, 18px) repeat(11, 1fr);
  padding: clamp(8px, 2.4%, 18px);
  border-radius: 10px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .08), transparent 40%),
    var(--hf-grain),
    linear-gradient(160deg, var(--hf-frame-a), var(--hf-frame-b));
  background-blend-mode: normal, soft-light, normal;
  box-shadow:
    0 28px 50px -12px rgba(0, 0, 0, .75),
    0 8px 14px rgba(0, 0, 0, .5),
    inset 0 2px 0 rgba(255, 255, 255, .12),
    inset 0 -3px 6px rgba(0, 0, 0, .55);
  /* the playing surface sits in a recess of the frame */
  position: relative;
}
.hf-board::before {
  content: "";
  position: absolute;
  inset: clamp(8px, 2.4%, 18px);
  border-radius: 3px;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, .7), 0 0 0 1px rgba(0, 0, 0, .8);
  pointer-events: none;
  z-index: 3;
}

/* ---------- cells: carved grooves ---------- */
.hf-cell {
  position: relative;
  display: grid;
  place-items: center;
  background:
    var(--hf-grain),
    radial-gradient(120% 120% at 30% 25%, var(--hf-slate-a), var(--hf-slate-b) 55%, var(--hf-slate-c));
  background-blend-mode: soft-light, normal;
  /* thin recessed line: dark upper-left groove, light lower-right lip */
  box-shadow:
    inset 1px 1px 0 var(--hf-groove),
    inset -1px -1px 0 var(--hf-bevel),
    inset 3px 3px 6px rgba(0, 0, 0, .35),
    inset -2px -2px 4px rgba(255, 255, 255, .03);
  transition: background-color .15s, box-shadow .15s;
}

/* ---------- special squares ---------- */
.hf-cell--throne,
.hf-cell--corner { isolation: isolate; }

.hf-cell--throne::before,
.hf-cell--corner::before {
  content: "";
  position: absolute;
  inset: 9%;
  z-index: 0;
  pointer-events: none;
}

/* throne: carved bronze diamond with an inner rune cross */
.hf-cell--throne {
  background:
    var(--hf-grain),
    radial-gradient(circle at 50% 50%, #6b5a38, #3c3422 70%, #2a2418);
  background-blend-mode: soft-light, normal;
}
.hf-cell--throne::before {
  border: 2px solid var(--hf-brass);
  transform: rotate(45deg) scale(.78);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, .55),
    inset 0 0 10px rgba(0, 0, 0, .6),
    0 0 8px rgba(185, 138, 46, .35);
}
.hf-cell--throne::after {
  content: "";
  position: absolute;
  inset: 30%;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(var(--hf-brass), var(--hf-brass)) center / 2px 100% no-repeat,
    linear-gradient(var(--hf-brass), var(--hf-brass)) center / 100% 2px no-repeat;
  opacity: .55;
}

/* corner exits: verdigris-stained oxidized brass, notched frame */
.hf-cell--corner {
  background:
    var(--hf-grain),
    radial-gradient(circle at 50% 50%, #3f5f55, #26373a 70%, #1b2528);
  background-blend-mode: soft-light, normal;
}
.hf-cell--corner::before {
  border: 2px solid var(--hf-verdigris);
  clip-path: polygon(0 18%, 18% 0, 82% 0, 100% 18%, 100% 82%, 82% 100%, 18% 100%, 0 82%);
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, .5), inset 0 0 12px rgba(0, 0, 0, .65);
}
.hf-cell--corner::after {
  content: "";
  position: absolute;
  inset: 14%;
  z-index: 0;
  pointer-events: none;
  background: var(--hf-rune-corner) center / contain no-repeat;
  /* carved look: dark under-edge plus a faint brass glow */
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .8)) drop-shadow(0 0 4px rgba(201, 154, 46, .35));
}

/* ---------- pieces ---------- */
.hf-piece {
  position: relative;
  z-index: 1;
  width: var(--hf-piece);
  height: var(--hf-piece);
  display: block;
  pointer-events: none;
  transition: transform .18s cubic-bezier(.2, .8, .3, 1), filter .18s;
  /* contact shadow tight, cast shadow soft: the token rests on the slab */
  filter:
    drop-shadow(0 1px 0 rgba(0, 0, 0, .8))
    drop-shadow(0 3px 3px rgba(0, 0, 0, .55))
    drop-shadow(0 8px 10px rgba(0, 0, 0, .4));
}
.hf-piece--king {
  width: var(--hf-king);
  height: var(--hf-king);
  filter:
    drop-shadow(0 1px 0 rgba(0, 0, 0, .85))
    drop-shadow(0 4px 4px rgba(0, 0, 0, .6))
    drop-shadow(0 10px 14px rgba(0, 0, 0, .5))
    drop-shadow(0 0 6px rgba(var(--hf-gold-glow), .25));
}

/* ---------- states ---------- */
.cell-hover,
.hf-cell.is-interactive:hover {
  cursor: pointer;
  background-color: rgba(var(--hf-gold-glow), .1);
  box-shadow:
    inset 1px 1px 0 var(--hf-groove),
    inset -1px -1px 0 var(--hf-bevel),
    inset 0 0 14px rgba(var(--hf-gold-glow), .22),
    inset 0 0 0 1px rgba(var(--hf-gold-glow), .25);
}

.piece-selected {
  transform: translateY(-6%) scale(1.07);
  filter:
    drop-shadow(0 1px 0 rgba(0, 0, 0, .8))
    drop-shadow(0 8px 6px rgba(0, 0, 0, .5))
    drop-shadow(0 16px 16px rgba(0, 0, 0, .45))
    drop-shadow(0 0 7px rgba(var(--hf-gold-glow), .85));
}
.hf-cell:has(> .piece-selected) {
  box-shadow:
    inset 1px 1px 0 var(--hf-groove),
    inset 0 0 0 2px rgba(var(--hf-gold-glow), .85),
    inset 0 0 18px rgba(var(--hf-gold-glow), .35);
}

.valid-move-target { cursor: pointer; }
.valid-move-target::after {
  content: "";
  position: absolute;
  z-index: 2;
  width: 26%;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(var(--hf-gold-glow), .95), rgba(185, 138, 46, .75));
  box-shadow:
    0 0 0 3px rgba(0, 0, 0, .35),
    0 0 10px rgba(var(--hf-gold-glow), .6),
    inset 0 1px 1px rgba(255, 255, 255, .6);
  animation: hf-pulse 1.4s ease-in-out infinite;
}
.valid-move-target:hover {
  background-color: rgba(var(--hf-gold-glow), .14);
}
/* throne and corner paint runes in ::after, so a target there rings the square instead of adding a dot */
.hf-cell--throne.valid-move-target::after {
  inset: 22%;
  width: auto;
  aspect-ratio: auto;
  border-radius: 0;
  background: none;
  border: 2px solid rgba(var(--hf-gold-glow), .9);
  box-shadow: 0 0 12px rgba(var(--hf-gold-glow), .6), inset 0 0 8px rgba(var(--hf-gold-glow), .4);
  animation: none;
}
.hf-cell--corner.valid-move-target {
  box-shadow:
    inset 0 0 0 2px rgba(var(--hf-gold-glow), .85),
    inset 0 0 18px rgba(var(--hf-gold-glow), .4);
}
.hf-cell--corner.valid-move-target::after {
  inset: 14%;
  width: auto;
  aspect-ratio: auto;
  border-radius: 0;
  background: var(--hf-rune-corner) center / contain no-repeat;
  box-shadow: none;
  filter: drop-shadow(0 0 6px rgba(var(--hf-gold-glow), .9));
  animation: none;
}

.last-moved {
  box-shadow:
    inset 1px 1px 0 var(--hf-groove),
    inset 0 0 0 2px rgba(224, 112, 47, .75),
    inset 0 0 16px rgba(224, 112, 47, .3);
}
@keyframes hf-pulse {
  0%, 100% { transform: scale(1);    opacity: .95; }
  50%      { transform: scale(1.18); opacity: .7;  }
}
@media (prefers-reduced-motion: reduce) {
  .valid-move-target::after { animation: none; }
  .hf-piece, .hf-cell { transition: none; }
}


/* ---------- coordinates ---------- */
.hf-lab {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(232, 220, 196, .6);
  font: 600 clamp(8px, 2.2vw, 12px)/1 Georgia, serif;
  user-select: none;
  position: relative;
  z-index: 4;
}

.bg-27-board-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.bg-27-hint p {
  margin: 6px 0 0;
  text-align: center;
  color: #d8c8a2;
  font-size: 13px;
}
