: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; }
html, body { height: 100%; }
body { margin: 0; display: flex; flex-direction: column; height: 100dvh; overflow: hidden; background: var(--sw-surface); }
#table-scene { position: fixed; inset: 0; z-index: 0; width: 100%; height: 100%; pointer-events: none; }
.bar, .table { position: relative; z-index: 1; }
html[data-table-scene]:not([data-table-scene=""]) body { background: transparent; }
[hidden] { display: none !important; }
a { color: inherit; text-underline-offset: .25em; }
button, input, select { font: inherit; }
button, input, select {
  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, select: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); }
select { padding: .45rem .6rem; background: var(--sw-surface); color: var(--sw-on-surface); max-width: 100%; }
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);
  background: color-mix(in srgb, var(--sw-surface) 88%, 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 { overflow: hidden; text-overflow: ellipsis; }
h1 { font: 800 clamp(1.3rem, 3.2vw, 1.8rem)/1.05 var(--sw-display); letter-spacing: -.035em; white-space: nowrap; }
.bar-actions { display: flex; gap: .45rem; margin-inline-start: auto; }
.bar-actions button { min-height: 2.5rem; padding-block: .4rem; white-space: nowrap; }
.gear { display: none; font-size: 1.15rem; line-height: 1; }
.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 grid and the number pad. The grid 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); }

