:root {
    color-scheme: light dark;

    --main-color: light-dark(black, #ddd);
    --main-background-color: light-dark(white, #353535);
    --code-color: light-dark(#f5f5f5, #2a2a2a);
    --link-color: light-dark(#3873ad, #fdbf35);
    --header-border-color: light-dark(#ddd, #d2d2d2);
    --crate-color: light-dark(var(--link-color), #d2991d);
    --module-color: var(--crate-color);
    --struct-color: light-dark(#ad378a, #2dbfb8);
    --trait-color: light-dark(#6e4fc9, #b78cf2);
    --type-color: var(--struct-color);
    --global-color: var(--crate-color);
    --fn-color: light-dark(#ad7c37, #2bab63);
    --primitive-color: var(--struct-color);
    --sidebar-color: light-dark(#f5f5f5, #505050);
    --search-result-active-color: light-dark(#ccc, #4f4f4f);
    --comment-color: light-dark(#8e908c, #8d8d8b);
    --target-color: light-dark(#fdffd3, #494a3d);
    --target-highlight-color: light-dark(#9b7b14, #ad7c37);
    --deprecated-color: light-dark(#fff5d6, #314559);
    --kw-color: light-dark(#8959a8, #ab8ac1);
    --bool-var-color: light-dark(#c82829, #ee6868);
    --number-color: light-dark(#718c00, #83a300);
    --string-color: light-dark(#718c00, #83a300);
    --doccomment-color: light-dark(#4d4d4c, #8ca375);
    --interpolation-color: light-dark(#119850, #bcca7d);
    --table-border-color: #e0e0e0;
    --table-alt-row-background-color: light-dark(#f5f5f5, #2a2a2a);

    --sidebar-toggle-height: 82px;
}

body {
    font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
    font-weight: 500;
    font-size: 1rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    color: var(--main-color);
    background-color: var(--main-background-color);
}

#main-contents {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-grow: 1;
}

main {
    padding: 28px 15px 40px 45px;
    max-width: 960px;
    position: relative;
    flex-grow: 1;
}

/* The heading and the search toggle sit in one flex row so the toggle aligns with the item's
   name; baseline alignment lines the toggle up with the heading text. The search input is a
   separate full-width row revealed below the heading when search is active. */
.heading-row {
    display: flex;
    align-items: baseline;
}

.heading-content {
    flex: 1;
    min-width: 0;
}

#search-toggle {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    margin-left: 1em;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
    color: var(--main-color);
    background: none;
    border: none;
    cursor: pointer;
}

#search-toggle:hover {
    opacity: 0.7;
}

/* The icon is a background image sized in `em` so it scales with the toggle's text (which is
   larger on mobile). The image itself is set per color scheme below. */
#search-toggle::before {
    content: "";
    display: inline-block;
    width: 1.1em;
    height: 1.1em;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

#search-input {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 24px;
    padding: 0.5em 0.75em;
    font-size: inherit;
    font-family: inherit;
    color: var(--main-color);
    background-color: var(--code-color);
    border: 1px solid var(--header-border-color);
    border-radius: 6px;
}

#search-input:focus {
    outline: 2px solid var(--link-color);
}

/* Search results are a three-column grid (kind, name, summary). Each `li` is a subgrid row, so
   every column lines up across rows while each row is still a single box that can be highlighted
   while navigating with the keyboard. */
ul.search-result-list {
    display: grid;
    /* The name column is capped so a very long qualified name wraps within it instead of
       stretching the column and starving the summary; the summary takes the rest and is
       truncated with an ellipsis. */
    grid-template-columns: max-content minmax(12em, 28em) minmax(0, 1fr);
    row-gap: 0.5em;
    list-style-type: none;
    width: 100%;
    margin: 0;
    padding: 0;
}

ul.search-result-list>li {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
    column-gap: 1.5em;
    align-items: baseline;
    padding: 4px 0;
}

ul.search-result-list>li.active,
ul.search-result-list>li:hover {
    background-color: var(--search-result-active-color);
}

/* The kind label and path prefix stay neutral; only the last name segment, which carries its
   own kind class (.struct, .fn, ...), is colored. */
.search-result-kind {
    color: var(--comment-color);
}

.search-result-name {
    color: var(--main-color);
    min-width: 0;
    overflow-wrap: anywhere;
}

.search-result-desc {
    font-family: "Source Serif 4", NanumBarunGothic, serif;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.search-guidance {
    color: var(--comment-color);
}

a {
    color: var(--link-color);
    text-decoration: none;
}

a:hover, a:focus-visible {
    text-decoration: underline;
}

pre {
    padding: 14px;
    background-color: var(--code-color);
}

code {
    font-family: "Source Code Pro",monospace;
    text-wrap: auto;
    white-space: pre-wrap;
}

:target {
    animation-name: highlight-target;
    animation-duration: 0.5s;
    background-color: var(--target-color);
    scroll-margin-top: 1rem;
}

@keyframes highlight-target {
    0% { background-color: var(--main-background-color); }
    10% { background-color: var(--main-background-color); }
    12% { background-color: var(--target-highlight-color); }
    100% { background-color: var(--target-color); }
}

.code-header {
    display: block;
    margin-top: 1em;
    margin-bottom: 1em;
}

h1, h2 {
    line-height: 1.25;
    padding-top: 3px;
    padding-bottom: 9px;
}

h1, h2, h3, h4 {
    margin: 25px 0 15px 0;
}

h2 {
    font-size: 1.375em;
    border-bottom: 1px solid var(--header-border-color);
}

ul.item-list, ul.sidebar-list {
    list-style-type: none;
    width: 100%;
    margin: 0;
    padding: 0;
}

.item-list {
    display: table;
}

.item-list>li {
    display: table-row;
    width: 100%;
    line-height: 2em;
}

.item-list>li>.item-name {
    width: 33%;
    display: table-cell;
    padding-right: 1.25em;
}

.item-list>li>.item-description {
    display: table-cell;
    font-family: "Source Serif 4", NanumBarunGothic, serif;
}

.comments {
    font-family: "Source Serif 4", NanumBarunGothic, serif;
}

.comments pre {
    overflow: auto;
}

.comments code, .item-description code {
    background-color: var(--code-color);
    border-radius: 6px;
    padding: 0 0.125em;
    font-weight: 400;
    font-size: 0.94em;
}

.crate {
    color: var(--crate-color);
}

.module {
    color: var(--module-color);
}

.struct {
    color: var(--struct-color);
}

.trait {
    color: var(--trait-color);
}

.type {
    color: var(--type-color);
}

.global {
    color: var(--global-color);
}

.fn {
    color: var(--fn-color);
}

.primitive {
    color: var(--primitive-color);
}

.method {
    color: var(--fn-color);
}

.field {
    color: var(--struct-color);
}

.padded-methods {
    padding-left: 2em;
}

.padded-description {
    padding-left: 2em;
}

.sidebar {
    scrollbar-width: thin;
    background-color: var(--sidebar-color);
    overflow-y: auto;
    overscroll-behavior: contain;
    position: sticky;
    height: 100vh;
    top: 0;
    left: 0;
    padding: 16px 15px 10px 24px;
}

.sidebar h1 {
    border-bottom: 0;
    margin: 0;
}

.sidebar h2 {
    border-bottom: 0;
    margin: 0;
    margin-top: 30px;
}

.sidebar h2#crate-name {
    border-bottom: 0;
    margin: 0;
    margin-top: 10px;
}

.sidebar h1 a, .sidebar h2 a {
    color: var(--main-color);
}

.sidebar h3 {
    border-bottom: 0;
    margin: 0;
    margin-top: 15px;
    margin-bottom: 15px;
}

.sidebar li {
   line-height: 2em; 
}

.comment {
    color: var(--comment-color);
}

.where-clause {
    font-size: 0.875em;
    white-space: pre-wrap;
}

.deprecated {
    background-color: var(--deprecated-color);
    padding: 3px;
    margin-bottom: 5px;
    border-radius: 3px;
    width: fit-content;
    font-family: "Source Serif 4", NanumBarunGothic, serif;
}

.emoji {
    text-shadow:  0 0 black,-1px 0 0 black,0 1px 0 black,0 -1px 0 black;
    margin-right: 0.3em;
}

.kw { 
    color: var(--kw-color);
}

.bool-var { 
    color: var(--bool-var-color);
}

.number { 
    color: var(--number-color);
}

.string { 
    color: var(--string-color);
}

.doccomment { 
    color: var(--doccomment-color);
}

.interpolation { 
    color: var(--interpolation-color);
}

#sidebar-toggle {
    display: flex;
    flex-direction: row;
    flex-grow: 1;
    width: 100%;
    background-color: var(--sidebar-color);
    height: var(--sidebar-toggle-height);
    position: sticky;
    top: 0;
    z-index: 10;
}

#sidebar-toggle button {
    background-color: var(--sidebar-color);
    border: none;
    width: 80px;
    height: 80px;
    padding: 1px 6px;
}

#sidebar-toggle-title {
    flex-grow: 1;
    text-align: center;
    align-self: center;
    font-size: 1.5em;
    font-weight: bold;
    overflow-x: hidden;
}

table {
    margin: .5em 0;
    border-collapse: collapse;
}

table th, table td {
    padding: .5em;
    border: 1px solid var(--table-border-color);
}

table tbody tr:nth-child(2n) {
    background: var(--table-alt-row-background-color);
}

/* mobile */
@media (max-width: 1199px) {
  body {
    font-size: 2rem;
  }

  .sidebar {
    display: none;
    width: 100%;
  }

  :target {
    scroll-margin-top: var(--sidebar-toggle-height);
  }

  /* The three-column grid would overflow on narrow screens, so stack each result instead:
     "kind name" on one line, the summary on the line below. */
  ul.search-result-list {
    display: block;
  }

  ul.search-result-list>li {
    display: block;
    margin-bottom: 1em;
  }

  .search-result-kind {
    margin-right: 0.5em;
  }

  .search-result-desc {
    display: block;
    padding-left: 1em;
  }
}

/* desktop */
@media (min-width: 1200px) {
  body {
    font-size: 1rem;
  }

  .sidebar {
      font-size: 0.875em;
      /* Fixed basis with no grow/shrink so the sidebar keeps the same width on every page,
         regardless of how wide the main content or the sidebar's own entries are. */
      flex: 0 0 306px;
  }

  #sidebar-toggle {
    display: none;
  }
}

@media (prefers-color-scheme: light) {
    #sidebar-toggle button::before {
        content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="none" stroke="black"> <path d="M3,5h16M3,11h16M3,17h16" stroke-width="2.75"/></svg>');
    }

    #search-toggle::before {
        background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="none" stroke="black" stroke-width="2.5"><circle cx="9" cy="9" r="6.5"/><path d="M14,14l6,6" stroke-linecap="round"/></svg>');
    }

    #search-toggle.exit::before {
        background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="none" stroke="black" stroke-width="2.75" stroke-linecap="round"><path d="M4,4l14,14M18,4L4,18"/></svg>');
    }
}

@media (prefers-color-scheme: dark) {
    #sidebar-toggle button::before {
        content: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="none" stroke="white"> <path d="M3,5h16M3,11h16M3,17h16" stroke-width="2.75"/></svg>');
    }

    #search-toggle::before {
        background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="none" stroke="white" stroke-width="2.5"><circle cx="9" cy="9" r="6.5"/><path d="M14,14l6,6" stroke-linecap="round"/></svg>');
    }

    #search-toggle.exit::before {
        background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 22" fill="none" stroke="white" stroke-width="2.75" stroke-linecap="round"><path d="M4,4l14,14M18,4L4,18"/></svg>');
    }
}