:root {
  /* WCAG AAA Compliant colors - important that luminence (the l in hsl) is 18% for font colors against the bg's luminence of 96-97% when the font-size is at least 14pt */
  --code-bg: hsl(262 33% 96% / 1);
  --gray: hsl(0 0% 18% / 1);
  --orange: hsl(25 100% 18% / 1);
  --green: hsl(115 100% 18% / 1);
  --cyan: hsl(190 100% 18% / 1);
  --blue: #05006d;
  --violet: #7c38f5;
  --violet-bg: hsl(262.22deg 87.1% 96%);
  --magenta: #a20031;
  --link-hover-color: #333;
  --link-color: var(--violet);
  --code-link-color: var(--violet);
  --text-color: #000;
  --text-hover-color: var(--violet);
  --body-bg-color: #ffffff;
  --border-color: #717171;
  --faded-color: #4c4c4c;
  --font-sans: -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace;
  --top-header-height: 67px;
  --sidebar-width: clamp(280px, 25dvw, 500px);
  --module-search-height: 56px;
  --module-search-padding-height: 16px;
  --module-search-form-padding-width: 20px;
  --sidebar-bg-color: hsl(from var(--violet-bg) h calc(s * 1.05) calc(l * 0.95));
}


a {
  color: var(--violet);
}

table tr th {
  border: 1px solid var(--gray);
}

table tr th,
table tr td {
  padding: 6px 13px;
}

.logo svg {
  height: 48px;
  width: 48px;
  fill: var(--violet);
}

.logo:hover {
  text-decoration: none;
}

.logo svg:hover {
  fill: var(--link-hover-color);
}

.pkg-full-name {
  display: flex;
  align-items: center;
  font-size: 24px;
  margin: 0 8px;
  font-weight: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-name {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: normal;
  background-color: var(--violet-bg);
  color: var(--text-color);
  width: auto;
  margin-top: 0;
  margin-bottom: 24px;
  padding: 12px 16px;
  border-left: 4px solid var(--violet);
  display: flex;
}

.entry-name strong {
    color: var(--text-color);
}

.entry-name code {
    background: none;
}

.entry-name:target {
  border: 4px solid var(--violet);
}

.entry-name a {
  visibility: hidden;
  display: inline-block;
  width: 18px;
  height: 14px;
  margin-left: -8px;
  margin-right: 4px;
  user-select: none;
  color: var(--violet);
}

.entry-name:hover a {
  visibility: visible;
  text-decoration: none;
}

.entry-name:not(:hover) a {
  visibility: hidden;
  transition: visibility 2s;
}

.pkg-full-name a {
  padding-top: 12px;
  padding-bottom: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a {
  text-decoration: none;
}

a:hover,
a:hover code {
  text-decoration: underline;
}

.pkg-and-logo {
  min-width: 0; /* necessary for text-overflow: ellipsis to work in descendants */
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  background-color: var(--violet-bg);
  padding: 16px;
}

.pkg-and-logo a,
.pkg-and-logo a:visited {
  color: var(--violet);
}

.pkg-and-logo a:hover {
  color: var(--link-hover-color);
  text-decoration: none;
}

.search-button {
  flex-shrink: 0; /* always shrink the package name before these; they have a relatively constrained length */
  padding: 12px 18px;
  margin-right: 42px;
  display: none; /* only show this in the mobile view */
}

.version {
  padding: 18px 10px;
  min-width: 48px;
  margin-right: 8px;
}

body {
  display: grid;
  grid-template-columns:
      [sidebar] var(--sidebar-width)
      [main-content] 1fr
      [content-end];
  grid-template-rows: 1fr;
  height: 100dvh;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--text-color);
  background-color: var(--body-bg-color);
  overflow: hidden;
}

main {
  grid-column-start: main-content;
  grid-column-end: content-end;
  box-sizing: border-box;
  position: relative;
  font-size: 14pt; /* This keeps links AAA compliant while still making the links distinctly colored. */
  line-height: 1.85em;
  margin-top: 2px;
  padding: 16px;
  padding-top: 0px;
  /* necessary for text-overflow: ellipsis to work in descendants */
  min-width: 0;
  overflow-x: auto;
  /* fixes issues with horizonatal scroll in cases where word is too long,
  like in one of the examples at https://www.roc-lang.org/builtins/Num#Dec */
  overflow-wrap: break-word;
  overflow-y: auto;
  display: grid;
  --main-content-width: clamp(100px, calc(100% - 32px), 60ch); 
  grid-template-columns: [main-start] minmax(16px,1fr) [main-content-start] var(--main-content-width) [main-content-end] minmax(16px,1fr) [main-end];
  grid-template-rows: auto;
  flex-direction: column;
  scrollbar-color: var(--violet) var(--body-bg-color);
  scrollbar-gutter: stable both-edges;
  scroll-padding-top: calc(16px + 16px + 1lh + 16px + 16px);
  align-content: start;
}

main > * {
    grid-column-start: main-content-start;
    grid-column-end: main-content-end;
}

/* Module links on the package index page (/index.html) */
.index-module-links {
    margin: 0;
    padding: 0;
    list-style-type: none;
}

section {
  padding: 0px 0px 16px 0px;
  margin: 36px 0px;
}

section blockquote {
  font-style: italic;
  position: relative;
  margin-left: 0;
  margin-right: 0;
}

section blockquote:before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 2px;
  height: 100%;
  background-color: var(--gray);
}


