/* Shared styling for the tiling demos. Colour tokens match index.html and
   audit.css, so the cards read as part of the site. The map itself takes
   its colours from map.js. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f3ec, #16161a);
  --panel: light-dark(rgba(255, 253, 248, 0.94), rgba(30, 30, 35, 0.94));
  --text: light-dark(#46443d, #c8c4b9);
  --h1: light-dark(#1a1a1a, #f5f3ec);
  --h3: light-dark(#38362e, #d8d4c9);
  --link: light-dark(#1552a1, #7aa6e0);
  --rule: light-dark(#ddd8cc, #3a3a3a);
  --ring: light-dark(rgba(0, 0, 0, 0.14), rgba(255, 255, 255, 0.16));
  --muted: light-dark(#7c786d, #918c80);
  --danger: light-dark(#c0263b, #ff6b7d);
  --shadow: light-dark(0 2px 10px rgba(40, 30, 10, 0.14), 0 2px 12px rgba(0, 0, 0, 0.5));
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--link); }

#map {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  outline: none;
}
#map.dragging { cursor: grabbing; }
#map.picking { cursor: crosshair; }

.card {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* The title and options cards share a top bar. They sit at either end on a
   wide screen and wrap onto two rows on a phone. The bar itself lets drags
   through to the map. */
.top {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
.top .card { position: static; pointer-events: auto; }

.title { max-width: 380px; padding: 0.7rem 0.9rem 0.75rem; }
.title .back { font-size: 0.85rem; text-decoration: none; }
.title .back:hover { text-decoration: underline; }
/* About sits in the title card's top right corner, level with the back
   link, since it explains the tiling the card names. */
.top .title { position: relative; }
.title .about-open { position: absolute; top: 0.55rem; right: 0.65rem; padding: 0.12rem 0.55rem; font-size: 0.8rem; }
.title h1 { font-size: 1.3rem; line-height: 1.2; color: var(--h1); margin: 0.2rem 0 0.25rem; font-weight: normal; }
.title p { margin: 0; font-size: 0.9rem; color: var(--muted); }
.title .row { display: flex; gap: 0.5rem; margin-top: 0.55rem; flex-wrap: wrap; align-items: center; }

/* The Hat | Spectre | Hat (extended) switch, styled as joined tabs of
   equal width. */
.switch {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--ring);
  border-radius: 7px;
  overflow: hidden;
  font-size: 0.85rem;
}
.switch a { padding: 0.2rem 0.55rem; text-decoration: none; color: var(--h3); text-align: center; white-space: nowrap; }
.switch a + a { border-left: 1px solid var(--ring); }
.switch a[aria-current="page"] { background: var(--ring); color: var(--h1); }
.switch a:hover { color: var(--h1); }

button, select {
  font: inherit;
  font-size: 0.88rem;
  color: var(--h3);
  background: transparent;
  border: 1px solid var(--ring);
  border-radius: 7px;
  padding: 0.28rem 0.6rem;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); color: var(--h1); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}
select { background: var(--panel); max-width: 100%; }

/* Options card, top right: shape, supertiles and grid. On a phone its body
   folds away behind a button, the card's only head. */
.options {
  margin-left: auto;
  padding: 0.55rem 0.65rem;
  width: 16.5rem;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}
