.wterm {
  /* Application overrides are owned by the renderer; each terminal is isolated. */
  --term-app-fg: initial;
  --term-app-bg: initial;
  --term-app-cursor: initial;

  --term-fg: #d4d4d4;
  --term-bg: #1e1e1e;
  --term-cursor: #aeafad;

  --term-color-0: #1e1e1e;
  --term-color-1: #f44747;
  --term-color-2: #6a9955;
  --term-color-3: #d7ba7d;
  --term-color-4: #569cd6;
  --term-color-5: #c586c0;
  --term-color-6: #4ec9b0;
  --term-color-7: #d4d4d4;
  --term-color-8: #808080;
  --term-color-9: #f44747;
  --term-color-10: #6a9955;
  --term-color-11: #d7ba7d;
  --term-color-12: #569cd6;
  --term-color-13: #c586c0;
  --term-color-14: #4ec9b0;
  --term-color-15: #ffffff;

  --term-font-family:
    "Menlo", "Consolas", "DejaVu Sans Mono", "Courier New", monospace;
  --term-font-size: 14px;
  --term-line-height: 1.2;
  --term-row-height: 17px;

  position: relative;
  background: var(--term-app-bg, var(--term-bg));
  color: var(--term-app-fg, var(--term-fg));
  font-family: var(--term-font-family);
  font-size: var(--term-font-size);
  font-kerning: none;
  font-variant-ligatures: none;
  line-height: var(--term-line-height);
  padding: 12px;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  outline: none;
  overflow: hidden;
  overflow-anchor: none;
}

.wterm:focus,
.wterm:focus-visible {
  outline: none;
}

.term-grid {
  display: block;
  position: relative;
  white-space: pre;
  contain: layout paint style;
  will-change: contents;
}

.term-announcements {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: pre;
  pointer-events: none;
  user-select: none;
}

.term-images {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

.term-search-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  user-select: none;
  z-index: 2;
}

.term-search-match {
  position: absolute;
  background: var(--term-search-match, rgb(255 200 0 / 25%));
}

.term-search-active {
  background: var(--term-search-active, rgb(255 150 0 / 40%));
  box-shadow: inset 0 0 0 1px var(--term-search-border, #ffb000);
}

.term-image-flow-spacer {
  display: block;
  height: 0;
  pointer-events: none;
}

.term-image {
  position: absolute;
  display: block;
  pointer-events: none;
  user-select: none;
}

.term-row {
  display: block;
  height: var(--term-row-height);
  line-height: var(--term-row-height);
  contain: layout style;
}

.term-select-all .term-row,
.term-rectangle-row {
  position: relative;
}

.term-select-all .term-row::after,
.term-rectangle-row::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--term-selection-bg, rgb(80 140 255 / 30%));
  pointer-events: none;
  user-select: none;
  z-index: 3;
}

.term-rectangle-row::after {
  left: var(--term-selection-left);
  width: var(--term-selection-width);
  right: auto;
}

.term-selection-status {
  position: sticky;
  bottom: 0;
  width: fit-content;
  max-width: 100%;
  white-space: normal;
  background: var(--term-app-bg, var(--term-bg));
  color: var(--term-app-fg, var(--term-fg));
  user-select: none;
  pointer-events: none;
  z-index: 4;
}

.term-selection-status:empty {
  display: none;
}

.term-scrollback-spacer {
  display: block;
  pointer-events: none;
}

.term-size-probe {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: pre;
  width: auto;
  height: var(--term-row-height);
}

.term-row > span,
.term-row > .term-link,
.term-link > span {
  display: inline-block;
  height: var(--term-row-height);
  vertical-align: top;
}

.term-row > span,
.term-link > span {
  width: calc(var(--term-span-cols, 1) * var(--term-cell-width, 1ch));
  /* Glyph ink may overhang its advance without moving the following cell. */
  overflow: visible;
}

.term-link {
  color: inherit;
  cursor: text;
}

.wterm.link-modifier-active .term-link:hover,
.term-link:focus-visible {
  cursor: pointer;
}

.wterm.link-modifier-active .term-link:hover > span,
.term-link:focus-visible > span {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.term-block {
  width: var(--term-cell-width, 1ch);
  overflow: hidden;
  -webkit-text-fill-color: transparent;
}

.term-box {
  --term-box-stroke: max(
    1px,
    round(calc(var(--term-cell-width, 1ch) * 0.18), 1px)
  );
  -webkit-text-fill-color: transparent;
}

.term-box-heavy,
.term-box-bold {
  --term-box-stroke: max(
    2px,
    round(calc(var(--term-cell-width, 1ch) * 0.3), 1px)
  );
}

.term-box-round {
  position: relative;
}

.term-box-round::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
  border: 0 solid currentColor;
  pointer-events: none;
}

.term-box-round-tl::after {
  inset: calc(50% - var(--term-box-stroke) * 0.5) 0 0
    calc(50% - var(--term-box-stroke) * 0.5);
  border-top-width: var(--term-box-stroke);
  border-left-width: var(--term-box-stroke);
  border-top-left-radius: 100%;
}

.term-box-round-tr::after {
  inset: calc(50% - var(--term-box-stroke) * 0.5)
    calc(50% - var(--term-box-stroke) * 0.5) 0 0;
  border-top-width: var(--term-box-stroke);
  border-right-width: var(--term-box-stroke);
  border-top-right-radius: 100%;
}

