/* ==========================================================================
   Backgammon ved kjøkkenbordet: ekte backgammon mot Teresa, Pappa eller Mormor.
   ========================================================================== */

.bg-game {
  --bg-wood: #6b4423;
  --bg-wood-dark: #4a2d15;
  --bg-felt: #f5e6c8;
  --bg-point-a: #b8753d;
  --bg-point-b: #f1dbb4;
  --bg-light: #f8ecd6;
  --bg-dark: #3a2416;
  display: grid;
  gap: 16px;
  padding: clamp(14px, 3vw, 24px);
  color: var(--fjord-deep);
  background: linear-gradient(180deg, #fff8ea, #f2e6d2);
  border: 3px solid rgba(92, 61, 34, .18);
  border-radius: 26px;
}
.bg-page .bg-game {
  position: relative;
  overflow: hidden;
}
.bg-page .bg-game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: url("../images/canonical/kjokkenet-sm.jpg") center 45% / cover no-repeat;
  opacity: .26;
  filter: blur(2px) saturate(1.05);
  pointer-events: none;
}
.bg-page .bg-game > * { position: relative; z-index: 1; }

.bg-game__header { display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-start; justify-content: space-between; }
.bg-game__header h3 { margin: 4px 0 6px; }
.bg-game__header p { margin: 0; max-width: 52ch; }
.bg-game__actions { display: grid; flex: 1 1 100%; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: center; }
.bg-game__levels {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 7px;
  background: rgba(255, 253, 247, .72);
  border: 2px solid rgba(92, 61, 34, .18);
  border-radius: 24px;
}
.bg-game__levels button {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  min-height: 58px;
  padding: 6px 12px 6px 7px;
  color: var(--fjord-deep);
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 18px;
  font-family: var(--font-title);
  font-weight: 900;
  touch-action: manipulation;
  transition: background .2s ease, transform .2s ease;
}
.bg-game__levels button:hover,
.bg-game__levels button:focus-visible { background: rgba(255, 255, 255, .9); transform: translateY(-1px); }
.bg-game__levels button[aria-pressed="true"] { color: var(--white); background: #8f6338; box-shadow: 0 4px 10px rgba(67, 41, 15, .25); }
.bg-game__levels button[aria-pressed="true"]:hover,
.bg-game__levels button[aria-pressed="true"]:focus-visible { background: #8f6338; }
.bg-game__levels button img,
.bg-game__levels button i {
  width: 44px;
  height: 44px;
  object-fit: cover;
  object-position: center 18%;
  border: 2px solid rgba(255, 253, 247, .9);
  border-radius: 50%;
  background: #fff3d6;
  box-shadow: 0 3px 8px rgba(67, 41, 15, .22);
}
.bg-game__levels button i { display: grid; place-items: center; font-style: normal; font-size: 1.25rem; letter-spacing: -.12em; }
.bg-game__levels button span { display: grid; line-height: 1.15; }
.bg-game__levels button strong { font-size: .98rem; }
.bg-game__levels button small { color: #6b5138; font-family: var(--font-body, inherit); font-size: .74rem; font-weight: 600; }
.bg-game__levels button[aria-pressed="true"] small { color: rgba(255, 253, 247, .86); }
.bg-game__sound { justify-self: end; }
.bg-game__lesson { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: rgba(255, 253, 247, .8); border-radius: 18px; }
.bg-game__lesson span { font-size: 1.6rem; }
.bg-game__lesson p { margin: 0; }

/* Spillflaten */
.bg-game__play { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.bg-board-wrap { display: grid; gap: 10px; }
.bg-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)) 34px repeat(6, minmax(0, 1fr)) 40px;
  grid-template-rows: 1fr 1fr;
  gap: 0;
  width: 100%;
  aspect-ratio: 13 / 8;
  padding: 10px;
  background: var(--bg-felt);
  border: 12px solid var(--bg-wood);
  border-radius: 14px;
  box-shadow: inset 0 0 0 2px rgba(74, 45, 21, .35), 0 14px 30px rgba(67, 41, 15, .28);
  box-sizing: border-box;
}
.bg-point {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  cursor: pointer;
  background: transparent;
  border: 0;
  touch-action: manipulation;
}
.bg-point::before {
  content: "";
  position: absolute;
  inset: 0 6%;
  background: var(--bg-point-a);
  clip-path: polygon(0 0, 100% 0, 50% 88%);
}
.bg-point.is-even::before { background: var(--bg-point-b); }
.bg-point.is-bottom::before { clip-path: polygon(50% 12%, 0 100%, 100% 100%); }
.bg-point.is-bottom { flex-direction: column-reverse; }
.bg-stack { position: relative; display: flex; flex-direction: inherit; align-items: center; width: 100%; height: 100%; }
.bg-checker {
  --checker: min(84%, calc(100% / 5.3));
  flex: 0 0 auto;
  width: var(--checker);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: 0 2px 3px rgba(0, 0, 0, .35), inset 0 -3px 5px rgba(0, 0, 0, .25), inset 0 2px 3px rgba(255, 255, 255, .45);
}
.bg-point .bg-checker { width: 84%; max-height: 19.5%; aspect-ratio: 1; }
.bg-checker.is-w { background: radial-gradient(circle at 35% 30%, #fff7e6, #e8cfa3 55%, #c9a874); border: 1px solid #a98354; }
.bg-checker.is-b { background: radial-gradient(circle at 35% 30%, #7a5236, #4a2f1c 55%, #2b1a0f); border: 1px solid #1c0f07; }
.bg-checker__count {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 6px;
  color: #fff;
  background: #123b53;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 900;
}
.bg-point.is-top .bg-checker__count { top: calc(5 * 19.5% - 8px); }
.bg-point.is-bottom .bg-checker__count { bottom: calc(5 * 19.5% - 8px); }
.bg-point.is-movable::after,
.bg-bar__slot.is-movable::after {
  content: "";
  position: absolute;
  inset: 4% 12%;
  border: 3px dashed rgba(47, 143, 98, .75);
  border-radius: 999px;
  pointer-events: none;
}
.bg-point.is-selected::before { filter: brightness(1.15) saturate(1.2); outline: 3px solid #f6c453; outline-offset: -3px; }
.bg-point.is-target::before { background: #6fbf8f !important; }
.bg-point.is-hit::before { background: #e06a52 !important; }
.bg-point.is-hint::before { outline: 3px solid #2f8f62; outline-offset: -3px; }
.bg-point.is-moving::before { filter: brightness(1.2); }
.bg-point:focus-visible { outline: 3px solid #f6c453; outline-offset: -2px; }

.bg-bar {
  display: grid;
  grid-template-rows: 1fr 1fr;
  margin: 0 3px;
  background: var(--bg-wood);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25);
}
.bg-bar__slot { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-height: 0; padding: 4px 0; cursor: pointer; background: transparent; border: 0; }
.bg-bar__slot.is-top { justify-content: flex-start; }
.bg-bar__slot .bg-stack { flex-direction: column; justify-content: inherit; }
.bg-bar__slot .bg-checker { width: 78%; max-height: 22%; }
.bg-bar__slot.is-selected { outline: 3px solid #f6c453; outline-offset: -3px; border-radius: 6px; }
.bg-bar__slot.is-moving { background: rgba(255, 255, 255, .18); }

.bg-off { display: grid; grid-template-rows: 1fr 1fr; gap: 6px; margin-left: 6px; }
.bg-off__tray {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  min-height: 0;
  padding: 6px 4px;
  cursor: pointer;
  background: rgba(74, 45, 21, .28);
  border: 2px solid rgba(74, 45, 21, .4);
  border-radius: 8px;
}
.bg-off__tray.is-bottom { justify-content: flex-end; }
.bg-off__stack { display: flex; flex-direction: column; gap: 2px; width: 100%; }
.bg-off__tray.is-bottom .bg-off__stack { flex-direction: column-reverse; }
.bg-off__chip { display: block; width: 100%; height: 5px; border-radius: 2px; }
.bg-off__chip.is-w { background: #e8cfa3; }
.bg-off__chip.is-b { background: #4a2f1c; }
.bg-off__count { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 1px 6px; color: #fff; background: #123b53; border-radius: 999px; font-size: .7rem; font-weight: 900; }
.bg-off__count:empty { display: none; }
.bg-off__tray.is-target { background: #6fbf8f; border-color: #2f8f62; box-shadow: 0 0 0 3px rgba(47, 143, 98, .35); }
.bg-off__tray.is-hint { border-color: #2f8f62; }

/* Terninger */
.bg-dice-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; justify-content: space-between; }
.bg-dice { display: flex; gap: 10px; min-height: 48px; align-items: center; }
.bg-dice.is-empty::before { content: "Ingen terninger kastet ennå"; color: #6b5138; font-size: .85rem; }
.bg-die {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 46px;
  height: 46px;
  padding: 6px;
  background: linear-gradient(160deg, #fffdf6, #f1e6d0);
  border: 1px solid #c9b48f;
  border-radius: 10px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, .25), inset 0 1px 2px #fff;
  box-sizing: border-box;
  animation: bg-die-roll .35s ease-out both;
}
.bg-dice.is-b .bg-die { background: linear-gradient(160deg, #5e3b22, #3a2416); border-color: #241407; }
.bg-die i { display: block; width: 100%; height: 100%; max-width: 9px; max-height: 9px; margin: auto; background: #2b1a0f; border-radius: 50%; }
.bg-dice.is-b .bg-die i { background: #f8ecd6; }
.bg-die.is-used { opacity: .35; }
.bg-die.is-double { width: 38px; height: 38px; }
@keyframes bg-die-roll { from { transform: rotate(-90deg) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.bg-game__turn { margin: 0; font-family: var(--font-title); font-weight: 900; }
.bg-game__pips { margin: 0; color: #6b5138; font-size: .8rem; }

/* Panelet ved brettet */
.bg-game__panel { display: grid; gap: 10px; }
.bg-game__status { margin: 0; padding: 12px 14px; font-weight: 700; background: rgba(255, 253, 247, .9); border-radius: 16px; }
.bg-game__help { margin: 0; padding: 10px 14px; font-size: .92rem; background: rgba(226, 239, 248, .75); border-radius: 14px; }
.bg-game__controls { display: flex; flex-wrap: wrap; gap: 8px; }
.bg-game__controls .button { flex: 1 1 auto; }
.bg-game__ask { gap: 8px; }
.bg-game__ask img { width: 26px; height: 26px; border: 2px solid rgba(255, 255, 255, .9); border-radius: 50%; object-fit: cover; object-position: 50% 18%; box-shadow: 0 2px 5px rgba(67, 41, 15, .25); }
.bg-opponent { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 12px; align-items: center; }
.bg-opponent__portrait { width: 72px; height: 72px; overflow: hidden; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 6px 14px rgba(67, 41, 15, .28); }
.bg-opponent__portrait img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.bg-opponent__bubble { position: relative; margin: 0; padding: 10px 14px; font-weight: 700; background: #fff; border-radius: 16px; box-shadow: 0 6px 16px rgba(18, 59, 83, .12); }
.bg-opponent__bubble::before { content: ""; position: absolute; top: 50%; left: -7px; width: 14px; height: 14px; background: #fff; transform: translateY(-50%) rotate(45deg); }
.bg-opponent__bubble.is-fresh,
.bg-mamma__bubble.is-fresh { animation: bg-bubble .35s ease-out both; }
@keyframes bg-bubble { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.bg-opponent[data-bg-opponent="venn"] { grid-template-columns: minmax(0, 1fr); }
.bg-opponent[data-bg-opponent="venn"] .bg-opponent__portrait { display: none; }
.bg-opponent[data-bg-opponent="venn"] .bg-opponent__bubble::before { display: none; }
.bg-mamma { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 10px; align-items: center; padding: 8px 10px; background: #fff6df; border: 2px solid #f0d87b; border-radius: 18px; }
.bg-mamma__portrait { width: 58px; height: 58px; overflow: hidden; border: 3px solid #fff; border-radius: 50%; box-shadow: 0 4px 10px rgba(67, 41, 15, .22); }
.bg-mamma__portrait img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.bg-mamma__bubble { position: relative; margin: 0; padding: 8px 12px; font-weight: 700; background: #fff; border-radius: 14px; }
.bg-mamma__bubble::before { content: ""; position: absolute; top: 50%; left: -7px; width: 12px; height: 12px; background: #fff; transform: translateY(-50%) rotate(45deg); }
.bg-game__finish { margin-top: 4px; }

/* Fullskjerm: brettet må få plass i én skjerm */
.bg-game.is-game-viewport .bg-game__header > div:not(.bg-game__actions),
.bg-game.is-game-viewport .bg-game__lesson,
.bg-game.is-game-viewport .bg-game__help { display: none; }
.bg-game.is-game-viewport { gap: 10px; padding: 10px 12px; }
.bg-game.is-game-viewport .bg-game__actions { display: flex; align-items: center; gap: 6px; }
.bg-game.is-game-viewport .bg-game__levels { display: flex; gap: 6px; padding: 3px; border-radius: 999px; }
.bg-game.is-game-viewport .bg-game__levels button { display: inline-flex; min-height: 36px; padding: 4px 10px; border-radius: 999px; font-size: .82rem; }
.bg-game.is-game-viewport .bg-game__levels button img,
.bg-game.is-game-viewport .bg-game__levels button i,
.bg-game.is-game-viewport .bg-game__levels button small { display: none; }
.bg-game.is-game-viewport .bg-game__play { grid-template-columns: minmax(0, 1fr) 260px; gap: 12px; }
.bg-game.is-game-viewport .bg-board { width: min(100%, calc((100vh - 215px) * 13 / 8)); margin: 0 auto; border-width: 8px; }
.bg-game.is-game-viewport .bg-opponent { grid-template-columns: 52px minmax(0, 1fr); }
.bg-game.is-game-viewport .bg-opponent__portrait { width: 52px; height: 52px; }
.bg-game.is-game-viewport .bg-opponent__bubble { padding: 6px 10px; font-size: .88rem; }
.bg-game.is-game-viewport .bg-mamma { grid-template-columns: 44px minmax(0, 1fr); padding: 6px 8px; }
.bg-game.is-game-viewport .bg-mamma__portrait { width: 44px; height: 44px; }
.bg-game.is-game-viewport .bg-game__status { padding: 8px 10px; font-size: .9rem; }

@media (max-width: 900px) {
  .bg-game__play { grid-template-columns: minmax(0, 1fr); }
  .bg-game__levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bg-game__actions { grid-template-columns: minmax(0, 1fr); }
  .bg-game__sound { justify-self: start; }
  .bg-game.is-game-viewport .bg-game__play { grid-template-columns: minmax(0, 1fr); }
  .bg-game.is-game-viewport .bg-game__actions { flex-wrap: wrap; row-gap: 5px; }
  .bg-game.is-game-viewport .bg-game__levels { flex: 1 1 100%; }
  .bg-game.is-game-viewport .bg-game__levels button { flex: 1 1 0; justify-content: center; }
  .bg-game.is-game-viewport .bg-board { width: min(100%, calc((100vh - 330px) * 13 / 8)); }
  .bg-game.is-game-viewport .bg-opponent { display: none; }
}
@media (max-width: 560px) {
  .bg-game { padding: 12px; gap: 12px; }
  .bg-board { border-width: 8px; padding: 6px; grid-template-columns: repeat(6, minmax(0, 1fr)) 22px repeat(6, minmax(0, 1fr)) 26px; }
  .bg-die { width: 40px; height: 40px; padding: 5px; }
  .bg-game__levels button { min-height: 52px; padding: 5px 8px 5px 6px; }
  .bg-game__levels button strong { font-size: .9rem; }
}

/* Egen side */
.bg-page .bg-hero .page-hero__image { object-position: center 40%; }
.bg-page .bg-page__game .bg-game { margin: 0; }
.bg-rules { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.bg-rule { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 14px; align-items: center; padding: 18px; color: var(--fjord-deep); background: #fff; border: 3px solid #eadcc4; border-radius: 22px; box-shadow: 0 9px 22px rgba(18, 59, 83, .09); }
.bg-rule > span { font-size: 2.1rem; text-align: center; }
.bg-rule strong { display: block; margin-bottom: 4px; font-family: var(--font-title); font-size: 1.08rem; }
.bg-rule small { color: #4d6e7d; font-size: .9rem; line-height: 1.35; }
@media (max-width: 900px) { .bg-rules { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .bg-rules { grid-template-columns: minmax(0, 1fr); } }

html[data-calm="true"] .bg-die,
html[data-calm="true"] .bg-opponent__bubble.is-fresh,
html[data-calm="true"] .bg-mamma__bubble.is-fresh { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .bg-die, .bg-opponent__bubble.is-fresh, .bg-mamma__bubble.is-fresh { animation: none; }
}

/* Brikker i Maram-stil (levert av Codex 4. sep 2026): bjørk og valnøtt. */
.bg-checker.is-w,
.bg-checker.is-b {
  border: 0;
  box-shadow: none;
  background-color: transparent;
  background-position: center;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35));
}
.bg-checker.is-w { background-image: url("../images/generated/games/backgammon/brikke-lys-v01.webp"); }
.bg-checker.is-b { background-image: url("../images/generated/games/backgammon/brikke-mork-v01.webp"); }
