@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,100..700;1,100..700&display=swap');

:root {
  font-family: "IBM Plex Sans", sans-serif;

  --base-font-size: 14pt;
  font-size: var(--base-font-size);

  --col-visited:          rgb(from var(--col-brand) calc(r + 40) g calc(b + 40));
  --col-visited-hover:    hsl(from var(--col-visited) h s calc(l + 12));
  --col-bg:               #222120;
  --col-bg-dark:          hsl(from var(--col-bg) h s calc(l - 4));
  --col-text:             #ccc;
  --col-text-dim:         hsl(from var(--col-text) h s calc(l - 20));
  --col-text-faint:       hsl(from var(--col-text) h s calc(l - 36));
  --col-form-face:        hsl(from var(--col-bg) h s calc(l + 6));
  --col-form-face-trim:   hsl(from var(--col-bg) h s calc(l + 9));
  --col-form-face-hilite: hsl(from var(--col-bg) h s calc(l + 12));
  --col-form-outline:     white;
  --col-support:          #80cd32;
  --col-code-bg:          #0004;

  --box-shadow-form-face-trim: inset 0 0 0 2px var(--col-form-face-trim);
  --box-shadow-card:           0 4px 8px #00000040;

  --col-invalid: #633;

  --col-brand:                       #88d;
  --col-brand-hover:                 hsl(from var(--col-brand) h s calc(l + 12));
  --col-brand-form-face:             hsl(from var(--col-brand) h calc(s - 20) calc(l - 20));
  --col-brand-form-face-trim:        hsl(from var(--col-brand-form-face) h s calc(l + 9));
  --col-brand-form-face-hilite:      hsl(from var(--col-brand-form-face) h s calc(l + 12));
  --box-shadow-brand-form-face-trim: inset 0 0 0 2px var(--col-brand-form-face-trim);

  --transition-len-sidepanel-slide: 0.4s;
}

