/* Hyperbolic Models Explorer. The colour tokens match the tiling explorer,
   so the cards read as part of the site. The view takes its colours from
   hyperbolic.js. Four cards sit in the corners: models top left, tiling top
   right, colours bottom left, motion and zoom bottom right. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f3ec, #16161a);
  --panel: light-dark(rgba(255, 253, 248, 0.92), rgba(30, 30, 35, 0.92));
  --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));
  --on: light-dark(#e3e9f2, #2c3340);
  --muted: light-dark(#7c786d, #918c80);
  --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.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--link); }

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

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

button, select {
  font: inherit;
  font-size: 0.86rem;
  color: var(--h3);
  background: transparent;
  border: 1px solid var(--ring);
  border-radius: 7px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); color: var(--h1); }
button:disabled { opacity: 0.35; cursor: default; }
button:disabled:hover { border-color: var(--ring); color: var(--h3); }
button[aria-pressed="true"] { background: var(--on); color: var(--h1); border-color: var(--muted); }
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%; }

/* Top row: the title and model card at left, the tiling card at right. */
.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;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}
.top .card { position: static; pointer-events: auto; }

.title {
  position: relative;
  width: 25rem;
  max-width: 100%;
  padding: 0.65rem 0.85rem 0.75rem;
  max-height: calc(100dvh - 120px);
  overflow-y: auto;
}
.title .back { font-size: 0.85rem; text-decoration: none; }
.title .back:hover { text-decoration: underline; }
.title h1 { font-size: 1.25rem; line-height: 1.2; color: var(--h1); margin: 0.25rem 0 0.15rem; font-weight: normal; }
.title-tools { position: absolute; top: 0.5rem; right: 0.6rem; display: flex; gap: 0.35rem; align-items: center; }
.small { padding: 0.1rem 0.5rem; font-size: 0.8rem; }
.icon, .theme-toggle { width: 1.9rem; height: 1.9rem; padding: 0; display: grid; place-items: center; }
.icon svg, .theme-toggle svg { width: 1.05rem; height: 1.05rem; display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: none; }

.section { margin: 0.55rem 0 0.3rem; font-size: 0.78rem; font-weight: normal; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.models { display: grid; gap: 0.3rem; }
.models.featured { grid-template-columns: repeat(3, 1fr); }
.models.featured button { padding: 0.35rem 0.4rem; font-size: 0.86rem; line-height: 1.2; }
.models.more { grid-template-columns: repeat(4, 1fr); margin-top: 0.3rem; }
.models.more button { padding: 0.2rem 0.15rem; font-size: 0.75rem; line-height: 1.25; white-space: nowrap; }
/* Two rows of four patterns, with Goldberg across the third row. Each
   column fits its longest label, and the spare width is shared equally. */
.patterns { display: grid; grid-template-columns: repeat(4, auto); gap: 0.3rem; }
.patterns button { padding: 0.25rem 0.3rem; font-size: 0.8rem; line-height: 1.25; white-space: nowrap; }
/* Goldberg: one row of the button, the m and n steppers and a small
   hand toggle, a little taller than the pattern buttons. */
.goldberg-row { display: grid; grid-template-columns: 6.6rem 1fr; gap: 0.3rem; margin-top: 0.3rem; }
.gp-main { display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 0.2rem 0.4rem; font-size: 0.9rem; line-height: 1.15; min-height: 2.5rem; }
.gp-main span { font-size: 0.74rem; opacity: 0.75; }
.gp-controls { display: grid; grid-template-columns: 1fr 1fr 3.1rem; gap: 0.3rem; align-items: stretch; }
.gp-controls .stepper { grid-template-columns: 1fr 1.1rem 1fr; gap: 0.15rem; }
.gp-controls .stepper button { height: auto; min-height: 1.9rem; }
.gp-controls .stepper output { text-align: center; }
.gp-hand { padding: 0 0.2rem; font-size: 0.78rem; }
.model-select, .pattern-select { display: none; font-size: 0.85rem; }
.colour-schemes .n { opacity: 0.6; }
.colours .section { margin-top: 0; }

.facts { margin: 0.6rem 0 0; font-size: 0.8rem; display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.6rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; color: var(--h3); }
.facts .made { grid-column: 1 / -1; color: var(--muted); font-style: italic; margin-top: 0.15rem; }

/* Tiling card, top right. */
.options { width: 17rem; max-width: calc(100vw - 24px); padding: 0.6rem 0.7rem; max-height: calc(100dvh - 120px); overflow-y: auto; }
.fold { display: none; width: 100%; text-align: left; }
.tile-row { display: flex; gap: 0.6rem; align-items: center; }
#tile { width: 112px; height: 112px; flex: none; border-radius: 50%; }
.tile-text { display: flex; flex-direction: column; font-size: 0.8rem; gap: 0.1rem; }
.tile-text strong { color: var(--h1); font-size: 1.05rem; font-weight: normal; }
.tile-text span:last-child { color: var(--muted); }
.presets { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 0.3rem; margin: 0.55rem 0; }
.presets button { grid-column: span 3; padding: 0.2rem; font-size: 0.82rem; }
.presets [data-preset] { grid-column: span 4; white-space: nowrap; }
.steppers { display: grid; gap: 0.25rem; margin-bottom: 0.55rem; }
.stepper { display: grid; grid-template-columns: 1fr 1.8rem 2rem 1.8rem; align-items: center; font-size: 0.82rem; gap: 0.25rem; }
.stepper button { padding: 0; height: 1.6rem; }
.stepper output { text-align: center; color: var(--h1); }
.segmented { display: flex; gap: 0.3rem; }
.segmented button { flex: 1; white-space: nowrap; }
.colour-schemes { display: grid; grid-template-columns: 1fr 1fr; }

/* Colours card, bottom left. */
.colours {
  left: max(12px, env(safe-area-inset-left));
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  width: 16rem;
  padding: 0.6rem 0.7rem;
}
.slider { display: grid; grid-template-columns: 1fr auto; font-size: 0.82rem; margin-top: 0.5rem; }
.slider input { grid-column: 1 / -1; width: 100%; }
.check { display: block; font-size: 0.82rem; margin-top: 0.2rem; }
.letter { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; margin-top: 0.5rem; }
.letter select { flex: 1; min-width: 0; font: inherit; padding: 0.1rem 0.2rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--bg); color: inherit; }
#orient { margin-top: 0.4rem; }
[hidden] { display: none !important; }
.letter input[type="text"] { width: 2.2em; text-align: center; font: inherit; font-weight: bold; padding: 0.05rem 0; border: 1px solid var(--rule); border-radius: 4px; background: transparent; color: inherit; }
.reset { height: 1.9rem; padding: 0 0.6rem; }
.motion .segmented + .segmented { padding-left: 0.5rem; border-left: 1px solid var(--rule); }
html:has(body.clear), body.clear { background: transparent; }

