/* basic bang */
  :not(:defined), .bang-el:not(.bang-styled):not([incremental-load]) {
    visibility: hidden;
  }
  
/* basic visual appearance */
  /* reset clause */
    *:not(ul, li, ol, script, noscript, style, datalist, option, head, head *, select, meter, input, label) {
      all: unset;
    }

    ol, ul, menu {
      list-style-type: none;
      padding: 0;
    }

    input:not([type="radio"], input[type="checkbox"], input[type="range"]) {
      all: unset;
    }

    /*
    :is(ul, button, input, select, textarea) {
      all: unset;
    }
    */

  /* basic */
      p, h1, h2, h3, h4, h5, h6, blockquote, div, article, section, nav, header, main, aside, footer,
      br, hr {
        display: block;
      }

      p {
        padding: 0.5em 0;
      }

    :root, body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
    }

    form fieldset {
      display: flex;
      flex-direction: column;
    }

  /* color scheme and light / dark variants */
    :root {
      /* nice light colors */
      --special: pink;
      --special: peachpuff;
      --special: lavendar;
      /* other colors */
      --special: deepskyblue;
      --special: gold;
      --special: turquoise;
      --special: darkturquoise;
      --special: lightsteelblue;
      --special: mediumaquamarine;
      --special: mediumturquoise;
      --special: palegreen;
      --special: paleturquoise;
      --special: thistle;
      --special: tomato;
      --special: whitesmoke;
      --special: skyblue;
      --special-contrast: dodgerblue;
      --neutral: whitesmoke;
      --light-contrast: whitesmoke;
      --light-super-contrast: lavender;
      --light-ultra-contrast: silver;
      --dark-contrast: #28292a; /*#272a47;*/
      --dark-super-contrast: #38393a; /*#272a47;*/
      --dark-ultra-contrast: #464848; /*#272a47;*/
      --contrast: var(--light-contrast);
      --super-contrast: var(--light-super-contrast);
      --ultra-contrast: var(--light-ultra-contrast);
      --light-text: var(--dark-super-contrast);
      --inactive-bg: silver;
      --inactive-fg: darkslategray;
      --ft: 16px;
      --lh: 1.618;
      --dark: #15141a;
      --light: #fbfbfe;
      --bg: var(--light);
      --fg: var(--dark);
      --fg-pure: black;
      --bg-pure: white;
      --nav-loading-gap: 2px;
      --mid: gray;
      accent-color: var(--special);
      font: normal normal 400 var(--ft)/var(--lh) system-ui;
      color: var(--fg);
      background: var(--bg);
    }

    @media screen and (prefers-color-scheme:dark) {
      :root {
        --special: teal;
        --special: darkcyan;
        --special: steelblue;
        --bg: var(--dark);
        --fg: var(--light);
        --special: royalblue;
        --light-text: var(--light-super-contrast);
        --contrast: var(--dark-contrast);
        --super-contrast: var(--dark-super-contrast);
        --ultra-contrast: var(--dark-ultra-contrast);
        --fg-pure: white;
        --bg-pure: black;
      }

      span.tab-selector bb-favicon {
        filter: invert(100%);
      }

      aside.modals legend img,
      button img, input[type="image"] {
        filter: invert(1.0);
      }
    }

  /* button, input, and link overrides */
    button {
      cursor: default;
      background: transparent;
      border: thin solid transparent;
      box-sizing: border-box;
      padding: 0;
      text-align: center;
      margin: 2px 0;
      transition: all 0.1s ease;
      margin: 0 0.5em;
    }

    nav button {
      border-radius: 100%;
      aspect-ratio: 1 / 1;
    }

    button:hover:not([disabled]) {
      background: radial-gradient(var(--contrast) 90%, var(--super-contrast));
    }

    input {
      background: var(--super-contrast) !important;
      padding: 1px 0.25rem;
    }

    a, a:link, a:visited {
      cursor: pointer;
      color: var(--special-contrast);
    }

    input[type="search"]::-webkit-search-cancel-button {
      -webkit-appearance: none;
      color: var(--fg);
      accent-color: var(--fg);
      height: 24px;
      width: 24px;
      margin-left: .4em;
      background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23777'><path d='M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z'/></svg>");
      cursor: pointer;
    }
    
    form.url input[type="search"] {
      padding: 0 1em;
      border-radius: 1.618em;
    }

  /* hidden, disabled, active, focus and hover states */
    [hidden] {
      display: none;
    }

    [disabled] {
      cursor: not-allowed;
      background: var(--contrast);
      filter: grayscale(1.0);
      opacity: 0.6;
    }

    input:focus {
      background: var(--contrast);
    }

    button, bb-select-tab {
      box-sizing: border-box;
      border: thin solid transparent;
    }

    :is(button, bb-select-tab):active:not([disabled]) {
      background: var(--special);
    }

    :is(button, bb-select-tab):focus:not(:active) {
      border: thin dotted var(--special);
    }

    a:hover {
      text-decoration: underline;
    }

    button:not(:active, :hover, :focus) {
      opacity: 0.618;
    }

  /* selection and other general pseudo classes */
    ::selection {
      background-color: var(--special);
    }

