@font-face {
  font-family: "Bodoni Moda";
  src: url("/bodoni.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}
:root {
  color-scheme: light;
  --paper: #fdfdfc;
  --grid: #e7e7e5;   /* the moving background grid */
  --line: #c4c4c0;   /* gray lines inside the board */
  --ink: #151515;    /* text and filled cells */
  --soft: #6b6b68;   /* quieter text */
  --hint: #a3a39f;
  --mark: #48d24e;   /* Mark the shark's green: your last move */
  --claude: #d97757; /* Claude orange: your opponent's last move */
  --red: #c8423f;    /* a trap that went off */
  --box: #383838;    /* filled boxes */
  --wash: #f0f0ee;   /* soft hover background */
  --press: #333;     /* main button on hover */
  --gem-double: #7d4fc4;
  --gem-pass: #128a7c;
  --gem-trap: #c8423f;
  --grid-step: 44px;
}

/* Same names, night colours. Green and orange stay as they are. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #141414;
  --grid: #232322;
  --line: #3a3a38;
  --ink: #eeeeeb;
  --soft: #a0a09b;
  --hint: #6e6e6a;
  --box: #d2d2cd;
  --wash: #262625;
  --press: #cfcfca;
  --gem-double: #ad86ee;
  --gem-pass: #35c2b0;
  --gem-trap: #ea6f6b;
}

* { box-sizing: border-box; border-radius: 0; }
[hidden] { display: none !important; }
html:has(#game:not([hidden])) { scrollbar-gutter: stable; } /* a scrollbar appearing must not resize the board */

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background: var(--paper);
  font: 400 18px/1.5 "Bodoni Moda", Georgia, serif;
  font-optical-sizing: none;
  font-variation-settings: "opsz" 6; /* the sturdiest thin strokes, for small text */
}

/* The grid sits on its own layer, slightly bigger than the screen. Sliding it
   by exactly one square and starting over makes it look endless. */
body::before {
  content: "";
  position: fixed;
  inset: calc(var(--grid-step) * -1);
  z-index: -1;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--grid-step) var(--grid-step);
}
@media (prefers-reduced-motion: no-preference) {
  body::before { animation: drift 16s linear infinite; }
  @keyframes drift { to { transform: translate(var(--grid-step), var(--grid-step)); } }
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 620px;
  margin: 0 auto;
  padding: 16px;
}
.logo { color: var(--ink); font-size: 28px; font-weight: 500; text-decoration: none; }
body:has(#home:not([hidden])) .logo { visibility: hidden; } /* the home page has the big title */
.eyebrow { font-size: 13px; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; }
.link, .choice legend { font-size: 17px; }
.link {
  border: 0;
  padding: 4px 0;
  background: none;
  color: var(--ink);
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}
a.link { font-variation-settings: normal; } /* buttons skip the page's setting, so match them */
.nav { display: flex; gap: 18px; }
@media (max-width: 400px) { .nav { gap: 10px; } .link { font-size: 15px; } }
.link:hover { text-decoration: underline; text-underline-offset: 4px; }

main { max-width: 620px; margin: 0 auto; padding: 0 16px 32px; }

#home, #missing, #host, #join, #history { text-align: center; }
#host h2, #join h2 { margin: 8px 0 22px; font-size: 42px; }
.eyebrow { margin: 7vh 0 0; color: var(--soft); }
h1, h2 {
  margin: 0;
  font-weight: 500;
  line-height: 1.05;
  font-variation-settings: "opsz" 28; /* at full contrast the bar of the "e" disappears */
}
#home h1 { margin-top: 10px; font-size: clamp(96px, 28vw, 168px); letter-spacing: -.03em; }
#missing h1 { margin-top: 10vh; font-size: clamp(40px, 10vw, 60px); }
.lead { max-width: 25em; margin: 18px auto 0; color: var(--soft); font-size: 20px; }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 30px; }
#home .actions .primary, #home .actions .secondary { min-width: 150px; }

