* {
  box-sizing: border-box;
}

:root {
  --bg: #fff;
  --fg: #000;
  --selection: #d9d9d9;
  --punct: #8a8a8a;
}

body.dark {
  --bg: #000;
  --fg: #fff;
  --selection: #4a4a4a;
  --punct: #b0b0b0;
}

@font-face {
  font-family: "Next Mono Pan";
  src:
    url("./NextMonoPan-Thin.otf") format("opentype"),
    local("NextMonoPan Thin"),
    local("NextMonoPan-Thin");
  font-style: normal;
  font-weight: 100;
  font-display: swap;
}

@font-face {
  font-family: "Planar Variable";
  src:
    url("./GT-Planar-Trial-VF.ttf") format("truetype"),
    local("Planar Variable"),
    local("Planar");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

::selection {
  background: var(--selection);
}

::-moz-selection {
  background: var(--selection);
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Next Mono Pan", "Courier New", Courier, monospace;
  font-size: 23px;
}

.app {
  width: 100%;
  height: 100%;
  padding: 2.5rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.52em;
}

.controls select {
  border: 0;
  border-bottom: 1px solid var(--fg);
  border-radius: 0;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  box-shadow: none;
  background-image: none;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  padding: 0.02em 0.1em 0.02em 0.02em;
  line-height: 1.1;
  cursor: pointer;
}

.controls select:focus {
  outline: none;
}

.controls select::-ms-expand {
  display: none;
}

.controls button {
  border: 0;
  border-bottom: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  padding: 0.02em 0.12em;
  line-height: 1.1;
  cursor: pointer;
}

.controls button:focus {
  outline: none;
}

.editor-shell {
  position: relative;
  width: min(100%, 72ch);
  flex: 1;
  max-height: 88vh;
  border: 0;
  padding: 1.25rem 0.75rem;
}

#display,
#measure,
#input {
  margin: 0;
  position: absolute;
  inset: 1.25rem 0.75rem;
  width: calc(100% - 1.5rem);
  height: calc(100% - 2.5rem);
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  tab-size: 4;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

#display {
  pointer-events: none;
}

body[data-mode="planar"] #display,
body[data-mode="planar"] #measure {
  font-family: "Planar Variable", "Planar", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

#measure {
  visibility: hidden;
  pointer-events: none;
}

#input {
  resize: none;
  color: transparent;
  caret-color: var(--fg);
}

#caret-layer {
  position: absolute;
  inset: 1.25rem 0.75rem;
  pointer-events: none;
}

#virtual-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1.2em;
  background: var(--fg);
  opacity: 0;
}

.char-cell,
.code-cell {
  display: inline-block;
  width: 1ch;
  height: 1em;
  line-height: 1em;
  vertical-align: top;
  overflow: hidden;
}

.code-cell {
  position: relative;
}

.seg {
  position: absolute;
  background: transparent;
  will-change: clip-path, opacity;
}

.seg.on {
  background: var(--fg);
}

.seg-animate-in {
  animation-duration: var(--seg-duration, 72ms);
  animation-timing-function: cubic-bezier(0.22, 0.75, 0.22, 1);
  animation-fill-mode: both;
}

.seg-animate-out {
  animation-duration: var(--seg-duration, 64ms);
  animation-timing-function: cubic-bezier(0.35, 0, 0.9, 1);
  animation-fill-mode: both;
}

.seg-animate-in.top,
.seg-animate-in.bottom {
  animation-name: drawH;
}

.seg-animate-in.left,
.seg-animate-in.right {
  animation-name: drawV;
}

.seg-animate-out.top,
.seg-animate-out.bottom {
  animation-name: eraseH;
}

.seg-animate-out.left,
.seg-animate-out.right {
  animation-name: eraseV;
}

