/* the daily blunder: badly cut out photos, tape and pixel chess on graph paper */
@font-face { font-family: "Pixelify Sans"; src: url("/fonts/pixelify-sans.ttf") format("truetype"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "Patrick Hand"; src: url("/fonts/patrick-hand.ttf") format("truetype"); font-display: swap; }

:root {
  --ink: #2a1a3a; --paper: #fffdf6; --pink: #f6c6dc; --hot: #e2457f; --blue: #3c64c8;
  --tape: rgba(255, 233, 150, .78); --grid: #cfe0ee; --shadow: 3px 4px 0 rgba(42, 26, 58, .22);
  --pixel: "Pixelify Sans", "Courier New", monospace; --hand: "Patrick Hand", "Comic Sans MS", cursive;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink); font: 19px/1.35 var(--hand); overflow-x: hidden;
  background-color: #f4f8fb;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
}
a { color: var(--blue); }
b { font-weight: 700; }
h1, h2, h3 { font-family: var(--pixel); font-weight: 600; margin: 0 0 6px; line-height: 1.1; }
h2 { font-size: 22px; } h3 { font-size: 16px; margin-top: 12px; }

/* ---------- paper scraps and tape ---------- */
.paper { background: var(--paper); box-shadow: var(--shadow); position: relative; }
.paper.lined { background: repeating-linear-gradient(#fffdf6 0 25px, #bcd4ef 25px 26px); }
.paper.grid { background-color: #fffef9; background-image: linear-gradient(#eadfcf 1px, transparent 1px), linear-gradient(90deg, #eadfcf 1px, transparent 1px); background-size: 12px 12px; }
.paper.pink { background: var(--pink); }
.torn { clip-path: polygon(0 1.5%, 6% 0, 14% 1.2%, 23% .2%, 35% 1.4%, 47% 0, 58% 1.1%, 70% .3%, 83% 1.3%, 94% 0, 100% 1%, 99.3% 14%, 100% 31%, 99.2% 52%, 100% 70%, 99.4% 88%, 100% 99%, 91% 100%, 79% 98.9%, 66% 100%, 52% 98.8%, 39% 100%, 27% 99%, 14% 100%, 4% 98.9%, 0 100%, .7% 82%, 0 63%, .8% 45%, 0 27%, .6% 12%); }
.torn-top { clip-path: polygon(0 12px, 5% 0, 11% 9px, 19% 2px, 28% 11px, 37% 1px, 46% 8px, 55% 0, 64% 10px, 73% 2px, 82% 9px, 91% 0, 100% 8px, 100% 100%, 0 100%); }
.tape { position: absolute; width: 92px; height: 26px; background: var(--tape); box-shadow: 0 1px 2px rgba(0,0,0,.12); z-index: 3; pointer-events: none;
  -webkit-mask: linear-gradient(90deg, transparent 0 3px, #000 3px calc(100% - 3px), transparent 0); mask: linear-gradient(90deg, transparent 0 3px, #000 3px calc(100% - 3px), transparent 0); }
.tape-tl { top: 4px; left: -12px; transform: rotate(-28deg); }
.tape-br { bottom: 6px; right: -14px; transform: rotate(-24deg); }
.tape-top { top: -10px; left: 50%; transform: translateX(-50%) rotate(-3deg); }
.tilt-l { transform: rotate(-1.2deg); } .tilt-r { transform: rotate(1deg); }

/* the cut-out photos around the edges */
.scraps { position: absolute; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; height: 100%; min-height: 100vh; }
.scrap { position: absolute; image-rendering: pixelated; filter: drop-shadow(3px 4px 0 rgba(42,26,58,.2)); }
.s-murcia { width: 318px; top: 14px; right: -26px; transform: rotate(6deg); }
.s-cat { width: 256px; top: 560px; left: -40px; transform: rotate(-8deg); }
.s-tea { width: 228px; top: 1040px; right: -10px; transform: rotate(9deg); }
.s-king1 { width: 146px; top: 150px; left: 8px; transform: rotate(-7deg); }
.s-king2 { width: 138px; top: 980px; left: 20px; transform: rotate(5deg); }

/* ---------- masthead: a ransom note ---------- */
.masthead { position: relative; z-index: 1; text-align: center; padding: 26px 16px 8px; }
.ransom { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; font-size: 46px; margin: 0 auto 14px; max-width: 760px; }
.ransom span { display: inline-block; padding: 2px 7px 4px; background: #fff; box-shadow: 2px 3px 0 rgba(42,26,58,.25); line-height: 1; }
.ransom .w span:nth-child(7n+1) { background: #111; color: #fff; font-family: var(--pixel); transform: rotate(-5deg); }
.ransom .w span:nth-child(7n+2) { background: var(--pink); font-family: Georgia, serif; font-style: italic; transform: rotate(4deg) translateY(3px); }
.ransom .w span:nth-child(7n+3) { background: #fff7c2; font-family: var(--pixel); color: var(--hot); transform: rotate(-2deg); }
.ransom .w span:nth-child(7n+4) { background: #cde7ff; font-family: "Courier New", monospace; font-weight: 700; transform: rotate(6deg) translateY(-2px); }
.ransom .w span:nth-child(7n+5) { background: #fff; font-family: Impact, "Arial Black", sans-serif; color: var(--blue); transform: rotate(-4deg) translateY(2px); }
.ransom .w span:nth-child(7n+6) { background: #ffe0c7; font-family: var(--hand); font-size: 1.1em; transform: rotate(3deg); }
.ransom .w span:nth-child(7n) { background: #e9ffd6; font-family: Georgia, serif; font-weight: 700; transform: rotate(-6deg) translateY(4px); }
.ransom .w { display: inline-flex; gap: 2px; background: none; box-shadow: none; padding: 0; transform: none; font: inherit; color: inherit; }
.ransom .w:nth-child(2) span:nth-child(odd) { transform: rotate(5deg) translateY(2px); }
.tagline { display: inline-block; margin: 0; padding: 8px 18px; transform: rotate(-1deg); font-size: 20px; }

/* ---------- the board and the cards ---------- */
.table { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 560px) minmax(0, 330px); gap: 30px; justify-content: center; padding: 18px 16px 30px; align-items: start; }
.board-wrap { padding: 26px 26px 18px; }
.board-box { position: relative; width: 100%; aspect-ratio: 1; background: #2a1a3a; padding: 6px; box-shadow: inset 0 0 0 3px #fff; }
#board, #fx { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: manipulation; }
#board { cursor: pointer; }
#fx { position: absolute; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); pointer-events: none; }
.note { font-size: 21px; margin: 14px 4px 0; min-height: 1.4em; text-align: center; }
.note.yours { font-family: var(--pixel); color: var(--hot); font-size: 24px; animation: wiggle 1.2s ease-in-out infinite; }
@keyframes wiggle { 50% { transform: rotate(-2deg) scale(1.04); } }
.banner { background: #111; color: #fff; font-family: var(--pixel); padding: 8px 12px; margin: 0 0 12px; text-align: center; transform: rotate(-1deg); font-size: 18px; }
.banner.nap { background: #6a5a8a; }
.banner.done { background: var(--hot); }
.robot { display: flex; justify-content: center; margin-top: 8px; }
.robot:empty { display: none; }

.promo { position: absolute; inset: 18% 8%; background: var(--paper); box-shadow: 5px 6px 0 rgba(42,26,58,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 12px; transform: rotate(-1.5deg); z-index: 4; }
.promo p { margin: 0 0 10px; font-size: 21px; }
.promo-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.promo-row button { background: var(--pink); border: 2px solid var(--ink); padding: 4px; cursor: pointer; box-shadow: 2px 2px 0 var(--ink); }
.promo-row button:hover, .promo-row button:focus-visible { background: #fff7c2; transform: translateY(-2px); }
.promo-row canvas { width: 56px; height: 56px; image-rendering: pixelated; display: block; }
.link-btn { background: none; border: 0; color: var(--blue); text-decoration: underline; font: inherit; margin-top: 10px; cursor: pointer; }

.side { display: flex; flex-direction: column; gap: 22px; }
.card { padding: 16px 18px 14px; }
.card p { margin: 0 0 8px; }
.card.small { font-size: 17px; }
.facts { list-style: none; margin: 0; padding: 0; }
.facts li { margin: 2px 0; }
.check { display: inline-block; background: var(--hot); color: #fff; font-family: var(--pixel); padding: 1px 8px; transform: rotate(-3deg); animation: wiggle .8s infinite; }
.army { display: inline-block; padding: 0 7px; border: 2px solid var(--ink); font-family: var(--pixel); font-size: 16px; }
.army.w { background: #fff6e2; } .army.b { background: #4e3478; color: #fff; }
.here { font-family: var(--pixel); font-size: 16px; color: var(--hot); }
.moves { max-height: 340px; overflow: auto; margin: 0 -4px; padding: 0 4px; }
.movetable { border-collapse: collapse; width: 100%; font-family: var(--pixel); font-size: 16px; }
.movetable caption { font-family: var(--hand); font-size: 17px; text-align: left; caption-side: top; }
.movetable th { width: 2.4em; text-align: right; padding: 2px 6px 2px 0; font-weight: 400; color: #8a7a9a; vertical-align: middle; }
.movetable td { padding: 2px 4px; width: 50%; white-space: nowrap; vertical-align: middle; }
.movetable td.mine { background: #fff7c2; box-shadow: inset 0 0 0 2px var(--hot); }
.movetable td.mine::after { content: "you!"; font-family: var(--hand); font-size: 13px; background: var(--hot); color: #fff; padding: 0 4px; margin-left: 4px; display: inline-block; transform: rotate(-4deg); }
.san { vertical-align: middle; }
.face { display: inline-block; width: 20px; height: 20px; margin-right: 4px; vertical-align: middle; background: url("/images/masters.png?v=1") calc(var(--i) * -20px) 0 / 320px 20px no-repeat; image-rendering: pixelated; image-rendering: crisp-edges; }
.you-face { display: inline-block; margin-top: 6px; font-size: 17px; }
.you-face .face { width: 28px; height: 28px; background-size: 448px 28px; background-position: calc(var(--i) * -28px) 0; margin: 0 2px; }
.pop-moves { max-height: 42vh; background: #fff; padding: 6px 8px; margin-bottom: 12px; }
.pgn-pop details { margin-bottom: 12px; }
.pgn-pop summary { cursor: pointer; color: var(--blue); }

/* ---------- hall of games ---------- */
.hall { position: relative; z-index: 1; max-width: 920px; margin: 10px auto 30px; padding: 30px 24px 22px; }
.hall h2 { font-size: 28px; text-align: center; }
.hall-sub { text-align: center; margin: 0 0 16px; }
.hall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 20px; }
.hall-grid .empty { grid-column: 1 / -1; text-align: center; color: #7a6a8a; }
.game { background: #fff; padding: 8px 8px 6px; box-shadow: var(--shadow); text-align: center; border: 0; font: inherit; color: inherit; cursor: pointer; }
.game:nth-child(odd) { transform: rotate(-1.5deg); } .game:nth-child(even) { transform: rotate(1.2deg); }
.game:hover, .game:focus-visible { transform: rotate(0) scale(1.04); outline: 2px dashed var(--hot); }
.game canvas { width: 100%; aspect-ratio: 1; display: block; image-rendering: pixelated; }
.game .res { font-family: var(--pixel); font-size: 16px; display: block; margin-top: 4px; }
.game .meta { font-size: 15px; display: block; color: #6a5a7a; }
.pgn-pop { max-width: min(520px, calc(100vw - 32px)); border: 0; padding: 20px; background: var(--paper); box-shadow: 6px 8px 0 rgba(42,26,58,.35); color: var(--ink); font: inherit; }
.pgn-pop::backdrop { background: rgba(42, 26, 58, .35); }
.pgn-pop pre { white-space: pre-wrap; word-break: break-word; font: 14px/1.4 "Courier New", monospace; background: #fff; padding: 10px; max-height: 50vh; overflow: auto; }
.pgn-pop .row { display: flex; gap: 14px; justify-content: flex-end; }
.btn { background: var(--pink); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); font: 17px var(--pixel); padding: 4px 12px; cursor: pointer; color: var(--ink); text-decoration: none; }

.foot { position: relative; z-index: 1; text-align: center; padding: 10px 16px 40px; font-size: 18px; }
.foot a { background: #fff; padding: 0 6px; }
.foot .home-blinkie { display: inline-block; background: none; padding: 0; margin-bottom: 10px; line-height: 0; }
.foot .home-blinkie img { display: block; image-rendering: pixelated; }
.foot .home-blinkie:hover, .foot .home-blinkie:focus-visible { transform: rotate(-2deg) scale(1.05); }

/* sub pages */
.page { position: relative; z-index: 1; max-width: 680px; margin: 30px auto; padding: 28px 30px; }
.page h1 { font-size: 30px; margin-bottom: 14px; }
.page li { margin: 6px 0; }

@media (max-width: 900px) {
  .table { grid-template-columns: minmax(0, 600px); }
  .scrap { opacity: .9; }
  .s-murcia { width: 190px; top: 4px; right: -60px; }
  .s-king1 { width: 90px; top: 6px; left: -18px; }
  .s-cat, .s-tea, .s-king2 { display: none; }
}
@media (max-width: 520px) {
  body { font-size: 18px; }
  .ransom { font-size: 30px; }
  .board-wrap { padding: 18px 12px 12px; }
  .hall { padding: 28px 14px 18px; }
  .hall-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
}
@media (prefers-reduced-motion: reduce) { .note.yours, .check { animation: none; } }