body {
  background-color: var(--col-bg);
  margin: 0;
  display: grid;
  /* display: flex; */
  color: var(--col-text-dim);
  height: 100vh;
  box-sizing: border-box;
  /* overflow: hidden; */

  /* transition: grid-template-columns var(--transition-len-sidepanel-slide) ease; */
  grid-template-columns: 1fr 2fr 0fr 1fr;
  /* &:not(:has(ul#watchlist-feature-list:empty)) { */
    /* grid-template-columns: 0.7fr 2fr 0.3fr 1fr; */
  /* } */
}
main {
  margin: 64px auto 0 auto;
  width: 100%;
  box-sizing: border-box;
  max-width: 768px;
  flex-grow: 1;
}
footer {
  text-align: center;
  color: var(--col-text-faint);
}
ul {
  margin: 0;
  list-style: none;
  padding-inline-start: 0;
}
a {
  text-decoration: none;
  color: inherit;
}
a:not(.feature-card) {
  transition: color .2s;
  &:not(:visited) {
    color: var(--col-brand);
    &:hover {
      color: var(--col-brand-hover);
    }
  }
  &:visited {
    color: var(--col-visited);
    &:hover {
      color: var(--col-visited-hover);
    }
  }
}
h1, h2, h3, h4, h5, h6, p {
  margin: 0;
  word-break: break-word;
}
h1, h2 {
  color: var(--col-text);
}
.standout {
  color: var(--col-text);
  font-weight: bold;
}
code {
  background-color: var(--col-code-bg);
  padding-inline: 6px;
  border-radius: 4px;
}
::selection {
  background-color: #777;
}
::-webkit-inner-spin-button {
  display: none; /* TODO see if you can style this just like the "X" on text inputs */
}
button {
  border: none;
  color: var(--col-text);
  font-family: inherit;
  font-size: inherit;
  background-color: var(--col-form-face);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 4px;

  &.noface {
    background-color: transparent;
    box-shadow: none;
    padding: 8px;
  }

  &.action {
    background-color: var(--col-brand-form-face);
    box-shadow: var(--box-shadow-card), var(--box-shadow-brand-form-face-trim);
    &:not(:disabled):hover {
      background-color: var(--col-brand-form-face-hilite);
    }
  }

  &.with-icon {
    display: flex;
    justify-content: center;
    gap: 6px;
    align-items: baseline;

    &::before {
      display: block;
      content: attr(icon);
      height: 1em;
      aspect-ratio: 1;
    }
  }

  transition: box-shadow .2s,
    background-color .2s,
    opacity .2s;
  box-shadow: var(--box-shadow-card), var(--box-shadow-form-face-trim);
  &:not(:disabled):hover {
    background-color: var(--col-form-face-hilite);
    box-shadow: var(--box-shadow-card);
    opacity: 1;
  }
  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  /* icons */
  &.icon {
    &::before {
      display: block;
      content: "";
      height: 1em;
      aspect-ratio: 1;
      background-color: var(--col-text);
      mask-size: contain;
    }
    &.edit {
      &::before {
        mask-image: url("assets/pencil.svg");
      }
    }
    &.remove {
      &::before {
        mask-image: url("assets/trash.svg");
      }
    }
  }
}
input {
  font-family: inherit;
  font-size: inherit;
  color: var(--col-text);
  background-color: var(--col-form-face);
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  &:invalid {
    background-color: var(--col-invalid);
  }
}
dialog {
  border: 2px solid var(--col-form-face-trim);
  border-radius: 8px;
  background-color: var(--col-bg); /* a bizarre quirk is that if `inherit` is used for `background-color` here, it is darkened along with the actual background as if it were behind the backdrop */
  color: inherit; /* the quirk described above does not occur for `color` */ 
  padding: 1.5em;
  max-width: 60vw;

  .controls {
    display: flex;
    gap: 16px;
    justify-content: end;
  }

  opacity: 0;
  transition:
    opacity 0.2s ease,
    display 0.2s ease allow-discrete,
    overlay 0.2s ease allow-discrete;
  &::backdrop {
    background-color: #0000;
    backdrop-filter: blur(0px);
    transition:
      background-color 0.2s ease,
      backdrop-filter 0.2s ease,
      display 0.2s ease allow-discrete;
  }
  &[open] {
    opacity: 1;
    &::backdrop {
      background-color: rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(2px);
    }
  }

  & > form {
    display: flex;
    flex-direction: column;
    gap: 1em;
  }
}
@starting-style {
  dialog[open] {
    opacity: 0;
    &::backdrop {
      background-color: #0000;
      backdrop-filter: blur(0px);
    }
  }
}

#main-and-footer {
  grid-column-start: 2;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

aside#watchlist-pane {
  position: fixed;
  width: 25vw;
  height: 100vh;
  right: 0;
  box-sizing: border-box;

  background-color: var(--col-bg-dark);
  padding: 1rem;

  display: flex;
  flex-direction: column;
  gap: 16px;
  & > ul#watchlist-feature-list {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
    & > li {
      display: flex;
      flex-direction: column;
      gap: 0.5em;

      background-color: var(--col-bg);
      padding: 1em;
      border-radius: 4px;
      color: var(--col-text-faint);
      .watchlist-feature-label {
        flex-grow: 1;
      }
      .watchlist-feature-title {
        color: var(--col-text);
        font-weight: bold;
      }
      .watchlist-feature-thresh {
        color: var(--col-support);
        font-weight: bold;
      }

      .watchlist-feature-bottom {
        display: flex;
        justify-content: space-between;
        align-items: end;
      }
    }
  }

  translate: 0;
  transition: translate var(--transition-len-sidepanel-slide) ease;
  &:has(ul#watchlist-feature-list:empty) {
    /* display: none; */
    translate: 100%;
  }
}
label[for="search-input"] {
  display: block;
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: .5em;
}
form#feature-search {
  --pad: 0.75em;

  display: grid;
  grid-template-columns: min-content 1fr;
  gap: var(--pad);
  place-items: center;

  box-sizing: border-box;
  width: 100%;
  padding: var(--pad);
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 1.5rem;
  background-color: var(--col-form-face);
  color: white;

  transition: all 0.2s;
  box-shadow: var(--box-shadow-card), var(--box-shadow-form-face-trim);
  outline: 2px solid rgb(from var(--col-form-outline) r g b / 0);
  &:hover:not(:focus) {
    box-shadow: var(--box-shadow-card);
    background-color: var(--col-form-face-hilite);
  }
  &:focus-within {
    outline-color: var(--col-form-outline);
  }

  &::before {
    display: block;
    background-color: #fff4;
    content: "";
    height: 1em;
    aspect-ratio: 1;
    mask-image: url("assets/magnifying-glass.svg");
    mask-size: contain;
  }

  & > input {
    background-color: initial;
    color: var(--col-text);
    border: none;
    font-size: inherit;
    font-family: inherit;
    margin: 0;
    outline: none;
    padding: 0;
    width: 100%;
    &::-webkit-search-cancel-button {
      display: none; /* TODO style this thing white or something if possible (not sure it is) */
    }
  }
} 

