* {
  margin: 0;
  padding: 0;
}

html,
body {
  overscroll-behavior: none;
}

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

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

#library-body {
  position: relative;
  width: 100%;
  margin-top: 57px;
  background-color: #1a1b26;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  border-top: none;
}

section {
  border-radius: 0;
}

#top-section {
  box-sizing: border-box;
  background-color: #16161e;
  margin: 0;
  display: flex;
  justify-content: space-between;
  padding: 10px;
  padding-bottom: 15px;
  border-radius: 10px 10px 0 0;
  border-bottom: none;
  position: fixed;
  width: calc(100% - 18px);
  z-index: 10;
  top: 87px;
  box-shadow: 0 -50px black;
}

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

input[type="search"] {
  width: 100%;
  font-size: 1.1rem;
  padding: 5px;
  padding-left: 40px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 5px 5px hsla(0, 0%, 10%, 1),
    0px 5px 10px 0px rgba(0, 0, 0, 0.4);
  border-radius: 10px;
  color: hsla(var(--color-green-light-a), 0.6);
  background-color: var(--color-gray-800);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' 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;
  font-family: var(--font-mono);
}

input[type="search"]::placeholder {
  color: var(--color-gray-600);
  font-family: var(--font-mono);
}

input[type="search"]:focus {
  background-color: var(--color-gray-750);
  box-shadow: inset 0 0 5px 5px hsla(0, 0%, 10%, 0.3),
    0px 5px 10px 0px rgba(0, 0, 0, 0.4);
  outline: none;
  border-radius: 10px;
}

input[type="search"]:focus::placeholder {
  color: var(--color-gray-500);
}

table:not(#author-section table) {
  width: 100%;
  border-collapse: collapse;
  background-color: #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 {
  background-color: #16161e;
  position: sticky;
  top: 0;
  z-index: 5;
}

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

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: #16161e;
}

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: var(--color-gray-400);
  border-bottom: 1px solid 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: rgba(255, 255, 255, 0.02);
}

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

table:not(#author-section table) td {
  padding: 8px 16px;
  font-size: 0.95rem;
  color: var(--color-gray-300);
  border-bottom: 1px solid 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: 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: rgba(64, 13, 115, 0.4);
}

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

table:not(#author-section table) tbody tr:nth-child(even).highlighted:hover {
  background-color: 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: white;
}

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

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

[type="reset"] {
  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(--font-mono);
}

[type="reset"]:hover {
  color: red;
}

#author-section table {
  width: 100%;
  border-collapse: collapse;
  background-color: #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: #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: var(--color-gray-400);
  border-bottom: 1px solid 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: rgba(255, 255, 255, 0.02);
}

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

#author-section table td {
  padding: 8px 16px;
  font-size: 0.95rem;
  color: var(--color-gray-300);
  border-bottom: 1px solid 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: 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 10px;
  box-sizing: border-box;
  background-color: #222333;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.8),
    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: rgba(255, 166, 0, 1);
  background-color: hsl(236, 23%, 24%);
  border-left: 1px solid hsla(230, 22%, 33%, 1);
  border-right: 1px solid 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 30px;
  line-height: 1;
  overflow-wrap: break-word;
  hyphens: auto;
}

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

section:not(#top-section) img {
  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 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; /* Keeps cells together */
}

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

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

.work-close {
  position: absolute;
  top: 20px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1.2rem;
  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: 55px;
  margin-bottom: 20px;
  color: gray;
}

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

section:not(#top-section) ul span {
  color: white;
}

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

#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;
}

/* ===========================
   MOBILE RESPONSIVE STYLES
   =========================== */

@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 - 150px);
  }

  /* 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: 15px;
    right: 15px;
    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: 600px) {
  #top-section {
    width: calc(100% - 12px);
    top: 62px;
  }

  #library-body {
    margin-top: 52px;
  }

  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;
  }
}

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

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