html,
body {
  overscroll-behavior: none;
}

main {
  border: none !important;
  background-color: transparent !important;
  box-shadow: none !important;

  &::before {
    display: none !important;
  }
}

header {
  position: fixed;
  width: 100vw;
  box-shadow: none;
}

main {
  display: block;
  border-radius: 10px;
  box-sizing: border-box;
}

body,
main {
  min-height: 100%;
}

#top-section {
  box-sizing: border-box;
  background-color: light-dark(#d6d8df, #16161e);
  margin: 0;
  display: flex;
  justify-content: space-between;
  padding: 10px;
  padding-bottom: 10px;
  border-radius: 20px 20px 0 0;
  border-bottom: none;
  position: fixed;
  width: calc(100% - 18px);
  z-index: 10;
  top: 87px;
  box-shadow: 0 -50px var(--c-canvas-bg);
  border: var(--glass-border);
  border-bottom: none;
}

search {
  position: relative;
  width: 100%;
  margin: 0 auto;
}

input[type="search"] {
  width: 100%;
  padding: 5px;
  padding-left: 40px;
  border: 1px solid light-dark(hsla(0, 0%, 0%, 0.4), hsla(0, 0%, 100%, 0.2));
  border-radius: var(--br-s);
  font-family: var(--ff-mono);
  font-size: 1.1rem;
  line-height: 1;

  background-image: url("data:image/svg+xml;utf8,\<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23808080' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'>\<circle cx='11' cy='11' r='8'/>\<line x1='21' y1='21' x2='16.65' y2='16.65'/>\</svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  background-size: 16px 16px;

  color: light-dark(SlateBlue, hsla(120, 100%, 50%, 0.6));
  background-color: light-dark(var(--c-g-35), var(--c-g-20));

  &::placeholder {
    color: light-dark(var(--c-g-55), var(--c-g-40));
  }

  &:focus {
    border-radius: var(--br-s);
    outline: none;
    background-color: light-dark(var(--c-g-20), var(--c-g-25));
  }

  &:focus::placeholder {
    color: light-dark(var(--c-g-60), var(--c-g-50));
  }
}

input[type="search"]:placeholder-shown ~ [type="reset"] {
  display: none;
}

input[type="search"]:not(:placeholder-shown) ~ [type="reset"] {
  display: inline;
}

[type="reset"] {
  width: 0;
  min-width: 20px;
  box-shadow: none;
  margin: 0;
  position: absolute;
  right: 0.5em;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.2em;
  display: block;
  padding: 0;
  color: orangered;
  font-family: var(--ff-mono);

  &:hover {
    color: red;
  }
}

/* ------------------------------------------- */

#library-body {
  position: relative;
  width: 100%;
  margin-top: 140px;
  background-color: light-dark(#d6d8df, #16161e);
  border-radius: 0 0 20px 20px;
  overflow: hidden;
  border-top: none;
  border: var(--glass-border);
  border-top: none;
}

section {
  border-radius: 0;
}

table:not(#author-section table) {
  width: 100%;
  border-collapse: collapse;
  background-color: light-dark(#e6e7ed, #1b1c2b);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

table:not(#author-section table) a {
  text-decoration: underline;
}

table:not(#author-section table) thead {
  display: table;
  width: 100%;
  table-layout: fixed;
  background-color: light-dark(#d6d8df, #16161e);
  z-index: 5;
}

table:not(#author-section table) tbody {
  display: block;
  height: calc(100vh - 176.5px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

table:not(#author-section table) tbody tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

table:not(#author-section table) thead,
table:not(#author-section table) tbody tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

table:not(#author-section table) thead {
  background-color: light-dark(#d6d8df, #16161e);
  line-height: 1.2;
}

table:not(#author-section table) thead th {
  text-align: left;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 5px 16px;
  color: light-dark(var(--c-g-65), var(--c-g-60));
  border-bottom: 1px solid
    light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.08));
}

table:not(#author-section table) tbody tr {
  transition: background-color 0.2s ease;
}

table:not(#author-section table) tbody tr:nth-child(even) {
  background-color: light-dark(rgba(0, 0, 0, 0.02), rgba(255, 255, 255, 0.02));
}

table:not(#author-section table) tbody tr:hover {
  background-color: light-dark(rgba(0, 0, 0, 0.05), rgba(255, 255, 255, 0.05));
}

table:not(#author-section table) td {
  padding: 5px 16px;
  font-size: 0.95rem;
  color: var(--c-g-70);
  border-bottom: 1px solid
    light-dark(rgba(0, 0, 0, 0.06), rgba(255, 255, 255, 0.06));
  vertical-align: middle;
}

table:not(#author-section table) tbody tr:last-child td {
  border-bottom: none;
}

table:not(#author-section table) tbody tr.highlighted {
  background-color: light-dark(
    rgba(64, 13, 115, 0.12),
    rgba(64, 13, 115, 0.35)
  );
  transition: background-color 0.3s ease;
}

table:not(#author-section table) tbody tr:nth-child(even).highlighted {
  background-color: light-dark(rgba(64, 13, 115, 0.16), rgba(64, 13, 115, 0.4));
}

table:not(#author-section table) tbody tr.highlighted:hover {
  background-color: light-dark(
    rgba(64, 13, 115, 0.22),
    rgba(64, 13, 115, 0.45)
  );
}

table:not(#author-section table) tbody tr:nth-child(even).highlighted:hover {
  background-color: light-dark(rgba(64, 13, 115, 0.26), rgba(64, 13, 115, 0.5));
}

table:not(#author-section table) thead th#title,
table:not(#author-section table) tbody td:nth-child(1) {
  width: 30%;
}

table:not(#author-section table) thead th#authors,
table:not(#author-section table) tbody td:nth-child(2) {
  width: 20% !important;
}

table:not(#author-section table) thead th#tags,
table:not(#author-section table) tbody td:nth-child(3) {
  width: 20% !important;
}

table:not(#author-section table) thead th#status,
table:not(#author-section table) tbody td:nth-child(4) {
  width: 10% !important;
}

table:not(#author-section table) thead th#rating,
table:not(#author-section table) tbody td:nth-child(5) {
  width: 10% !important;
}

table:not(#author-section table) thead th {
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

table:not(#author-section table) thead th:hover {
  color: light-dark(black, white);
}

#author-section table {
  width: 100%;
  border-collapse: collapse;
  background-color: light-dark(#e6e7ed, #1b1c2b);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

#author-section table a {
  text-decoration: underline;
}

#author-section table thead {
  background-color: light-dark(#d6d8df, #16161e);
}

#author-section table thead th {
  text-align: left;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 5px 16px;
  color: light-dark(var(--c-g-65), var(--c-g-40));
  border-bottom: 1px solid
    light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.08));
}

#author-section table tbody tr {
  transition: background-color 0.2s ease;
}

#author-section table tbody tr:nth-child(even) {
  background-color: light-dark(rgba(0, 0, 0, 0.02), rgba(255, 255, 255, 0.02));
}

#author-section table tbody tr:hover {
  background-color: light-dark(rgba(0, 0, 0, 0.05), rgba(255, 255, 255, 0.05));
}

#author-section table td {
  padding: 8px 16px;
  font-size: 0.95rem;
  color: light-dark(var(--c-g-70), var(--c-g-65));
  border-bottom: 1px solid
    light-dark(rgba(0, 0, 0, 0.06), rgba(255, 255, 255, 0.06));
  vertical-align: middle;
}

#author-section table tbody tr:last-child td {
  border-bottom: none;
}

#author-section table thead th {
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  -webkit-user-select: none;
}

#author-section table thead th:hover {
  color: light-dark(black, white);
}

section:not(#top-section) {
  position: absolute;
  top: 0;
  right: 0;
  min-height: calc(100vh - 150px);
  max-height: calc(100vh - 200px);
  min-width: 400px;
  width: 600px;
  max-width: 65vw;
  padding: 10px 0 0 5px;
  box-sizing: border-box;
  background-color: light-dark(#dbdce1, #222333);
  box-shadow:
    light-dark(0 0 15px rgba(0, 0, 0, 0.25), 0 0 15px rgba(0, 0, 0, 0.8)),
    light-dark(
      inset 0 5px 5px -5px rgba(0, 0, 0, 0.15),
      inset 0 5px 5px -5px rgba(0, 0, 0, 0.8)
    );
  resize: vertical;
  transform: translateX(110%);
  transition: transform 0.35s ease;
  z-index: 10;
  will-change: transform;
}

section:not(#top-section)::before {
  content: "|";
  position: absolute;
  left: 0;
  top: 0;
  font-size: 1.5rem;
  width: 4px;

  height: var(--handle-height);
  color: var(--c-highlight);
  background-color: light-dark(hsl(236, 23%, 78%), hsl(236, 23%, 24%));
  border-left: 1px solid
    light-dark(hsla(230, 22%, 65%, 1), hsla(230, 22%, 33%, 1));
  border-right: 1px solid
    light-dark(hsla(230, 22%, 65%, 1), hsla(230, 22%, 33%, 1));
  box-shadow: inset 0 5px 5px -5px rgba(0, 0, 0, 0.8);
  cursor: ew-resize;
  display: flex;
  align-items: center;
  justify-content: center;
}

section:not(#top-section) h1 {
  font-size: clamp(1.9rem, 6vw, 3rem);
  box-sizing: border-box;
  margin: 20px 50px 10px 20px;
  line-height: 1;
  overflow-wrap: break-word;
  hyphens: auto;
  text-align: left;
  color: light-dark(#1a1a2e, white);
  font-family: var(--ff-type);
}

#author-section > div {
  max-height: calc(100vh - 235px);
  overflow-y: auto;
  padding: 20px;
  padding-top: 5px;
  border-bottom: 1px dashed
    light-dark(rgba(0, 100, 100, 0.12), rgba(0, 255, 255, 0.03));
}

section:not(#top-section) img {
  user-select: none;
  max-height: 40vh;
  max-width: 40%;
  float: right;
  margin: 0 0 15px 20px;
  border-radius: 8px;
  box-shadow: 2px 2px 10px 0 rgba(0, 0, 0, 0.5);
}

section:not(#top-section) img[src=""] {
  display: none;
}

section:not(#top-section) *:not(table, img, h1):not(table *) {
  line-height: 2;
  font-size: 1.2rem;
  overflow-wrap: break-word;
  hyphens: auto;
}

section:not(#top-section) table {
  border: 1px solid light-dark(rgba(0, 0, 0, 0.12), rgba(255, 255, 255, 0.1));
  margin-top: 10px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 2px 2px 10px 0 rgba(0, 0, 0, 0.5);
  border-collapse: separate;
  border-spacing: 0;
}

section:not(#top-section) table * {
  overflow-wrap: normal;
  hyphens: none;
}

section.is-open {
  transform: translateX(0) !important;
}

.work-close {
  position: absolute;
  top: 0px;
  right: 0px;
  width: 40px;
  height: 40px;
  padding: 0 0 10px 10px;
  border-radius: 0px 0px 0px 50px;
  background-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1));
  color: light-dark(#1a1a2e, #fff);
  font-size: 2rem !important;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.work-close:hover {
  background-color: hsla(0, 82%, 30%, 0.5);
  color: #fff;
  transform: scale(1.05);
}

.work-close:active {
  transform: scale(0.9);
}

section:not(#top-section) a {
  text-decoration: underline;
}

section:not(#top-section) ul {
  padding-left: 40px;
  margin-bottom: 20px;
  color: light-dark(#666, gray);
}

#work-section > ul {
  border-block: light-dark(rgba(0, 0, 0, 0.15), hsl(0, 0%, 0%, 0.2)) 2px dashed;
  padding-block: 15px 5px;
  background-color: light-dark(rgba(0, 0, 0, 0.05), hsl(0, 0%, 0%, 0.1));
}

section:not(#top-section) ul span {
  color: light-dark(#1a1a2e, white);
}

section:not(#top-section) ul li::marker {
  content: "◈ ";
  color: var(var(--c-highlight));
}

#s-note {
  padding-left: 20px;
}

#s-note ol,
#s-note ul {
  padding-left: 30px;
}

#s-note ol input,
#s-note ul input {
  margin-right: 5px;
}

table,
table td,
table th {
  table-layout: fixed;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

section:not(#top-section) table {
  table-layout: auto;
  width: 100%;
}

section:not(#top-section) table th {
  padding: 2px 8px;
}

section:not(#top-section) table td {
  line-height: 1;
  padding: 8px 8px;
}

@media screen and (max-width: 768px) {
  /* Adjust top section for mobile */

  [type="reset"] {
    font-size: 1.5em;
    right: 0.3em;
  }

  /* Hide columns 3, 4, 5 on mobile - keep only title and authors */
  table:not(#author-section table) thead th#tags,
  table:not(#author-section table) thead th#status,
  table:not(#author-section table) thead th#rating,
  table:not(#author-section table) tbody td:nth-child(3),
  table:not(#author-section table) tbody td:nth-child(4),
  table:not(#author-section table) tbody td:nth-child(5) {
    display: none;
  }

  /* Adjust column widths for mobile - only 2 columns visible */
  table:not(#author-section table) thead th#title,
  table:not(#author-section table) tbody td:nth-child(1) {
    width: 60% !important;
  }

  table:not(#author-section table) thead th#authors,
  table:not(#author-section table) tbody td:nth-child(2) {
    width: 40% !important;
  }

  /* Adjust table header and cell padding for mobile */
  table:not(#author-section table) thead th {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  table:not(#author-section table) td {
    padding: 10px;
    font-size: 0.9rem;
  }

  /* Adjust tbody height for mobile */
  table:not(#author-section table) tbody {
    height: calc(100vh - 138px);
    overscroll-behavior-y: contain;
  }

  /* Make detail section full-width on mobile */
  section:not(#top-section) {
    min-width: 100vw;
    width: 100vw;
    max-width: 100vw;
    min-height: 100vh;
    max-height: 100vh;
    padding: 10px;
    resize: none;
  }

  section:not(#top-section)::before {
    display: none; /* Hide resize handle on mobile */
  }

  section:not(#top-section) h1 {
    font-size: clamp(1.5rem, 8vw, 2.5rem);
    margin: 15px 45px 10px 15px;
  }

  section:not(#top-section) *:not(table, img, h1):not(table *) {
    font-size: 1rem;
    line-height: 1.6;
  }

  section:not(#top-section) img {
    max-width: 100%;
    float: none;
    margin: 15px 0;
  }

  #author-section > div {
    max-height: calc(100vh - 120px);
    padding: 15px;
    padding-bottom: 80px; /* Extra bottom padding for scroll clearance */
  }

  /* Ensure author section table is scrollable */
  #author-section {
    overflow-y: auto;
    padding-bottom: 40px;
  }

  section:not(#top-section) ul {
    padding-left: 30px;
  }

  .work-close {
    top: 0px;
    right: 0px;
    width: 40px;
    height: 40px;
    font-size: 1.4rem;
  }

  /* Make author section table more mobile-friendly */
  #author-section table thead th {
    padding: 8px;
    font-size: 0.85rem;
  }

  #author-section table td {
    padding: 10px 8px;
    font-size: 0.9rem;
  }
}

/* Extra small devices */
@media screen and (max-width: 660px) {
  #top-section {
    width: calc(100% - 10px);
    top: 55px;
  }

  #library-body {
    margin-top: 105px !important;
  }

  input[type="search"] {
    font-size: 14px;
  }

  table:not(#author-section table) thead th {
    padding: 6px 8px;
    font-size: 0.75rem;
  }

  table:not(#author-section table) td {
    padding: 8px;
    font-size: 0.85rem;
  }

  section:not(#top-section) h1 {
    font-size: clamp(1.3rem, 8vw, 2rem);
    margin: 10px 40px 10px 10px;
  }

  section:not(#top-section) *:not(table, img, h1):not(table *) {
    font-size: 0.95rem;
  }

  .work-close {
    width: 36px;
    height: 36px;
    font-size: 1.3rem;
  }
}

section .is-read td {
  background-color: hsla(120, 100%, 30%, 0.2) !important;
  font-weight: bold;
}

section #s-note {
  color: grey !important;
  font-style: oblique;
}

section #s-note * {
  color: light-dark(#1a1a2e, white) !important;
  font-style: normal;
}

section #s-note h2 {
  margin-top: 20px;
  line-height: 1 !important;
  font-size: 2rem !important;
  font-family: var(--font-typewriter);
}

#crit-lit {
  padding: 0px 5px 0px 15px;
  display: inline-flex;
  align-items: center;
  font-size: 23px;
}

main a:any-link,
main span a:any-link,
a::selection {
  color: var(--c-g-65) !important;
  border-radius: 2px;
  outline-offset: 2px;

  &:hover,
  &:hover::selection {
    color: light-dark(black, white);
  }
}

.is-read:not(section .is-read) td:nth-child(1),
.is-read:not(section .is-read) td:nth-child(1) *,
.is-read:not(section .is-read) td:nth-child(1)::selection,
.is-read:not(section .is-read) td:nth-child(1) *::selection {
  color: hsl(120, 100%, 30%) !important;
  font-weight: bold;
}

#theory-link::before {
  content: "";
  mask-image: url("/SRC/asset/svg/icon-notebook-pen.svg");
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  background-color: var(--c-g-65);
  mask-repeat: no-repeat;
  mask-size: contain;
  vertical-align: middle;
  margin: 3.5px 4px 0 10px;
  transform: scale(0.9);
  transition: transform 0.2s ease;
}

#theory-link:hover:before {
  background-color: var(--c-g-90);
  transform: scale(1);
}

#theory-link:active:before {
  background-color: var(--c-g-40);
  transform: scale(0.85);
}

@media (max-width: 660px) {
  main#library,
  body:has(main#library) {
    min-height: calc(100vh - var(--body-margin-top-mobile) - 100px) !important;
  }
}