ul#feature-search-results {
  margin-block: 1em;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(380px, 100%), 1fr));
  gap: 8px;
  
  & > li {
    display: flex;
    & > a {
      flex-grow: 1;

      display: flex;
      flex-direction: column;
      gap: 12px;
      /* height: max-content; */

      background-color: var(--col-form-face);
      cursor: pointer;
      padding: 16px;
      border-radius: 4px;

      transition: all .2s;
      box-shadow: var(--box-shadow-card), var(--box-shadow-form-face-trim);
      opacity: .8;
      &:hover {
        background-color: var(--col-form-face-hilite);
        box-shadow: var(--box-shadow-card);
        opacity: 1;
      }
    }
  }
  hgroup {
    width: 100%;
    box-sizing: border-box;
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: start;
    & > h1 {
      font-size: 1.5rem;
      margin: 0;
    }
    & > p > code {
      background-color: unset;
      padding: unset;
      border-radius: unset;
      font-style: italic;
      color: #fff3;
      word-break: break-word;
    }
  }
}

article#feature-content {
  display: flex;
  flex-direction: column;
  gap: 16px;

  ul#feature-search-results:not(:empty) + & {
    display: none;
  }

  p#feature-description {
    color: var(--col-text-dim);
  }
}

article#links {
  margin-top: 1em;

  & > h2 {
    color: var(--col-text-faint);
    font-weight: normal;
    font-size: var(--base-font-size);
  }
  & > ul {
    margin-top: 0.5em;
    display: inline-flex;
    gap: 8px;
    flex-wrap: wrap;

    .link-separator {
      color: var(--col-text-faint);
    }
  }
}
form#watch-form,
form#watch-edit-form {
  .msg-with-input {
    color: var(--col-text-dim);
  }
  input#desired-support-threshold {
    width: 3em;
  }
}

ul#confirm-dialog-feature-list {
  list-style: revert;
  padding-inline-start: revert;
}

.split-items {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
}
.global-percentage {
  font-size: 18pt;
  flex-shrink: 0;
}
.global-percentage-num {
  color: var(--col-support);
  font-weight: bold;
}
.msg-with-input {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  input {
    margin-inline: 8px;
  }
}

@media (max-width: 700px) {
  body {
    flex-direction: column-reverse;
  }
  aside#watchlist-pane {
    overflow: auto;
    & > ul#watchlist-feature-list {
      overflow: auto;
    }
  }
  main {
    width: 100%;
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --col-bg: white;
    --col-text: #444;
    --col-text-dim:         hsl(from var(--col-text) h s calc(l + 16));
    --col-text-faint:       hsl(from var(--col-text) h s calc(l + 24));
    --col-form-face:        hsl(from var(--col-bg) h s calc(l - 6));
    --col-form-face-trim:   hsl(from var(--col-bg) h s calc(l - 9));
    --col-form-face-hilite: hsl(from var(--col-bg) h s calc(l - 12));
    --col-form-outline:     var(--col-brand);
    --col-brand-form-face:  var(--col-brand);
    --col-code-bg:          #0002;
  }

  form#feature-search {
    color: var(--col-text);
    &::before {
      background-color: #0004;
    }
  }
  
  ul#feature-search-results {
    hgroup {
      code {
        color: #0003;
      }
    }
  }
}