/* Tilings: the suite's shared look (copied from the L-system Explorer, which matches the Polyhedra
   Atlas): Catppuccin Mocha / Latte tokens, glass islands floating over a full-window canvas, Inter
   type. Keep the token names; see ../WEBAPPS.md. */
:root {
  --rosewater: #f5e0dc; --rosewater-rgb: 245 224 220;
  --flamingo: #f2cdcd; --flamingo-rgb: 242 205 205;
  --pink: #f5c2e7; --pink-rgb: 245 194 231;
  --mauve: #cba6f7; --mauve-rgb: 203 166 247;
  --red: #f38ba8; --red-rgb: 243 139 168;
  --maroon: #eba0ac; --maroon-rgb: 235 160 172;
  --peach: #fab387; --peach-rgb: 250 179 135;
  --yellow: #f9e2af; --yellow-rgb: 249 226 175;
  --green: #a6e3a1; --green-rgb: 166 227 161;
  --teal: #94e2d5; --teal-rgb: 148 226 213;
  --sky: #89dceb; --sky-rgb: 137 220 235;
  --sapphire: #74c7ec; --sapphire-rgb: 116 199 236;
  --blue: #89b4fa; --blue-rgb: 137 180 250;
  --lavender: #b4befe; --lavender-rgb: 180 190 254;
  --text: #cdd6f4; --text-rgb: 205 214 244;
  --subtext1: #bac2de; --subtext1-rgb: 186 194 222;
  --subtext0: #a6adc8; --subtext0-rgb: 166 173 200;
  --overlay2: #9399b2; --overlay2-rgb: 147 153 178;
  --overlay1: #7f849c; --overlay1-rgb: 127 132 156;
  --overlay0: #6c7086; --overlay0-rgb: 108 112 134;
  --surface2: #585b70; --surface2-rgb: 88 91 112;
  --surface1: #45475a; --surface1-rgb: 69 71 90;
  --surface0: #313244; --surface0-rgb: 49 50 68;
  --base: #1e1e2e; --base-rgb: 30 30 46;
  --mantle: #181825; --mantle-rgb: 24 24 37;
  --crust: #11111b; --crust-rgb: 17 17 27;
  --deep-rgb: 11 11 18; --shine-rgb: 255 255 255; --shadow-rgb: 17 17 27; --on-accent: #11111b;
  --glass: rgb(var(--base-rgb) / 0.52);
  --glass-strong: rgb(var(--mantle-rgb) / 0.72);
  --glass-card: rgb(var(--surface0-rgb) / 0.38);
  --glass-hover: rgb(var(--surface1-rgb) / 0.55);
  --edge: rgb(var(--text-rgb) / 0.10);
  --edge-strong: rgb(var(--text-rgb) / 0.18);
  --shine: inset 0 1px 0 rgb(var(--shine-rgb) / 0.06);
  --blur: blur(18px) saturate(150%);
  --radius: 16px;
  --topbar-h: 56px;
  --below-bar: 80px;
  --panel-w: 380px;

  --mono: ui-monospace, "JetBrains Mono", "Fira Code", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

/* Catppuccin Latte (light), as in the Atlas */
:root[data-theme="light"] {
  --rosewater: #dc8a78; --rosewater-rgb: 220 138 120;
  --flamingo: #dd7878; --flamingo-rgb: 221 120 120;
  --pink: #ea76cb; --pink-rgb: 234 118 203;
  --mauve: #8839ef; --mauve-rgb: 136 57 239;
  --red: #d20f39; --red-rgb: 210 15 57;
  --maroon: #e64553; --maroon-rgb: 230 69 83;
  --peach: #fe640b; --peach-rgb: 254 100 11;
  --yellow: #df8e1d; --yellow-rgb: 223 142 29;
  --green: #40a02b; --green-rgb: 64 160 43;
  --teal: #179299; --teal-rgb: 23 146 153;
  --sky: #04a5e5; --sky-rgb: 4 165 229;
  --sapphire: #209fb5; --sapphire-rgb: 32 159 181;
  --blue: #1e66f5; --blue-rgb: 30 102 245;
  --lavender: #7287fd; --lavender-rgb: 114 135 253;
  --text: #4c4f69; --text-rgb: 76 79 105;
  --subtext1: #5c5f77; --subtext1-rgb: 92 95 119;
  --subtext0: #6c6f85; --subtext0-rgb: 108 111 133;
  --overlay2: #7c7f93; --overlay2-rgb: 124 127 147;
  --overlay1: #8c8fa1; --overlay1-rgb: 140 143 161;
  --overlay0: #9ca0b0; --overlay0-rgb: 156 160 176;
  --surface2: #acb0be; --surface2-rgb: 172 176 190;
  --surface1: #bcc0cc; --surface1-rgb: 188 192 204;
  --surface0: #ccd0da; --surface0-rgb: 204 208 218;
  --base: #eff1f5; --base-rgb: 239 241 245;
  --mantle: #e6e9ef; --mantle-rgb: 230 233 239;
  --crust: #dce0e8; --crust-rgb: 220 224 232;
  --deep-rgb: 210 214 224; --shine-rgb: 255 255 255; --shadow-rgb: 76 79 105; --on-accent: #eff1f5;
  color-scheme: light;
  --glass: rgb(var(--base-rgb) / 0.62);
  --glass-strong: rgb(var(--base-rgb) / 0.82);
  --glass-card: rgb(var(--shine-rgb) / 0.45);
  --glass-hover: rgb(var(--surface0-rgb) / 0.7);
  --edge: rgb(var(--text-rgb) / 0.12);
  --edge-strong: rgb(var(--text-rgb) / 0.2);
  --shine: inset 0 1px 0 rgb(var(--shine-rgb) / 0.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 var(--sans);
  color: var(--text);
  background: var(--crust);
  overflow: hidden;
}
/* aurora backdrop that the glass blurs (as in the Atlas) */
body::before {
  content: '';
  position: fixed;
  inset: -20%;
  z-index: -1;
  background:
    radial-gradient(38% 42% at 18% 22%, rgb(var(--mauve-rgb) / 0.09), transparent 70%),
    radial-gradient(34% 38% at 78% 18%, rgb(var(--blue-rgb) / 0.07), transparent 70%),
    radial-gradient(40% 40% at 70% 82%, rgb(var(--pink-rgb) / 0.05), transparent 70%),
    radial-gradient(36% 40% at 22% 85%, rgb(var(--teal-rgb) / 0.05), transparent 70%),
    linear-gradient(160deg, var(--mantle) 0%, var(--crust) 60%, rgb(var(--deep-rgb)) 100%);
  animation: aurora 40s ease-in-out infinite alternate;
}
@keyframes aurora {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(3%, -2%) rotate(6deg); }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }

/* ---------- buttons (Atlas style) */
button {
  font: inherit;
  color: inherit;
  border: 1px solid var(--edge);
  background: var(--glass-card);
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: var(--shine);
  transition: background 0.18s, border-color 0.18s, transform 0.1s, box-shadow 0.18s, color 0.18s;
}
button:hover:not(:disabled) { border-color: rgb(var(--lavender-rgb) / 0.45); background: var(--glass-hover); box-shadow: var(--shine), 0 0 18px rgb(var(--lavender-rgb) / 0.12); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary {
  background: linear-gradient(135deg, rgb(var(--mauve-rgb) / 0.85), rgb(var(--blue-rgb) / 0.85));
  border-color: rgb(var(--shine-rgb) / 0.15); color: var(--on-accent); font-weight: 700;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(135deg, rgb(var(--mauve-rgb) / 0.95), rgb(var(--blue-rgb) / 0.95)); }

/* ---------- top bar */
.topbar {
  position: fixed;
  top: 12px; left: 12px; right: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--topbar-h);
  padding: 9px 14px 9px 18px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--edge);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shine), 0 10px 40px rgb(var(--shadow-rgb) / 0.45);
}
.brand { font-weight: 700; letter-spacing: 0.3px; font-size: 17px; white-space: nowrap; }
.logo { color: var(--mauve); text-shadow: 0 0 14px rgb(var(--mauve-rgb) / 0.8); }
.top-actions { display: flex; gap: 8px; }
.top-actions button:not(.primary) { background: rgb(var(--surface0-rgb) / 0.25); }
.theme-toggle .sun { display: none; }
:root[data-theme="light"] .theme-toggle .sun { display: inline; }
:root[data-theme="light"] .theme-toggle .moon { display: none; }

