:root {
  background: var(--sw-surface);
  color: var(--sw-on-surface);
  font-family: var(--sw-body);
  line-height: 1.4;
}
*, *::before, *::after { box-sizing: border-box; }
button, a { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
[hidden] { display: none !important; }
a { color: inherit; text-underline-offset: .25em; }
button, input { font: inherit; }
button, input {
  min-height: 2.75rem;
  border: 1px solid var(--sw-border);
  border-radius: calc(var(--sw-radius) / 2);
}
button, .button {
  color: var(--sw-on-raised);
  background: var(--sw-raised);
  font-weight: 680;
  padding: .65rem 1rem;
}
button:not(:disabled):not([aria-disabled="true"]) { cursor: pointer; }
button:disabled { opacity: .64; }
button:not(:disabled):not([aria-disabled="true"]):hover { border-color: var(--sw-accent); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--sw-focus);
  outline-offset: 3px;
}
input {
  width: 100%;
  min-width: 0;
  padding: .55rem .7rem;
  background: var(--sw-surface);
  color: var(--sw-on-surface);
}
input::placeholder { color: var(--sw-muted); }
h1, h2, h3, h4, p { margin: 0; }

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: clamp(.6rem, 2.5vw, 1.75rem);
  padding: .4rem max(clamp(.75rem, 2.5vw, 1.75rem), env(safe-area-inset-right)) .4rem max(clamp(.75rem, 2.5vw, 1.75rem), env(safe-area-inset-left));
  border-bottom: 1px solid color-mix(in srgb, var(--sw-border) 55%, transparent);
}
.launcher { font-weight: 800; letter-spacing: -.02em; text-decoration: none; font-size: .9rem; color: var(--sw-muted); }
.title { display: flex; align-items: baseline; gap: .75rem; min-width: 0; overflow: hidden; }
h1 { font: 800 clamp(1.3rem, 3.2vw, 1.8rem)/1.05 var(--sw-display); letter-spacing: -.035em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-actions { display: flex; gap: .45rem; margin-inline-start: auto; }
.bar-actions button { min-height: 2.5rem; padding-block: .4rem; white-space: nowrap; }
.icon { display: grid; place-items: center; min-width: 2.5rem; padding-inline: .5rem; }
.icon svg { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon .speaker { fill: currentColor; }
#sound[data-sound="on"] .cross, #sound[data-sound="off"] .waves { display: none; }
#sound[data-sound="off"] { color: var(--sw-muted); }

/* The table: information, the board and the tools. The board takes whatever the screen leaves. */
.table {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "info" "well" "pad";
  gap: .5rem;
  padding: .5rem max(.75rem, env(safe-area-inset-right)) max(.6rem, env(safe-area-inset-bottom)) max(.75rem, env(safe-area-inset-left));
}
.info { grid-area: info; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 .75rem; }
.name { display: flex; align-items: center; gap: .6rem; min-width: 0; flex-wrap: wrap; }
.info h2 { font: 700 clamp(1.05rem, 2.2vw, 1.35rem)/1.15 var(--sw-display); }
.small { min-height: 2rem; padding: .2rem .6rem; font-size: .8rem; }
.clock { font: 700 1.2rem/1 var(--sw-body); font-variant-numeric: tabular-nums; color: var(--sw-muted); }
#puzzle-status { grid-column: 1 / -1; color: var(--sw-muted); font-size: .9rem; min-height: 1.3em; }
.table[data-status="finished"] #puzzle-status { color: var(--sw-accent); }
.result { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .75rem; margin-top: .25rem; }
.result p { color: var(--sw-muted); font-size: .9rem; flex: 1 1 14rem; }
.result p:empty { display: none; }
.result button { min-height: 2.5rem; padding-block: .3rem; }

.well { grid-area: well; min-height: 0; min-width: 0; display: grid; place-items: center; overflow: hidden; }
.board {
  --cell: 20px;
  /* Unknown squares are a neutral gray from the theme's text and surface, squares known to be empty are black,
     and the gaps between squares are the surface, so empty areas read as holes in the picture. */
  --unknown: color-mix(in srgb, var(--sw-on-surface) 30%, var(--sw-surface));
  --empty: color-mix(in srgb, #000 86%, var(--sw-surface));
  --gap: var(--sw-surface);
  display: grid;
  grid-template-columns: max-content repeat(var(--n, 1), var(--cell));
  grid-template-rows: auto repeat(var(--n, 1), var(--cell));
  width: max-content;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.line { display: contents; }
.corner { min-width: 0; min-height: 0; }

.clue {
  display: flex;
  min-width: 0;
  min-height: 0;
  color: var(--sw-on-surface);
  font-size: calc(var(--cell) * .52);
  font-weight: 650;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.clue.col {
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: calc(var(--cell) * .12);
  padding-bottom: calc(var(--cell) * .12);
}
.clue.row {
  justify-content: flex-end;
  align-items: center;
  gap: calc(var(--cell) * .26);
  padding-inline: calc(var(--cell) * .1) calc(var(--cell) * .2);
  white-space: nowrap;
}
.clue[data-edge-right="true"] { box-shadow: inset -2px 0 0 color-mix(in srgb, var(--sw-board-line) 70%, transparent); }
.clue[data-edge-bottom="true"] { box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--sw-board-line) 70%, transparent); }
.clue[data-line="true"] { background: var(--sw-board-cell-target); }
.clue[data-done="true"] { color: var(--sw-muted); opacity: .42; font-weight: 500; }

.cell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--sw-muted);
  background: var(--unknown);
  box-shadow: inset -1px -1px 0 var(--gap);
  touch-action: none;
  transition: background-color 90ms ease-out;
}
.cell[data-edge-right="true"] { box-shadow: inset -2px -1px 0 var(--gap); }
.cell[data-edge-bottom="true"] { box-shadow: inset -1px -2px 0 var(--gap); }
.cell[data-edge-right="true"][data-edge-bottom="true"] { box-shadow: inset -2px -2px 0 var(--gap); }
.cell:disabled { opacity: 1; }
.cell[data-state="filled"] { background: var(--sw-accent); }
.cell[data-state="crossed"] { background: var(--empty); }
/* A drag in progress shows what it will do. */
.cell[data-preview="filled"] { background: color-mix(in srgb, var(--sw-accent) 60%, var(--unknown)); }
.cell[data-preview="crossed"] { background: color-mix(in srgb, var(--empty) 65%, var(--unknown)); }
.cell[data-preview="unknown"] { background: color-mix(in srgb, var(--unknown) 75%, var(--sw-on-surface)); }
/* Photo puzzles. With the setting on, a line whose filled squares match its clue shows its part of the faded photo:
   filled squares plainly, the rest darkened, so the pattern stays readable. A drag's preview shows over it. */
.cell[data-hint="true"] {
  background-image: var(--hint);
  background-size: calc(var(--n) * var(--cell)) calc(var(--n) * var(--cell));
  background-position: calc(var(--c) * var(--cell) * -1) calc(var(--r) * var(--cell) * -1);
}
.cell[data-hint="true"]:not([data-state="filled"])::after {
  content: "";
  position: absolute;
  inset: 0 1px 1px 0;
  background: rgb(0 0 0 / .58);
  pointer-events: none;
}
.cell[data-hint="true"][data-preview] { background-image: none; }
.cell[data-hint="true"][data-preview]::after { display: none; }
/* A solved photo puzzle fades its photo in over the squares. */
.board { position: relative; }
.photo { position: absolute; z-index: 2; pointer-events: none; opacity: 0; background: center / cover no-repeat; transition: opacity 1100ms ease; }
.board.revealed .photo[data-shown="true"] { opacity: 1; }
.cell[data-selected="true"] { outline: 2px solid var(--sw-focus); outline-offset: -2px; z-index: 1; }
.cell:focus-visible { outline: 3px solid var(--sw-focus); outline-offset: -3px; z-index: 1; }
.cell:not(:disabled):hover { border: 0; }
.cell[data-reveal="blank"] { background: var(--sw-board-inert); }
.cell[data-reveal="art"], .cell[data-reveal="win"] { background: var(--sw-accent); }
.board.revealed .cell { transition: background-color 700ms ease; transition-delay: calc(var(--i, 0) * 28ms); }
.board.revealed .cell[data-reveal="art"] { background: var(--art, var(--sw-board-cell-win)); }
.board.revealed .cell[data-reveal="win"] { background: var(--sw-board-cell-win); }
.board:not(.revealed) .cell[data-reveal] { transition: none; }
.cell[data-reveal][data-selected="true"], .cell[data-reveal]:focus-visible { outline: 0; }

.pad { grid-area: pad; display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: .4rem; }
.mode { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; }
.pad button { min-height: 2.9rem; padding-block: .3rem; font-size: 1.05rem; }
.pad button[aria-pressed="true"] { color: var(--sw-on-action); background: var(--sw-action); border-color: var(--sw-action); }
.mode button { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.swatch { width: .85em; height: .85em; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px color-mix(in srgb, var(--sw-on-raised) 35%, transparent); }
#mode-fill .swatch { background: var(--sw-accent); }
#mode-cross .swatch { background: color-mix(in srgb, #000 86%, var(--sw-surface)); }
/* Ctrl or Cmd held: a click does the other mode, so that button shows a dashed edge. */
.pad[data-flipped="true"] .mode button[aria-pressed="false"] { outline: 2px dashed var(--sw-action); outline-offset: -4px; }
.keys { grid-column: 1 / -1; font-size: .78rem; text-align: center; }
kbd { font: inherit; font-weight: 700; padding: 0 .3em; border: 1px solid color-mix(in srgb, var(--sw-border) 70%, transparent); border-radius: 4px; }
@media (hover: none) { .keys { display: none; } }

/* Wider than tall: the board on the left and the controls beside it, together in the middle. */
@media (orientation: landscape) and (min-width: 36rem) {
  .table {
    width: min(100%, 78rem);
    margin-inline: auto;
    grid-template-columns: minmax(0, 1fr) minmax(13rem, 18rem);
    grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
    grid-template-areas: "well ." "well info" "well pad" "well .";
    column-gap: clamp(.75rem, 3vw, 2rem);
    row-gap: .5rem;
  }
  .well { place-items: center end; }
  .pad { grid-template-columns: 1fr; }
  .pad button { min-height: 3rem; }
}
@media (orientation: landscape) and (max-height: 32rem) {
  .pad { grid-template-columns: 1fr; gap: .3rem; }
  .pad button { min-height: 2.45rem; }
  #puzzle-status { font-size: .85rem; }
  .bar { padding-block: .25rem; }
  .table { padding-block: .35rem; }
}
.primary { color: var(--sw-on-action); background: var(--sw-action); border-color: var(--sw-action); }
.primary:not(:disabled):hover { filter: brightness(1.08); border-color: var(--sw-focus); }
.hint { color: var(--sw-muted); font-size: .9rem; }
.hint.error { color: var(--sw-danger); margin-top: .4rem; }
/* Over the table, so a message never changes the size of the grid. */
.activity {
  position: fixed;
  inset: auto 0 max(.75rem, env(safe-area-inset-bottom));
  z-index: 4;
  width: fit-content;
  max-width: calc(100vw - 1.5rem);
  margin-inline: auto;
  padding: .45rem .9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  border: 1px solid var(--sw-border);
  border-radius: calc(var(--sw-radius) / 2);
  background: var(--sw-raised);
  color: var(--sw-accent);
  font-size: .9rem;
}
.activity:has(p:empty):has(button[hidden] + button[hidden]) { display: none; }

dialog {
  width: min(34rem, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: clamp(1rem, 3vw, 1.5rem);
  color: var(--sw-on-raised);
  background: var(--sw-raised);
  border: 1px solid var(--sw-border);
  border-radius: var(--sw-radius);
  overflow: auto;
}
dialog::backdrop { background: color-mix(in srgb, var(--sw-surface) 72%, transparent); }
dialog header { display: flex; justify-content: space-between; align-items: center; margin-bottom: .8rem; }
dialog h2 { font: 700 1.5rem/1.1 var(--sw-display); }
dialog h3 { font: 700 1.1rem/1.1 var(--sw-display); margin-block: 1.1rem .5rem; }
dialog h4 { font-size: .9rem; margin-block: .8rem .35rem; color: var(--sw-muted); }
.close { min-width: 2.75rem; padding: 0; }
.options { border: 0; padding: 0; margin: 0 0 1rem; display: grid; gap: .4rem; min-width: 0; }
.options legend { padding: 0; margin-bottom: .4rem; font-weight: 720; font-size: .9rem; }
.options label { position: relative; display: block; cursor: pointer; }
.options input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; opacity: 0; cursor: pointer; }
.options span { display: block; border: 2px solid color-mix(in srgb, var(--sw-border) 60%, transparent); border-radius: calc(var(--sw-radius) / 2); padding: .5rem .75rem; }
.options small { display: block; color: var(--sw-muted); font-size: .84rem; }
.options input:checked + span { border-color: var(--sw-accent); }
.options input:checked + span strong { color: var(--sw-accent); }
.options input:focus-visible + span { outline: 2px solid var(--sw-focus); outline-offset: 2px; }
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .3rem; font-weight: 720; font-size: .9rem; }
.field input { max-width: 14rem; }
.field .hint { margin-top: .4rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .6rem; }
#new-form .actions { grid-template-columns: 1fr; margin-top: 1rem; }
#result .actions { margin: .9rem 0 0; }
#result p { margin-top: .4rem; color: var(--sw-muted); }
.menu-tools { display: flex; flex-wrap: wrap; gap: .5rem; }
.switch { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .8rem; padding: .45rem 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.switch > span { display: block; }
.switch small { display: block; color: var(--sw-muted); font-size: .84rem; }
.switch::after {
  content: "";
  grid-column: 2;
  grid-row: 1;
  width: 2.6rem;
  height: 1.5rem;
  border-radius: 1rem;
  border: 1px solid var(--sw-border);
  background: radial-gradient(circle at .72rem 50%, var(--sw-muted) 0 .5rem, transparent .55rem) var(--sw-surface);
}
.switch:has(input:checked)::after { background: radial-gradient(circle at 1.85rem 50%, var(--sw-on-action) 0 .5rem, transparent .55rem) var(--sw-action); border-color: var(--sw-action); }
.switch:has(input:focus-visible)::after { outline: 2px solid var(--sw-focus); outline-offset: 2px; }
.button { display: inline-grid; place-items: center; min-height: 2.75rem; border: 1px solid var(--sw-border); border-radius: calc(var(--sw-radius) / 2); text-decoration: none; }
.menu-tools .button { padding-inline: 1rem; }
#mine-status:empty, #active-list:empty, #done-list:empty, #best-list:empty { display: none; }
#menu ul { list-style: none; padding: 3px; margin: 0; display: grid; gap: .35rem; max-height: 12rem; overflow: auto; }
#menu li button { width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .15rem .5rem; text-align: left; padding: .45rem .65rem; }
#menu li button[aria-current="true"] { border-color: var(--sw-accent); }
#menu li button span, #menu li.best span { color: var(--sw-muted); font-size: .8rem; font-weight: 500; }
#menu li.best { display: grid; padding: .25rem .1rem; }
.realm { display: flex; margin-top: 1rem; font-size: .84rem; }
.realm a { color: var(--sw-muted); padding: .45rem .6rem; text-decoration: none; }
.realm a[aria-current] { color: var(--sw-on-raised); font-weight: 720; text-decoration: underline; }

@media (max-width: 40rem) {
  .bar { gap: .55rem; }
  .launcher { font-size: .78rem; }
  .bar-actions { gap: .35rem; }
  .bar-actions button { padding-inline: .6rem; font-size: .9rem; }
  .bar-actions .icon { min-width: 2.25rem; padding-inline: .35rem; }
  h1 { font-size: 1.2rem; }
}
@media (max-width: 24rem) {
  .bar .launcher { display: none; }
}
@media (max-height: 32rem) {
  .options small, #number-hint { display: none; }
  .options span { padding-block: .3rem; }
  dialog { padding-block: .75rem; }
  dialog header { margin-bottom: .4rem; }
  .options { margin-bottom: .5rem; }
  #new-form .actions { margin-top: .5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* New game and Pictures */
.options.sizes { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.options.sizes legend { grid-column: 1 / -1; }
.options.pick { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.options.pick legend { grid-column: 1 / -1; }
.options.pick span { text-align: center; padding: .3rem; }
.options.sizes span { text-align: center; padding-inline: .3rem; }
.options input:disabled + span { opacity: .4; }
#new-form .actions { grid-template-columns: 2fr 1fr; }
#new-form .hint { margin-bottom: .6rem; }
#pictures { width: min(40rem, calc(100vw - 1.5rem)); }
#pictures h3 { margin-top: .9rem; }
.tiles { list-style: none; margin: 0; padding: 3px; display: grid; grid-template-columns: repeat(auto-fill, minmax(5.2rem, 1fr)); gap: .4rem; }
.tile {
  width: 100%;
  min-height: 5.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .2rem;
  padding: .35rem .2rem;
  font-size: .78rem;
  line-height: 1.1;
}
.tile canvas { image-rendering: pixelated; width: 3.2rem; height: 3.2rem; background: var(--sw-board-inert); border-radius: 3px; }
.tile .unknown { display: grid; place-items: center; width: 3.2rem; height: 3.2rem; border: 1px dashed var(--sw-border); border-radius: 3px; color: var(--sw-muted); font-size: 1.3rem; text-align: center; }
.tile[data-solved="false"] .unknown { font-size: 1.2rem; }
.tile small { color: var(--sw-muted); font-size: .72rem; font-weight: 500; }
@media (prefers-reduced-motion: reduce) {
  .cell, .board.revealed .cell { transition: none !important; }
}
