/* ==========================================================================
   Sjakkbrettet: ekte sjakk mot Rita, Sunniva eller Teresa.
   ========================================================================== */

.chess-game {
  --chess-light: #f3e4c4;
  --chess-dark: #9c6b3f;
  --chess-frame: #5c3d22;
  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;
}
.chess-game__header { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-start; justify-content: space-between; }
.chess-game__header h3 { margin: 4px 0 6px; }
.chess-game__header p { margin: 0; max-width: 52ch; }
.chess-game__actions { display: grid; flex: 0 0 auto; gap: 9px; justify-items: end; }
.chess-game__levels {
  display: flex;
  gap: 6px;
  padding: 5px;
  background: rgba(255, 253, 247, .72);
  border: 2px solid rgba(92, 61, 34, .18);
  border-radius: 999px;
}
.chess-game__levels button {
  min-height: 42px;
  padding: 7px 12px;
  color: var(--fjord-deep);
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-title);
  font-weight: 900;
  touch-action: manipulation;
}
.chess-game__levels button[aria-pressed="true"] { color: var(--white); background: #8f6338; box-shadow: 0 4px 10px rgba(67, 41, 15, .25); }
.chess-game__lesson { display: flex; gap: 12px; align-items: center; padding: 12px 14px; background: rgba(255, 253, 247, .8); border-radius: 18px; }
.chess-game__lesson span { font-size: 1.6rem; }
.chess-game__lesson p { margin: 0; }

.chess-game__play {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(220px, .7fr);
  gap: 16px;
  align-items: start;
}
.chess-board-wrap { display: grid; gap: 8px; }
.chess-captured {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 30px;
  padding: 4px 8px;
  background: rgba(255, 253, 247, .7);
  border-radius: 12px;
}
.chess-captured span { display: block; width: 26px; height: 26px; }
.chess-captured svg, .chess-captured img { display: block; width: 100%; height: 100%; }
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: min(100%, 560px);
  aspect-ratio: 1;
  padding: 8px;
  background: linear-gradient(180deg, #6b4626, var(--chess-frame));
  border: 4px solid #3f2812;
  border-radius: 14px;
  box-shadow: 0 12px 26px rgba(67, 41, 15, .3);
  user-select: none;
  -webkit-user-select: none;
}
.chess-board.is-flipped { transform: rotate(180deg); }
.chess-board.is-flipped .chess-square { transform: rotate(180deg); }
.chess-square {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  padding: 6%;
  place-items: center;
  background: var(--chess-light);
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}
.chess-square.is-dark { background: var(--chess-dark); }
.chess-square svg, .chess-square img { display: block; width: 100%; height: 100%; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3)); pointer-events: none; }
.chess-square.is-last { box-shadow: inset 0 0 0 100px rgba(255, 218, 79, .35); }
.chess-square.is-selected { box-shadow: inset 0 0 0 4px var(--sun), inset 0 0 0 100px rgba(255, 218, 79, .35); }
.chess-square.is-target::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  background: rgba(18, 61, 84, .45);
  border-radius: 50%;
}
.chess-square.is-capture { box-shadow: inset 0 0 0 4px #e94e43; }
.chess-square.is-check { box-shadow: inset 0 0 0 100px rgba(233, 78, 67, .5); }
.chess-square.is-hint { box-shadow: inset 0 0 0 4px #2f7d53; }
.chess-square:focus-visible { outline: 4px solid var(--sun); outline-offset: -4px; z-index: 1; }
.chess-board.is-thinking { opacity: .92; }
.chess-game__turn {
  margin: 0;
  font-family: var(--font-title);
  font-size: 1.1rem;
  text-align: center;
}
.chess-game__panel { display: grid; gap: 10px; }
.chess-game__status { margin: 0; padding: 12px 14px; font-weight: 700; background: rgba(255, 253, 247, .9); border-radius: 16px; }
.chess-game__help { margin: 0; padding: 10px 14px; font-size: .92rem; background: rgba(226, 239, 248, .75); border-radius: 14px; }
.chess-game__controls { display: flex; flex-wrap: wrap; gap: 8px; }
.chess-game__controls .button { flex: 1 1 auto; }
.chess-game__moves { margin: 0; padding: 0 0 0 18px; font-size: .88rem; }
.chess-game__moves li { margin: 2px 0; }
.chess-game__finish[hidden] { display: none; }

/* Fullskjerm: brettet fyller det som er igjen. */
.chess-game.is-game-viewport { gap: 8px; }
.chess-game.is-game-viewport .chess-game__header > div:not(.chess-game__actions),
.chess-game.is-game-viewport .chess-game__lesson,
.chess-game.is-game-viewport .chess-game__moves,
.chess-game.is-game-viewport .chess-game__help { display: none; }
.chess-game.is-game-viewport .chess-game__header > .chess-game__actions { display: flex; align-items: center; gap: 6px; }
.chess-game.is-game-viewport .chess-game__levels { padding: 3px; }
.chess-game.is-game-viewport .chess-game__levels button { min-height: 36px; padding: 4px 10px; font-size: .82rem; }
.chess-game.is-game-viewport .chess-board { width: min(100%, calc(var(--maram-game-height, 100vh) - 250px)); }

@media (max-width: 900px) {
  .chess-game__play { grid-template-columns: minmax(0, 1fr); }
  .chess-game__actions { justify-items: start; }
  .chess-game.is-game-viewport .chess-game__header > .chess-game__actions { flex-wrap: wrap; row-gap: 5px; }
  .chess-game.is-game-viewport .chess-game__levels { flex: 1 1 100%; }
  .chess-game.is-game-viewport .chess-game__levels button { flex: 1 1 0; text-align: center; }
  .chess-game.is-game-viewport .chess-board { width: min(100%, calc(var(--maram-game-height, 100vh) - 300px)); }
  .chess-game.is-game-viewport .chess-game__status { padding: 8px 10px; font-size: .9rem; }
}
@media (max-width: 700px) {
  .chess-game { padding: 12px; gap: 12px; }
  .chess-board { padding: 5px; border-width: 3px; }
  .chess-captured span { width: 20px; height: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .chess-board, .chess-square { transition: none; }
}

/* Egen side */
.chess-page .chess-hero .page-hero__content { padding-bottom: 52px; }
.chess-page .chess-page__game .chess-game { margin: 0; }

/* ==========================================================================
   Grafisk løft: stua som bakteppe, treramme med koordinater, motstander ved brettet,
   brikker som glir, og tre-brikker med lys og skygge.
   ========================================================================== */

.chess-page .chess-game {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 248, 234, .9), rgba(242, 230, 210, .94)),
    url("../images/canonical/stuen-sm.jpg") center 40% / cover no-repeat;
}
.chess-page .chess-game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background: url("../images/canonical/stuen-sm.jpg") center 40% / cover no-repeat;
  opacity: .28;
  filter: blur(2px) saturate(1.05);
  pointer-events: none;
}
.chess-page .chess-game > * { position: relative; z-index: 1; }

