main[data-css="atom_io_devtools"] {
  --fg-color: #ccc;
  --fg-light: #aaa;
  --fg-soft: #888;
  --fg-faint: #777;
  --fg-hint: #4a4a4a;
  --fg-max: #fff;
  --bg-color: #111;
  --bg-accent: #00f;
  --bg-max: #000;
  --bg-tint1: #222;
  --bg-tint2: #333;
  --fg-border: 1px solid var(--fg-color);
  --fg-border-soft: 1px solid var(--fg-soft);
  --fg-border-hint: 1px solid var(--fg-hint);

  @media (prefers-color-scheme: light) {
    --fg-color: #444;
    --fg-light: #777;
    --fg-soft: #888;
    --fg-faint: #999;
    --fg-hint: #ccc;
    --fg-max: #000;
    --bg-color: #ddd;
    --bg-accent: #0ff;
    --bg-max: #fff;
    --bg-tint1: #e3e3e3;
    --bg-tint2: #f3f3f3;
  }

  & * {
    box-sizing: border-box;
  }

  & {
    pointer-events: all;
    box-sizing: border-box;
    color: var(--fg-color);
    background-color: var(--bg-color);
    border: 2px solid var(--fg-color);
    flex-flow: column;
    width: 100%;
    max-width: 500px;
    height: 100%;
    max-height: 800px;
    display: flex;
    position: fixed;
    bottom: 0;
    right: 0;
    overflow-y: scroll;
  }

  & * {
    color: var(--fg-color);
    font-family: theia, monospace;
    font-size: 14px;
    line-height: 1em;
  }

  & > header {
    justify-content: space-between;
    padding-bottom: 0;
    display: flex;

    & h1 {
      margin: 2px 4px;
      font-family: charter, serif;
      font-size: 24px;
    }

    & nav {
      flex-flow: row;
      height: 24px;
      margin-top: 4px;
      display: flex;
      position: relative;
      overflow: scroll visible;

      & button {
        cursor: pointer;
        z-index: 1000;
        background: none;
        border: none;
        height: 24px;
        margin-bottom: -2px;
        padding: 0 5px;

        &:disabled {
          cursor: default;
          background-color: var(--fg-color);
          color: var(--bg-color);
          border: var(--fg-border);
        }
      }
    }
  }

  & > main {
    background: var(--bg-tint1);
    flex-flow: column;
    flex-grow: 1;
    gap: 0;
    display: flex;
    overflow-y: scroll;

    & article.index {
      border-top: var(--fg-border);
      flex-flow: column;
      flex-shrink: 0;
      min-height: calc(100% - 24px);
      margin-bottom: 0;
      padding-bottom: 24px;
      display: flex;

      & .node .node {
        background: #ffffff08;
        border-right: none;
        padding-right: 0;

        @media (prefers-color-scheme: light) {
          background: #00000004;
        }
      }

      & .index-empty-state {
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 100%;
        font-style: italic;
        display: flex;
      }

      & .node > .node {
        border-left: var(--fg-border-soft);
        width: calc(100% - 9px);
        margin: 0 0 0 9px;

        &:first-of-type {
          border-top: var(--fg-border-soft);
        }

        &:last-of-type {
          border-bottom: none;
        }
      }

      & .node {
        border-bottom: var(--fg-border-soft);
        flex-flow: column;
        width: 100%;
        display: flex;
        position: relative;
        overflow: visible;

        &.transaction_update {
          padding: 0;
        }

        & > header {
          z-index: 999;
          background: var(--bg-tint2);
          border-bottom: none;
          flex-flow: row;
          justify-content: space-between;
          align-items: center;
          width: auto;
          height: 22px;
          display: flex;
          position: sticky;
          top: 0;
          overflow: hidden;

          & > main {
            cursor: help;
            flex-flow: row;
            flex-shrink: 0;
            align-items: center;
            height: 100%;
            display: flex;

            & * {
              place-content: center;
              align-items: center;
              height: 100%;
              display: flex;
            }

            & h2 {
              margin: 0;
            }
          }

          & > footer {
            flex-shrink: 1;
            justify-content: flex-start;
            align-items: center;
            width: fit-content;
            min-width: 0;
            height: 16px;
            display: flex;

            & > button {
              border: none;
              border-left: var(--fg-border-soft);
              background: none;
            }

            & > .json_viewer {
              color: var(--fg-light);
              flex-shrink: 1;
              align-self: center;
              align-items: flex-start;
              overflow: scroll;
            }

            & > .json_editor, & > .json_viewer {
              white-space: pre;
              border-left: var(--fg-border-soft);
              flex-flow: row;
              justify-content: flex-start;
              align-items: center;
              min-width: 10px;
              height: 16px;
              margin-right: 0;
              padding-left: 4px;
              padding-right: 2px;
              display: flex;
              overflow-x: scroll;

              &:focus-within {
                background-color: var(--bg-max);
                outline: 2px solid var(--fg-max);

                & * {
                  color: var(--fg-max);
                }
              }

              & main {
                height: 100%;
              }

              & > span {
                z-index: 0;
                padding: 0 5px;
              }

              & input {
                outline: none;
              }
            }
          }

          & .detail {
            color: #777;
            margin-left: 5px;

            @media (prefers-color-scheme: light) {
              color: #999;
            }
          }
        }
      }

      & section.transaction_log {
        margin-top: 0;

        & main {
          flex-flow: wrap;
          gap: 0;
          display: flex;

          & article.transaction_update {
            border-bottom: none;
            border-left: none;
            border-top: var(--fg-border);
            flex-flow: row;
            place-content: flex-start;
            place-items: flex-start;
            width: 100%;
            display: flex;

            & header {
              flex-flow: column;
              height: 100%;
              padding: 5px;
              display: flex;

              & h4 {
                font-size: inherit;
                margin: 0;
                padding: 0;
              }
            }

            & main {
              border-left: 1px solid #333;
              flex-flow: column;
              flex-grow: 1;
              gap: 0;
              margin-left: 0;
              display: flex;

              & section ~ section {
                border-top: 1px solid #333;
              }

              & section {
                border-bottom: none;
                margin: 0;
                padding: 5px;

                &.transaction_output {
                  border-right: none;
                }

                &.transaction_impact {
                  padding: 5px;
                }

                & article {
                  border-left: var(--fg-border);
                  border-right: var(--fg-border);
                  padding: 3px 6px;

                  &:first-of-type {
                    border-top: var(--fg-border);
                  }

                  & .summary {
                    white-space: nowrap;
                  }
                }
              }
            }
          }
        }
      }

      & section.timeline_log {
        & header {
          display: flex;

          & > main {
            flex-grow: 1;
            width: 100%;
            display: flex;

            & .gap {
              flex-grow: 1;
            }

            & nav {
              flex-flow: row;
              gap: 5px;
              display: flex;
            }
          }
        }

        & .timeline_update {
          border-left: var(--fg-border);
          padding: 5px;

          & h4 {
            font-size: inherit;
            margin: 0;
            padding: 0;
          }

          & main {
            margin: 0;

            & .node.atom_update {
              border-left: var(--fg-border);
            }
          }
        }

        & .you_are_here {
          background: var(--fg-color);
          color: var(--bg-color);
          text-align: center;
        }
      }
    }
  }

  & > footer {
    z-index: 10000;
    justify-content: flex-end;
    display: flex;

    & button {
      cursor: pointer;
      padding: none;
      background: none;
      border: none;
      position: absolute;
      bottom: 0;
      right: 0;
    }
  }

  & .json_editor {
    flex-flow: column;
    display: flex;

    & > header {
      white-space: nowrap;
      flex-flow: row;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      display: flex;
      overflow: hidden;

      &:has( > main > button.carat) {
        height: 21px;
      }

      & > main {
        flex-flow: row;
        flex-shrink: 1;
        align-self: center;
        align-items: center;
        padding-right: 2px;
        display: flex;
        overflow-x: hidden;

        & > .json_viewer {
          height: 21px;
          color: var(--fg-soft);
          flex-shrink: 1;
          align-items: center;
          margin-left: 0;
          font-size: 14px;
          display: flex;
          overflow-x: scroll;
        }

        & > button {
          padding: 0;

          &.carat {
            font-size: 14px;
            line-height: .5em;
          }
        }
      }
    }

    & > .json_editor_array, & > .json_editor_object {
      flex-grow: 1;
      width: 100%;
    }

    & input {
      background: none;
      font-family: theia, monospace;

      &:disabled {
        border: none;
      }
    }

    & input, & select {
      &:focus-within {
        outline: 2px solid var(--fg-max);
        background: var(--bg-max);
        color: var(--fg-max);
      }
    }

    & button:disabled {
      cursor: default;

      & > span.json_editor_icon {
        color: var(--fg-hint);
      }

      &:hover {
        background: none;
      }
    }

    & input::selection {
      background: var(--bg-accent);
    }

    & button {
      color: #777;
      min-width: 21px;
      height: 21px;
      margin: none;
      cursor: pointer;
      background: none;
      border: none;
      padding: 4px 4px 6px;
      font-family: theia, monospace;
      font-size: 14px;

      &:hover, &:focus-within {
        background-color: var(--fg-faint);

        &, & > * {
          color: var(--bg-color);
        }
      }

      &:active {
        background: var(--fg-color);

        &, & > * {
          color: var(--bg-color);
        }
      }
    }

    & select {
      color: #777;
      background: none;
      border: none;
      font-family: theia, monospace;
      font-size: 14px;

      @media (prefers-color-scheme: light) {
        color: #999;
      }
    }

    & .json_editor_unofficial {
      background-color: #777;

      & button {
        color: #333;
      }
    }

    & .json_editor_missing {
      background-color: #f055;
    }

    & .json_editor_key {
      padding-right: 0;

      &:after {
        content: ":";
        color: var(--fg-soft);
      }

      & input {
        color: var(--fg-color);
      }
    }

    & .json_editor_object, & .json_editor_array {
      border-left: var(--fg-border-soft);
      width: calc(100% - 9px);
      margin-left: 9px;

      & > footer {
        flex-flow: row;
        justify-content: flex-start;
        place-items: baseline flex-start;
        height: 21px;
        display: flex;
        position: relative;
      }

      & .json_editor_properties, & .json_editor_elements {
        border-top: var(--fg-border-soft);

        & .json_editor_property, & .json_editor_element {
          border-bottom: var(--fg-border-soft);
          min-height: 21px;
          margin-bottom: 0;
          display: flex;

          & > header {
            & > main {
              & > span {
                & input {
                  min-width: 10px;
                }

                & > * {
                  border: var(--fg-border-hint);
                }
              }
            }
          }
        }

        &.readonly {
          & .json_editor_property, & .json_editor_element {
            &:last-of-type {
              border-bottom: none;
            }

            & span > * {
              border: 1px solid #0000;
            }
          }
        }
      }
    }
  }

  & .json_editor_icon {
    color: var(--fg-soft);
  }

  & button.carat {
    cursor: pointer;
    background: none;
    border: none;

    & > .json_editor_icon {
      line-height: 4px;
    }

    &.open {
      transform: rotate(90deg);
    }

    &:disabled {
      & > .json_editor_icon {
        cursor: default;
        color: var(--fg-hint);
      }
    }
  }
}