.well { grid-area: well; min-height: 0; min-width: 0; container-type: size; display: grid; place-items: center; }
.grid {
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  container-type: inline-size;
  display: grid;
  grid-template-rows: repeat(9, 1fr);
  border: 3px solid var(--sw-board-line);
  border-radius: calc(var(--sw-radius) / 3);
  background: var(--sw-board-inert);
  overflow: hidden;
  box-shadow: 0 .6rem 2.2rem color-mix(in srgb, black 35%, transparent);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.line { display: grid; grid-template-columns: repeat(9, 1fr); min-height: 0; }
.cell {
  --thin: color-mix(in srgb, var(--sw-board-line) 50%, transparent);
  position: relative;
  min-height: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--sw-on-raised);
  background: var(--sw-board-cell);
  box-shadow: inset -1px -1px 0 var(--thin);
  font-family: var(--sw-display);
  font-weight: 500;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.table[data-tap-order="popup"] .cell { touch-action: none; }
.cell[data-edge-right="true"] { box-shadow: inset -3px 0 0 var(--sw-board-line), inset 0 -1px 0 var(--thin); }
.cell[data-edge-bottom="true"] { box-shadow: inset 0 -3px 0 var(--sw-board-line), inset -1px 0 0 var(--thin); }
.cell[data-edge-right="true"][data-edge-bottom="true"] { box-shadow: inset -3px -3px 0 var(--sw-board-line); }
.cell:disabled { opacity: 1; }
.cell[data-state="given"] { background: var(--sw-game-given); }
.cell[data-peer="true"] { background: var(--sw-game-peer); }
.cell[data-state="given"][data-peer="true"] { background: color-mix(in srgb, var(--sw-game-peer) 60%, var(--sw-game-given)); }
.cell[data-noted="true"] { background: color-mix(in srgb, var(--sw-game-match) 45%, var(--sw-board-cell)); }
.cell[data-same="true"] { background: var(--sw-game-match); }
.cell[data-selected="true"] { background: var(--sw-board-cell-active); }
.cell[data-conflict="true"] { background: color-mix(in srgb, var(--sw-danger) 26%, var(--sw-board-cell)); }
.cell[data-solved="true"] { background: var(--sw-board-cell-win); }
.cell:focus-visible { outline: 3px solid var(--sw-focus); outline-offset: -3px; z-index: 1; }
.cell:not(:disabled):hover { border: 0; }
@media (hover: hover) {
  .cell:not(:disabled):not([data-selected="true"]):hover { filter: brightness(1.12); }
}
.digit {
  display: block;
  font-size: 7cqw;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.cell[data-state="given"] .digit { font-weight: 800; }
.cell[data-state="entry"] .digit { color: var(--sw-accent); font-weight: 600; }
.cell:is([data-selected="true"], [data-same="true"])[data-state="entry"] .digit { color: var(--sw-on-raised); }
.cell[data-conflict="true"] .digit { color: var(--sw-danger); }
.cell[data-conflict="true"][data-state="given"] .digit { text-decoration: underline; text-decoration-thickness: .08em; }
.cell[data-solved="true"] .digit { color: var(--sw-on-raised); }
.notes {
  position: absolute;
  inset: 5%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  font-size: 2.9cqw;
  line-height: 1;
  font-weight: 650;
  color: var(--sw-muted);
}
.notes span { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 30%; }
.notes span.hit { background: var(--sw-accent); color: var(--sw-surface); font-weight: 800; }
.cell[data-selected="true"] .notes, .cell[data-same="true"] .notes { color: var(--sw-on-raised); }
.cell:not([data-value=""]) .notes { display: none; }
.grid.celebrate .cell { animation: solved 700ms ease both; animation-delay: calc(var(--i) * 45ms); }
@keyframes solved { 40% { transform: scale(1.1); z-index: 1; } }

.pad { grid-area: pad; display: grid; gap: .4rem; }
html[data-table-scene]:not([data-table-scene=""]) :is(.pad, .info) {
  padding: .55rem;
  border: 1px solid color-mix(in srgb, var(--sw-border) 70%, transparent);
  border-radius: var(--sw-radius);
  background: color-mix(in srgb, var(--sw-surface) 86%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.modes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); padding: 3px; gap: 3px; border: 1px solid var(--sw-border); border-radius: calc(var(--sw-radius) / 2 + 3px); background: var(--sw-board-inert); }
.modes button { min-height: 2.3rem; padding-block: .25rem; border-color: transparent; background: transparent; color: var(--sw-muted); }
.modes button[aria-pressed="true"] { color: var(--sw-on-action); background: var(--sw-action); border-color: var(--sw-action); }
.digits { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: .3rem; }
.digits button {
  position: relative;
  min-width: 0;
  min-height: 2.9rem;
  padding: 0;
  font-family: var(--sw-display);
  font-size: 1.45rem;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.pad-digit { font-variant-numeric: tabular-nums; }
.left { position: absolute; top: .15rem; right: .3rem; font-size: .62rem; font-weight: 650; color: var(--sw-muted); font-family: var(--sw-body); }
.digits button[data-done="true"] { color: var(--sw-muted); opacity: .55; }
.digits button[data-focus="true"] { border-color: var(--sw-accent); box-shadow: inset 0 0 0 1px var(--sw-accent); }
.digits button[aria-pressed="true"] { color: var(--sw-on-action); background: var(--sw-action); border-color: var(--sw-action); opacity: 1; }
.digits button[aria-pressed="true"] .left { color: inherit; }
.table[data-notes="true"] .digits .pad-digit { font-size: .72em; font-weight: 600; }
.digits button:active:not(:disabled) { transform: scale(.96); }
.tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .3rem; }
.tools button { min-height: 2.6rem; padding-block: .3rem; }
.pad-hint { color: var(--sw-muted); font-size: .82rem; min-height: 1.2em; text-align: center; }
.pad-hint:empty { display: none; }

/* The pop-up pad, over the pressed cell. */
.popup {
  position: fixed;
  z-index: 5;
  left: var(--x, 0);
  top: var(--y, 0);
  display: grid;
  gap: .3rem;
  padding: .4rem;
  border: 1px solid var(--sw-accent);
  border-radius: var(--sw-radius);
  background: var(--sw-raised);
  box-shadow: 0 .8rem 2rem color-mix(in srgb, black 45%, transparent);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}
.popup-digits { display: grid; grid-template-columns: repeat(3, 3.1rem); gap: .3rem; }
.popup-digits button { min-height: 3.1rem; padding: 0; font: 700 1.45rem/1 var(--sw-display); -webkit-tap-highlight-color: transparent; }
.popup-digits button[data-done="true"] { color: var(--sw-muted); }
.popup-digits button[data-hover="digit"] { background: var(--sw-action); color: var(--sw-on-action); border-color: var(--sw-action); }
.popup-digits button[data-hover="note"] { background: var(--sw-accent); color: var(--sw-surface); border-color: var(--sw-accent); font-size: .95rem; }
.table[data-notes="true"] ~ .popup .popup-digits button { font-size: 1rem; font-weight: 600; }
.popup-tools { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; }
.popup-tools button { min-height: 2.3rem; padding: .2rem .4rem; font-size: .85rem; }
.popup-tools button[aria-pressed="true"] { color: var(--sw-on-action); background: var(--sw-action); border-color: var(--sw-action); }
@media (prefers-reduced-motion: no-preference) {
  .popup[data-open] { animation: popup-in 110ms ease-out; }
  @keyframes popup-in { from { opacity: 0; transform: scale(.92); } }
}

/* Wider than tall: the grid on the left and the controls beside it, together in the middle. */
@media (orientation: landscape) and (min-width: 36rem) {
  .table {
    width: min(100%, 74rem);
    margin-inline: auto;
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 21rem);
    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; }
  .digits { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
  .digits button { min-height: 3.4rem; font-size: 1.65rem; }
  .tools button { min-height: 2.9rem; }
  .left { font-size: .65rem; }
}
@media (orientation: landscape) and (max-height: 32rem) {
  .digits { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .3rem; }
  .digits button { min-height: 2.45rem; font-size: 1.25rem; }
  .tools button { min-height: 2.45rem; }
  #puzzle-status { font-size: .85rem; }
}
@media (orientation: portrait) {
  /* Digits on top, then the mode switch and the tools sharing one row. */
  .pad { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "digits digits" "modes tools" "hint hint"; }
  .modes button, .tools button { min-width: 0; padding-inline: .3rem; }
  .digits { grid-area: digits; }
  .modes { grid-area: modes; }
  .tools { grid-area: tools; }
  .pad-hint { grid-area: hint; }
  .modes button, .tools button { min-height: clamp(2.6rem, 5.5vh, 3.2rem); }
  .digits button { min-height: clamp(3.1rem, 7vh, 4rem); padding-bottom: .55rem; }
  .left { top: auto; right: 0; left: 0; bottom: .12rem; text-align: center; }
}

.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; }
.actions.single { grid-template-columns: 1fr; margin-top: 1rem; }
.options.inline { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.options.inline legend { width: 100%; }
.options.inline span { padding: .35rem .9rem; font-weight: 650; }
.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; }
#settings h3 { border-top: 1px solid color-mix(in srgb, var(--sw-border) 60%, transparent); padding-top: 1rem; }
#settings select { width: 100%; }
.keys { width: 100%; border-collapse: collapse; margin-top: .6rem; font-size: .86rem; }
.keys th, .keys td { text-align: left; vertical-align: top; padding: .3rem .4rem .3rem 0; border-top: 1px solid color-mix(in srgb, var(--sw-border) 40%, transparent); }
.keys th { white-space: nowrap; font-weight: 600; }
.keys td { color: var(--sw-muted); }
kbd { display: inline-block; min-width: 1.4em; padding: .05rem .3rem; border: 1px solid var(--sw-border); border-bottom-width: 2px; border-radius: 4px; font: 600 .8rem/1.2 var(--sw-body); text-align: center; background: var(--sw-surface); }
@media (hover: none) and (pointer: coarse) { .keys { display: none; } }
#result .actions { margin: .9rem 0 0; }
#result p { margin-top: .4rem; color: var(--sw-muted); }
.menu-tools { display: flex; flex-wrap: wrap; gap: .5rem; }
.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; }