/* Ramme og koordinater */
.chess-board-frame {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 20px;
  width: min(100%, 600px);
  padding: 10px 12px 8px 4px;
  background:
    repeating-linear-gradient(95deg, rgba(0, 0, 0, .05) 0 3px, transparent 3px 18px),
    linear-gradient(180deg, #7a5230, #5a3a1f 60%, #472c15);
  border-radius: 18px;
  box-shadow: 0 16px 30px rgba(67, 41, 15, .35), inset 0 2px 0 rgba(255, 255, 255, .18);
}
.chess-board-frame .chess-board {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  padding: 0;
  border: 3px solid #2f1c0c;
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(255, 231, 190, .25), inset 0 8px 18px rgba(0, 0, 0, .35);
}
.chess-board__files, .chess-board__ranks {
  display: grid;
  color: rgba(255, 236, 200, .85);
  font-family: var(--font-title);
  font-size: .78rem;
  font-weight: 800;
}
.chess-board__files { grid-column: 2; grid-row: 2; grid-template-columns: repeat(8, minmax(0, 1fr)); text-align: center; align-items: end; }
.chess-board__ranks { grid-column: 1; grid-row: 1; grid-template-rows: repeat(8, minmax(0, 1fr)); align-items: center; text-align: center; }
.chess-board.is-flipped ~ .chess-board__files { direction: rtl; }
.chess-board.is-flipped ~ .chess-board__ranks { flex-direction: column-reverse; transform: scaleY(-1); }
.chess-board.is-flipped ~ .chess-board__ranks span { transform: scaleY(-1); display: block; }

/* Rutene: lyst og mørkt tre med svak lysning */
.chess-square {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .22), rgba(0, 0, 0, .04)),
    var(--chess-light);
}
.chess-square.is-dark {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .1), rgba(0, 0, 0, .12)),
    var(--chess-dark);
}
.chess-square svg, .chess-square img { filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .35)); }
.chess-square img, .chess-mini__sq img, .chess-captured img, .chess-board__ghost img { background: transparent; border: 0; border-radius: 0; box-shadow: none; }
.chess-square img { padding: 0; box-sizing: border-box; object-fit: contain; transform: scale(1.1); transform-origin: 50% 88%; }
.chess-mini__sq img { padding: 2%; box-sizing: border-box; }
.chess-square.is-landing svg, .chess-square.is-landing img { animation: chess-land .38s ease-out both; }
@keyframes chess-land {
  0% { transform: scale(.7); opacity: 0; }
  70% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}

