:root {
  color-scheme: light;

  --clr-bg-page: hsl(60, 42%, 95%); // $nicotine-light

  --clr-bg-ui: hsl(0, 0%, 100%);
  --clr-text-ui: #000; // $fg-dark

  --clr-bg-theme: hsl(200, 28%, 34%); // $highlight-light
  --clr-text-theme: #fff; // $fg-light

  --clr-bg-highlight: hsl(0, 0%, 93%); // $highlight-light2
  --clr-text-highlight: #111111;

  --clr-bg-accent: hsl(63, 19%, 61%); // $nicotine-dark
  --clr-border-accent: hsl(63, 19%, 35%);

  --clr-border: #aaa; // $border-color2
  
  --clr-shadow: var(--clr-border); 

  --clr-link: #0066cc;
  --clr-link-visited: #531a89;
  --clr-heading-link-visited: #fcc; // $visited

  --font-family: sans-serif;
  --font-size: 14px;
  --font-family-heading: serif; // $heading-fonts
}


@mixin dark-theme-mixin {
  color-scheme: dark;

  --clr-bg-page: hsl(0, 0%, 6%);

  --clr-bg-ui: hsl(0, 0%, 18%);
  --clr-text-ui: #ddd;

  --clr-bg-theme: hsl(0, 0%, 2%);
  --clr-text-theme: var(--clr-text-ui);

  --clr-bg-highlight: hsl(0, 0%, 11%);
  --clr-text-highlight: #fff;

  --clr-bg-accent: hsl(200, 32%, 28%);
  --clr-border-accent: hsl(200, 8%, 12%);

  --clr-border: hsl(0, 0%, 30%);

  --clr-shadow: #000;

  --clr-link: #8a8aff;
  --clr-link-visited: #ffadff;
  --clr-heading-link-visited: var(--clr-link-visited);
}
 
:root[data-theme='dark'] {
  @include dark-theme-mixin;
}

// Makes theme match the user's OS preference when JS is disabled
@media (prefers-color-scheme: dark) {
  :root:not([data-has-js="true"]) {
    @include dark-theme-mixin;
  }
}

* {
  box-sizing: border-box;
}

a {
  color: var(--clr-link);
}

a:visited {
  color: var(--clr-link-visited);
}

input, textarea, select {
  color: inherit;
}

h1 a, h2 a {
  color: var(--clr-text-theme);
}
h1 a:visited, h2 a:visited {
  color: var(--clr-heading-link-visited);
}
progress {
  width: 10ch;
}

body {
  background-color: var(--clr-bg-page);
  color: var(--clr-text-ui);
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: 1.6;
  margin-left: auto;
  margin-right: auto;
  max-width: 120ch;
  padding: 0;
}

#frontpage {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr;
  grid-gap: 1ch;
  align-items: start;
  justify-content: start;
  margin-top: 1ch;
  margin-bottom: 1ch;
  // named grid areas
  grid-template-areas:
        "frontpage-about frontpage-news"
        "frontpage-tips  frontpage-news";

  @media (max-device-width: 624px) {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-gap: 1ch;
    align-items: start;
    justify-content: start;
    margin-top: 1ch;
    margin-bottom: 1ch;
    // named grid areas
    grid-template-areas:
            "frontpage-about"
            "frontpage-tips"
            "frontpage-news";

    * { max-width: unset !important; min-width: unset !important; }
  }

  #frontpage-news {
    grid-area: frontpage-news;
    max-width: 40ch;
    @extend .dialog;
  }
  #frontpage-about {
    grid-area: frontpage-about;
    min-width: 40ch;
    @extend .dialog;
  }
  #frontpage-tips {
    grid-area: frontpage-tips;
    min-width: 40ch;
    @extend .dialog;
  }
}

#siteinfo-nav {
  display: block;
  width: 100%;
  @extend .dialog;
  padding: 0.25ch !important;
  margin-top: 1.5ch;


  ul {
    list-style: none;
    padding: 0;
    margin: 1ch;

    li {
      display: inline;
      padding: 1ch;
      background-color: var(--clr-bg-highlight);

      a {
        text-decoration: none;
        display: inline-block;
        color: var(--clr-text-highlight);
      }
    }

    li.current {
      background-color: var(--clr-bg-theme);
      a {
        color: var(--clr-text-theme);
      }
    }
  }
}

