:root {color-scheme: light dark; --bg: #fff; --fg: #000; --muted: #777; --line: #ccc; --border: #555; --hover: #eee; --panel: #fafafa;}
@media (prefers-color-scheme: dark) {
  :root {--bg: #181818; --fg: #e8e8e8; --muted: #999; --line: #444; --border: #888; --hover: #333; --panel: #222;}
}
body {background: var(--bg); color: var(--fg); text-align: center; margin: 0; font-family: Georgia, serif; font-size: 18px;}
nav {width: 100%; box-sizing: border-box; background: #000; padding: 5px; color: #fff;}
nav a {text-decoration: none; color: #fff;}
/* The header's links wrap; the gap before a dot belongs to the link on its left, the dot and the gap after it to the link on its right */
nav:has(> a) {display: flex; flex-wrap: wrap; justify-content: center;}
nav a:has(+ a) {padding-right: 18px;}
nav a + a::before {content: "·"; padding-right: 18px;}
nav + nav {top: unset;}
p {text-align: left; padding: 0 30px; max-width: 1000px; margin: 1em auto;}
form div {display: inline;}
#instructions a {color: inherit; text-decoration: underline var(--fg) dotted;}
h1 {font-size: 8vw; font-family: Cambria, Georgia, serif; margin: .3em 0 0 0;}
h1 span {margin: 0 0.2em;}
button {font-family: Georgia, serif; font-size: 18px; box-sizing: border-box; background: var(--bg); color: var(--fg); border: 1px solid var(--border); border-radius: 2px;}
#board button, #types button, #topics button {overflow-wrap: anywhere; position: relative; line-height: 1.5em; max-height: calc(var(--lines, 4) * 1.5em); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--lines, 4);}
button:hover {background: var(--hover);}
#board.start button {width: min(10em, (100vw - 2 * min(30px, 3vw) - (var(--n) - 1) * 2px) / var(--n)); height: 5em; overflow-wrap: anywhere;}
/* Clusters darken (lighten in dark mode) as they fill up: --fill is their share of a complete cluster */
.cluster, .achievements .unseen, #buttons [data-level="1"] {font-weight: bold; background: color-mix(in srgb, var(--fg) calc(var(--fill) * 40%), var(--bg));}
.cluster .size, .achievements [class^=level] {position: absolute; right: 0; bottom: 0; background: var(--fg); color: var(--bg); padding: 0 8px 3px 8px; line-height: 1em;}
/* Achievements on the profile look like the board's buttons in wrap mode with 10 lines, unseen ones like a half complete cluster */
.achievements {list-style: none; max-width: 1000px; margin: 1em auto; padding: min(30px, 3vw); display: grid; gap: 2px; grid-auto-rows: 1fr; grid-template-columns: repeat(auto-fill, minmax(8em, 1fr)); justify-items: center;}
.achievements li {width: 100%; max-width: 14em; box-sizing: border-box; padding: 1px 6px; border: 1px solid var(--border); border-radius: 2px; overflow-wrap: anywhere; position: relative; line-height: 1.5em; min-height: calc(3em + 4px); display: flex; align-items: center; justify-content: center;}
.achievements li > :last-child {overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 10;}
.achievements .unseen, #buttons [data-level="1"] {--fill: 1;}
.achievements img {position: absolute; left: 0; bottom: 0; height: 1em; padding: 0 4px 3px 4px;}

.shake {animation: shake 0.5s; animation-iteration-count: 1;}


#popout {position: fixed; inset: 0; background: #0006; display: flex; align-items: center; justify-content: center;}
#popout[hidden] {display: none;}
#popout div {background: var(--bg); padding: 1em 2em; border-radius: 4px; max-width: 80vw; max-height: 80vh; overflow-y: auto;}
#popout div > * {display: block;}
#popout b {margin-bottom: .5em;}
#popout i {color: var(--muted);}
#popout table {display: table; margin: 0 auto 1em; border-collapse: collapse;}
#popout td, #popout th {padding: 0 .5em;}
#popout .self {background: var(--hover);}
#popout .codebox {display: flex; gap: 5px; margin: .5em 0;}
#popout .code {flex: auto; min-width: 0; font: inherit;}
#popout button[form] {margin: 1em auto 0;}
#popout ul {text-align: left; margin: 1em 0 0; padding-left: 1.2em;}
#popout .share {flex: auto; white-space: pre-line; text-align: left; overflow-wrap: anywhere; padding: .3em .5em; border: 1px solid var(--border);}

#daily {font-size: 1.6em; margin: 1em 16px 0;}
#daily button {font-size: inherit; padding: .1em .8em; background: var(--fg); color: var(--bg);}
#daily button:hover {background: var(--muted);}

/* The game lists and the new game form share the width of a game button, which fits a 375px phone */
#play {width: 19em; max-width: calc(100% - 32px); margin: 1em auto; text-align: left;}
#play summary, #play h3 {font-size: 1.1em; font-weight: normal; margin: .8em 0 .3em; cursor: pointer;}
#play h3 {cursor: auto;}
.game {display: grid; grid-template-columns: 1fr 3.4em 1.2em 2.8em; gap: .6em; padding: .2em .6em; margin-bottom: 2px; border: 1px solid var(--border); border-radius: 2px; color: inherit; text-decoration: none; font-variant-numeric: tabular-nums;}
.game:hover {background: var(--hover);}
.game :nth-child(2) {text-align: center;}
.game :nth-child(4) {text-align: right;}
#buttons {display: grid; grid-template-columns: auto 1fr; gap: .6em 1em; align-items: center; padding: .8em 1em; border: 1px solid var(--line); border-radius: 6px; background: var(--panel);}
#buttons label[for] {text-align: right;}
#buttons label:not([for]) {grid-column: 2;}
#buttons details {grid-column: 1 / -1;}
#buttons summary {cursor: pointer;}
#buttons small {color: var(--muted);}
#buttons select {justify-self: start; font: inherit; padding: .2em .4em; border: 1px solid var(--border); border-radius: 2px; background: var(--bg); color: var(--fg);}
/* Types and topics are buttons as on the board in wrap mode, two lines high; types that are on look selected,
   topics like a cluster by their level: unclustered when off, half finished when easy, selected when medium, finished when hard */
#types, #topics {--lines: 2; margin-top: .4em;}
#types .on, #buttons [data-level="2"] {filter: invert(100%);}
#buttons [data-level="3"] {font-weight: bold; background: hsl(var(--hue) 70% 85%); color: #000;}
#levels {margin-top: .4em;}
#levels span {display: inline-block; padding: 0 6px; border: 1px solid var(--border); border-radius: 2px; background: var(--bg);}
#buttons button[type=submit] {grid-column: 1 / -1; justify-self: center; padding: .3em 2em; background: var(--fg); color: var(--bg);}
#buttons button[type=submit]:hover {background: var(--muted);}
#board {padding: min(30px, 3vw);}
#board, #types, #topics {display: grid; gap: 2px; grid-auto-rows: 1fr;}
#board.grid {display: inline-grid; grid-template-columns: repeat(var(--n), 1fr);}
/* A game's grid fills the space below the navs, so small games fill the screen */
body:has(#board.grid:not(.start)) {display: flex; flex-direction: column; min-height: 100dvh;}
#board.grid {flex-grow: 1; min-width: min-content;}
#board.wrap, #types, #topics {grid-template-columns: repeat(auto-fill, minmax(8em, 1fr)); justify-items: center;}
#board.wrap button, #types button, #topics button {width: 100%; max-width: 14em;}
#board.grid button, #board.wrap button, #types button, #topics button {min-height: calc(min(2, var(--lines, 4)) * 1.5em + 4px);}
#board.tight {display: flex; flex-wrap: wrap;}
#board.tight button {display: block; white-space: nowrap; text-overflow: ellipsis; max-width: 18em;}
.gone {visibility: hidden;}
#board.tight .gone, #board .gone:not(:has(~ :not(.gone))) {display: none;}

@keyframes shake {
  0%  {transform: translateX(1px)  rotate(0deg); }
  10% {transform: translateX(-1px) rotate(-1deg);}
  20% {transform: translateX(-3px) rotate(1deg); }
  30% {transform: translateX(3px)  rotate(0deg); }
  40% {transform: translateX(1px)  rotate(1deg); }
  50% {transform: translateX(-1px) rotate(-1deg);}
  60% {transform: translateX(-3px) rotate(0deg); }
  70% {transform: translateX(3px)  rotate(-1deg);}
  80% {transform: translateX(-1px) rotate(1deg); }
  90% {transform: translateX(1px)  rotate(0deg); }
  100%{transform: translateX(1px)  rotate(-1deg);}
}

/* The feedback view: suggestion columns that stack on narrow screens, finished categories as tags in their board colour, answers as buttons, the selected one inverted */
#feedback {text-align: left; padding: 0 min(30px, 3vw) 1em; font-size: 16px;}
#feedback h2 {display: flex; justify-content: space-between; align-items: center; gap: .5em;}
#feedback small {display: block; color: var(--muted); font-size: 13px; margin: .1em 0 .3em;}
#feedback .columns {display: grid; grid-template-columns: repeat(auto-fit, minmax(15em, 1fr)); gap: 1em; align-items: start; margin: .5em 0;}
#feedback .column > b {display: block;}
#feedback .card {border: 1px solid var(--line); border-radius: 2px; padding: .3em .5em; margin-top: .4em;}
#feedback .info {white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
#feedback .tag {color: #000; padding: 0 .25em; border-radius: 2px;}
#feedback button {font-size: 14px; padding: .2em .6em; min-height: 2em;}
#feedback button.on {background: var(--fg); color: var(--bg);}
#feedback .choices {display: flex; flex-wrap: wrap; gap: .25em;}
#feedback .chip {margin: .2em .2em 0 0; padding: .1em .3em;}
#feedback .chip.obscure .tag::after {content: " · obscure";}
#feedback .more {display: block; margin: .4em auto 0;}
#feedback summary {cursor: pointer; margin: .3em 0;}
#feedback > details {border-top: 1px solid var(--line); padding-top: .5em;}
#feedback input, #feedback textarea {display: block; width: 100%; box-sizing: border-box; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--border);}