/* Flukt-laget: brikken glir over brettet */
.chess-board__flight { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.chess-board__ghost {
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  padding: 6%;
  place-items: center;
  transition: transform .36s cubic-bezier(.3, .7, .3, 1);
}
.chess-board__ghost svg, .chess-board__ghost img { width: 100%; height: 100%; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, .4)); }

/* Motstanderen sitter ved brettet */
.chess-opponent {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}
.chess-opponent__portrait {
  display: block;
  width: 84px;
  height: 84px;
  overflow: hidden;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 8px 16px rgba(18, 59, 83, .25);
}
.chess-opponent__portrait img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.chess-opponent__bubble {
  position: relative;
  padding: 10px 14px;
  color: var(--fjord-deep);
  background: #fff;
  border: 2px solid rgba(18, 61, 84, .2);
  border-radius: 16px;
  font-weight: 700;
}
.chess-opponent__bubble::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -9px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-bottom: 2px solid rgba(18, 61, 84, .2);
  border-left: 2px solid rgba(18, 61, 84, .2);
  transform: translateY(-50%) rotate(45deg);
}
.chess-opponent__bubble.is-fresh { animation: chess-bubble .35s ease-out both; }
@keyframes chess-bubble {
  0% { transform: scale(.92); opacity: .4; }
  100% { transform: scale(1); opacity: 1; }
}
.chess-game.is-game-viewport .chess-opponent { grid-template-columns: 56px minmax(0, 1fr); }
.chess-game.is-game-viewport .chess-opponent__portrait { width: 56px; height: 56px; }
.chess-game.is-game-viewport .chess-opponent__bubble { padding: 6px 10px; font-size: .88rem; }
.chess-game.is-game-viewport .chess-board-frame { width: min(100%, calc(var(--maram-game-height, 100vh) - 240px)); }
.chess-game.is-game-viewport .chess-board-frame .chess-board { width: 100%; }

@media (max-width: 900px) {
  .chess-game.is-game-viewport .chess-game__play { grid-template-rows: auto auto; }
  .chess-game.is-game-viewport .chess-board-frame { width: min(100%, calc(var(--maram-game-height, 100vh) - 330px)); margin: 0 auto; }
  .chess-game.is-game-viewport .chess-opponent { grid-template-columns: 44px minmax(0, 1fr); }
  .chess-game.is-game-viewport .chess-opponent__portrait { width: 44px; height: 44px; }
}
@media (max-width: 700px) {
  .chess-board-frame { grid-template-columns: 16px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 16px; padding: 6px 8px 4px 2px; }
  .chess-board__files, .chess-board__ranks { font-size: .62rem; }
}
html[data-calm="true"] .chess-board__ghost,
html[data-calm="true"] .chess-square.is-landing svg,
html[data-calm="true"] .chess-opponent__bubble.is-fresh { transition: none; animation: none; }
@media (prefers-reduced-motion: reduce) {
  .chess-board__ghost { transition: none; }
  .chess-square.is-landing svg, .chess-opponent__bubble.is-fresh { animation: none; }
}

/* To spillere på samme skjerm: ingen motstanderportrett, bare hvem sin tur det er. */
.chess-opponent[data-chess-opponent="venn"] { grid-template-columns: minmax(0, 1fr); }
.chess-opponent[data-chess-opponent="venn"] .chess-opponent__portrait { display: none; }
.chess-opponent[data-chess-opponent="venn"] .chess-opponent__bubble::before { display: none; }

/* ==========================================================================
   Mer innbydende side: stua som hero-bilde, motstanderkort med portrett,
   og «Slik går brikkene» som små brett med prikker.
   ========================================================================== */

.chess-page .chess-hero .page-hero__image { object-position: center 42%; }
.chess-page .chess-hero .page-hero__content { padding-bottom: 0; }