/* ---------- floating side panel */
#panel {
  position: absolute;
  top: var(--below-bar); right: 12px; bottom: 12px;
  width: var(--panel-w);
  z-index: 2;
  overflow-y: auto; overflow-x: hidden;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  border-radius: calc(var(--radius) + 4px);
  background: var(--glass);
  border: 1px solid var(--edge);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shine), 0 14px 50px rgb(var(--shadow-rgb) / 0.55);
  scrollbar-width: thin;
  scrollbar-color: var(--surface1) transparent;
}
.card {
  background: var(--glass-card);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shine);
  flex-shrink: 0;
}
h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--subtext0);
}

.hint {
  margin: -4px 0 10px;
  font-size: 12px;
  color: var(--overlay1);
}

.field {
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.field > span, .rows-head, .param > span {
  font-size: 12px;
  color: var(--subtext0);
}
.rows-head { margin: 12px 0 6px; }

input, select { font: inherit; color: var(--text); }

/* text fields as the Atlas's notation input */
input:not([type="range"]):not([type="checkbox"]), select {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  background: rgb(var(--crust-rgb) / 0.4);
  border: 1px solid var(--edge-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
input:not([type="range"]):not([type="checkbox"]):hover, select:hover { border-color: rgb(var(--lavender-rgb) / 0.35); }
input:not([type="range"]):not([type="checkbox"]):focus, select:focus {
  border-color: var(--lavender);
  box-shadow: 0 0 12px rgb(var(--lavender-rgb) / 0.15);
}
input:disabled { opacity: 0.35; }
input::placeholder { color: var(--overlay0); }
select option { background: var(--mantle); }

.mono { font: 500 13px var(--mono); }
input.mono { font: 500 13px var(--mono); }

input[type="range"] { width: 100%; accent-color: var(--mauve); }
input[type="checkbox"] { accent-color: var(--mauve); }
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button { display: none; }

/* themed dropdowns (selectmenu.js): the native <select> stays as the hidden source of truth */
.sm { position: relative; display: block; min-width: 0; }
.sm-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }
.sm-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-width: 0; height: 32px;
  padding: 0 10px;
  background: rgb(var(--crust-rgb) / 0.4);
  border: 1px solid var(--edge-strong);
  border-radius: 10px;
  box-shadow: none;
  backdrop-filter: none;
  color: var(--text);
  font: inherit;
  text-align: left;
}
.sm-btn .sm-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sm-btn svg { flex-shrink: 0; color: var(--overlay1); transition: transform 0.15s; }
.sm-btn:hover:not(:disabled) { background: rgb(var(--crust-rgb) / 0.4); border-color: rgb(var(--lavender-rgb) / 0.35); box-shadow: none; }
.sm-btn:focus-visible, .sm-btn.on { outline: none; border-color: var(--lavender); box-shadow: 0 0 12px rgb(var(--lavender-rgb) / 0.15); }
.sm-btn.on svg { transform: rotate(180deg); color: var(--lavender); }
.sm-btn:active:not(:disabled) { transform: none; }
.sm-pop {
  position: fixed; z-index: 100;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 5px;
  background: var(--glass-strong);
  border: 1px solid var(--edge-strong);
  border-radius: 12px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shine), 0 14px 40px rgb(var(--shadow-rgb) / 0.5);
  font-size: 13.5px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface1) transparent;
}
.sm-group {
  padding: 8px 10px 3px;
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase;
  color: var(--overlay1);
}
.sm-opt {
  position: relative;
  padding: 6px 10px 6px 26px;
  border-radius: 8px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.sm-opt.act { background: var(--glass-hover); }
.sm-opt.sel { color: var(--mauve); font-weight: 600; }
.sm-opt.sel::before { content: '✓'; position: absolute; left: 9px; color: var(--mauve); }
.sm-opt.sel.act { background: rgb(var(--mauve-rgb) / 0.14); }
.sm-opt.dis { opacity: 0.4; cursor: default; }

/* ---------- stage: the full window, under the islands */
#stage { position: fixed; inset: 0; }
#stage::before {
  /* faint dot grid, as behind the Atlas's solid */
  content: '';
  position: absolute; inset: 0;
  background:
    radial-gradient(circle, rgb(var(--overlay0-rgb) / 0.32) 1.1px, transparent 1.6px) 0 0 / 30px 30px,
    radial-gradient(70% 70% at 55% 50%, rgb(var(--crust-rgb) / 0.15), rgb(var(--deep-rgb) / 0.55));
  pointer-events: none;
}
:root[data-theme="light"] #stage::before {
  background:
    radial-gradient(circle, rgb(var(--overlay1-rgb) / 0.45) 1.1px, transparent 1.6px) 0 0 / 30px 30px,
    radial-gradient(70% 70% at 55% 50%, rgb(var(--shine-rgb) / 0.25), rgb(var(--crust-rgb) / 0.5));
}
#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#canvas.dragging { cursor: grabbing; }