.dialog {
  border: 1px solid var(--clr-border);
  box-shadow: 0 0 1ch var(--clr-shadow);
  background-color: var(--clr-bg-ui);
  padding: 1ch;

  h2 {
    margin: 0;
    font-family: sans-serif;
    font-weight: normal;
    padding: 0.5ch;
    font-size: 12pt;
    background-color: var(--clr-bg-theme);
    color: var(--clr-text-theme);
  }
}

header {
  background-color: var(--clr-bg-accent);
  border: 1px solid var(--clr-border-accent);
  color: var(--clr-text-ui);
  box-shadow: 0 0 0.5ch var(--clr-shadow);
  margin-bottom: 1ch;
  display: flex;
  align-items: center;
  justify-content: space-between;

  nav {
    a {
      text-decoration: none;
      color: var(--clr-text-ui);
      padding: .5ch;
      display: inline-block;
    }

    a:visited {
      color: var(--clr-text-ui);
    }

    a.extra {
      background: #ccc linear-gradient(45deg,
              hsl(0, 100%, 70%) 0%,
              hsl(120, 100%, 70%) 50%,
              hsl(240, 100%, 70%) 100%);
      color: black;
      text-shadow: 0 0 0.5ch #fff;
    }

    a:hover, a:focus {
      background: var(--clr-bg-theme);
      color: var(--clr-text-theme);
    }
  }
}

#theme {
  padding: .5ch;
  display: none;

  [data-has-js='true'] & {
    display: block;
  }
}

#complaint {
  @extend .dialog;
  max-width: 60ch;
  margin-left: auto;
  margin-right: auto;
  margin-top: 2ch;

  textarea {
    width: 100%;
    height: 10ch;
  }
}

#siteinfo {
  margin-top: 1ch;
  display: flex;
  gap: 1ch;
  flex-grow: 0.5;
  flex-shrink: 0.5;
  flex-basis: 10ch 10ch;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: stretch;
  align-items: stretch;
  justify-content: stretch;

  #index-info, #link-info {
    width: 32ch;
    @extend .dialog;
  }
  #screenshot {
    @extend .dialog;
  }
  #screenshot img {
    width: 30ch;
    height: 22.5ch;
  }
}

.infobox {
  h2 {
    @extend .heading;
  }

  background-color: var(--clr-bg-ui);
  padding: 1ch;
  margin: 1ch;
  border: 1px solid var(--clr-border);
  box-shadow: 0 0 1ch var(--clr-shadow);
}

section.cards {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  padding-top: 1ch;
  gap: 2ch;
  justify-content: flex-start;

  .card {
    background-color: var(--clr-bg-ui);
    border-left: 1px solid #ecb;
    border-top: 1px solid #ecb;
    box-shadow: var(--clr-shadow) 0 0 5px;

    h2 {
      @extend .heading;
      word-break: break-word;
    }

    h2 a {
      display: block !important;
      color: inherit;
      text-decoration: none;
    }
    a:focus img  {
      filter: sepia(100%);
      box-shadow: #444 0px 0px 20px;
    }
    a:focus:not(.nofocus) {
      background-color: black;
      color: white;
    }

    .description {
      padding-left: 1ch;
      padding-right: 1ch;
      overflow: auto;
      -webkit-hyphens: auto;
      -moz-hyphens: auto;
      -ms-hyphens: auto;
      hyphens: auto;
    }

    img {
      width: 28ch;
      height: auto;
    }

    .info {
      padding-left: 1ch;
      padding-right: 1ch;
      line-height: 1.6;
    }

    [data-theme='dark'] & {
      border: 1px solid var(--clr-border);
    }
  }
}

.positions {
  box-shadow: 0 0 2px var(--clr-shadow);
  backdrop-filter: brightness(90%);
  color: var(--clr-text-highlight);
  padding: 2px;
  margin-right: -1ch;
  margin-left: 1ch;
}


footer {
  clear: both;

  padding: 2ch;
  margin: 16ch 0 0 0;

  font-size: 12pt;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;

  h1 {
    font-weight: normal;
    border-bottom: 4px solid var(--clr-bg-theme);
  }

  h2 {
    font-size: 14pt;
    font-weight: normal;
    border-bottom: 2px solid var(--clr-bg-theme);
    width: 80%;
  }

  section {
    line-height: 1.5;
    flex-basis: 40ch;
    flex-grow: 1.1;

    background-color: var(--clr-bg-ui);
    border-left: 1px solid var(--clr-border);
    box-shadow: -1px -1px 5px var(--clr-shadow);

    padding-left: 1ch;
    padding-right: 1ch;
    margin-left: 1ch;
    padding-bottom: 1ch;
    margin-bottom: 1ch;
  }
}