.choice { border: 0; padding: 0; margin: 0 0 22px; min-width: 0; }
.choice legend { padding: 0; margin: 0 auto 10px; color: var(--soft); }
.choice label { flex: 1 1 0; min-width: 0; }
.choice:not([hidden]) { display: flex; justify-content: center; }
.choice input { position: absolute; opacity: 0; }
.choice label + label span { border-left: 0; }
.choice span {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  padding: 11px 6px;
  border: 1px solid var(--ink);
  background: var(--paper);
  font-size: 20px;
  line-height: 1.2;
  cursor: pointer;
}
.choice small { margin-top: 4px; color: var(--soft); font-size: 12px; letter-spacing: .02em; }
.choice input:checked + span { background: var(--ink); color: var(--paper); }
.choice input:checked + span small { color: inherit; }
.choice input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

/* The host page's options, sorted into groups. */
.rule-group { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); }
.group-title { margin: 0 0 12px; font-size: 21px; font-weight: 500; }
.rule-group .choice:last-child { margin-bottom: 0; }
.extras { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 14px; }
.extras .choice { margin-bottom: 0; }
@media (max-width: 480px) { .extras small { display: none; } .extras .choice span { padding-block: 8px; } }

.code-label { display: block; margin-bottom: 10px; color: var(--soft); font-size: 17px; }
#join-code {
  width: min(100%, 300px);
  padding: 12px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: 400 26px "Bodoni Moda", Georgia, serif;
  letter-spacing: .1em;
  text-align: center;
}
.code { flex: 0 0 100%; text-align: center; font-size: 30px; letter-spacing: .1em; }
.summary { margin: 10px 0 0; color: var(--soft); font-size: 15px; text-align: center; }

.primary, .secondary {
  display: inline-block;
  padding: 11px 30px;
  border: 1px solid var(--ink);
  font-family: inherit;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}
.primary { background: var(--ink); color: var(--paper); }
.primary:hover:not(:disabled) { background: var(--press); }
.secondary { background: var(--paper); color: var(--ink); }
.secondary:hover { background: var(--wash); }
.primary:disabled { border-color: var(--line); background: var(--paper); color: var(--soft); cursor: default; }
:is(button, a, input):focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.status { margin: 6px 0 16px; text-align: center; }
/* The space above the board never changes size, or the board would jump around
   as the text changes. One line of headline, two of detail. */
.status h2 {
  overflow: hidden;
  font-size: clamp(25px, 7.4vw, 38px);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status p { height: 3em; margin: 4px 0 0; overflow: hidden; color: var(--soft); font-size: 18px; }
.status.mine h2 { font-weight: 700; }

.panel { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 16px; }
#invite { gap: 8px 0; }
#invite .primary { padding-inline: 18px; white-space: nowrap; }
#invite-link {
  flex: 1 1 0;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--ink);
  border-right: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px "Bodoni Moda", Georgia, serif;
}

#game { width: 100%; max-width: min(100%, 68dvh); margin: 0 auto; }
.board-wrap { width: 100%; }
#board, .replay-board {
  container-type: inline-size; /* lets cells size their pattern from the board */
  display: grid;
  aspect-ratio: 1;
  background: var(--paper);
  outline: 1px solid var(--ink);
  touch-action: manipulation;
}
.cell {
  position: relative;
  display: block;
  min-width: 0;
  padding: 0;
  border: 0;
  box-shadow: inset -1px -1px 0 var(--line);
  background: var(--paper);
  cursor: default;
}
.cell.black {
  /* Shark's pixel art: a cell is 32 units wide. --u is one unit. Going in from
     the edge: 1 see-through, 2 colour, then thin stripes. Everything that
     isn't coloured is see-through, so the board shows behind it. */
  --stripe: var(--box);
  --u: calc(100cqw / var(--cells) / 32);
  background: none;
  box-shadow: inset -1px -1px 0 var(--line);
}
.cell.black::before {
  content: "";
  position: absolute;
  /* 1px more on the right and bottom, where the cell's own gray line sits,
     so the gaps look even on all sides. */
  inset: var(--u) calc(var(--u) + 1px) calc(var(--u) + 1px) var(--u);
  border: calc(var(--u) * 2) solid var(--stripe);
  background: repeating-linear-gradient(-45deg,
    var(--stripe) 0 calc(var(--u) * 1.6), transparent 0 calc(var(--u) * 5.66));
}
/* Whole-pixel sizes, so the browser never rounds one side of a box differently
   from the other. */
