:root {
  --bg: #11141a;
  --panel: #1a1f29;
  --panel-2: #232a36;
  --fg: #e6e9ef;
  --fg-dim: #98a0ad;
  --accent: #6cd3ff;
  --accent-2: #ffb86c;
  --border: #2a3140;
  --stale: #555;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN",
               "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
header h1 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
}
header .hint {
  margin: 0;
  color: var(--fg-dim);
  font-size: 12px;
}
header code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
}

section {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  background: var(--panel);
}
.ctrl {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}
.ctrl label {
  font-size: 12px;
  color: var(--fg-dim);
  display: flex;
  align-items: center;
  gap: 4px;
}
.ctrl label.sub, .ctrl .sub {
  font-size: 11px;
  color: var(--fg-dim);
}
.ctrl input[type="number"],
.ctrl input[type="file"],
.ctrl select {
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 13px;
  width: 100%;
}
.ctrl input[type="number"] {
  width: 70px;
}
.ctrl .sub input[type="number"] {
  width: 56px;
  margin: 0 6px 0 2px;
}
.ctrl.actions {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  min-width: auto;
}
button {
  background: var(--accent);
  color: #0b1118;
  border: 0;
  border-radius: 4px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
button:disabled {
  background: var(--stale);
  color: #888;
  cursor: not-allowed;
}
button.tab {
  background: var(--panel-2);
  color: var(--fg-dim);
  font-weight: 400;
}
button.tab.active {
  background: var(--accent-2);
  color: #1a1108;
  font-weight: 600;
}

.status {
  background: var(--panel);
  font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
#status { flex: 1; }
progress {
  width: 200px;
  height: 8px;
}

.formula .tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.formula .tabs .sub { margin-left: auto; }

.formula-box {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  max-height: 360px;
  overflow: auto;
  font-size: 14px;
}

#formula-expanded {
  max-height: 480px;
}

.expanded-header {
  margin-bottom: 6px;
  color: var(--accent);
}

.expanded-flow {
  line-height: 1.9;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--fg);
}

/* "1行表示" mode: don't wrap; let the container scroll horizontally. */
.expanded-flow.one-line {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
  overflow-x: auto;
}
.expanded-flow.one-line .expanded-chunk,
.expanded-flow.one-line .expanded-plus {
  display: inline-block;
  vertical-align: middle;
  white-space: nowrap;
}

.expanded-chunk {
  display: inline;
}

.expanded-chunk .katex {
  font-size: 0.95em;
}

.expanded-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 11px;
  color: var(--fg-dim);
  font-family: ui-monospace, Consolas, monospace;
}

.expanded-plus {
  display: inline;
  color: var(--accent-2);
  font-weight: 600;
  padding: 0 2px;
}

.tbl-h {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.tbl-scroll {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

table.tbl {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  border-collapse: collapse;
  width: 100%;
}
table.tbl th,
table.tbl td {
  padding: 2px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
table.tbl thead th {
  background: var(--panel);
  color: var(--fg-dim);
  position: sticky;
  top: 0;
  font-weight: 500;
}
table.tbl tbody tr:hover {
  background: rgba(108, 211, 255, 0.06);
}

.canvases {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.canvases h2 {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-dim);
}
canvas {
  width: 100%;
  height: auto;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: 4px;
  display: block;
}
canvas.stale {
  filter: grayscale(1) brightness(0.6);
}

#detail { cursor: grab; }
#detail.dragging { cursor: grabbing; }