section > *:last-child {
  margin-bottom: 0;
}

section h1,
section h2,
section h3,
section h4,
section p {
padding: 0px 16px;
}

#sidebar-nav {
    grid-column-start: sidebar;
    grid-column-end: main-content;
    position: relative;
    display: grid;
    grid-template-rows: min-content 1fr;
    box-sizing: border-box;
    width: 100%;
    background-color: var(--sidebar-bg-color);
    transition: all 1s linear;
}

#sidebar-nav .module-links-container {
    position: relative;
}


#sidebar-nav .module-links {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-color: var(--violet) var(--sidebar-bg-color);
    scrollbar-gutter: stable;
    padding: 16px 8px;
    transition: all .2s linear;
}

.top-header {
  grid-column-start: sidebar;
  grid-column-end: end;
  grid-row-start: top-header;
  grid-row-end: top-header;
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
  box-sizing: border-box;
  font-family: var(--font-sans);
  font-size: 20px;
  height: 100%;
  background-color: var(--violet-bg);
  /* min-width must be set to something (even 0) for text-overflow: ellipsis to work in descendants, but we want this anyway. */
  min-width: 1024px;
}

p {
  overflow-wrap: break-word;
  margin: 24px 0;
}

footer {
  max-width: var(--main-content-max-width);
  font-size: 14px;
  box-sizing: border-box;
  padding: 16px;
}

footer p {
  display: inline-block;
  margin-top: 0;
  margin-bottom: 8px;
}