@keyframes drawH {
  from {
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes drawV {
  from {
    clip-path: inset(100% 0 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes eraseH {
  from {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
  to {
    clip-path: inset(0 100% 0 0);
    opacity: 0;
  }
}

@keyframes eraseV {
  from {
    clip-path: inset(0 0 0 0);
    opacity: 1;
  }
  to {
    clip-path: inset(100% 0 0 0);
    opacity: 0;
  }
}

.seg.top,
.seg.bottom {
  left: 3px;
  right: 3px;
  height: 1px;
}

.seg.left,
.seg.right {
  top: 3px;
  bottom: 3px;
  width: 1px;
}

.seg.top {
  top: 3px;
}

.seg.bottom {
  bottom: 3px;
}

.seg.left {
  left: 3px;
}

.seg.right {
  right: 3px;
}

.seg.top.inner,
.seg.bottom.inner {
  left: 6px;
  right: 6px;
  height: 1px;
}

.seg.left.inner,
.seg.right.inner {
  top: 6px;
  bottom: 6px;
  width: 1px;
}

.seg.top.inner {
  top: 6px;
}

.seg.bottom.inner {
  bottom: 6px;
}

.seg.left.inner {
  left: 6px;
}

.seg.right.inner {
  right: 6px;
}

.code-cell.curve-cell .seg.curve-svg {
  left: 0 !important;
  right: 0 !important;
  top: 0 !important;
  bottom: 0 !important;
  width: 100% !important;
  height: 100% !important;
  overflow: visible;
  background: transparent;
  clip-path: none !important;
}

.code-cell.curve-cell .seg.curve-svg .seg-path {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  opacity: 0;
}

.code-cell.curve-cell .seg.curve-svg.on .seg-path {
  stroke-dashoffset: 0;
  opacity: 1;
}

.code-cell.curve-cell .seg.curve-svg.seg-animate-in .seg-path {
  animation: drawCurve var(--seg-duration, 72ms) cubic-bezier(0.22, 0.75, 0.22, 1) both;
  animation-delay: var(--seg-delay, 0ms);
}

.code-cell.curve-cell .seg.curve-svg.seg-animate-out .seg-path {
  animation: eraseCurve var(--seg-duration, 64ms) cubic-bezier(0.35, 0, 0.9, 1) both;
  animation-delay: var(--seg-delay, 0ms);
}

@keyframes drawCurve {
  from {
    stroke-dashoffset: 100;
    opacity: 1;
  }
  to {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

@keyframes eraseCurve {
  from {
    stroke-dashoffset: 0;
    opacity: 1;
  }
  to {
    stroke-dashoffset: 100;
    opacity: 0;
  }
}

.fade-char {
  font-family: "Next Mono Pan", "Courier New", Courier, monospace;
}

.final-char {
  font-family: Helvetica, Arial, sans-serif;
  opacity: 1;
}

.punct-char {
  color: var(--punct);
}

.planar-char,
.planar-upright-char,
.planar-confirm-char {
  font-family: "Planar Variable", "Planar", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.planar-upright-char {
  font-variation-settings: "slnt" 0;
}

.planar-confirm-char {
  display: inline-block;
  font-variation-settings: "slnt" var(--from-slnt, 0);
  animation: planarToUpright 110ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes planarToUpright {
  from {
    font-variation-settings: "slnt" var(--from-slnt, 0);
  }
  to {
    font-variation-settings: "slnt" 0;
  }
}

.transition-cell {
  display: inline-block;
  width: 1ch;
  height: 1em;
  line-height: 1em;
  vertical-align: top;
  position: relative;
  overflow: hidden;
}

.transition-cell .code-cell {
  position: absolute;
  inset: 0;
}

.transition-letter {
  position: absolute;
  inset: 0;
  font-family: "Next Mono Pan", "Courier New", Courier, monospace;
  opacity: 0;
  animation: letterIn 38ms ease-out both;
}

.transition-letter-out {
  position: absolute;
  inset: 0;
  font-family: "Next Mono Pan", "Courier New", Courier, monospace;
  opacity: 1;
  animation: letterOut 32ms ease-in both;
}

@keyframes letterIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes letterOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

#caret-marker {
  display: inline-block;
  width: 0;
  height: 1.2em;
  vertical-align: top;
}