.options .head { display: none; }
.options .body { display: flex; flex-direction: column; gap: 0.4rem; }
.options .section { border-top: 1px solid var(--rule); padding-top: 0.45rem; display: flex; flex-direction: column; gap: 0.35rem; }
.options .section:first-child { border-top: none; padding-top: 0; }
.options .section-title { font-size: 0.75rem; color: var(--muted); letter-spacing: 0.02em; }
.options label { font-size: 0.88rem; color: var(--h3); display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.options input[type="checkbox"], .options input[type="radio"] { accent-color: var(--link); width: 1rem; height: 1rem; margin: 0; flex: none; }
.options .sub { padding-left: 1.4rem; display: flex; flex-direction: column; gap: 0.3rem; }
.options .inline { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; }
.options .hint { font-size: 0.75rem; color: var(--muted); margin: 0; line-height: 1.35; }
.options .linkish, .legend .linkish { border: none; padding: 0; font-size: 0.8rem; color: var(--link); background: none; }

/* A labelled slider with its value alongside. */
.slider { display: grid; grid-template-columns: 1fr auto; gap: 0.1rem 0.5rem; align-items: center; font-size: 0.85rem; color: var(--h3); }
.slider input[type="range"] { grid-column: 1 / -1; width: 100%; margin: 0; accent-color: var(--link); }
.slider output { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.8rem; }
/* The strip under the bend slider marks where tiles start to overlap. */
.limits { grid-column: 1 / -1; height: 4px; border-radius: 2px; margin: -0.1rem 0 0.1rem; background: var(--ring); }
.limit-note { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); }
.ticks { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--muted); margin-top: -0.15rem; }
.ticks button { border: none; padding: 0; font-size: 0.68rem; color: var(--muted); background: none; }
.ticks button:hover, .ticks button.on { color: var(--link); }
/* Ticks placed under their slider values, the end ones kept inside. */
.ticks.placed { display: block; position: relative; height: 1.1em; }
.ticks.placed button { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.ticks.placed button:first-child { transform: none; }
.ticks.placed button:last-child { transform: translateX(-100%); }
/* The zero of a signed slider: a mark across the strip and a 0 to click. */
.limits { position: relative; }
.limits::after { content: ""; position: absolute; left: calc(50% - 1px); top: -3px; width: 2px; height: 10px; border-radius: 1px; background: var(--h3); }
.ticks.zero { justify-content: center; }
.ticks.zero button { font-size: 0.8rem; font-weight: 600; padding: 0 0.4rem; }

.theme-toggle, .dice {
  width: 2rem;
  height: 2rem;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
}
.theme-toggle svg, .dice svg { display: block; width: 1.05rem; height: 1.05rem; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: none; }

/* Zoom buttons and compass, bottom right, stacked as on a map. */
.zoom {
  right: max(12px, env(safe-area-inset-right));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.zoom button {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 0;
  font-size: 1.35rem;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}
.zoom button + button { border-top: 1px solid var(--rule); }
.zoom button:hover { background: var(--ring); }
.zoom svg { width: 1.15rem; height: 1.15rem; display: block; }
.zoom .compass svg { transition: transform 0.05s linear; }

/* Colour panel, bottom left: the scheme menu, the dice, the theme toggle
   and the key. Each group of orientations sits in one box, and clicking a
   tile in it picks a new colour for the whole group. */
.legend {
  left: max(12px, env(safe-area-inset-left));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  padding: 0.5rem 0.7rem 0.55rem;
  max-width: calc(100vw - 90px);
  max-height: 45vh;
  overflow-y: auto;
}
.legend-head { display: flex; align-items: center; gap: 0.4rem; }
.legend-head select { flex: 1; min-width: 7.5rem; }
.legend-head .linkish { margin-left: 0.2rem; }
.legend .dice { width: 2.3rem; height: 2.3rem; }
.legend .dice svg { width: 1.35rem; height: 1.35rem; }
#legend-body { margin-top: 0.45rem; display: flex; flex-direction: column; gap: 0.3rem; }
#legend-body[hidden] { display: none; }
.legend .groups { display: grid; gap: 0.3rem; justify-content: start; }
.legend .group {
  display: grid;
  justify-content: start;
  gap: 0 0.15rem;
  border: 1px solid var(--rule);
  border-radius: 7px;
  padding: 0.15rem 0.25rem 0.1rem;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.legend .group:hover { border-color: var(--muted); }
.legend figure { margin: 0; display: flex; flex-direction: column; align-items: center; min-width: 1.9rem; }
.legend svg { width: 1.8rem; height: 1.8rem; display: block; overflow: visible; }
.legend figcaption { font-size: 0.66rem; color: var(--text); line-height: 1.1; white-space: nowrap; }
.legend input[type="color"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* About sheet. */
.about {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(580px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 1.1rem 1.25rem 0.4rem;
  font-size: 0.95rem;
  z-index: 5;
}
.about h2 { font-size: 1.15rem; font-weight: normal; color: var(--h1); margin: 0 2rem 0.6rem 0; }
.about p { margin: 0 0 0.8rem; }
.about ul { margin: 0 0 0.9rem; padding-left: 1.2rem; }
.about li { margin-bottom: 0.25rem; }
.about .close { position: absolute; top: 0.7rem; right: 0.7rem; width: 2rem; height: 2rem; padding: 0; border-radius: 50%; font-size: 1.1rem; }

.status {
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.75rem;
  font-size: 0.82rem;
  color: var(--muted);
  pointer-events: none;
}
.fail { top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 1rem 1.25rem; max-width: calc(100vw - 24px); }

/* On a phone the title card drops its description, the options fold behind
   a button, and the status pill moves above the key. */
@media (max-width: 640px) {
  .title { padding: 0.5rem 0.75rem 0.6rem; }
  .title p.hint { display: none; }
  .title h1 { font-size: 1.1rem; }
  .title .row { margin-top: 0.35rem; }
  .title .about-open { top: 0.4rem; right: 0.5rem; }
  .switch { font-size: 0.8rem; }
  .switch a { padding: 0.2rem 0.4rem; }
  .options { width: auto; }
  .options .head { display: block; }
  .options:not(.folded) .body { margin-top: 0.45rem; }
  .options.folded .body { display: none; }
  .status { bottom: 5.5rem; }
  .legend svg { width: 1.55rem; height: 1.55rem; }
  .legend figure { min-width: 1.6rem; }
}