#mcfeast, #menu-close {
  display: none;
}

.shadowbox {
  box-shadow: 0 0 1ch var(--clr-shadow);
  border: 1px solid var(--clr-border);
}

.heading {
  margin: 0;
  padding: 0.5ch;
  background-color: var(--clr-bg-theme);
  border-bottom: 1px solid var(--clr-border);
  font-family: var(--font-family-heading);
  font-weight: normal;
  color: var(--clr-text-theme);
  font-size: 12pt;
  word-break: break-word;
}


.sidebar-narrow {
  display: grid;
  grid-template-columns: auto max-content;
  grid-gap: 1ch;
  align-items: start;
}

#crosstalk-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto 1fr;
  grid-gap: 1ch;
  align-content: start;
  justify-content: start;
  align-items: start;
}

#similar-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    grid-gap: 1ch;
    align-content: start;
    justify-content: start;
    align-items: start;
  table {
    th {
      text-align: left;
    }
  }
  .screenshot {
    width: 100%;
    height: auto;
  }
}

#similar-view[data-layout="lopsided"] {
  #similar-info {
    @extend .dialog;
    grid-column: 1;
    grid-row: 1 / span 2;
  }
  #similar-domains {
    @extend .dialog;
    grid-column: 2;
    grid-row: 1;
  }
  #similar-links {
    @extend .dialog;
    grid-row: 2;
    grid-column: 2;
  }

}

#similar-view[data-layout="balanced"] {
  #similar-info {
    @extend .dialog;
  }
  #similar-domains {
    grid-row: span 2;
    @extend .dialog;
  }
  #similar-links {
    @extend .dialog;
  }
}

@media (max-device-width: 900px) {
  #similar-view, #crosstalk-view {
    display: block;
    * {
      margin-bottom: 1ch;
    }
  }
}

@media (max-device-width: 840px) {
  section.cards {
    display: block;
    .card {
      margin-bottom: 2ch;
      img {
        width: 100% !important;
        height: auto;
      }
    }
  }
}

#search-box {
  @extend .shadowbox;

  padding: 0.5ch;
  background-color: var(--clr-bg-ui);
  display: grid;
  grid-template-columns: max-content 0 auto max-content;
  grid-gap: 0.5ch;
  grid-auto-rows: minmax(1ch, auto);
  width: 100%;

  h1 {
    margin: 0;
    padding: 0.5ch;
    font-size: 14pt;
    word-break: keep-all;
    background-color: var(--clr-bg-theme);
    color: var(--clr-text-theme);
    font-family: var(--font-family-heading);
    font-weight: normal;
    text-align: center;
    display: flex;
    justify-content: space-between;
  }

  #suggestions-anchor {
    margin: -0.5ch; // We need this anchor for the typeahead suggestions, but we don't want it to affect the layout
    padding: 0;
  }

  input[type="text"] {
    font-family: monospace;
    font-size: 12pt;
    padding: 0.5ch;
    border: 1px solid var(--clr-border);
    background-color: inherit;
  }

  input[type="submit"] {
    font-size: 12pt;
    border: 1px solid var(--clr-border);
    background-color: var(--clr-bg-ui);
    cursor: pointer;
  }

  // white suggesitons looks fine in dark mode
  .suggestions {
    background-color: #fff;
    padding: .5ch;
    margin-top: 5.5ch;
    margin-left: 1ch;
    position: absolute;
    display: inline-block;
    width: 300px;
    border-left: 1px solid #ccc;
    border-top: 1px solid #ccc;
    box-shadow: 5px 5px 5px var(--clr-shadow);
    z-index: 10;

    a {
      display: block;
      color: #000;
      font-size: 12pt;
      font-family: 'fixedsys', monospace, serif;
      text-decoration: none;
      outline: none;
    }

    a:focus {
      display: block;
      background-color: #000;
      color: #eee;
    }
  }

}

.filter-toggle-on {
  a:before {
    content: '✓';
    margin-right: 1.5ch;
  }
}
.filter-toggle-off {
  a:before {
    content: '✗';
    margin-right: 1.5ch;
  }
}