.chess-game__header { gap: 14px 18px; }
.chess-game__actions { flex: 1 1 100%; grid-template-columns: minmax(0, 1fr) auto; align-items: center; justify-items: stretch; }
.chess-game__levels {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 7px;
  border-radius: 24px;
}
.chess-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;
  text-align: left;
  border-radius: 18px;
  transition: background .2s ease, transform .2s ease;
}
.chess-game__levels button:hover,
.chess-game__levels button:focus-visible { background: rgba(255, 255, 255, .9); transform: translateY(-1px); }
.chess-game__levels button[aria-pressed="true"]:hover,
.chess-game__levels button[aria-pressed="true"]:focus-visible { background: #8f6338; }
.chess-game__levels button img,
.chess-game__levels button i {
  width: 44px;
  height: 44px;
  object-fit: cover;
  object-position: center 18%;
  border-radius: 50%;
  border: 2px solid rgba(255, 253, 247, .9);
  box-shadow: 0 3px 8px rgba(67, 41, 15, .22);
  background: #fff3d6;
}
.chess-game__levels button i { display: grid; place-items: center; font-style: normal; font-size: 1.25rem; letter-spacing: -.12em; }
.chess-game__levels button span { display: grid; line-height: 1.15; }
.chess-game__levels button strong { font-size: .98rem; }
.chess-game__levels button small { color: #6b5138; font-family: var(--font-body, inherit); font-size: .74rem; font-weight: 600; }
.chess-game__levels button[aria-pressed="true"] small { color: rgba(255, 253, 247, .86); }
.chess-game__sound { justify-self: end; }

.chess-game.is-game-viewport .chess-game__levels { display: flex; gap: 6px; padding: 3px; border-radius: 999px; }
.chess-game.is-game-viewport .chess-game__levels button { display: inline-flex; min-height: 36px; padding: 4px 10px; border-radius: 999px; }
.chess-game.is-game-viewport .chess-game__levels button img,
.chess-game.is-game-viewport .chess-game__levels button i,
.chess-game.is-game-viewport .chess-game__levels button small { display: none; }

.chess-lessons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.chess-lesson {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 16px;
  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);
}
.chess-lesson strong { display: block; margin-bottom: 4px; font-family: var(--font-title); font-size: 1.12rem; }
.chess-lesson small { color: #4d6e7d; font-size: .9rem; line-height: 1.35; }
.chess-mini {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  width: 112px;
  aspect-ratio: 1;
  border: 4px solid #5c3d22;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(67, 41, 15, .22);
}
.chess-mini__sq { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; background: #f3e4c4; }
.chess-mini__sq.is-dark { background: #9c6b3f; }
.chess-mini__sq.has-dot::after,
.chess-mini__sq.has-capture::after {
  content: "";
  width: 40%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #2f8f62;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .55);
}
.chess-mini__sq.has-capture::after { background: #d6503a; }
.chess-mini__sq svg { width: 92%; height: 92%; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3)); }
.chess-mini__sq img { width: 92%; height: 92%; object-fit: contain; }

@media (max-width: 900px) {
  .chess-lessons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chess-game__levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chess-game__actions { grid-template-columns: minmax(0, 1fr); }
  .chess-game__sound { justify-self: start; }
}
@media (max-width: 560px) {
  .chess-lessons { grid-template-columns: minmax(0, 1fr); }
  .chess-lesson { grid-template-columns: 96px minmax(0, 1fr); padding: 14px; }
  .chess-mini { width: 96px; }
  .chess-game__levels button { min-height: 52px; padding: 5px 8px 5px 6px; }
  .chess-game__levels button strong { font-size: .9rem; }
}

/* «Spør mamma»: rådet kommer fra mamma i en snakkeboble ved brettet. */
.chess-game__ask { gap: 8px; }
.chess-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); }
.chess-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;
}
.chess-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); }
.chess-mamma__portrait img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.chess-mamma__bubble { position: relative; margin: 0; padding: 8px 12px; font-weight: 700; background: #fff; border-radius: 14px; }
.chess-mamma__bubble::before { content: ""; position: absolute; top: 50%; left: -7px; width: 12px; height: 12px; background: #fff; transform: translateY(-50%) rotate(45deg); }
.chess-mamma__bubble.is-fresh { animation: chess-bubble .35s ease-out both; }
.chess-game.is-game-viewport .chess-mamma { grid-template-columns: 44px minmax(0, 1fr); padding: 6px 8px; }
.chess-game.is-game-viewport .chess-mamma__portrait { width: 44px; height: 44px; }
.chess-game.is-game-viewport .chess-mamma__bubble { padding: 6px 10px; font-size: .88rem; }
html[data-calm="true"] .chess-mamma__bubble.is-fresh { animation: none; }
