/* Guilty Gambit — the playable board at /play. Loaded after styles.css, which supplies the colours and buttons. */

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.play-page .site-header { padding: 0.7rem 0; }
.play-page main { padding-bottom: 2.5rem; }
.play-page [hidden] { display: none !important; }

/* ---------- The table: board on the left, everything else beside it ---------- */

.table {
  --side: clamp(280px, 30vw, 380px);
  --board: max(280px, min(100vh - 8.5rem, 100vw - var(--side) - 4.5rem, 820px));
  display: grid; gap: 1rem 1.6rem;
  grid-template-columns: var(--board) var(--side);
  grid-template-areas: "board status" "board side";
  grid-template-rows: auto 1fr;
  justify-content: center; align-items: start;
  width: min(100% - 2rem, 1280px); margin: 0.4rem auto 0;
}
@supports (height: 100dvh) {
  .table { --board: max(280px, min(100dvh - 8.5rem, 100vw - var(--side) - 4.5rem, 820px)); }
}

.status {
  grid-area: status;
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem 1.1rem; min-height: 6.2rem;
}
.status p { margin: 0; }
.status .headline { font-size: 1.3rem; font-weight: 800; line-height: 1.25; }
.status .detail { color: var(--ink-soft); margin-top: 0.25rem; }
.status .note-line, .status .hint {
  margin-top: 0.55rem; padding: 0.45rem 0.7rem; border-radius: 10px; font-weight: 600; font-size: 0.98rem; line-height: 1.4;
  background: var(--bg-sunk); border-left: 4px solid #c7d1e0;
}
.status .hint { border-left-color: var(--gold); }
.status .hint.refusal { border-left-color: #ff9a3d; color: #ffc58f; }

.board-wrap { grid-area: board; }
.side { grid-area: side; display: grid; gap: 0.9rem; align-content: start; }

/* ---------- The board ---------- */

.board {
  position: relative; width: var(--board); height: var(--board);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 0 0 7px #33201a, 0 0 0 8px #000, 0 22px 50px rgba(0, 0, 0, 0.55);
  margin: 8px;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}

.sq {
  position: relative; display: block; min-width: 0; min-height: 0;
  margin: 0; padding: 0; border: 0; border-radius: 0;
  background: #e6cca1; color: #805438;
  font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.sq.dark { background: #805438; color: #e6cca1; }
.sq:focus { outline: none; }
.sq:focus-visible { outline: 3px solid #fff; outline-offset: -3px; z-index: 1; border-radius: 0; }

/* The letters and numbers along two edges. */
.sq .file, .sq .rank {
  position: absolute; font-size: clamp(0.5rem, calc(var(--board) / 60), 0.8rem); font-weight: 700; line-height: 1; opacity: 0.85;
  pointer-events: none;
}
.sq .file { right: 6%; bottom: 5%; }
.sq .rank { left: 6%; top: 5%; }

/* ::before is a wash of colour over the whole square; ::after is a mark in the middle of it. */
.sq::before, .sq::after { content: ""; position: absolute; pointer-events: none; }
.sq::before { inset: 0; }

.sq.last::before { background: rgba(242, 204, 77, 0.45); }
.sq.work-absolving::before { background: radial-gradient(circle, rgba(255, 212, 90, 0.95) 0 30%, rgba(255, 212, 90, 0.35) 75%); }
.sq.work-shaming::before { background: radial-gradient(circle, rgba(181, 108, 255, 0.95) 0 30%, rgba(181, 108, 255, 0.35) 75%); }
.sq.harmless::before { background: rgba(199, 209, 224, 0.4); box-shadow: inset 0 0 0 3px #c7d1e0; }
.sq.check::before {
  background: radial-gradient(circle, rgba(224, 54, 61, 0.95) 0 35%, rgba(224, 54, 61, 0.4) 80%);
  box-shadow: inset 0 0 0 3px #e0363d; animation: gg-pulse 1.1s ease-in-out infinite;
}
.sq.sel::before { background: rgba(255, 212, 90, 0.5); box-shadow: inset 0 0 0 4px #ffd45a; }

.sq.dot::after { inset: 36%; border-radius: 50%; background: rgba(18, 22, 27, 0.4); }
.sq.dot.shame::after { inset: 31%; background: #b56cff; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8), 0 0 10px #b56cff; }
.sq.dot.absolve::after { inset: 31%; background: #ffd45a; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8), 0 0 10px #ffd45a; }
.sq.cap::after {
  inset: 4%; border-radius: 16%; border: 4px solid #e0363d; background: rgba(224, 54, 61, 0.22);
  animation: gg-pulse 1.1s ease-in-out infinite;
}
.sq.cap.friend::after { border-color: #f2cc4d; background: rgba(242, 204, 77, 0.22); }

@keyframes gg-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- Pieces ---------- */

.pieces { position: absolute; inset: 0; pointer-events: none; }

.piece {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
  transition: transform 0.24s ease, opacity 0.28s ease;
  --pf: #f4e9d2; --ps: #4a392a; --pl: #4a392a; --c: var(--unaffected);
}
.piece.black { --pf: #292a33; --ps: #08080b; --pl: #8f94a6; }
.piece.gone { opacity: 0; }
.piece.fresh { transition: none; }

.piece svg {
  position: absolute; left: 9%; top: 3%; width: 82%; height: 82%; overflow: visible;
  fill: var(--pf); stroke: var(--ps); stroke-width: 3.4; stroke-linejoin: round; stroke-linecap: round;
  filter: drop-shadow(0 1.5px 1.5px rgba(0, 0, 0, 0.45));
}
.piece svg .gg-line { fill: none; stroke: var(--pl); stroke-width: 3; }
.piece svg .gg-dot { stroke: none; fill: var(--pl); }
.piece.changed svg { animation: gg-turn 0.6s ease; }
@keyframes gg-turn { 0% { transform: scale(1); } 40% { transform: scale(0.2, 1); } 100% { transform: scale(1); } }
.piece svg { transform-origin: 50% 60%; }

/* The chip a piece stands on shows its mood. */
.piece .chipmark {
  position: absolute; left: 7%; right: 7%; bottom: 2%; height: 27%; border-radius: 50%;
  background: repeating-linear-gradient(90deg, var(--c) 0 13%, #f6f1e6 13% 20%);
  box-shadow: 0 1.5px 0 rgba(0, 0, 0, 0.55), inset 0 0 0 1.5px rgba(0, 0, 0, 0.3);
}
.piece .chipmark.dormant { background: none; box-shadow: inset 0 0 0 2.5px var(--c), 0 0 0 1px rgba(0, 0, 0, 0.35); }
.piece.mood-devastated { --c: var(--devastated); }
.piece.mood-guilt { --c: var(--guilt); }
.piece.mood-unaffected { --c: var(--unaffected); }
.piece.mood-berserk { --c: var(--berserk); }
.piece.mood-bloodlust { --c: #101014; }
.piece.mood-bloodlust .chipmark { background: repeating-linear-gradient(90deg, #101014 0 13%, #e0363d 13% 20%); }
.piece.frozen svg { filter: drop-shadow(0 1.5px 1.5px rgba(0, 0, 0, 0.45)) saturate(0.5) brightness(0.9); }

/* Dots over a piece: turns left for a devastated piece, captures made for a berserker. */
.piece .counter { position: absolute; left: 0; right: 0; top: 1%; display: flex; justify-content: center; gap: 5%; }
.piece .counter i {
  width: 12%; padding-bottom: 12%; height: 0; border-radius: 50%;
  background: rgba(10, 10, 14, 0.55); box-shadow: 0 0 0 1.5px #f6f1e6;
}
.piece .counter i.on { background: var(--c); }
.piece.mood-bloodlust .counter i.on { background: #e0363d; }

/* A halo over a bishop that is working on a piece beside it. */
.piece.halo-absolving, .piece.halo-shaming { --halo: var(--absolve); }
.piece.halo-shaming { --halo: var(--shame); }
.piece.halo-absolving::before, .piece.halo-shaming::before {
  content: ""; position: absolute; left: 26%; right: 26%; top: 0; height: 12%; border-radius: 50%;
  border: 2.5px solid var(--halo); box-shadow: 0 0 8px 1px var(--halo), inset 0 0 4px var(--halo);
  z-index: 1;
}

/* ---------- Beside the board ---------- */

.side .tray {
  display: grid; grid-template-columns: auto 1fr; gap: 0.9rem; align-items: center; text-align: left;
  padding: 0.9rem 1rem; border-width: 9px; border-radius: 18px;
}
.side .die { width: 4rem; height: 4rem; margin: 0; padding: 0.5rem; border-radius: 0.8rem; box-shadow: 0 4px 0 #cfc7b6, 0 8px 14px rgba(0, 0, 0, 0.35); }
.side .verdict { min-height: 0; margin: 0; font-size: 0.98rem; line-height: 1.35; }
.side .verdict b { font-size: 1.05rem; }

.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.controls .button { padding: 0.6rem 1.05rem; font-size: 0.98rem; flex: 1 1 auto; text-align: center; }
.button.pass { width: 100%; font-size: 1.05rem; }
.button.wide { width: 100%; text-align: center; }
.button:disabled { opacity: 0.5; cursor: default; }

.key, .history {
  background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.1rem 1.1rem 0.7rem; margin: 0; font-size: 0.93rem;
}
.key summary, .history summary { padding: 0.65rem 0; list-style-position: inside; }
.key:not([open]), .history:not([open]) { padding-bottom: 0.1rem; }
.key ul { list-style: none; padding: 0; margin: 0 0 0.6rem; display: grid; gap: 0.35rem; }
.key li { color: var(--ink-soft); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.key li b { color: var(--ink); }
.key .chip { width: 1.05rem; height: 1.05rem; }
.key p { color: var(--ink-soft); margin: 0 0 0.35rem; line-height: 1.4; }
.key .swatch { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.35rem; vertical-align: -0.02rem; }
.key .swatch.absolve { background: var(--absolve); box-shadow: 0 0 6px var(--absolve); }
.key .swatch.shame { background: var(--shame); box-shadow: 0 0 6px var(--shame); }

/* ---------- History: what happened, turn by turn, and why ---------- */

.history { padding-bottom: 0.9rem; }
.history .count { color: var(--ink-faint); font-weight: 400; font-size: 0.88rem; margin-left: 0.55rem; }
.history p { margin: 0; }
.history-empty { color: var(--ink-soft); line-height: 1.4; }
.history-list {
  list-style: none; margin: 0; padding: 0 0.35rem 0 0; display: grid; gap: 0.6rem;
  max-height: min(24rem, 55vh); overflow: auto; overscroll-behavior: contain;
}
.history-list:focus-visible { outline: 2px solid #fff; outline-offset: 3px; border-radius: 6px; }
.history-list .who {
  display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.2rem;
  color: var(--ink-faint); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
}
.history-list .who::before {
  content: ""; width: 0.62rem; height: 0.62rem; border-radius: 50%; background: #f4e9d2; box-shadow: 0 0 0 1px #4a392a;
}
.history-list .black .who::before { background: #292a33; box-shadow: 0 0 0 1px #8f94a6; }
.history-list .line, .history-list .more { padding-left: 0.6rem; border-left: 3px solid transparent; line-height: 1.4; }
.history-list .line { color: var(--ink); }
.history-list .line + .line, .history-list .more + .line { margin-top: 0.3rem; }
.history-list .more { color: var(--ink-soft); font-size: 0.88rem; margin-top: 0.15rem; }
.history-list .shame, .history-list .shame + .more { border-left-color: var(--shame); }
.history-list .cure, .history-list .cure + .more { border-left-color: var(--absolve); }
.history-list .gone { border-left-color: var(--devastated); }
.history-list .berserk { border-left-color: var(--berserk); }
.history-list .roll { border-left-color: #c7d1e0; }
.history-list .note { color: var(--ink-soft); }
.history-list .end { font-weight: 800; }
.history-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.8rem; }
.history-actions .button { flex: 1 1 auto; padding: 0.5rem 0.9rem; font-size: 0.95rem; text-align: center; }
.history .fine { color: var(--ink-faint); font-size: 0.85rem; line-height: 1.4; margin-top: 0.55rem; }

.about { color: var(--ink-faint); font-size: 0.9rem; margin: 0; }

/* ---------- Cards over the board: new game, promotion, result, rules ---------- */

dialog.sheet {
  width: min(100vw - 1.5rem, 430px); max-height: calc(100vh - 1.5rem); overflow: auto;
  margin: auto; padding: 1.4rem 1.4rem 1.2rem; border: 1px solid var(--line); border-radius: 22px;
  background: #1c222b; color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
@supports (height: 100dvh) { dialog.sheet { max-height: calc(100dvh - 1.5rem); } }
dialog.sheet::backdrop { background: rgba(5, 7, 10, 0.55); }
/* For browsers without <dialog>: the page opens these by hand. */
dialog.sheet.manual { position: fixed; inset: 0; z-index: 30; height: -moz-fit-content; height: fit-content; display: block; }
.manual-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(5, 7, 10, 0.55); }

dialog.sheet h2 { font-size: 1.7rem; margin: 0 0 0.2rem; }
dialog.sheet .sub { color: var(--ink-soft); margin: 0 0 1rem; }
dialog.sheet .caption { color: var(--ink-soft); font-size: 0.88rem; line-height: 1.4; margin: 0.4rem 0 0; }
dialog.sheet .credit-line { color: var(--ink-faint); margin-top: 0.9rem; }
dialog.sheet .row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.1rem; }
dialog.sheet .row .button { flex: 1 1 auto; text-align: center; }
dialog.sheet .button.wide { margin-top: 1rem; }
dialog.sheet .button.wide + .button.wide { margin-top: 0.6rem; }
#result { text-align: center; }
#result h2 { font-size: 1.5rem; }

.segmented { border: 0; padding: 0; margin: 1rem 0 0; display: flex; flex-wrap: wrap; gap: 0; min-width: 0; }
.segmented legend { padding: 0; margin-bottom: 0.35rem; font-weight: 700; font-size: 0.95rem; }
.segmented label { flex: 1 1 0; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.segmented span {
  display: block; text-align: center; padding: 0.5rem 0.4rem; font-weight: 600; font-size: 0.98rem;
  background: var(--bg-sunk); border: 1px solid var(--line); border-left-width: 0; color: var(--ink-soft);
}
.segmented label:first-of-type span { border-left-width: 1px; border-radius: 12px 0 0 12px; }
.segmented label:last-of-type span { border-radius: 0 12px 12px 0; }
.segmented input:checked + span { background: var(--gold); border-color: var(--gold); color: #1a1408; }
.segmented input:focus-visible + span { outline: 3px solid #fff; outline-offset: 2px; position: relative; z-index: 1; }

.switch { display: flex; align-items: center; gap: 0.8rem; margin-top: 0.9rem; cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; width: 3rem; height: 1.8rem; margin: 0; cursor: pointer; }
.switch .track {
  flex: none; width: 3rem; height: 1.8rem; border-radius: 999px; background: var(--bg-sunk); border: 1px solid var(--line);
  position: relative; transition: background 0.15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: calc(1.8rem - 6px); height: calc(1.8rem - 6px);
  border-radius: 50%; background: var(--ink-soft); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--gold); border-color: var(--gold); }
.switch input:checked + .track::after { transform: translateX(1.2rem); background: #1a1408; }
.switch input:focus-visible + .track { outline: 3px solid #fff; outline-offset: 2px; }
.switch .text { display: grid; line-height: 1.3; }
.switch .text b { font-size: 0.98rem; }
.switch .text small { color: var(--ink-soft); font-size: 0.86rem; }

button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--gold); text-decoration: underline; text-underline-offset: 0.18em; cursor: pointer; }

.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-top: 0.9rem; }
.choices button {
  display: grid; justify-items: center; gap: 0.1rem; padding: 0.5rem 0.2rem 0.6rem; cursor: pointer;
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); font: inherit; font-weight: 700; font-size: 0.9rem;
}
.choices button:hover { border-color: var(--gold); }
.choices .piece { position: relative; width: 3.4rem; height: 3.4rem; }

dialog.sheet.tall { width: min(100vw - 1.5rem, 520px); display: none; }
dialog.sheet.tall[open] { display: flex; flex-direction: column; }
.scroll { overflow: auto; margin-top: 0.6rem; padding-right: 0.3rem; min-height: 0; }
.scroll h3 { font-size: 1.02rem; margin: 0.9rem 0 0.15rem; }
.scroll p { color: var(--ink-soft); margin: 0 0 0.3rem; font-size: 0.98rem; line-height: 1.45; white-space: pre-line; }
.scroll p.plain { color: var(--ink); margin-top: 0.9rem; }

/* ---------- Narrow screens: everything in one column ---------- */

@media (max-width: 820px) {
  .table {
    --board: max(240px, min(100vw - 28px, 100vh - 5rem, 640px));
    /* The board comes first so that nothing above it changes height and moves it under a finger. */
    grid-template-columns: 1fr; grid-template-areas: "board" "status" "side";
    grid-template-rows: auto; gap: 0.7rem; width: min(100% - 12px, 680px); margin-top: 0;
  }
  @supports (height: 100dvh) {
    .table { --board: max(240px, min(100vw - 28px, 100dvh - 5rem, 640px)); }
  }
  .status { min-height: 4.6rem; padding: 0.7rem 0.9rem; margin: 0 6px; }
  .status .headline { font-size: 1.15rem; }
  .status .detail { font-size: 0.95rem; }
  .board-wrap { display: flex; justify-content: center; }
  .board { margin: 8px auto; }
  .side { padding: 0 6px; }
  .play-page .site-header .wrap { justify-content: space-between; }
  .play-page .site-nav a { padding: 0.3rem 0.55rem; font-size: 0.95rem; }
  .play-page .wordmark { font-size: 1.05rem; }
}

/* ---------- Short screens: the start card closes up, so both credits at its foot show without scrolling ---------- */

@media (max-height: 800px) {
  dialog.sheet { padding: 1rem 1.1rem 0.9rem; }
  dialog.sheet h2 { font-size: 1.45rem; }
  dialog.sheet .sub { margin-bottom: 0.5rem; }
  .segmented { margin-top: 0.65rem; }
  .segmented legend { margin-bottom: 0.25rem; }
  .segmented span { padding: 0.4rem 0.4rem; }
  .switch { margin-top: 0.6rem; }
  dialog.sheet .caption { margin-top: 0.3rem; line-height: 1.35; }
  dialog.sheet .button.wide { margin-top: 0.8rem; }
  dialog.sheet .credit-line { margin-top: 0.6rem; font-size: 0.8rem; }
}
/* Shorter still, as on a phone with the browser's own bars showing: the tagline gives up its line. */
@media (max-height: 700px) {
  dialog.sheet { padding: 0.8rem 1.1rem 0.75rem; }
  dialog.sheet h2 { font-size: 1.3rem; }
  dialog.sheet .sub { display: none; }
  .segmented { margin-top: 0.5rem; }
  .segmented legend { font-size: 0.9rem; margin-bottom: 0.2rem; }
  .segmented span { padding: 0.32rem 0.4rem; }
  .switch { margin-top: 0.5rem; }
  dialog.sheet .button.wide { margin-top: 0.65rem; }
  dialog.sheet .credit-line { margin-top: 0.45rem; font-size: 0.76rem; }
}

@media (prefers-reduced-motion: reduce) {
  .piece, .switch .track, .switch .track::after { transition: none; }
  .sq.check::before, .sq.cap::after, .piece.changed svg { animation: none; }
}