#filters {
  @extend .shadowbox;
  margin-top: 1ch;
  background-color: var(--clr-bg-ui);

  h2 {
    @extend .heading;
    background-color: var(--clr-bg-theme);
  }
  h3 {
    @extend .heading;
    background-color: var(--clr-bg-highlight);
    color: var(--clr-text-highlight);
    font-family: sans-serif;
    border-bottom: 1px solid #000;
  }

  hr {
    border-top: 0.5px solid var(--clr-border);
    border-bottom: none;
  }
  ul {
    list-style-type: none;
    padding-left: 0;

    li {
      padding: 1ch;
      a {
        color: inherit;
        text-decoration: none;
      }
      a:hover, a:focus {
        border-bottom: 1px solid var(--clr-bg-theme);
      }
    }

    li.current {
      border-left: 4px solid var(--clr-bg-theme);
      background-color: var(--clr-bg-highlight);
      a {
        margin-left: -4px;
      }
    }
  }
}

.search-result {
  @extend .shadowbox;
  margin: 1ch 0 2ch 0;

  .url {
    background-color: var(--clr-bg-theme);
    padding-left: 0.5ch;

    a {
      word-break: break-all;
      font-family: monospace;
      font-size: 8pt;
      color: var(--clr-text-theme);
      text-shadow: 0 0 1ch #000; // guarantee decent contrast across background colors
    }
    a:visited {
      color: var(--clr-heading-link-visited);
    }
  }

  h2 {
    a {
      word-break: break-all;
      color: var(--clr-text-ui);
      text-decoration: none;
    }
    font-size: 12pt;
    @extend .heading;
    background-color:var(--clr-bg-highlight);
  }

  .description {
    background-color: var(--clr-bg-ui);
    word-break: break-word;
    padding: 1ch;
    margin: 0;
  }

  ul.additional-results {
    background-color: var(--clr-bg-ui);
    padding: 1ch;
    list-style: none;
    margin: 0;
    a {
        color: inherit;
    }
  }
}

.search-result[data-ms-rank="1"] {  .url, h2 { filter: grayscale(0%); } }
.search-result[data-ms-rank="2"] {  .url, h2 { filter: grayscale(5%); } }
.search-result[data-ms-rank="3"] {  .url, h2 { filter: grayscale(15%); } }
.search-result[data-ms-rank="4"] {  .url, h2 { filter: grayscale(20%); } }
.search-result[data-ms-rank="5"] {  .url, h2 { filter: grayscale(30%); } }
.search-result[data-ms-rank="10"] { .url, h2 { filter: grayscale(60%); } }

.utils {
  display: flex;
  font-size: 10pt;
  padding: 1ch;
  background-color: var(--clr-bg-highlight);

  > * {
    margin-right: 1ch;
    margin-left: 1ch;
  }
  .meta {
    flex-grow: 2;
    text-align: right;
  }
  .meta > * {
    padding-left: 4px;
  }
  a {
    color: var(--clr-text-highlight);
  }
}

@media (max-device-width: 624px) {
  [data-has-js="true"] body { // This property is set via js so we can selectively enable these changes only if JS is enabled;
                             // This is desirable since mobile navigation is JS-driven.  If JS is disabled, having a squished
                             // GUI is better than having no working UI.
    margin: 0 !important;
    padding: 0 0 0 0 !important;
    max-width: 100%;

    #suggestions-anchor { display: none; } // suggestions are not useful on mobile

    .sidebar-narrow {
      display: block; // fix for bizarre chrome rendering issue
    }

    #mcfeast {
      display: inline;
      float: right;
      width: 2rem;
      font-size: 1rem;
    }

    #menu-close {
      float: right;
      display: inline;
    }

    #filters {
      display: none;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      margin: 0;
      padding: 0;
      z-index: 100;
    }

    .sidebar-narrow {
      grid-template-columns: auto;
    }

    #search-box {
      grid-template-columns: auto;
    }

    #filters {
      margin-top: 0;
    }

    .search-result {
      margin-left: 0;
      margin-right: 0;
    }
  }
}

.page-link {
  padding-top: 0.25ch;
  padding-bottom: 0.25ch;
  padding-left: 0.5ch;
  padding-right: 0.5ch;
  margin-right: 0.5ch;

  font-size: 12pt;
  border: 1px solid var(--clr-border);
  background-color: var(--clr-bg-highlight);
  color: var(--clr-text-ui) !important;
  text-decoration: none;
}

.page-link.active {
  border: 1px solid var(--clr-text-ui);
  background-color: var(--clr-bg-ui);
}

// The search results page is very confusing on text-based browsers, so we add a hr to separate the search results.  This is
// hidden on modern browsers via CSS.

hr.w3m-helper { display: none; }

// This is a screenreader-only class that hides content from visual browsers, but allows screenreaders and
// text-based browsers to access it.

.screenreader-only {
  position:absolute;
  left:-10000px;
  top:auto;
  width:1px;
  height:1px;
  overflow:hidden;
}