@supports (width: round(down, 1px, 1px)) {
  #board, .replay-board { width: round(down, 100%, calc(var(--cells) * 1px)); margin-inline: auto; }
  .cell.black { --u: max(1px, round(calc(100cqw / var(--cells) / 32), 1px)); }
}
.cell.playable { cursor: pointer; }
.cell.playable:hover { background: var(--wash); box-shadow: inset 0 0 0 1px var(--ink); }
.cell:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.cell.my-last { --stripe: var(--mark); }
.cell.their-last { --stripe: var(--claude); }

/* Your own trap, and the cell where a trap just went off. */
.cell.my-trap::after {
  content: "";
  position: absolute;
  inset: 26%;
  border: 2px solid var(--mark);
}
.cell.sprung { box-shadow: inset 0 0 0 3px var(--red); }

.hints .cell.live::before, .sample.live::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  background: var(--hint);
  transform: translate(-50%, -50%);
}
.hints .cell.poisoned::before, .sample.poisoned::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  background:
    linear-gradient(45deg, transparent calc(50% - .6px), var(--hint) calc(50% - .6px), var(--hint) calc(50% + .6px), transparent calc(50% + .6px)),
    linear-gradient(-45deg, transparent calc(50% - .6px), var(--hint) calc(50% - .6px), var(--hint) calc(50% + .6px), transparent calc(50% + .6px));
}

/* A rock is one solid box, so it can't be mistaken for a striped filled cell. */
.cell.rock { background: var(--ink); }

/* Gems are cut out of solid colour with a mask, so the same class works on the
   board, in a player's box, and on the rules page. Each type has its own shape
   as well as its own colour. */
.gem {
  display: block;
  pointer-events: none;
  background: var(--gem-colour);
  -webkit-mask: var(--gem-shape) center / contain no-repeat;
  mask: var(--gem-shape) center / contain no-repeat;
}
.gem.double {
  --gem-colour: var(--gem-double);
  --gem-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M8 3l7 9-7 9-7-9zM16 3l7 9-7 9-7-9z'/%3E%3C/svg%3E");
}
.gem.pass {
  --gem-colour: var(--gem-pass);
  --gem-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 1l10 6v10l-10 6-10-6V7zM6.5 7.5l5 4.5-5 4.5zM12.5 7.5l5 4.5-5 4.5z'/%3E%3C/svg%3E");
}
.gem.trap {
  --gem-colour: var(--gem-trap);
  --gem-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill-rule='evenodd' d='M12 1l11 11-11 11L1 12zM8.5 8.5v7h7v-7z'/%3E%3C/svg%3E");
}
.cell .gem { position: absolute; inset: 19%; }
.sample .gem { position: absolute; inset: 3px; }
.gem.floating { position: fixed; z-index: 10; }

/* A destroyed gem: faded, with a crack through it. */
.gem.dead {
  background:
    linear-gradient(112deg, transparent 46%, var(--paper) 46% 52%, transparent 52%),
    linear-gradient(68deg, transparent 58%, var(--paper) 58% 63%, transparent 63%),
    var(--hint);
  opacity: .6;
}
/* The live and poisoned hints sit on top of a gem. */
.cell.live::before, .cell.poisoned::before { z-index: 1; }
.cell:has(> .gem:not([hidden])).live::before { box-shadow: 0 0 0 2px var(--paper); }

