/* Vaseinator on the web: the desktop app, dark like it (light if the browser or the View menu asks). */
:root {
  --bg: #1b1e23;
  --panel: #23272e;
  --raised: #2b3038;
  --well: #1a1c21;
  --grid: #2a2e36;
  --line: #3b4049;
  --text: #e1e6ec;
  --muted: #9aa3ad;
  --accent: #f0a356;
  --accent-ink: #1b1e23;
  --ok: #6fdc8c;
  --bad: #ff6b6b;
  --warn: #f2c14e;
  --view-top: #3a4150;
  --view-bottom: #15171b;
  --scale: 1;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef0f3;
    --panel: #ffffff;
    --raised: #f3f4f6;
    --well: #f7f8fa;
    --grid: #e3e6ea;
    --line: #d0d5db;
    --text: #1d2228;
    --muted: #5c6670;
    --accent: #c46a1e;
    --accent-ink: #ffffff;
    --ok: #1d8a45;
    --bad: #c62828;
    --warn: #9a6a00;
    --view-top: #dfe5ee;
    --view-bottom: #aab3c0;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eef0f3;
  --panel: #ffffff;
  --raised: #f3f4f6;
  --well: #f7f8fa;
  --grid: #e3e6ea;
  --line: #d0d5db;
  --text: #1d2228;
  --muted: #5c6670;
  --accent: #c46a1e;
  --accent-ink: #ffffff;
  --ok: #1d8a45;
  --bad: #c62828;
  --warn: #9a6a00;
  --view-top: #dfe5ee;
  --view-bottom: #aab3c0;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: calc(15px * var(--scale)); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible, select:focus-visible,
textarea:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input[type="number"], input[type="text"], select, textarea {
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--raised);
}
kbd { margin-left: auto; padding-left: 1.5rem; color: var(--muted); font: inherit; font-size: 0.8rem; }

/* ---------------------------------------------------------------- header and menus */
header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.4rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: relative;
  z-index: 5;
}
.logo { width: 34px; height: 34px; }
.brand h1 { margin: 0; font-size: 1.2rem; color: var(--accent); }
.brand p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.menubar { display: flex; gap: 0.1rem; margin-left: 0.6rem; }
.menu { position: relative; }
.menu summary {
  list-style: none;
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary, .menu summary:hover { background: var(--raised); }
.menu .items {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 15rem;
  max-height: 75vh;
  overflow-y: auto;
  padding: 0.3rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.35);
  display: flex;
  flex-direction: column;
}
.menu .items button {
  display: flex;
  align-items: center;
  text-align: left;
  border: none;
  background: none;
  padding: 0.4rem 0.6rem;
}
.menu .items button:hover { background: var(--raised); }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 0.25rem 0; width: 100%; }
nav { margin-left: auto; display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
nav a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
}
nav a:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- layout */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(310px, 400px) 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas: "panel viewer" "panel below";
}
#panel {
  grid-area: panel;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.6rem 1rem 1.5rem;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
#viewer { grid-area: viewer; position: relative; min-height: 0; }
#below {
  grid-area: below;
  display: grid;
  grid-template-columns: minmax(260px, 2fr) 3fr;
  height: 34vh;
  min-height: 210px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
#plots { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; padding: 0.4rem 0.6rem; min-height: 0; }
#plots figure { margin: 0; display: flex; flex-direction: column; min-height: 0; }
#plots figcaption { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.2rem; }
#plots canvas { flex: 1; width: 100%; min-height: 0; border-radius: 6px; }
#info { overflow-y: auto; padding: 0.3rem 1rem 0.8rem; border-left: 1px solid var(--line); font-size: 0.9rem; }