/* Touches for particular theme scenery. The colors still come from the theme. */
[data-table-scene="rain"] .grid { box-shadow: 0 0 2.4rem color-mix(in srgb, var(--sw-accent) 22%, transparent); }
[data-table-scene="rain"] .digit { text-shadow: 0 0 .35em color-mix(in srgb, var(--sw-accent) 55%, transparent); }
[data-table-scene="rain"] .cell[data-state="given"] .digit { text-shadow: 0 0 .3em color-mix(in srgb, var(--sw-on-raised) 40%, transparent); }
[data-table-scene="rain"] .modes button[aria-pressed="true"], [data-table-scene="rain"] .primary { box-shadow: 0 0 1rem color-mix(in srgb, var(--sw-action) 45%, transparent); }
[data-table-scene="drafting"] .grid { box-shadow: 0 0 0 1px var(--sw-board-line), .5rem .5rem 0 color-mix(in srgb, black 25%, transparent); }
[data-table-scene="drafting"] .cell { --thin: color-mix(in srgb, var(--sw-board-line) 32%, transparent); }
[data-table-scene="drafting"] .cell[data-state="entry"] .digit { font-family: var(--sw-body); font-style: italic; }
[data-table-scene="drafting"] .notes { font-family: var(--sw-body); font-style: italic; }

@media (max-width: 40rem) {
  .bar { gap: .55rem; }
  .launcher { font-size: .78rem; }
  .bar-actions button { padding-inline: .7rem; font-size: .9rem; }
  h1 { font-size: 1.2rem; }
}
@media (max-width: 30rem) {
  .bar .launcher { display: none; }
  #open-settings { padding-inline: .7rem; }
  #open-settings .gear { display: block; }
  #open-settings .label { display: none; }
}
@media (max-width: 22rem) {
  .bar { gap: .4rem; padding-inline: .5rem; }
  .bar-actions { gap: .3rem; }
  .bar-actions button { padding-inline: .5rem; font-size: .85rem; }
  h1 { font-size: 1.05rem; }
}
@media (max-height: 40rem) {
  .pad-hint { 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) {
  .grid.celebrate .cell { animation: none; }
  * { transition: none !important; }
}
