/* Trope Table - a chemistry-classroom wall chart: chalk-white paper, slate ink, six pastel element families.
 * Dark mode is a blackboard: deep slate, the same families as dim tiles with light text. */
:root {
  --bg: #f3f1ea; --paper: #fffdf7; --ink: #1f2633; --muted: #5a6273; --line: #d8d3c6; --soft: #ebe7dc;
  --accent: #3b4fd8; --accent-ink: #ffffff; --ok: #1d7a4a; --warn: #a3480f; --info: #3d5a8a;
  --f-pair: #f6c4cf; --f-pair-ink: #6b1d33; --f-device: #f8d58e; --f-device-ink: #6a4300;
  --f-au: #bfe3b4; --f-au-ink: #1f5419; --f-dyn: #b9d6f5; --f-dyn-ink: #163f6b;
  --f-tone: #d9c9f3; --f-tone-ink: #45247a; --f-form: #cfd6de; --f-form-ink: #2c3a48;
  --f-custom: #ffffff; --f-custom-ink: #1f2633;
  --dim: 0.5; --shadow: 0 1px 0 rgba(31, 38, 51, 0.08), 0 6px 18px rgba(31, 38, 51, 0.06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #11161f; --paper: #19202c; --ink: #e9edf5; --muted: #a3acbd; --line: #2f3a4b; --soft: #222b39;
  --accent: #8fa0ff; --accent-ink: #0f1420; --ok: #6fd39c; --warn: #ffab73; --info: #9cc0ff;
  --f-pair: #5a2836; --f-pair-ink: #ffd6df; --f-device: #57421a; --f-device-ink: #ffe3a6;
  --f-au: #23452a; --f-au-ink: #cdf0c4; --f-dyn: #1f3a5a; --f-dyn-ink: #cfe4ff;
  --f-tone: #3c2c5e; --f-tone-ink: #e6dbff; --f-form: #313c49; --f-form-ink: #dde5ee;
  --f-custom: #2a3342; --f-custom-ink: #f2f5fa;
  --dim: 0.46; --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--accent); }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 0.86rem; } .muted { color: var(--muted); } .mono { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* Header */
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 2px solid var(--ink); background: var(--paper); flex-wrap: wrap; }
.back { text-decoration: none; font-size: 0.9rem; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.logo { width: 26px; height: 26px; }
.lg-a { fill: var(--f-pair); } .lg-b { fill: var(--f-device); } .lg-c { fill: var(--f-au); } .lg-d { fill: var(--f-tone); }
.logo rect { stroke: var(--ink); stroke-width: 1.4; }
.session { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 4px; border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 0.88rem; cursor: pointer; text-decoration: none; }
.pill:hover { background: var(--soft); }
.pill.solid { background: var(--ink); color: var(--paper); }
.pill.solid:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill.ghost { border-style: dashed; cursor: default; }
.pill.tiny { padding: 3px 9px; font-size: 0.8rem; }
.pill:disabled { opacity: 0.45; cursor: not-allowed; }

main { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; }

/* Hero */
.hero { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 22px; align-items: center; padding: 26px 0 18px; }
.kicker { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.78rem; color: var(--muted); margin: 0 0 4px; font-weight: 700; }
h1 { font-size: clamp(2.1rem, 6vw, 3.4rem); line-height: 1.02; margin: 0 0 10px; letter-spacing: -0.02em; font-weight: 900; }
.lede { margin: 0 0 14px; max-width: 60ch; }
.samples { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { border: 1.5px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 8px; padding: 5px 10px; font: inherit; font-size: 0.86rem; cursor: pointer; }
.chip:hover { border-color: var(--ink); }
.chip.on { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.hero-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

/* Element tiles */
.el { position: relative; border-radius: 6px; padding: 4px 5px 5px; min-height: 58px; display: flex; flex-direction: column; justify-content: flex-end; border: 1.5px solid transparent; opacity: var(--dim); transition: opacity .2s, transform .2s; overflow: hidden; }
.el.lit { opacity: 1; border-color: var(--ink); box-shadow: var(--shadow); }
.el-n { position: absolute; top: 3px; left: 5px; font-size: 0.66rem; font-weight: 700; }
.el-sym { font-weight: 900; font-size: 1.25rem; line-height: 1; margin-top: 14px; letter-spacing: -0.02em; }
.el-name { font-size: 0.64rem; line-height: 1.15; margin-top: 2px; }
.el-where { position: absolute; top: 3px; right: 4px; font-size: 0.6rem; font-weight: 800; letter-spacing: 0.04em; }
.small-el { min-height: 86px; padding: 6px 8px; opacity: 1; border-color: var(--ink); }
.small-el .el-sym { font-size: 1.9rem; margin-top: 18px; }
.small-el .el-name { font-size: 0.74rem; }
.fam-pair { background: var(--f-pair); color: var(--f-pair-ink); }
.fam-device { background: var(--f-device); color: var(--f-device-ink); }
.fam-au { background: var(--f-au); color: var(--f-au-ink); }
.fam-dyn { background: var(--f-dyn); color: var(--f-dyn-ink); }
.fam-tone { background: var(--f-tone); color: var(--f-tone-ink); }
.fam-form { background: var(--f-form); color: var(--f-form-ink); }
.fam-custom { background: var(--f-custom); color: var(--f-custom-ink); border: 1.5px dashed var(--ink); }
.el.st-cut { opacity: 0.6; text-decoration: line-through; }
.el.st-twisted::after, .el.st-straight::after { content: ""; position: absolute; left: 24px; top: 5px; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid currentColor; }
.el.st-twisted::after { background: currentColor; }

/* Layout */
.layout { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.3fr); gap: 14px; }
.panel { background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.inbox { grid-row: span 2; }
.tablebox { grid-row: span 2; }
.checkbox, .askbox { grid-column: 1 / -1; }
.ph { margin: 0 0 10px; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.num-tag { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 5px; background: var(--ink); color: var(--paper); font-size: 0.85rem; font-weight: 800; }
.lbl { display: block; font-size: 0.86rem; font-weight: 600; margin: 10px 0 4px; }
textarea, input[type="text"], select { width: 100%; border: 1.5px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; background: var(--bg); color: var(--ink); }
textarea:focus, select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.dropping { border-color: var(--accent); border-style: dashed; }
.filerow { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.filebtn { cursor: pointer; }
.wc { margin: 8px 0 0; }

/* The table */
.formula-row { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.formula { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.mini { display: inline-grid; place-items: center; min-width: 34px; height: 30px; padding: 0 5px; border-radius: 5px; border: 1.5px solid var(--ink); font-size: 0.95rem; }
.mini b { font-weight: 900; }
.plus { font-weight: 800; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
.fam-h { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; padding: 3px 4px; border-radius: 4px; text-align: center; opacity: 1; line-height: 1.15; }
.legend { margin: 10px 0 0; }
.fam-short { display: none; }
.key { display: inline-grid; place-items: center; min-width: 18px; padding: 0 3px; border: 1.5px solid var(--ink); border-radius: 3px; font-size: 0.7rem; font-weight: 800; margin: 0 2px; }

/* Verdict */
.lean { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.lean-l { display: flex; flex-direction: column; gap: 4px; max-width: 70ch; }
.lean-r { display: flex; gap: 8px; }
.lean-r div { display: flex; flex-direction: column; align-items: center; border: 1.5px solid var(--line); border-radius: 8px; padding: 4px 12px; min-width: 64px; }
.lean-r b { font-size: 1.4rem; line-height: 1.1; }
.lean-r span { font-size: 0.74rem; color: var(--muted); }
.badge { display: inline-block; align-self: flex-start; border-radius: 6px; padding: 3px 10px; font-weight: 800; font-size: 0.88rem; border: 1.5px solid var(--ink); background: var(--soft); color: var(--ink); }
.badge.v-bare { background: var(--f-device); color: var(--f-device-ink); }
.badge.v-pileup { background: var(--f-pair); color: var(--f-pair-ink); }
.badge.v-fresh { background: var(--f-au); color: var(--f-au-ink); }
.badge.v-twist { background: var(--f-dyn); color: var(--f-dyn-ink); }
.flags, .recon, .asks, .hlist { list-style: none; padding: 0; margin: 10px 0 0; }
.flags li, .recon li { padding: 5px 0; border-top: 1px dashed var(--line); font-size: 0.9rem; }
.lv { display: inline-block; font-size: 0.7rem; font-weight: 800; text-transform: uppercase; border-radius: 4px; padding: 0 6px; margin-right: 6px; border: 1px solid currentColor; }
.lv-fix .lv, .recon .warn::before { color: var(--warn); }
.lv-warn .lv { color: var(--warn); } .lv-info .lv { color: var(--info); }
.recon .warn::before { content: "check "; font-weight: 800; font-size: 0.72rem; text-transform: uppercase; }
.recon .info::before { content: "note "; font-weight: 800; font-size: 0.72rem; text-transform: uppercase; color: var(--info); }
.rules { margin: 10px 0 0; }
.none { color: var(--muted); font-style: italic; padding: 4px 0; }

/* Run */
.askbox form { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.go { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 12px 22px; font: inherit; font-weight: 800; font-size: 1.02rem; cursor: pointer; }
.go:disabled { opacity: 0.5; cursor: not-allowed; }
.note { margin: 0; padding: 6px 10px; border-left: 3px solid var(--info); background: var(--soft); border-radius: 4px; font-size: 0.9rem; }
.note.warn { border-color: var(--warn); }
.gate { margin: 0; font-size: 0.9rem; }
.meter { margin: 0; }
.progress { margin-top: 14px; }
.stages { list-style: none; padding: 0; margin: 8px 0; }
.stage { padding: 2px 0; color: var(--muted); } .stage.done { color: var(--ok); } .stage.active { color: var(--ink); font-weight: 700; }
.stage-ic { display: inline-block; width: 1.1em; font-family: ui-monospace, Menlo, monospace; }
.raw { white-space: pre-wrap; word-break: break-word; font-size: 0.82rem; max-height: 360px; overflow: auto; }

/* Result */
.result { margin-top: 18px; background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.rhead h2 { margin: 6px 0; font-size: clamp(1.4rem, 4vw, 2rem); line-height: 1.15; overflow-wrap: anywhere; }
.summary { margin: 8px 0 0; }
.cards { list-style: none; padding: 0; margin: 16px 0 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.card { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg); }
.card.st-cut { opacity: 0.82; }
.card.st-cut .big .el-sym { text-decoration: line-through; }
.big { position: relative; align-self: start; border-radius: 8px; border: 1.5px solid var(--ink); padding: 6px; min-height: 92px; display: flex; flex-direction: column; justify-content: flex-end; }
.big .el-sym { font-size: 2.1rem; margin-top: 18px; }
.big .el-name { font-size: 0.72rem; }
.card-top { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.stamp { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 6px; }
.s-straight { color: var(--info); } .s-twisted { color: var(--ok); } .s-cut { color: var(--warn); } .s-none { color: var(--muted); }
.axis { font-size: 0.74rem; font-weight: 700; background: var(--ink); color: var(--paper); border-radius: 4px; padding: 0 6px; }
.crow { margin: 4px 0 0; font-size: 0.9rem; }
.crow b { font-weight: 700; }
.crow.tw { border-left: 3px solid var(--accent); padding-left: 8px; }
.twin { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 12px; margin-top: 14px; }
.catalyst, .blurb { border: 1.5px dashed var(--ink); border-radius: 10px; padding: 10px 12px; }
.catalyst h3, .blurb h3, .askfirst h3, .afterword h3 { margin: 0 0 4px; font-size: 1rem; }
.blurb #rBlurb { font-family: Georgia, "Times New Roman", serif; font-size: 1.02rem; }
.cardrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.askfirst { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: var(--soft); }
.askq label { display: block; font-weight: 600; margin: 8px 0 3px; }
.afterword { margin-top: 14px; }
.exports, .history { margin-top: 14px; }
.exports h3, .history h3 { margin: 0 0 6px; }
.hrow { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px dashed var(--line); }
.hinfo { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.hinfo b { overflow-wrap: anywhere; }

.foot { max-width: 1180px; margin: 0 auto; padding: 10px 16px 40px; color: var(--muted); font-size: 0.86rem; }
.toasts { position: fixed; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 50; max-width: calc(100vw - 24px); }
.toast { background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: 8px; font-size: 0.9rem; box-shadow: var(--shadow); transition: opacity .5s; }
.toast.err { background: var(--warn); color: #ffffff; }
:root[data-theme="dark"] .toast.err { color: #1a0f05; }
.toast a { color: inherit; font-weight: 700; }
.toast.gone { opacity: 0; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero-strip { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .small-el { min-height: 58px; padding: 4px; }
  .small-el .el-sym { font-size: 1.15rem; margin-top: 14px; }
  .small-el .el-name { display: none; }
  .layout { grid-template-columns: 1fr; }
  .inbox, .tablebox { grid-row: auto; }
  .cards, .twin { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .el { min-height: 46px; padding: 3px; }
  .el-name { display: none; }
  .el-sym { font-size: 1.02rem; margin-top: 12px; }
  .el-n { font-size: 0.58rem; left: 3px; }
  .el-where { font-size: 0.52rem; right: 2px; }
  .fam-h { font-size: 0.62rem; padding: 3px 1px; letter-spacing: 0.02em; }
  .fam-long { display: none; } .fam-short { display: inline; }
  .el.st-twisted::after, .el.st-straight::after { left: auto; right: 3px; top: auto; bottom: 3px; width: 7px; height: 7px; }
  .grid { gap: 3px; }
  .card { grid-template-columns: 70px minmax(0, 1fr); }
  .big { min-height: 72px; } .big .el-sym { font-size: 1.6rem; }
  .lean-r div { min-width: 56px; padding: 4px 8px; }
}
@media print {
  .bar, .samples, .askbox, .checkbox, .exports, .history, .foot, .cardrow, .toasts, #askForm { display: none !important; }
  body { background: #fff; color: #000; }
}