/* basic layout */
  :root, body, main, bb-view {
    height: 100%;
    max-height: 100%;
  }

  :root {
    display: block;
    position: relative;
    overscroll-behavior: none;
    overflow: hidden;
  }

  body {
    display: flex;
  }

  iframe {
    display: none;
  }

  hr {
    border-bottom: thin solid var(--ultra-contrast);
  }

  main, bb-view {
    position: relative;
    width: 100%;
  }

  main {
    display: grid;
    grid-template-areas:
      "info     info    info    info    info"
      "tabs     tabs    tabs    tabs    tabs"
      "ctrl     ctrl    ctrl    ctrl    ctrl"
      "screen   screen  screen  screen  screen"
    ;
    grid-template-columns: auto 1fr auto auto auto;
    grid-template-rows: 1rem 2rem 2rem /*calc(2rem - var(--nav-loading-gap))*/ minmax(0,1fr);
  }

  main.no-chrome {
    position: relative;
    display: grid;
    grid-template-areas:
      "screen screen screen screen screen"
    ;
    grid-template-columns: auto 1fr auto auto auto;
    grid-template-rows: 1fr;
    width: 100%;
    height: 100%;
  }

  main.no-chrome :is(header, nav) {
    display: none;
  }

  bb-top-bar {
    grid-area: info;
    max-height: 1rem;
  } 

  header.topbar {
    font-size: smaller;
    max-height: 100%;
    color: #555555;
  }

  header.topbar span.super {
    font-size: 0.8rem;
    line-height: 1.3;
    vertical-align: super;
  }

  header.topbar span.network-status.offline {
    color: red;
  }

  header.topbar span.connection-status {
    color: orange;
  }

  header.topbar span.webrtc-status {
    color: dodgerblue;
    opacity: 0.8;
  }

  header.topbar span.audio-status {
    color: purple;
    opacity: 0.8;
  }

  bb-tabs {
    grid-area: tabs;
    position: relative;
    max-width: 100%;
  }

  nav.targets {
    overflow-x: scroll;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  nav.targets::-webkit-scrollbar {
    display: none;
  }

  nav.targets {
    display: flex;
    max-height: 100%;
    height: 100%;
    width: auto;
    white-space: nowrap;
  }

  nav.targets bb-select-tab {
    width: min(30%, 300px);
    border-top: thin solid var(--ultra-contrast);
    border-right: thin solid var(--ultra-contrast);
    background: var(--contrast);
    overflow: hidden;
    min-width: 125px;
    padding-left: 0.5em;
    border-top-left-radius: 0.25em;
    border-top-right-radius: 0.25em;
  }

  nav.targets bb-select-tab.active {
    background: var(--super-contrast);
  }

  nav.targets span:not(.new) {
    padding-left: 0.25rem;
  }

  nav.targets span.new button {
    box-sizing: border-box;
    width: 2rem;
  }

  span.tab-selector button.close {
    border-color: transparent;
    background: transparent;
    opacity: 0.618;
  }

  span.tab-selector button.close:is(:active, :hover, :focus) {
    opacity: 1.0;
  }

  span.tab-selector {
    position: relative;
    display: inline-flex;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    height: 100%;
  }

  span.tab-selector:not(.active) {
    opacity: 0.618;
  }

  span.tab-selector:not(.active):hover {
    opacity: 0.85;
  }

  span.tab-selector a {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
  }

  bb-favicon, img.favicon {
    width: 1.25rem;
    vertical-align: middle;
  }

  button img, input[type="image"] {
    pointer-events: none;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(0.618);
  }

  button img.no-small {
    transform: scale(1);
  }

  bb-favicon {
    margin-right: 0.25rem;
    height: 100%;
    display: flex;
    align-items: center;
  }

  bb-omni-box {
    grid-area: omni;
  }

  nav.history {
    grid-area: history;
    width: calc(2px + 4rem);
    padding-left: 2px;
  }

  nav.url {
    display: flex;
    align-items: center;
    height: 100%;
  }

  nav.url form {
    display: flex;
    width: 100%;
  }

  nav.url form input:not(:focus) {
    opacity: 0.618;
  }

  nav.url form input {
    flex-grow: 1;
  }

  nav.url form * {
    margin: 0;
  }
  
  bb-resize-button {
    grid-area: reset;
  }

  bb-settings-button {
    grid-area: menu;
    height: 100%;
    padding-right: 1px;
  }

  nav.viewport-reset-button {
    height: 100%;
    width: 2rem;
  }

  nav.settings-button, 
  nav.sidebar-menu-button {
    grid-area: menu;
    height: 100%;
    width: 2rem;
  }

  article.tab-viewport {
    grid-area: screen;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  article.tab-viewport canvas {
    height: 100%;
    user-select: none;
      -webkit-user-select: none;
      -webkit-touch-callout: none;
  }

  article.tab-viewport select {
    position: absolute;
    left: 50%;
    top: 19.1%;
    transform: translate(-50%, -50%);
    font-size: xx-large;
    opacity: 0.75;
    z-index: 1000;
    min-width: 10em;
    text-align: center;
    padding: 0.5em;
  }

  article.tab-viewport select:not(.open) {
    display: none;
  }

  bb-loading-indicator, aside.loading-indicator {
    position: absolute;
    width: 100%;
    max-height: var(--nav-loading-gap);
    height: var(--nav-loading-gap);
    /*
    transform: translate(0,-100%);
    */
    top: 0;
  }

  bb-loading-indicator {
    transform: translate(0,-150%);
  }

  aside.loading-indicator {
    overflow: hidden;
  }

  aside.loading-indicator meter {
    height: var(--nav-loading-gap);
    vertical-align: top;
    width: 105%;
    position: absolute;
    height: 30px;
    top: -14px;
    left: -2.5%;
    background: transparent;
  }

  aside.loading-indicator meter::-webkit-meter-bar {
    background: transparent;
  }

  aside.loading-indicator meter::-webkit-meter-optimum-value {
    background: var(--special-contrast);
  }

  aside.loading-indicator meter::-moz-meter-optimum-value {
    background: var(--special-contrast);
  }

  nav.keyinput {
    position: absolute;
    top: 0;
    right: 0;
    /*
    visibility: hidden;
    z-index: -1;
    */
  }

  nav.sidebar-menu {
    display: none;
  }

  nav :is(form, button) {
    height: 100%;
  }

  nav button {
    margin: 0;
  }

  bb-ctrl {
    grid-area: ctrl;
  }

  div.ctrl {
    display: grid;
    grid-template-areas:
      "history  omni    omni    reset   menu"
    ;
    grid-template-columns: auto 1fr 1fr auto auto;
    grid-template-rows: calc(2rem - var(--nav-loading-gap));
  }

  div.ctrl nav {
  }

/* special sections */
  /* context menu */
    bb-context-menu { 
      position: fixed;
      display: flex;
      visibility: hidden;
      flex-direction: column;
      z-index: 10;
      background: var(--bg);
      color: var(--fg);
      user-select: none;
      padding: 0.25rem 0;
      box-shadow: 1px 1px 1px var(--fg);
      /* -webkit */
        -webkit-user-select: none;
        -webkit-touch-callout: none;
    }

    aside.context-menu menu {
      display: flex;
      flex-direction: column;
    }

    aside.context-menu li {
      cursor: default; 
      font-size: smaller; 
      padding: 0 1.5rem;
    }

    aside.context-menu li:hover {
      background-color: var(--ultra-contrast);
    }

    aside.context-menu li:active {
      background-color: var(--special);
    }

    aside.context-menu #load-test {
      display: contents;
    }
  
  /* modal dialogs */
    bb-modals, aside.modals, ::backdrop, dialog::backdrop {
      display: flex;
      position: absolute;
      top: 0;
      left: 0;
      z-index: 10000000000;
      width: 100%;
      height: 100%;
      align-items: center;
      justify-content: center;
      background: rgba(30,30,30,0.5);
    }

    aside.modals :is(article, dialog) {
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      position: relative;
      margin: 0 auto;
      padding: 0.81em 0.81em 0.4em 1.31em;
      box-sizing: border-box;
      min-width: max(30%, 300px);
      min-height: 130px;
      max-width: min(600px, 61.8%);
      max-height: min(61.8%, 400px);
      box-shadow: 1px 1px 1px var(--contrast);
      background: var(--bg);
      overflow-x: hidden;
      overflow-y: auto;
    }

    aside.modals :is(article, dialog):not(.notice) {
      word-break: break-work;
    }

    aside.modals p:last-of-type {
      display: flex;
      justify-content: end;
    }

    aside.modals :is(a, button) {
      padding: 0.25em 0.81em;
      margin: 0 2px;
    }

    bb-modals:not(.open), 
    aside.modals :is(article, dialog):not(.open) {
      display: none;
    }

    aside.modals :is(article, dialog) :is(form, fieldset) {
      display: flex;
      width: 100%;
      height: 100%;
      border: 0;
    }

    aside.modals :is(article, dialog) fieldset {
      flex-direction: column;
      justify-content: space-between;
    }

    aside.modals legend {
      color: var(--contrast);
      width: 100%;
      margin-bottom: 1em;
    }

    aside.modals legend h1 {
      display: flex;
      align-items: center;
      color: var(--fg);
      filter: contrast(0.4);
    }

    aside.modals legend h1 img {
      padding-right: 0.5em;
      margin-top: -2px;
    }

    aside.modals legend i {
      color: var(--mid);
      font-size: smaller;
      font-style: italic;
      display: block;
      margin-top: 1.5em;
    }

    aside.modals h1 {
      color: var(--light-text);
    }

    aside.modals:not(.active) {
      display: none;
    }

    aside.modals > article:not(.open) {
      display: none;
    }

    aside.modals :is(textarea, input:not([type="checkbox"], [type="radio"], [type="range"]), select) {
      width: 100%;
      box-sizing: border-box;
    }

    aside.modals input[type="range"].radio {
      width: 2rem;
    }

    aside.modals form p:last-of-type {
      text-align: right;
    }

/* text input overrides */
  nav.keyinput {
    opacity: 0;
    pointer-events: none;
  }

/* mobile ovverides */
  span.tab-selector button.close {
    flex-shrink: 0;
    width: 1.2rem;
    aspect-ratio: 1 / 1;
    padding: 0;
    margin: 0.5rem;
    box-sizing: border-box;
  }

  span.tab-selector button.close img {
    transform: scale(0.7);
  }

/* custom checkbox input toggle */
  /* The switch - the box around the slider */
    .switch {
      position: relative;
      display: inline-block;
      width: 60px;
      height: 34px;
    }

    /* Hide default HTML checkbox */
    .switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    /* The slider */
    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: #ccc;
      -webkit-transition: .2s;
      transition: .2s;
    }

    .slider:before {
      position: absolute;
      content: "";
      height: 26px;
      width: 26px;
      left: 4px;
      bottom: 4px;
      background-color: white;
      -webkit-transition: .2s;
      transition: .2s;
    }

    input:checked + .slider {
      background-color: #2196F3;
    }

    input:focus + .slider {
      box-shadow: 0 0 1px #2196F3;
    }

    input:checked + .slider:before {
      -webkit-transform: translateX(26px);
      -ms-transform: translateX(26px);
      transform: translateX(26px);
    }

    /* Rounded sliders */
    .slider.round {
      border-radius: 34px;
    }

    .slider.round:before {
      border-radius: 50%;
    } 