.players { display: flex; gap: 10px; margin-top: 16px; }
.player { flex: 1 1 0; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); background: var(--paper); }
.player-top { display: flex; justify-content: space-between; gap: 8px; }
.player-name { display: block; min-width: 0; overflow: hidden; color: var(--soft); font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.player-clock { color: var(--soft); font-size: 15px; font-variant-numeric: tabular-nums lining-nums; }
.player-clock.running { color: var(--ink); font-weight: 700; }
.player-clock.low { color: var(--red); }
.tokens { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 34px; color: var(--soft); font-size: 15px; }
.token {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.token:hover:not(:disabled) { background: var(--wash); }
.token:disabled { border-color: var(--line); cursor: default; }
.token .gem { width: 18px; height: 18px; }
.token small { color: var(--soft); font-size: 13px; }
.token.last-turn small { color: var(--red); font-weight: 700; }

.nickname {
  width: min(100%, 240px);
  padding: 6px 10px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font: 400 18px "Bodoni Moda", Georgia, serif;
  text-align: center;
}
/* The main menu's box, with a pencil inside it to show you can type there. */
.name-box { position: relative; width: min(100%, 260px); margin: 26px auto 0; }
.name-box::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  background: var(--soft);
  pointer-events: none;
  transform: translateY(-50%);
  -webkit-mask: var(--pencil) center / contain no-repeat;
  mask: var(--pencil) center / contain no-repeat;
  --pencil: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 21l1.2-5.2L16.5 3.5a2.1 2.1 0 0 1 3 0l1 1a2.1 2.1 0 0 1 0 3L8.2 19.8z'/%3E%3C/svg%3E");
}
.name-box .nickname { width: 100%; padding: 8px 36px; }
.nickname::placeholder { color: var(--soft); opacity: 1; }
.name-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; color: var(--soft); font-size: 15px; }
.name-row .nickname { flex: 0 1 200px; padding: 3px 8px; font-size: 16px; text-align: left; }

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 16px;
  margin-top: 14px;
  color: var(--soft);
  font-size: 15px;
}
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { accent-color: var(--ink); margin: 0; }
.problem { color: var(--ink); font-weight: 700; text-align: center; }

dialog {
  width: min(92vw, 490px);
  max-height: 88dvh;
  padding: 28px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgb(21 21 21 / .3); }
dialog h2 { font-size: 36px; }
dialog h3 { margin: 18px 0 4px; color: var(--soft); font-size: 17px; font-weight: 500; }
dialog p, dialog ol { margin: 4px 0; font-size: 17px; }
dialog ol { padding-left: 22px; }
dialog b { font-weight: 700; }
dialog form { margin-top: 22px; }
.key { display: flex; align-items: center; gap: 10px; }
.sample { position: relative; flex: none; width: 28px; height: 28px; border: 1px solid var(--line); }

/* The swing chart after a game, and the board it can show. */
.review { margin-top: 22px; text-align: left; }
.review-note { margin: 0 0 8px; color: var(--soft); font-size: 16px; text-align: center; }
.swing { display: block; width: 100%; height: auto; touch-action: pan-y; cursor: pointer; }
.swing text { fill: var(--soft); font-size: 13px; }
.swing .middle { stroke: var(--line); stroke-dasharray: 4 4; }
.swing .ahead { fill: var(--mark); opacity: .28; }
.swing .behind { fill: var(--claude); opacity: .28; }
.swing .trace { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; }
.swing .marker { stroke: var(--ink); stroke-width: 1; }
.swing .dot { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.swing .turning { fill: var(--paper); stroke: var(--red); stroke-width: 2; }
.review-slider { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--ink); }
.review-step { min-height: 3em; margin: 8px 0 0; font-size: 16px; text-align: center; }
.replay-wrap { width: min(100%, 320px); margin: 10px auto 0; }

/* One finished game in the history list. */
#history-list { margin-top: 18px; border-top: 1px solid var(--line); }
.history-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 16px;
  width: 100%;
  padding: 10px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.history-row:hover { background: var(--wash); }
.history-row small { color: var(--soft); font-size: 15px; }
.history-row .rules { flex: 0 0 100%; }