.content {
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.sidebar-entry ul {
  list-style-type: none;
  margin: 0;
}

.sidebar-entry a {
  box-sizing: border-box;
  min-height: 40px;
  min-width: 48px;
  padding: 8px 16px;
  font-family: var(--font-mono);
}

.sidebar-entry a,
.sidebar-entry a:visited {
  color: var(--text-color);
}

.sidebar-sub-entries {
    font-size: 12pt;
    display: none;
}

.active + .sidebar-sub-entries {
    display: block;
}

.sidebar-sub-entries a {
  display: block;
  line-height: 24px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: 20px;
  padding-left: 27px;
  border-left: 2px solid rgb(from var(--gray) r g b / .30);
  white-space: nowrap;
  display: flex;
  align-items: center;
}

.sidebar-sub-entries a:first-child {
    margin-top: 8px;
    padding-top: 0;
}

.sidebar-sub-entries a:last-child {
    margin-bottom: 8px;
    padding-bottom: 0;
}

.sidebar-sub-entries a:hover {
    border-left-color: rgb(from var(--violet) r g b / .60);
    color: var(--violet);
    text-decoration: none;
}

.module-name {
  font-size: 40pt;
  line-height: 1em;
  font-family: var(--font-mono);
  font-weight: bold;
  margin-top: 36px;
  margin-bottom: 16px;
  color: var(--violet);
}

main h2 {
    font-size: 28pt;
}
main h3 {
    font-size: 24pt;
}
main h4 {
    font-size: 20pt;
}

.module-name a,
.module-name a:visited {
color: inherit;
}

.module-name a:hover {
  color: var(--link-hover-color);
}

a.sidebar-module-link {
  box-sizing: border-box;
  font-size: 14pt;
  line-height: 24px;
  font-family: var(--font-mono);
  display: flex;
  flex-direction: row-reverse;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-module-link:hover {
    text-decoration: none;

    span:hover {
        color: var(--violet);
    }
}

.sidebar-module-link span {
    display: inline-block;
    flex-grow: 1;
}

.sidebar-module-link.active {
  font-weight: bold;
}

.sidebar-module-link > .entry-toggle {
    background-color: transparent;
    appearance: none;
    border: none;
    color: transparent;
    color: rgba(from var(--text-color) r g b / .6);
    transition: all 80ms linear;
    text-decoration: none;
    font-size: 0.6rem;
    cursor: pointer;
    padding: 8px 16px;
    
    &:hover {
        color: var(--violet);
    }
}

:hover >  .entry-toggle {
    color: var(--text-color);
}

.active .entry-toggle {
    rotate: 90deg;
}

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

h3 {
  font-size: 32px;
  margin: 48px 0 24px 0;
}

h4 {
  font-size: 24px;
}

.type-def {
  font-size: 24px;
  color: var(--link-color);
}

.code-snippet {
  padding: 8px 16px;
  display: block;
  box-sizing: border-box;
  font-family: var(--font-mono);
  background-color: var(--code-bg);
}

code {
  font-family: var(--font-mono);
  color: var(--code-color);
  background-color: var(--code-bg);
  display: inline-block;
}

p code {
  padding: 0 8px;
}

code a,
a code {
  text-decoration: none;
  color: var(--code-link-color);
  background: none;
  padding: 0;
  font-weight: bold; /* Important for AAA compliance while keeping color distinct */
}

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

pre {
  margin: 36px 0;
  padding: 8px 16px;
  box-sizing: border-box;
  background-color: var(--code-bg);
  position: relative;
  word-wrap: normal;
}

pre>samp {
    overflow-x: auto;
    display: block;
    scrollbar-color: var(--violet) var(--code-bg);
    scrollbar-width: thin;
    scrollbar-gutter: stable;
}

.hidden {
  /* Use !important to win all specificity fights. */
  display: none !important;
}

#module-search-form {
  display: flex;
  align-items: center;
  align-content: center;
  height: 100%;
  position: sticky;
  flex-grow: 1;
  box-sizing: border-box;
  padding-block: 16px;
  background-color: var(--body-bg-color);
  top: 0;
  z-index: 1;
}

.menu-toggle {
    display: none;
    margin-right: 8px;
    appearance: none;
    background-color: transparent;
    outline: none;
    border: none;
    color: var(--violet);
    padding: 0;
    cursor: pointer;
}

.menu-toggle svg {
    height: 48px;
    width: 48px;
}


#module-search,
#module-search:focus {
  opacity: 1;
  padding: 12px 16px;
  height: var(--module-search-height);
}

#module-search {
  border-radius: 8px;
  display: block;
  position: relative;
  box-sizing: border-box;
  width: 100%;
  box-sizing: border-box;
  font-size: 16px;
  line-height: 18px;
  border: none;
  color: var(--faded-color);
  background-color: var(--body-bg-color);
  font-family: var(--font-serif);
  border: 2px solid var(--violet-bg);
}

@media (prefers-color-scheme: light) {
    #module-search {
        outline: 1px solid var(--gray);
    }
}

#module-search::placeholder {
  color: var(--faded-color);
  opacity: 1;
}

