/* Wikipedia-style layout overrides for the Torillic theme */

@font-face {
  font-family: 'Philosopher';
  src: url('../fonts/Philosopher-Regular.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Philosopher';
  src: url('../fonts/Philosopher-Italic.ttf') format('truetype');
  font-style: italic;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'Philosopher';
  src: url('../fonts/Philosopher-Bold.ttf') format('truetype');
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

@font-face {
  font-family: 'Philosopher';
  src: url('../fonts/Philosopher-BoldItalic.ttf') format('truetype');
  font-style: italic;
  font-weight: 700;
  font-display: swap;
}

:root {
  --header-height: 2.25rem;
  --sidebar-width: 280px;
  --sidebar-padding-x: 1.75rem;
  --sidebar-border-width: 1px;
  --content-gap: 5px;
  --content-offset: calc(var(--sidebar-width) + var(--sidebar-padding-x) + var(--sidebar-border-width) + var(--content-gap));
  color: #202124;
  background-color: #f8f9fa;
  font-family: 'Philosopher', sans-serif;
}

html {
  scroll-behavior: smooth;
  min-height: 100vh;
  background-image: url('/css/torillic/assets/torillic-bg.jpg') !important;
  background-position: top center !important;
  background-repeat: repeat-y !important;
  background-attachment: fixed !important;
  background-size: cover !important;
  background-color: #f8f9fa !important;
}

body {
  margin: 0;
  padding: 0;
  padding-top: var(--header-height);
  background: #f8f9fa;
  min-height: 100vh;
  font-family: 'Philosopher', sans-serif;
}

.torillic-header,
.torillic-header nav,
.wiki-top-nav,
.torillic-page,
#wiki-sidebar,
button,
input,
select,
textarea {
  font-family: 'Philosopher', sans-serif;
}

.torillic-header h1,
.torillic-header h1 a,
.torillic-page h1,
.torillic-page h2,
.torillic-page h3,
.torillic-page h4,
.torillic-page h5,
.torillic-page h6 {
  font-family: 'Philosopher', sans-serif;
}

html,
body,
.torillic-background,
body.torillic-background,
html.torillic-background {
  min-height: 100vh;
}

.torillic-background,
body.torillic-background,
html.torillic-background {
  background-image: url('/css/torillic/assets/torillic-bg.jpg') !important;
  background-position: top center !important;
  background-repeat: repeat-y !important;
  background-attachment: fixed !important;
  background-size: cover !important;
  background-color: #f8f9fa !important;
}

body.torillic-background {
  padding: var(--header-height) 0 0 !important;
}

.torillic-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  padding: 0 1rem;
  background: #fff;
  border-bottom: 1px solid #dfe1e5;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  width: 100% !important;
  margin: 0 !important;
  box-sizing: border-box;
}

.torillic-header h1 {
  margin: 0 1rem 0 1rem;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  color: #111;
  white-space: nowrap;
  flex: 0 0 auto;
}

.torillic-header h1 a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.torillic-header h1 a:hover {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.torillic-header nav {
  flex: 1 1 auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-start;
  width: auto !important;
  max-width: none !important;
}

.top-nav-item {
  position: relative;
}

.mobile-nav-toggle,
.mobile-contents-toggle {
  display: none;
}

.top-nav-button,
.top-nav-item > a.top-nav-button {
  text-align: left;
  display: inline-block;
  font-family: 'Philosopher', sans-serif;
}

.top-nav-button {
  border: 1px solid transparent;
  background: transparent;
  padding: 0.35rem 0.6rem;
  font: inherit;
  font-family: 'Philosopher', sans-serif;
  color: #202124;
  cursor: pointer;
  border-radius: 0.35rem;
  font-size: 0.95rem;
}

.top-nav-button:hover,
.top-nav-button:focus {
  background: transparent;
  color: #202124;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  outline: none;
}

.top-nav-item[aria-expanded='true'] .top-nav-button {
  background: transparent;
  color: #202124;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.top-nav-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 14rem;
  background: #fff;
  border: 1px solid #dfe1e5;
  border-radius: 0.35rem;
  box-shadow: 0 8px 16px rgba(60, 64, 67, 0.15);
  padding: 0.25rem 0;
  white-space: nowrap;
  z-index: 1100;
}

.top-nav-item[aria-expanded='true'] .top-nav-dropdown {
  display: block;
}

.top-nav-dropdown a,
.top-nav-dropdown .has-sub > .sub-row > span {
  display: block;
  padding: 0.45rem 1rem;
  font-family: 'Philosopher', sans-serif;
  color: #202124;
  text-decoration: none;
  font-size: 0.95rem;
}

.top-nav-dropdown a:hover,
.top-nav-dropdown a:focus,
.top-nav-dropdown .has-sub:hover > .sub-row,
.top-nav-dropdown .has-sub[aria-expanded='true'] > .sub-row {
  background: transparent;
  color: #202124;
}

.top-nav-dropdown a:hover,
.top-nav-dropdown a:focus,
.top-nav-dropdown .has-sub:hover > .sub-row > a,
.top-nav-dropdown .has-sub:hover > .sub-row > span,
.top-nav-dropdown .has-sub[aria-expanded='true'] > .sub-row > a,
.top-nav-dropdown .has-sub[aria-expanded='true'] > .sub-row > span {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.top-nav-dropdown .has-sub {
  position: relative;
}

.top-nav-dropdown .sub-row {
  display: flex;
  align-items: stretch;
  min-width: 14rem;
}

.top-nav-dropdown .sub-row > a,
.top-nav-dropdown .sub-row > span {
  flex: 1 1 auto;
  padding-right: 0.5rem;
}

.top-nav-dropdown .sub-button {
  border: none;
  background: transparent;
  text-align: center;
  width: 2.25rem;
  padding: 0.45rem 0.5rem;
  font: inherit;
  font-family: 'Philosopher', sans-serif;
  font-size: 0.95rem;
  color: #202124;
  cursor: pointer;
}

.top-nav-dropdown .sub-button:hover,
.top-nav-dropdown .sub-button:focus {
  background: transparent;
  color: #202124;
  outline: none;
}

.top-nav-subdropdown {
  display: none;
  position: absolute;
  top: 0;
  left: 100%;
  min-width: 12rem;
  background: #fff;
  border: 1px solid #dfe1e5;
  border-radius: 0.35rem;
  box-shadow: 0 8px 16px rgba(60, 64, 67, 0.12);
  padding: 0.25rem 0;
  white-space: nowrap;
  z-index: 1200;
}

.top-nav-subdropdown a {
  display: block;
  padding: 0.45rem 1rem;
  font-family: 'Philosopher', sans-serif;
  color: #202124;
  text-decoration: none;
}

.top-nav-subdropdown a:hover {
  background: transparent;
  color: #202124;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.top-nav-item .has-sub:hover > .top-nav-subdropdown,
.top-nav-item .has-sub[aria-expanded='true'] > .top-nav-subdropdown {
  display: block;
}

main.torillic-page,
.torillic-page {
  box-sizing: border-box !important;
  width: auto !important;
  max-width: calc(100% - var(--content-offset) - var(--content-gap)) !important;
  background: #fff !important;
  column-count: 1 !important;
  column-gap: normal !important;
}

main.torillic-page {
  margin: var(--content-gap) var(--content-gap) 1.5rem var(--content-offset) !important;
  padding: 1.25rem 1.5rem 1.5rem 1.25rem !important;
  min-height: calc(100vh - var(--header-height) - var(--content-gap) - 1.5rem) !important;
  box-shadow: 0 1px 4px rgba(60, 64, 67, 0.08) !important;
  border-radius: 0.35rem !important;
  border: 1px solid #dfe1e5 !important;
  overflow: visible !important;
}

#wiki-sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 1000;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid #dfe1e5;
  padding: 1rem 0.75rem 1rem 1rem;
  box-shadow: 1px 0 0 rgba(0, 0, 0, 0.03);
}

.wiki-sidebar-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #202124;
}

.wiki-sidebar-list,
.wiki-sidebar-sublist,
.wiki-sidebar-grandlist {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.wiki-sidebar-item {
  margin-bottom: 0.22rem;
}

.wiki-sidebar-item a {
  color: #000;
  text-decoration: none;
  display: inline-block;
  padding: 0.12rem 0;
  line-height: 1.25;
}

.wiki-sidebar-item a:hover {
  text-decoration: underline;
}

.wiki-sidebar-section summary {
  list-style: none;
  cursor: pointer;
}

.wiki-sidebar-section summary::-webkit-details-marker {
  display: none;
}

.wiki-sidebar-summary {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  color: #000;
}

.toc-toggle {
  border: none;
  background: transparent;
  font: inherit;
  padding: 0 0.25rem;
  cursor: pointer;
  transform: rotate(0deg);
}

.wiki-sidebar-section[open] > summary .toc-toggle {
  transform: rotate(90deg);
}

.wiki-sidebar-sublist,
.wiki-sidebar-grandlist {
  margin-left: 1.2rem;
  margin-top: 0.12rem;
}

main.torillic-page > * {
  break-inside: avoid-column;
}

.torillic-page:first-child,
#write:first-child,
#typora-source:first-child {
  margin-block-start: 0;
}

main.torillic-page h1,
.torillic-page h1 {
  font-size: 2rem;
  margin: 0 0 1rem 0;
  line-height: 1.15;
  color: #2b2b2b;
}

main.torillic-page h2,
main.torillic-page h3,
main.torillic-page h4,
main.torillic-page h5,
main.torillic-page h6,
.torillic-page h2,
.torillic-page h3,
.torillic-page h4,
.torillic-page h5,
.torillic-page h6 {
  margin-block-start: 0.225em;
  margin-block-end: 0.08em;
}

body:not(.mobile-sidebar-hidden) .torillic-page {
  margin-left: var(--content-offset) !important;
  position: relative;
  z-index: 1;
}

.torillic-page figure,
.torillic-page .image-frame,
.torillic-page .state-image-container {
  box-sizing: border-box;
  max-width: 100%;
}

.torillic-page figure,
.torillic-page .image-frame {
  padding: 0.75rem;
  background: #fff;
  border-radius: 0.35rem;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.06);
  margin: 0 0 1.25rem 0;
}

.torillic-page img {
  box-sizing: border-box;
  max-width: 50%;
  height: auto;
  display: block;
  padding: 0.75rem;
  margin: 0 auto;
}

.torillic-page .state-thumb {
  box-sizing: border-box;
}

.page-subtitle,
.article-subtitle,
.post-meta,
.page-meta,
.subtitle,
.page-breadcrumb,
.torillic-backlink {
  display: none !important;
}

.headerlink,
.headerlink:hover,
.headerlink:focus {
  display: none !important;
  visibility: hidden !important;
  position: absolute !important;
  left: -9999px !important;
}

blockquote.torillic-toc {
  display: none !important;
}

@media (max-width: 900px) {
  body,
  body.torillic-background {
    padding-top: var(--header-height) !important;
    overflow-x: hidden;
  }

  .torillic-header {
    height: auto;
    min-height: var(--header-height);
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
  }

  .torillic-header h1 {
    margin: 0;
    font-size: 1.15rem;
  }

  .mobile-nav-toggle,
  .mobile-contents-toggle {
    border: 1px solid #d3d6db;
    background: #fffdf7;
    color: #202124;
    font: inherit;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(60, 64, 67, 0.12);
  }

  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.35rem 0.85rem;
    border-radius: 0.35rem;
    font-size: 1rem;
    white-space: nowrap;
  }

  .mobile-nav-toggle::after {
    content: '+';
  }

  body.mobile-nav-open .mobile-nav-toggle::after {
    content: '-';
  }

  .torillic-header nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-basis: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.15rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border-bottom: 1px solid #dfe1e5;
    box-shadow: 0 3px 8px rgba(60, 64, 67, 0.12);
    max-height: calc(100vh - var(--header-height));
    overflow-y: auto;
  }

  body.mobile-nav-open .torillic-header nav {
    display: flex;
  }

  .top-nav-item,
  .top-nav-button,
  .top-nav-item > a.top-nav-button {
    width: 100%;
    box-sizing: border-box;
  }

  .top-nav-button,
  .top-nav-item > a.top-nav-button {
    padding: 0.45rem 0.55rem;
  }

  .top-nav-dropdown,
  .top-nav-subdropdown {
    position: static;
    box-shadow: none;
    border-radius: 0;
    min-width: auto;
    white-space: normal;
    border: 0;
    background: transparent;
  }

  .top-nav-subdropdown {
    display: block !important;
    margin-left: 1rem;
    padding: 0;
  }

  .top-nav-dropdown .sub-row {
    min-width: 0;
    width: 100%;
  }

  .top-nav-dropdown .sub-button {
    display: none;
  }

  .top-nav-dropdown .sub-row > a,
  .top-nav-dropdown .sub-row > span {
    width: 100%;
    padding-right: 1rem;
  }

  .top-nav-subdropdown a {
    padding-left: 1rem;
  }

  #wiki-sidebar {
    position: static;
    display: block;
    width: auto;
    bottom: auto;
    overflow: visible;
    background: transparent;
    border-right: 0;
    padding: var(--content-gap) var(--content-gap) 0;
    box-shadow: none;
    box-sizing: border-box;
  }

  .wiki-sidebar-title {
    display: none;
  }

  .mobile-contents-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.55rem 1rem;
    border-radius: 0.35rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    text-align: left;
  }

  .mobile-contents-toggle::after {
    content: '+';
    letter-spacing: 0;
    font-weight: 700;
  }

  #wiki-sidebar.mobile-contents-open .mobile-contents-toggle::after {
    content: '-';
  }

  #wiki-sidebar .wiki-sidebar-list {
    display: none;
  }

  #wiki-sidebar.mobile-contents-open .wiki-sidebar-list {
    display: block;
    margin-top: var(--content-gap);
    padding: 0.65rem 1rem;
    background: #fff;
    border: 1px solid #dfe1e5;
    border-radius: 0.35rem;
    box-shadow: 0 2px 6px rgba(60, 64, 67, 0.1);
  }

  main.torillic-page,
  .torillic-page,
  body:not(.mobile-sidebar-hidden) .torillic-page {
    max-width: calc(100% - (var(--content-gap) * 2)) !important;
    width: auto !important;
    margin: var(--content-gap) !important;
    margin-left: var(--content-gap) !important;
    padding: 1rem !important;
  }

  .torillic-page figure,
  .torillic-page .image-frame {
    padding: 0.6rem;
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
  }

  .torillic-page .state-image-container {
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
  }

  .torillic-page img {
    max-width: 100% !important;
    padding: 0.6rem;
  }

  .torillic-page .state-thumb {
    width: 100%;
    max-width: 100%;
  }
}