/* other */
  .ct-extend, .ct-home {
    display: inline-block;
    margin: 0;
  }

  .ct-extend {
    margin-left: 0.25rem;
  }

  .ct-home {
    margin-right: 0.25rem;
  }

  .ct-home:hover, .ct-home:active {
    color: black;
    font-weight: bold;
    background: aquamarine;
  }

  .align-right {
    text-align: right;
  }

  #debugBox {
    display: none;
  }

/* splash & more */
  .frame-holder {
    display: none;
  }

  @font-face {
    font-family: "Retro";
    src: url("./WebPlus_IBM_VGA_9x14.woff");
  }

  #splash {
    position: absolute;
    z-index: 1000000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    background: #1fe;

    & img {
      display: inline-block;
      max-width: 100px;
      opacity: 0.8;
      filter: grayscale(1) contrast(0.98);
      transform: scaleX(-1);
      mix-blend-mode: multiply;
    }

    & .text {
      font-family: "Retro", monospace;
    }
  }

  @media screen and (prefers-color-scheme: dark) {
    #splash {
      background: #076;

      & img {
        filter: grayscale(1) contrast(0.98) invert(1);
        mix-blend-mode: color-dodge;
      }

      & .text {
        color: white;
        opacity: 0.8;
      }
    }
  }