#module-search:focus, #module-search:hover {
  outline: 2px solid var(--violet);
}

#search-type-ahead {
  font-family: var(--font-mono);
  display: flex;
  gap: 0px;
  flex-direction: column;
  position: absolute;
  top: calc(var(--module-search-padding-height) + var(--module-search-height));
  left: var(--module-search-form-padding-width);
  width: calc(100% - 2 * var(--module-search-form-padding-width));
  box-sizing: border-box;
  z-index: 100;
  background-color: var(--body-bg-color);
  border-width: 1px;
  border-style: solid;
  border-color: var(--border-color);
  list-style-type: none;
  margin: 0;
  padding: 0;
}

.search-icon {
    fill: var(--faded-color);
    pointer-events: none;
    opacity: 0.6;
    position: absolute;
    right: 32px;
}

#search-type-ahead .type-ahead-link {
  font-size: 1rem;
  color: var(--text-color);
  line-height: 2em;
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  padding: 4px 8px;

  max-height: 6em;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;

  /* if it wraps, indent after the first line */
  padding-left: calc(2em + 8px);
  text-indent: -2em;


  span {
    margin: 0px;
  }

  .type-ahead-module-name, .type-ahead-def-name {
    color: var(--violet);
    font-size: 1rem;
  }
}

#search-type-ahead li {
  box-sizing: border-box;
  position: relative;
}

#search-type-ahead a:focus {
  outline: none;
  background: var(--violet-bg);
}

#module-search-form:focus-within #search-label, #module-search-form:focus-within .search-icon {
  display: none;
}

#search-label {
  color: var(--faded-color);
  box-sizing: border-box;
  align-items: center;
  font-size: 18px;
  pointer-events: none;
  position: absolute;
  right: 72px;
}

#search-shortcut-key {
  font-family: var(--font-mono);
  border: 1px solid #666;
  border-radius: 5px;
  padding: 1px 3px 3px;
  font-style: normal;
  line-height: 15px;
  pointer-events: none;
}

.builtins-tip {
  padding: 1em;
  font-style: italic;
  line-height: 1.3em;
}

.ai-docs-link {
  margin-bottom: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
      /* WCAG AAA Compliant colors */
    --code-bg: hsl(228.95deg 37.25% 15%);
    --gray: hsl(0 0% 70% / 1);
    --orange: hsl(25 98% 70% / 1);
    --green: hsl(115 40% 70% / 1);
    --cyan: hsl(176 84% 70% / 1);
    --blue: hsl(243 43% 80% / 1);
    --violet: #caadfb;
    --violet-bg: hsl(262 25% 15% / 1);
    --magenta: hsl(348 79% 80% / 1);
      --link-hover-color: #fff;

      --link-color: var(--violet);
      --code-link-color: var(--violet);
      --text-color: #eaeaea;
      --body-bg-color: hsl(from var(--violet-bg) h s calc(l * .5));
      --border-color: var(--gray);
      --code-color: #eeeeee;
      --logo-solid: #8f8f8f;
      --faded-color: #bbbbbb;
      --sidebar-bg-color: hsl(from var(--violet-bg) h calc(s * 1.1) calc(l * 0.75));
  }

  html {
      scrollbar-color: #8f8f8f #2f2f2f;
  }
}