.term-box-round-br::after {
  inset: 0 calc(50% - var(--term-box-stroke) * 0.5)
    calc(50% - var(--term-box-stroke) * 0.5) 0;
  border-bottom-width: var(--term-box-stroke);
  border-right-width: var(--term-box-stroke);
  border-bottom-right-radius: 100%;
}

.term-box-round-bl::after {
  inset: 0 0 calc(50% - var(--term-box-stroke) * 0.5)
    calc(50% - var(--term-box-stroke) * 0.5);
  border-bottom-width: var(--term-box-stroke);
  border-left-width: var(--term-box-stroke);
  border-bottom-left-radius: 100%;
}

@media (forced-colors: active), print {
  .term-block {
    background: none !important;
    -webkit-text-fill-color: currentColor;
  }

  .term-box {
    background-image: none !important;
    -webkit-text-fill-color: currentColor;
  }

  .term-box-round::after {
    display: none;
  }
}

.term-wide {
  --term-span-cols: 2;
  overflow: visible;
}

.term-cursor {
  color: var(--term-cell-fg, inherit);
  background: var(--term-cell-bg, transparent);
  outline: 1px solid var(--term-app-cursor, var(--term-cursor));
  outline-offset: -1px;
}

/* Native text selection can blur the input until click-to-focus runs. Keep
   the cursor active during that press without cancelling the selection. */
.wterm:is(.focused, :active) .term-cursor {
  background: var(--term-app-cursor, var(--term-cursor));
  color: var(--term-app-bg, var(--term-bg));
  outline: none;
}

.wterm:is(.focused, :active) .term-grid[data-cursor-shape="bar"] .term-cursor,
.wterm:is(.focused, :active) .term-grid[data-cursor-shape="underline"] .term-cursor {
  background: var(--term-cell-bg, transparent);
  color: var(--term-cell-fg, inherit);
  box-shadow: var(--term-cursor-shadow);
  --term-cursor-animation: cursor-line-blink;
}

.term-grid[data-cursor-shape="bar"] .term-cursor {
  --term-cursor-shadow: inset 2px 0 0 var(--term-app-cursor, var(--term-cursor));
}

.term-grid[data-cursor-shape="underline"] .term-cursor {
  --term-cursor-shadow: inset 0 -2px 0
    var(--term-app-cursor, var(--term-cursor));
}

.wterm:is(.focused, :active).cursor-blink .term-cursor,
.wterm:is(.focused, :active):not(.cursor-steady)
  .term-grid[data-cursor-blink="true"]
  .term-cursor {
  animation: var(--term-cursor-animation, cursor-blink) 1s step-end infinite;
}

@keyframes cursor-blink {
  0%,
  100% {
    background: var(--term-app-cursor, var(--term-cursor));
    color: var(--term-app-bg, var(--term-bg));
  }
  50% {
    background: var(--term-cell-bg, transparent);
    color: var(--term-cell-fg, inherit);
  }
}

@keyframes cursor-line-blink {
  0%,
  100% {
    box-shadow: var(--term-cursor-shadow);
  }
  50% {
    box-shadow: none;
  }
}

.wterm.has-scrollback,
.wterm.has-image-flow {
  overflow-y: auto;
}

.wterm ::selection {
  background: rgba(86, 156, 214, 0.3);
}

/* Solarized Dark */
.wterm.theme-solarized-dark {
  --term-fg: #839496;
  --term-bg: #002b36;
  --term-cursor: #93a1a1;
  --term-color-0: #073642;
  --term-color-1: #dc322f;
  --term-color-2: #859900;
  --term-color-3: #b58900;
  --term-color-4: #268bd2;
  --term-color-5: #d33682;
  --term-color-6: #2aa198;
  --term-color-7: #eee8d5;
  --term-color-8: #586e75;
  --term-color-9: #cb4b16;
  --term-color-10: #586e75;
  --term-color-11: #657b83;
  --term-color-12: #839496;
  --term-color-13: #6c71c4;
  --term-color-14: #93a1a1;
  --term-color-15: #fdf6e3;
}

/* Monokai */
.wterm.theme-monokai {
  --term-fg: #f8f8f2;
  --term-bg: #272822;
  --term-cursor: #f8f8f0;
  --term-color-0: #272822;
  --term-color-1: #f92672;
  --term-color-2: #a6e22e;
  --term-color-3: #f4bf75;
  --term-color-4: #66d9ef;
  --term-color-5: #ae81ff;
  --term-color-6: #a1efe4;
  --term-color-7: #f8f8f2;
  --term-color-8: #75715e;
  --term-color-9: #f92672;
  --term-color-10: #a6e22e;
  --term-color-11: #f4bf75;
  --term-color-12: #66d9ef;
  --term-color-13: #ae81ff;
  --term-color-14: #a1efe4;
  --term-color-15: #f9f8f5;
}

/* Light */
.wterm.theme-light {
  --term-fg: #383a42;
  --term-bg: #fafafa;
  --term-cursor: #526eff;
  --term-color-0: #383a42;
  --term-color-1: #e45649;
  --term-color-2: #50a14f;
  --term-color-3: #c18401;
  --term-color-4: #4078f2;
  --term-color-5: #a626a4;
  --term-color-6: #0184bc;
  --term-color-7: #fafafa;
  --term-color-8: #a0a1a7;
  --term-color-9: #e45649;
  --term-color-10: #50a14f;
  --term-color-11: #c18401;
  --term-color-12: #4078f2;
  --term-color-13: #a626a4;
  --term-color-14: #0184bc;
  --term-color-15: #ffffff;
}