/* ---------------------------------------------------------------- the panel */
.modes { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 0.7rem; }
.modes button { border-radius: 0; padding: 0.5rem; }
.modes button:first-child { border-radius: 6px 0 0 6px; }
.modes button:last-child { border-radius: 0 6px 6px 0; }
.modes button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#panel h2 { margin: 0 0 0.6rem; font-size: 1.3rem; color: var(--accent); }
#panel h3 { margin: 1.1rem 0 0.45rem; font-size: 1.05rem; color: var(--accent); }
.row { display: flex; gap: 0.5rem; align-items: center; }
.row > .big { flex: 1; }
.big { padding: 0.6rem 0.8rem; font-weight: 600; }
.wide { width: 100%; margin-top: 0.4rem; }
.numbers label { display: flex; align-items: center; gap: 0.35rem; flex: 1; }
.numbers input { width: 4.6rem; padding: 0.4rem; }
#boxrow .numbers { flex-wrap: wrap; row-gap: 0.4rem; }
#boxrow .numbers label { flex: 0 1 auto; }
#boxrow .numbers input { width: 3.6rem; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.2rem 0.3rem;
  font-size: 0.82rem;
  line-height: 1.15;
}
.tile svg { width: 46px; height: 46px; }
.tile[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 18%, var(--raised));
  color: var(--text);
  border: 2px solid var(--accent);
}
#twist { flex: 1; accent-color: var(--accent); }
.words { min-width: 10rem; color: var(--muted); }
.swatches { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.swatch { width: 2.3rem; height: 2.3rem; padding: 3px; border-radius: 50%; }
.swatch span { display: block; width: 100%; height: 100%; border-radius: 50%; overflow: hidden; }
.swatch[aria-pressed="true"] { border: 3px solid var(--accent); background: var(--raised); }
a.save { display: block; box-sizing: border-box; text-align: center; text-decoration: none; margin-top: 0.8rem; }
.save {
  width: 100%;
  margin-top: 1.4rem;
  padding: 0.8rem;
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
button.lid { width: 100%; margin-top: 0.5rem; padding: 0.6rem; font-weight: 600; }
.files { margin-top: 0.5rem; flex-wrap: wrap; }
.files button { flex: 1; font-size: 0.88rem; }
details#printer { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.6rem; }
details#printer summary { cursor: pointer; font-weight: 600; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0; }
.grid { display: grid; grid-template-columns: 1fr; gap: 0.35rem; }
.grid label { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; font-size: 0.9rem; }
.grid input { width: 5rem; margin-left: auto; }

/* ---------------------------------------------------------------- Advanced: every setting */
.namerow { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.namerow input { flex: 1; }
.group { border: 1px solid var(--line); border-radius: 8px; margin-top: 0.7rem; background: var(--bg); }
.group > summary {
  cursor: pointer;
  padding: 0.45rem 0.7rem;
  font-weight: 600;
  color: var(--accent);
}
.group .rows {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.35rem 0.6rem;
  align-items: center;
  padding: 0.2rem 0.7rem 0.7rem;
}
.rows > .label { text-align: right; font-size: 0.9rem; color: var(--muted); }
.rows > .control { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.rows > .whole { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.35rem; }
.control input[type="number"] { width: 6.5rem; }
.control select { max-width: 100%; min-width: 0; flex: 1; }
.control input[type="range"] { flex: 1; accent-color: var(--accent); }
.control input[type="color"] { width: 3rem; height: 1.9rem; padding: 0.1rem; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); }
.control .unit, .control .none { color: var(--muted); font-size: 0.85rem; }
.control .dice { padding: 0.2rem 0.5rem; }
.whole canvas { width: 100%; border-radius: 6px; display: block; }
.whole textarea { width: 100%; min-height: 5.5rem; font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.88rem; }
.whole .row { flex-wrap: wrap; }
.whole .row button, .whole .row select { font-size: 0.85rem; padding: 0.25rem 0.5rem; }
.whole .row select { flex: 1; min-width: 0; max-width: 100%; }
.outlinebox canvas { height: 300px; }

/* ---------------------------------------------------------------- the 3D view */
#viewer { background: linear-gradient(var(--view-top), var(--view-bottom)); }
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewbar {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  pointer-events: none;
}
.viewbar > * { pointer-events: auto; }
.viewbar button { background: color-mix(in srgb, var(--panel) 88%, transparent); }
.viewbar button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.views { display: flex; margin-right: auto; }
.views button { border-radius: 0; }
.views button:first-child { border-radius: 6px 0 0 6px; }
.views button:last-child { border-radius: 0 6px 6px 0; }
.views button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.help { position: absolute; left: 0.8rem; bottom: 0.4rem; margin: 0; font-size: 0.82rem; color: var(--muted);
  text-shadow: 0 0 4px var(--bg); }
#busy {
  position: absolute;
  top: 3.1rem;
  left: 0.6rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  font-size: 0.85rem;
}
.spinner {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -2px;
  animation: turn 0.9s linear infinite;
}
@keyframes turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  z-index: 2;
}
#loading img { width: 72px; height: 72px; margin-bottom: 0.5rem; }
#loading p { max-width: 30rem; margin: 0.3rem 0; }
#loadingtext { color: var(--muted); }
#loading.failed #loadingtext { color: var(--bad); }

/* ---------------------------------------------------------------- the report (the desktop app's own HTML) */
#report h3 { margin: 0.5rem 0 0.3rem; color: var(--accent); font-size: 1rem; }
#report td { padding: 0.12rem 0.6rem 0.12rem 0; vertical-align: top; }
#report .k { color: var(--muted); }
#report td.k { white-space: nowrap; }
#report .e { color: var(--bad); }
#report .w { color: var(--warn); }
#report .ok { color: var(--ok); }
#report p { margin: 0.35rem 0; }
#report ul { padding-left: 1.2rem; margin: 0.3rem 0; }
.status { color: var(--accent); font-size: 0.88rem; min-height: 1.2em; margin: 0.4rem 0 0; }

/* ---------------------------------------------------------------- dialogs */
dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 1rem 1.2rem;
  max-width: min(1100px, 94vw);
  max-height: 90dvh;
}
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
.dialoghead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.dialoghead h2 { margin: 0; color: var(--accent); font-size: 1.25rem; }
.designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6rem; margin-top: 0.5rem; }
.design { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; padding: 0.4rem; }
.design img { width: 150px; height: 190px; object-fit: contain; }
.design b { font-size: 0.9rem; }
#steplist ol { padding-left: 1.4rem; }
#steplist li { margin: 0.35rem 0; }
#help { width: min(760px, 94vw); }
.helptext { max-height: 62dvh; overflow-y: auto; line-height: 1.45; }
.helptext code { color: var(--accent); }
.helptext td { padding: 2px 8px; vertical-align: top; }
#helpexamples { margin-top: 0.8rem; }
#helpexamples select { max-width: 24rem; }
dialog.full {
  width: 96vw;
  height: 94dvh;
  max-width: none;
  max-height: none;
  display: none;
  flex-direction: column;
  gap: 0.6rem;
}
dialog.full[open] { display: flex; }
dialog.full canvas { flex: 1; width: 100%; min-height: 0; border-radius: 8px; touch-action: none; }
.tools { flex-wrap: wrap; }
.tools input { width: 4.5rem; }

/* ---------------------------------------------------------------- narrow screens: one column */
@media (max-width: 900px) {
  body { height: auto; }
  main { display: flex; flex-direction: column; }
  #viewer { order: 1; height: 60vh; }
  #panel { order: 2; border-right: none; border-top: 1px solid var(--line); overflow: visible; }
  #below { order: 3; grid-template-columns: 1fr; height: auto; }
  #plots { height: 220px; }
  #info { border-left: none; border-top: 1px solid var(--line); }
  .brand p { display: none; }
  header { flex-wrap: wrap; }
  .menubar { order: 3; width: 100%; margin-left: 0; }
}