@media only screen and (max-width: 768px) {
    :root {
        --sidebar-width: clamp(280px, 50dvw, 385px);
    }
    body {
        display: block;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #sidebar-nav {
        left: calc(-1 * var(--sidebar-width));
        top: 0;
        bottom: 0;
        position: fixed;
        z-index: 2;
        transition: all .2s linear;
    }

    .entry-toggle {
        height: 48px;
        width: 48px;
    }

    body.sidebar-open #sidebar-nav {
        left: 0;
    }

    main {
        display: block;
        margin: 0 16px;
        --main-content-width: minmax(calc(100% - 32px), 60ch);
    }

    :root {
        --top-header-height: 160px;
    }

    #search-shortcut-key, .header-start-extension, .header-end-extension, #search-label {
        display: none;
    }

    #module-search-form {
        padding: 16px 16px;
        height: auto;
        margin-bottom: 16px;
        grid-column-start: main-content-start;
        grid-column-end: main-content-end;
        position: fixed;
        left: 0;
        right: 0;
    }

    .menu-toggle {
        display: inline-block;
        margin-right: 8px;
        appearance: none;
        background-color: transparent;
        outline: none;
        border: none;
        color: var(--text-color);
        padding: 0;
    }

    .menu-toggle svg {
        height: 48px;
        width: 48px;
    }

    /* Hide the Copy Link button on mobile. */
    .entry-name a:first-of-type {
        display: none;
    }

    .search-icon {
        display: block; /* This is only visible in mobile. */
        top: calc(1lh / 2 + 16px);
    }

    .top-header {
        flex-direction: column;
        height: auto;
        justify-content: space-between;
        /* min-width must be set to something (even 0) for text-overflow: ellipsis to work in descendants. */
        min-width: 0;
    }

    .pkg-full-name {
        font-size: 20px;
        padding-bottom: 14px;
    }

    .pkg-full-name a {
        vertical-align: middle;
        padding: 18px 0;
    }

    .logo {
        width: 50px;
        height: 54px;
    }

    .version {
        margin: 0;
        font-weight: normal;
        font-size: 18px;
        padding-bottom: 16px;
    }

    .module-name {
        font-size: 24px;
        margin-top: 8px;
        margin-bottom: 8px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    main {
        padding: 18px;
        font-size: 16px;
        padding-top: calc(16px + 16px + 1lh + 16px);
    }

    #sidebar-nav {
        margin-top: 0;
        padding-left: 0;
        width: var(--sidebar-width);
    }

    #sidebar-heading {
        font-size: 24px;
        margin: 16px;
    }

    h3 {
        font-size: 18px;
        margin: 0;
        padding: 0;
    }

    h4 {
        font-size: 16px;
    }

    body {
        margin: 0;
        min-width: 320px;
        max-width: 100dvw;
    }

    .top-header-triangle {
        display: none;
    }

    .pkg-and-logo {
        padding-block: 4px;
    }

    .pkg-full-name {
        flex-grow: 1;
    }

    .pkg-full-name a {
        padding-top: 24px;
        padding-bottom: 12px;
    }
}

/* Comments `#` and Documentation comments `##` */
samp .comment,
code .comment {
  color: var(--green);
}

/* Number, String, Tag literals */
samp .storage.type,
code .storage.type,
samp .string,
code .string,
samp .string.begin,
code .string.begin,
samp .string.end,
code .string.end,
samp .constant,
code .constant,
samp .literal,
code .literal {
  color: var(--cyan);
}

/* Keywords and punctuation */
samp .keyword,
code .keyword,
samp .punctuation.section,
code .punctuation.section,
samp .punctuation.separator,
code .punctuation.separator,
samp .punctuation.terminator,
code .punctuation.terminator,
samp .kw,
code .kw {
    color: var(--magenta);
}

/* Operators */
samp .op,
code .op,
samp .keyword.operator,
code .keyword.operator {
  color: var(--orange);
}

/* Delimieters */
samp .delimiter,
code .delimiter {
  color: var(--gray);
}

/* Variables modules and field names */
samp .function,
code .function,
samp .meta.group,
code .meta.group,
samp .meta.block,
code .meta.block,
samp .lowerident,
code .lowerident {
  color: var(--blue);
}

/* Types, Tags, and Modules */
samp .type,
code .type,
samp .meta.path,
code .meta.path,
samp .upperident,
code .upperident {
  color: var(--green);
}

samp .dim,
code .dim {
  opacity: 0.55;
}

.button-container {
  position: absolute;
  top: 0;
  right: 0;
}

.copy-button {
  background: var(--code-bg);
  border: 1px solid var(--magenta);
  color: var(--magenta);
  display: inline-block;
  cursor: pointer;
  margin: 8px;
}

.copy-button:hover {
  border-color: var(--link-hover-color);
  color: var(--link-hover-color);
}
