@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 */
  --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;
}

* { box-sizing: border-box; border-radius: 0; }
[hidden] { display: none !important; }

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;
  cursor: pointer;
}
.nav { display: flex; gap: 18px; }
.link:hover { text-decoration: underline; text-underline-offset: 4px; }

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

#home, #missing, #host, #join { 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; }

.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; }
.status h2 { font-size: 38px; }
.status p { margin: 4px 0 0; min-height: 1.5em; 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 {
  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 { 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));
}

.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); }
