@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap');

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f4f2ed; --bg2: #eceae4; --bg3: #e2dfd8;
  --border: #ccc9c0; --text: #1a1814; --text2: #6b6860; --text3: #9e9b93;
  --red: #c0392b; --blue: #1a4f7a; --green: #2a6b3c; --orange: #b85c00;
  --mono: 'IBM Plex Mono', monospace; --sans: 'IBM Plex Sans', sans-serif;
  
  --left-w: 196px;
  --right-w: 136px;
  --plots-h: 160px;
}

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  overflow: hidden;
}

#app {
  width: 100%; height: 100%; display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  grid-template-rows: 1fr var(--plots-h);
  grid-template-areas: "left mid right" "left plots right";
}

#left {
  grid-area: left;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.ps {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border);
}

.pl {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}

#cBtns {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.cbtn {
  padding: 5px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  text-align: left;
  transition: all .1s;
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
}

.cbtn:hover {
  background: var(--bg3);
  color: var(--text);
}

.cbtn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.cdot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.gr {
  margin-bottom: 5px;
}

.gm {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.gn {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text2);
}

.gv {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text);
  font-weight: 500;
}

input[type=range] {
  width: 100%;
  height: 3px;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}

.ck {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  cursor: pointer;
  margin-bottom: 4px;
}

input[type=checkbox] {
  accent-color: var(--text);
  cursor: pointer;
}

.btn {
  width: 100%;
  padding: 5px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  cursor: pointer;
  transition: all .12s;
  text-align: center;
  margin-bottom: 3px;
  display: block;
}

.btn:hover {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.btn.danger {
  border-color: var(--red);
  color: var(--red);
}

.btn.danger:hover {
  background: var(--red);
  color: #fff;
}

.btn.ok {
  border-color: var(--green);
  color: var(--green);
}

.btn.ok:hover {
  background: var(--green);
  color: #fff;
}

#cInfo {
  font-family: var(--sans);
  font-size: 10px;
  line-height: 1.5;
  color: var(--text2);
}

#mid {
  grid-area: mid;
  position: relative;
  overflow: hidden;
  min-height: 0;
  /* Add this! It prevents the grid from blowing out */
}

#c3d {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#c3d:active {
  cursor: grabbing;
}

#failOverlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(192, 57, 43, .07);
  z-index: 10;
}

#failBox {
  background: var(--bg);
  border: 1px solid #d0a0a0;
  border-radius: 4px;
  padding: 16px 18px;
  width: 310px;
  max-height: 88%;
  overflow-y: auto;
}

#failBox h3 {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--red);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

#failBox p {
  font-size: 11px;
  color: var(--text2);
  line-height: 1.55;
  margin-bottom: 8px;
}

.fblock {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg2);
  padding: 8px 10px;
  border-radius: 3px;
  margin-bottom: 8px;
  line-height: 1.8;
}

.fl {
  color: var(--text3);
}

.fv {
  color: var(--text);
  font-weight: 500;
}

.fg {
  color: var(--green);
  font-weight: 500;
}

#clickHint {
  position: absolute;
  bottom: 7px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text3);
  pointer-events: none;
  letter-spacing: .05em;
  text-transform: uppercase;
}

#plots {
  grid-area: plots;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  position: relative;
}

.pw {
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.pw:last-child {
  border-right: none;
}

.pw canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#right {
  grid-area: right;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  grid-row: 1 / 3;
  position: relative;
}

#statusBig {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .05em;
  padding: 7px 11px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.sr {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2px 0;
}

.sk {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text3);
}

.sv {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text);
  font-weight: 500;
}

#phasewrap {
  padding: 7px 11px;
  border-top: 1px solid var(--border);
}

#mathModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 24, 20, .5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

#mathModal.open {
  display: flex;
}

#mathBox {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  width: min(860px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

#mathBox header {
  background: var(--text);
  color: var(--bg);
  padding: 11px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#mathBox header span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
}

#mathClose {
  background: transparent;
  border: 1px solid #555;
  color: #aaa;
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
}

#mathClose:hover {
  background: #333;
}

#mathTabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.mtab {
  font-family: var(--mono);
  font-size: 10px;
  padding: 7px 11px;
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg2);
  color: var(--text2);
  white-space: nowrap;
  flex-shrink: 0;
}

.mtab:hover {
  background: var(--bg3);
}

.mtab.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
}

#mathBody {
  overflow-y: auto;
  padding: 18px 22px;
  flex: 1;
}

#mathBody h2 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text3);
  margin: 16px 0 6px;
}

#mathBody h2:first-child {
  margin-top: 0;
}

#mathBody p {
  color: var(--text2);
  font-size: 12px;
  line-height: 1.65;
  margin-bottom: 8px;
}

#mathBody .eq {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg2);
  border-left: 3px solid #5b3a8a;
  padding: 10px 14px;
  margin: 6px 0 12px;
  color: var(--text);
  line-height: 2.1;
  white-space: pre-wrap;
  border-radius: 0 3px 3px 0;
}

#mathBody .note {
  font-family: var(--mono);
  font-size: 10px;
  color: #7a6a30;
  background: #faf7e8;
  border: 1px solid #e0d890;
  border-radius: 3px;
  padding: 8px 11px;
  line-height: 1.6;
  margin-bottom: 12px;
}

#mathBody table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: 8px 0 14px;
}

#mathBody td,
#mathBody th {
  padding: 6px 10px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  vertical-align: top;
}

#mathBody tr:hover td {
  background: var(--bg3);
}

#mathBody th {
  background: var(--bg2);
  color: var(--text3);
  font-size: 9px;
  letter-spacing: .05em;
  text-transform: uppercase;
}

#mathBody .ok {
  color: var(--green);
}

#mathBody .bad {
  color: var(--red);
}

.irow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
}

.irow label {
  width: 130px;
  flex-shrink: 0;
}

.irow input[type=number] {
  width: 72px;
  padding: 3px 5px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text);
  border-radius: 2px;
}

.irow span {
  color: var(--text3);
}

#ic_result {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg2);
  padding: 10px 12px;
  border-radius: 3px;
  line-height: 1.9;
  display: none;
  margin-top: 8px;
}

.rg {
  color: var(--green);
  font-weight: 500;
}

.ro {
  color: var(--orange);
}

.calcbtn {
  font-family: var(--mono);
  font-size: 10px;
  padding: 5px 16px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  margin-top: 6px;
}

.calcbtn:hover {
  opacity: .85;
}

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

#countOverlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(244, 242, 237, .6);
  z-index: 15;
  flex-direction: column;
  pointer-events: none;
}

#countText {
  font-family: var(--mono);
  font-size: 64px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 10px;
}

#countLabel {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--text2);
}

@media(max-width:680px) {
  #app {
    grid-template-columns: 160px 1fr;
    grid-template-rows: 1fr 110px;
    grid-template-areas: "left mid" "left plots";
  }

  #right {
    display: none;
  }
}

.resizer-v,
.resizer-h {
  position: absolute;
  z-index: 50;
  transition: background 0.2s;
}

.resizer-v:hover,
.resizer-h:hover {
  background: var(--text);
  opacity: 0.3;
}

.resizer-v {
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
}

.resizer-h {
  left: 0;
  right: 0;
  height: 8px;
  cursor: row-resize;
}

/* Position the handles exactly over the borders */
#drag-left {
  right: -4px;
}

#drag-right {
  left: -4px;
}

#drag-plots {
  top: -4px;
}