/* Motion and zoom card, bottom right. */
.motion {
  right: max(12px, env(safe-area-inset-right));
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  padding: 0.5rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.motion .segmented button { min-width: 3.2rem; }
.zoom-row { display: flex; gap: 0.3rem; }
.zoom-row .icon { font-size: 1.15rem; line-height: 1; }

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

/* A laptop of modest height: drop the long model list into a menu. */
@media (max-height: 840px) {
  .models.more, .facts { display: none; }
  .model-select { display: block; margin-top: 0.4rem; }
  .model-select select { margin-left: 0.3rem; }
  .model-select .main-only { display: none; }
}

/* Leave room for the full Colours card below the models on a short tablet. */
@media (min-height: 741px) and (max-height: 900px) {
  .title { max-height: calc(100dvh - 405px); }
  .facts { display: none; }
}
@media (min-height: 741px) and (max-height: 840px) {
  .title { padding-bottom: 0.55rem; }
  .title .section { margin-block: 0.3rem 0.2rem; }
  .models.featured button { padding-block: 0.3rem; }
  .model-select select { padding-block: 0.15rem; }
}

/* Phones and short windows: the title card keeps one menu, and the tiling
   and colour cards fold behind their headings. */
@media (max-width: 640px), (max-height: 740px) {
  .title { width: auto; flex: 1 1 auto; padding: 0.45rem 0.65rem 0.5rem; }
  .facts, .models, .patterns, .title .section, .colours .section { display: none; }
  .pattern-select { display: block; margin-top: 0.3rem; }
  .goldberg-row { display: block; }
  .goldberg-row:not(.active), .gp-main { display: none; }
  .title h1 { font-size: 1rem; margin: 0.15rem 0 0.25rem; padding-right: 0; }
  .title .back { font-size: 0.78rem; }
  .model-select { display: block; margin-top: 0; }
  .model-select .main-only { display: block; }
  .title-tools { top: 0.35rem; right: 0.45rem; }
  .title-tools .small { display: none; }
  .options { width: auto; flex: none; padding: 0.4rem; }
  .options .fold, .colours .fold { display: block; }
  .options.folded .body, .colours.folded .body { display: none; }
  .options:not(.folded) .body, .colours:not(.folded) .body { margin-top: 0.45rem; }
  .options:not(.folded) { width: 15.5rem; }
  .colours { width: auto; padding: 0.4rem; }
  .colours:not(.folded) { width: 15rem; max-height: calc(100dvh - 178px); overflow-y: auto; }
  .motion { padding: 0.35rem; gap: 0.35rem; }
  .motion .segmented button { min-width: 0; padding: 0.25rem 0.45rem; }
  .zoom-row .icon { width: 1.8rem; height: 1.8rem; }
}
@media (max-height: 520px) {
  .title { flex: 0 1 auto; }
  .title .back { display: none; }
  .title h1 { padding-right: 4.3rem; }
}
@media (max-width: 480px) {
  .title:has(+ .options:not(.folded)) { display: none; }
}
/* Touch screens pan and zoom with two fingers, so the Plane/Pan switch and
   the zoom buttons give way on a phone. */
@media (pointer: coarse) and (max-width: 900px) {
  .motion [data-drag], .zoom-row #zoom-in, .zoom-row #zoom-out { display: none; }
  .motion .segmented + .segmented { padding-left: 0; border-left: 0; }
}
@media (max-width: 400px) {
  .title .back { display: inline-block; max-width: calc(100% - 4rem); }
  .zoom-row #zoom-in, .zoom-row #zoom-out { display: none; }
}