/* ---------- app-specific: Tilings */
:root { --info-w: 304px; }
@media (max-width: 1250px) { :root { --info-w: 260px; } }
.info-panel {
  position: absolute; top: var(--below-bar); left: 12px; width: var(--info-w); z-index: 2;
  max-height: calc(100% - var(--below-bar) - var(--title-h, 130px) - 24px); /* ends above the tiling's title panel (its height is measured) */
  overflow-y: auto; overflow-x: hidden; padding: 10px; display: flex; flex-direction: column; gap: 10px;
  border-radius: calc(var(--radius) + 4px); background: var(--glass); border: 1px solid var(--edge);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shine), 0 14px 50px rgb(var(--shadow-rgb) / 0.45);
  scrollbar-width: thin; scrollbar-color: var(--surface1) transparent;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.card-head .hint { margin: 0; font-size: 11px; text-align: right; }

.stage-title {
  position: absolute; left: 12px; bottom: 12px; pointer-events: none; max-width: min(720px, calc(100% - var(--panel-w) - 48px));
  padding: 10px 16px 12px; border-radius: calc(var(--radius) + 4px);
  background: var(--glass); border: 1px solid var(--edge);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shine), 0 14px 50px rgb(var(--shadow-rgb) / 0.45);
}
.stage-title h1 { margin: 6px 0 2px; font-size: 28px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.15; }
.notation { color: var(--subtext0); font: 500 13px var(--mono); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stage-title h1 { overflow-wrap: anywhere; }
.family-chip {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: 0.9px; text-transform: uppercase;
  padding: 3px 10px; border-radius: 99px;
  background: color-mix(in srgb, var(--c, #7f849c) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--c, #7f849c) 55%, transparent);
  color: var(--c, var(--subtext0));
  box-shadow: 0 0 14px color-mix(in srgb, var(--c, #11111b) 25%, transparent);
}
.family-chip:empty { display: none; }
.info-title { overflow-wrap: anywhere; font-size: 19px; font-weight: 700; margin: 8px 0 2px; }
.info-sub { font-size: 12px; color: var(--overlay2); margin-bottom: 4px; }
.stats { display: flex; gap: 8px; margin: 10px 0; }
.stat { flex: 1; min-width: 0; text-align: center; background: rgb(var(--crust-rgb) / 0.28); border: 1px solid var(--edge); border-radius: 10px; padding: 6px 0; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11px; color: var(--subtext0); }
.faces { display: flex; flex-wrap: wrap; gap: 6px; }
.facechip { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 9px; border-radius: 99px; background: rgb(var(--crust-rgb) / 0.25); border: 1px solid var(--edge); flex-wrap: wrap; max-width: 100%; }
.facechip .sw + .sw { margin-left: -3px; }
.facechip .sw-more { margin-left: -3px; color: var(--overlay1); font-size: 11px; line-height: 1; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); vertical-align: -1px; box-shadow: 0 0 6px var(--c); }
.configs { margin-top: 8px; font: 12px var(--mono); color: var(--subtext0); line-height: 1.6; }
.configs b { color: var(--text); font-weight: 600; }
.desc { font-size: 13px; color: var(--subtext1); line-height: 1.45; margin: 8px 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 99px; color: var(--subtext1); background: rgb(var(--surface0-rgb) / 0.35); border: 1px solid var(--edge); }
.tag.on { color: var(--green); border-color: rgb(var(--green-rgb) / 0.45); background: rgb(var(--green-rgb) / 0.1); }
.orbifold { display: flex; align-items: baseline; gap: 10px; margin: 2px 0 6px; }
.orbifold b { font: 700 26px var(--mono); color: var(--mauve); text-shadow: 0 0 16px rgb(var(--mauve-rgb) / 0.35); }
.orbifold span { font: 500 14px var(--mono); color: var(--subtext0); }
.dsym { max-height: 96px; overflow-y: auto; scrollbar-width: thin; font: 11.5px var(--mono); color: var(--subtext0); overflow-wrap: anywhere; background: rgb(var(--crust-rgb) / 0.3); border: 1px solid var(--edge); border-radius: 8px; padding: 6px 8px; margin-top: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12px; color: var(--subtext0); }
.kv b { color: var(--text); font-weight: 500; }

.seed-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.seed-row { flex-wrap: nowrap; }
.seed-row button { flex: 1 1 0; min-width: 0; padding: 5px 4px; font-size: 12px; }
.field.named { grid-template-columns: 60px 1fr; margin: 0; }
.notation-row { display: flex; gap: 6px; margin-bottom: 6px; }
.notation-row input { flex: 1; }
.notation-row button { flex-shrink: 0; }
.notation-hint { font-size: 11.5px; color: var(--subtext0); min-height: 15px; margin-bottom: 8px; overflow-wrap: anywhere; }
.notation-hint .bad { color: var(--red); }
.ops { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.op { min-width: 0; text-align: left; display: flex; gap: 9px; align-items: center; padding: 7px 9px; min-height: 48px; background: rgb(var(--crust-rgb) / 0.22); }
.op .letter {
  flex-shrink: 0; width: 27px; height: 27px; border-radius: 8px; display: grid; place-items: center;
  font: 700 14px var(--mono); background: rgb(var(--blue-rgb) / 0.14); color: var(--blue);
  border: 1px solid rgb(var(--blue-rgb) / 0.25);
}
.op .txt { flex: 1; min-width: 0; overflow: hidden; }
.op .nm { font-size: 13px; font-weight: 600; }
.op .res { font-size: 11px; color: var(--subtext0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op .res.unch { color: var(--overlay1); font-style: italic; }
.op .res.same { color: var(--overlay0); }

/* strip operations */
.strip-fam + .strip-fam { margin-top: 12px; }
.strip-head { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.op.strip .letter { background: rgb(var(--teal-rgb) / 0.14); color: var(--teal); border-color: rgb(var(--teal-rgb) / 0.3); font-size: 15px; }
.op.strip .letter sub { font-size: 9px; }
.strip-none { margin: 0; }
.op.dis .letter { background: rgb(var(--peach-rgb) / 0.14); color: var(--peach); border-color: rgb(var(--peach-rgb) / 0.3); font-size: 15px; }
.dis-more { margin-top: 8px; width: 100%; font-size: 12px; }

/* symmetry overlay controls */
.sym-controls { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.sym-toggle { font-size: 12.5px; padding: 6px 10px; }
.sym-toggle.on { color: var(--mauve); border-color: rgb(var(--mauve-rgb) / 0.6); background: rgb(var(--mauve-rgb) / 0.12); box-shadow: 0 0 12px rgb(var(--mauve-rgb) / 0.2); }
.sym-legend { display: flex; flex-wrap: wrap; gap: 5px; }
.sym-legend.off { opacity: 0.55; }
.sym-item { display: flex; align-items: center; gap: 6px; font-size: 11.5px; padding: 3px 8px 3px 5px; border-radius: 99px; background: rgb(var(--crust-rgb) / 0.3); color: var(--overlay1); }
.sym-item.on { color: var(--text); border-color: rgb(var(--lavender-rgb) / 0.45); }
.sym-item svg { flex-shrink: 0; border-radius: 4px; background: rgb(var(--overlay0-rgb) / 0.35); }
.sym-item:not(.on) svg { opacity: 0.4; }
.g-line { stroke: #fff; stroke-width: 2; }
.g-sym { fill: #11111b; stroke: #fff; stroke-width: 1.1; }
.g-dom { fill: rgb(255 255 255 / 0.45); stroke: var(--mauve); stroke-width: 1.6; }
.g-cell { fill: none; stroke: var(--yellow); stroke-width: 1.6; stroke-dasharray: 3 2; }

/* Wythoff blend triangle and snub flap (as in the Atlas) */
.blend-wrap { display: flex; justify-content: center; position: relative; }
#blendSvg { width: 100%; max-width: 270px; touch-action: none; user-select: none; cursor: pointer; color: var(--mauve); overflow: visible; }
.bl-tri { fill: rgb(var(--lavender-rgb) / 0.07); stroke: rgb(var(--lavender-rgb) / 0.45); stroke-width: 1.4; stroke-linejoin: round; }
.bl-flap { fill: rgb(var(--peach-rgb) / 0.07); stroke: rgb(var(--peach-rgb) / 0.4); stroke-width: 1.2; stroke-dasharray: 4 3; stroke-linejoin: round; }
.bl-lab { font: 700 12px var(--mono); fill: var(--subtext0); text-anchor: middle; transition: fill 0.15s; pointer-events: none; }
.bl-lab.corner { font-size: 11.5px; }
.bl-lab.inner { fill: var(--overlay1); }
.bl-lab.known { fill: var(--mauve); }
.bl-lab.unch { fill: var(--overlay0); }
.bl-lab.on { font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.bl-lab.end { text-anchor: end; }
.bl-dual { position: absolute; top: 2px; left: 0; z-index: 1; font-size: 11.5px; padding: 3px 8px; }
.bl-dual.on { color: var(--mauve); border-color: rgb(var(--mauve-rgb) / 0.6); box-shadow: 0 0 10px rgb(var(--mauve-rgb) / 0.25); }
.blend-wrap.dual .bl-tri, .blend-wrap.dual .bl-flap { stroke-dasharray: 4 3; }
.bl-lab.start { text-anchor: start; }
.bl-hint { font: italic 10px var(--sans); fill: var(--overlay1); text-anchor: middle; pointer-events: none; }
.bl-tick { fill: var(--surface2); stroke: var(--base); stroke-width: 1; }
.bl-tick.known { fill: var(--mauve); }
.bl-tick.unch { fill: var(--overlay0); }
#blendDot { fill: var(--mauve); stroke: var(--base); stroke-width: 2; filter: drop-shadow(0 0 6px rgb(var(--mauve-rgb) / 0.8)); transition: r 0.12s; }
#blendDot.tick { animation: bl-tick 0.28s ease-out; }
@keyframes bl-tick { 0% { r: 7; } 40% { r: 10; } 100% { r: 7; } }
.blend-status { font-size: 12px; line-height: 1.45; min-height: 34px; margin-top: 4px; }
.blend-block { margin-bottom: 10px; }
.lens-wrap { display: flex; flex-direction: column; align-items: center; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--edge); }
.lens-wrap .pull-name { align-self: flex-start; text-transform: none; letter-spacing: 0; font-size: 12px; font-weight: 600; color: var(--subtext0); }
#lensSvg { width: 100%; max-width: 270px; touch-action: none; user-select: none; cursor: pointer; color: var(--peach); overflow: visible; }
.ln-track { stroke: rgb(var(--lavender-rgb) / 0.55); stroke-width: 3; stroke-linecap: round; }
.ln-flap { fill: rgb(var(--peach-rgb) / 0.07); stroke: rgb(var(--peach-rgb) / 0.4); stroke-width: 1.2; stroke-dasharray: 4 3; stroke-linejoin: round; }
.ln-flap.w { fill: rgb(var(--teal-rgb) / 0.07); stroke: rgb(var(--teal-rgb) / 0.4); }
#lensDot { fill: var(--peach); stroke: var(--base); stroke-width: 2; filter: drop-shadow(0 0 6px rgb(var(--peach-rgb) / 0.8)); }
#lensDot.tick { animation: bl-tick 0.28s ease-out; }
.pull-name { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--overlay1); margin: 4px 0 0; }
body[data-mode="pad"] .blend-block { margin-bottom: 4px; }
#conwayCard .card-head #back { padding: 3px 10px; font-size: 12px; }
.field.named { margin-bottom: 10px; }
.blend-status .unch { color: var(--overlay1); font-style: italic; }
.reach-legend { display: flex; gap: 12px; justify-content: center; font-size: 11px; color: var(--subtext0); margin-top: 4px; }
.reach-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
.reach-legend .known i { background: var(--mauve); }
.reach-legend .unch i { background: var(--overlay0); }

/* small controls, as in the Atlas */
button.small { padding: 4px 10px; font-size: 13px; }
button.danger { color: var(--red); }
kbd { font: 600 11px var(--mono); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 4px; opacity: 0.6; }
.hidden { display: none !important; }
.dim { color: var(--overlay1); }
.op .res.new, .blend-status .new { color: var(--yellow); }
.bl-lab.new { fill: var(--yellow); }
.bl-tick.new { fill: var(--yellow); }
.reach-legend .new i { background: var(--yellow); }

/* progress in the top bar */
.progress { flex: 1; display: flex; gap: 10px; justify-content: center; align-items: center; font-size: 12px; color: var(--subtext0); min-width: 0; }
.pgbar { display: flex; width: min(300px, 26vw); height: 8px; border-radius: 4px; overflow: hidden; background: rgb(var(--surface2-rgb) / 0.45); }
.pgbar i { display: block; height: 100%; transition: width 0.6s; }
.pgtext { white-space: nowrap; }
.pgtext b { color: var(--text); font-size: 13px; }
.top-actions { align-items: center; }
.top-actions button { white-space: nowrap; }

/* toasts */
.toasts { position: fixed; right: calc(var(--panel-w) + 30px); bottom: 18px; z-index: 5; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast {
  background: var(--glass-strong); border: 1px solid var(--edge-strong); border-radius: 12px; padding: 10px 14px; backdrop-filter: var(--blur);
  font-size: 13px; max-width: 340px; animation: toastIn 0.35s ease-out; box-shadow: var(--shine), 0 8px 24px rgb(var(--shadow-rgb) / 0.45);
}
.toast.discover {
  border-color: rgb(var(--yellow-rgb) / 0.55);
  background: linear-gradient(135deg, rgb(var(--peach-rgb) / 0.22), rgb(var(--mauve-rgb) / 0.22)), var(--glass-strong);
  box-shadow: var(--shine), 0 0 30px rgb(var(--yellow-rgb) / 0.18);
}
.toast.discover b { color: var(--yellow); }
.toast.out { opacity: 0; transform: translateY(8px); transition: all 0.4s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* settings */
.help {
  position: relative; margin: auto; max-width: 560px; width: calc(100vw - 24px); max-height: 86vh; overflow: auto; padding: 22px 26px; font-size: 14px; line-height: 1.55;
  background: var(--glass-strong); border: 1px solid var(--edge-strong); border-radius: 20px;
  backdrop-filter: var(--blur); box-shadow: var(--shine), 0 20px 60px rgb(var(--shadow-rgb) / 0.6);
}
.help h2 { margin: 0 0 12px; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }
.help h3 { margin: 14px 0 6px; font-size: 14px; color: var(--mauve); }
.help .close { position: absolute; top: 12px; right: 12px; }
.muted { color: var(--subtext0); }
.seg { display: flex; border: 1px solid var(--edge-strong); border-radius: 12px; overflow: hidden; background: rgb(var(--crust-rgb) / 0.3); }
.seg button { flex: 1; border: 0; border-radius: 0; padding: 9px 6px; font-size: 13px; background: transparent; box-shadow: none; }
.seg button + button { border-left: 1px solid var(--edge-strong); }
.seg button.on { background: rgb(var(--mauve-rgb) / 0.2); color: var(--mauve); font-weight: 700; box-shadow: inset 0 0 14px rgb(var(--mauve-rgb) / 0.15); }
.mode-desc { font-size: 12.5px; min-height: 36px; margin: 8px 2px 0; }
/* interaction modes: the pad, the buttons, or both */
.ops-note { display: none; margin: 8px 0 0; }
body[data-mode="pad"] .ops-note { display: block; }
body[data-mode="pad"] #ops { display: none; }
body[data-mode="buttons"] #blendCard { display: none; }

/* overlays: map and encyclopedia */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgb(var(--crust-rgb) / 0.55); backdrop-filter: blur(10px); display: flex; flex-direction: column; }
#mapOverlay { background: var(--crust); }
#encOverlay { background: rgb(var(--crust-rgb) / 0.72); backdrop-filter: blur(16px); }
.map-head {
  position: absolute; top: 12px; left: 12px; right: 12px; z-index: 2;
  display: flex; align-items: center; gap: 14px; padding: 8px 12px 8px 16px; flex-wrap: wrap;
  border-radius: var(--radius); background: var(--glass); border: 1px solid var(--edge);
  backdrop-filter: var(--blur); box-shadow: var(--shine), 0 10px 40px rgb(var(--shadow-rgb) / 0.5);
}
.map-head h2 { margin: 0; font-size: 17px; text-transform: none; letter-spacing: 0; color: var(--text); }
.map-sub { font-size: 12px; color: var(--subtext0); }
.map-counts { flex: 1; display: flex; gap: 6px 12px; justify-content: center; flex-wrap: wrap; font-size: 11px; color: var(--subtext0); }
.map-counts .mc { white-space: nowrap; cursor: default; }
.map-counts .mc b { font-size: 13px; color: var(--text); }
.map-counts .mc-tot { opacity: 0.7; }
.map-actions { display: flex; gap: 8px; }
#mapLinks.on { border-color: var(--lavender); background: rgb(var(--lavender-rgb) / 0.18); color: var(--lavender); }
#mapCanvas { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; cursor: grab; }
.map-legend {
  max-width: calc(100% - 28px); position: absolute; left: 14px; bottom: 14px; font-size: 11px; color: var(--subtext0);
  background: var(--glass); border: 1px solid var(--edge); border-radius: 12px; padding: 9px 12px; line-height: 1.7; pointer-events: none;
  backdrop-filter: var(--blur); box-shadow: var(--shine);
}
.map-zoom { position: absolute; right: 14px; bottom: 14px; z-index: 2; display: flex; flex-direction: column; gap: 6px; }
.map-zoom button { width: 40px; height: 40px; padding: 0; font-size: 20px; line-height: 1; border-radius: 12px; background: var(--glass); backdrop-filter: var(--blur); box-shadow: var(--shine); }
.map-tip {
  position: fixed; z-index: 30; max-width: 300px; pointer-events: none; font-size: 12px; line-height: 1.5; padding: 8px 11px;
  background: var(--glass-strong); border: 1px solid var(--edge-strong); border-radius: 10px; backdrop-filter: var(--blur); box-shadow: var(--shine), 0 8px 24px rgb(var(--shadow-rgb) / 0.45);
}
.map-tip b { font-size: 13px; margin-right: 6px; }
.map-tip .mono { color: var(--subtext0); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

.enc {
  position: relative; margin: 18px; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px 16px;
  background: rgb(var(--mantle-rgb) / 0.9); border: 1px solid var(--edge-strong); border-radius: 20px;
  backdrop-filter: var(--blur); box-shadow: var(--shine), 0 20px 60px rgb(var(--shadow-rgb) / 0.6);
}
.enc-head { display: flex; align-items: center; gap: 14px; }
.enc-head h2 { margin: 0; font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); }
#encSearch { flex: 1; max-width: 420px; font-size: 13px; }
.enc-head .primary { margin-left: auto; }
.enc-filters { display: flex; flex-direction: column; gap: 6px; }
.enc-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.enc-chip { font-size: 12px; padding: 4px 10px; border-radius: 99px; display: flex; gap: 5px; align-items: center; background: rgb(var(--crust-rgb) / 0.3); }
.enc-chip b { font-weight: 600; }
.enc-chip .tot { opacity: 0.6; margin-left: -3px; }
.enc-chip.on { border-color: var(--c, var(--lavender)); background: color-mix(in srgb, var(--c, #b4befe) 18%, transparent); }
.enc-chip .dot { margin: 0; }
.enc-taglabel { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--overlay1); margin-right: 4px; min-width: 84px; }
.enc-body { flex: 1; min-height: 0; display: flex; gap: 14px; }
.enc-grid {
  flex: 1; min-width: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  align-content: start; grid-auto-rows: max-content; gap: 10px; padding: 2px 4px 2px 0; scrollbar-width: thin; scrollbar-color: var(--surface1) transparent;
}
.enc-card { min-width: 0; padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; background: rgb(var(--crust-rgb) / 0.28); border-radius: 14px; }
.enc-card.sel { border-color: var(--c); box-shadow: 0 0 18px color-mix(in srgb, var(--c) 30%, transparent); }
.enc-card.here .enc-name::after { content: ' ●'; color: var(--mauve); }
.enc-thumb { width: 104px; height: 104px; display: grid; place-items: center; border-radius: 12px; overflow: hidden; background: rgb(var(--crust-rgb) / 0.3); }
.enc-thumb canvas, .enc-big canvas { width: 100%; height: 100%; display: block; }
.enc-name { font-size: 12px; font-weight: 600; line-height: 1.25; max-width: 100%; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.enc-name.long { font-size: 11px; }
.enc-sub { font-size: 11px; color: var(--subtext0); font-family: var(--mono); }
.enc-locked { grid-column: 1 / -1; text-align: center; padding: 18px; color: var(--overlay2); font-size: 13px; border: 1px dashed var(--edge-strong); border-radius: 14px; }
.enc-detail {
  width: 360px; flex-shrink: 0; overflow-y: auto; padding: 14px; border-radius: 16px; background: rgb(var(--base-rgb) / 0.85); border: 1px solid var(--edge);
  scrollbar-width: thin; scrollbar-color: var(--surface1) transparent;
}
.enc-detail h2 { margin: 8px 0 4px; font-size: 19px; text-transform: none; letter-spacing: 0; color: var(--text); }
.enc-big { width: 220px; height: 220px; margin: 0 auto 10px; border-radius: 16px; overflow: hidden; background: rgb(var(--crust-rgb) / 0.3); }
.enc-empty { color: var(--overlay2); text-align: center; margin-top: 40%; font-size: 13px; }
.enc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 10px; }
.enc-table th { text-align: left; font-weight: 600; color: var(--subtext0); padding: 6px 10px 6px 0; vertical-align: top; width: 36%; border-top: 1px solid var(--edge); }
.enc-table td { padding: 6px 0; border-top: 1px solid var(--edge); }
.enc-tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; margin: 1px 0; border-radius: 99px; border: 1px solid var(--edge-strong); background: rgb(var(--crust-rgb) / 0.3); }
.enc-link { all: unset; cursor: pointer; color: var(--blue); }
.enc-link:hover { text-decoration: underline; }
.enc-actions { display: flex; gap: 8px; margin-top: 12px; }
@media (max-width: 1000px) { .top-actions .lbl, .map-actions .lbl { display: none; } .pgbar { display: none; } }
.map-actions { flex-wrap: wrap; }
@media (max-width: 860px) {
  .enc { margin: 8px; }
  .enc-body { flex-direction: column; }
  .enc-detail { width: auto; max-height: 45%; }
  .map-sub, .map-counts { display: none; }
}

/* ---------- phones: the drawing on top, the panel below it */
@media (max-width: 760px) {
  :root { --panel-w: 0px; }
  .brand-name, .top-actions .lbl { display: none; }
  .brand .logo { font-size: 20px; }
  #stage { bottom: auto; height: 50vh; }
  #panel { position: relative; top: auto; left: auto; right: auto; bottom: auto; width: auto; margin: calc(50vh + 8px) 8px 8px; overflow: visible; }
  .info-panel { position: relative; top: auto; left: auto; width: auto; max-height: none; margin: 0 8px 8px; overflow: visible; }
  body { overflow-y: auto; height: auto; }
  .stage-title { left: 14px; bottom: 10px; max-width: calc(100% - 28px); }
  .stage-title h1 { font-size: 22px; }
}
