﻿@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Manrope:wght@500;600;700&display=swap");

:root {
  --font-primary: "Inter", "Segoe UI", sans-serif;
  --font-secondary: "Manrope", "Segoe UI", sans-serif;

  --color-bg-app: #f3f3f3;
  --color-text-main: #16181d;
  --color-text-muted: #586173;
  --color-text-inverse: #ffffff;

  --color-surface-1: #ffffff;
  --color-surface-2: #f8f9fc;
  --color-surface-3: #f0f0f0;

  --color-border-soft: #dddddd;
  --color-border-mid: #d8deeb;

  --color-accent: #4f6ef7;
  --color-accent-strong: #3d5be8;

  --shadow-card: 0 8px 24px rgb(16 24 40 / 0.09);
  --shadow-hero: 0 14px 34px rgb(16 24 40 / 0.12);
}

body.dark-mode {
  --color-bg-app: #16181c;
  --color-text-main: #e7e9ed;
  --color-text-muted: #b8bec8;
  --color-text-inverse: #f5f6f8;

  --color-surface-1: #1f2227;
  --color-surface-2: #272b31;
  --color-surface-3: #2d3239;

  --color-border-soft: #343942;
  --color-border-mid: #404752;

  --color-accent: #8ca0c1;
  --color-accent-strong: #9ab0d4;

  --shadow-card: 0 10px 28px rgb(0 0 0 / 0.28);
  --shadow-hero: 0 14px 34px rgb(0 0 0 / 0.4);
}

body.dark-mode.invert-pdfs {
  --color-bg-app: #000000;
  --color-surface-1: #000000;
  --color-surface-2: #050505;
  --color-surface-3: #111111;
  --color-border-soft: #2a2a2a;
  --color-border-mid: #3a3a3a;
  --color-accent: #a7bce2;
  --color-accent-strong: #bfd0ef;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg-app);
  color: var(--color-text-main);
  font-family: var(--font-primary);
  /* override shared stylesheet which disables scrolling globally */
  overflow: auto !important;
}

body.due-dates-popup-open {
  overflow: hidden !important;
}

.home-shell {
  width: min(1220px, calc(100vw - 32px));
  margin: 16px auto 34px;
}

.hero {
  position: relative;
  width: 100%;
  height: clamp(300px, 52vw, 520px);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-hero);
  border: 1px solid var(--color-border-soft);
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hero-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 18px;
  background: linear-gradient(180deg, rgb(0 0 0 / 0.08) 0%, rgb(0 0 0 / 0.55) 100%);
}

.hero-kicker {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: rgb(255 255 255 / 0.84);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 5px 0 0;
  color: var(--color-text-inverse);
  font-size: clamp(28px, 5vw, 44px);
  font-family: var(--font-secondary);
}

.section-wrap {
  margin-top: 28px;
}

.section-header {
  margin-bottom: 12px;
}

.section-header-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.books-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.books-search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.books-search-input {
  width: min(340px, 46vw);
  max-width: 100%;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  color: var(--color-text-main);
  padding: 0 36px 0 12px;
  font-size: 13px;
  font-family: var(--font-primary);
  box-shadow: var(--shadow-card);
}

.books-search-input:focus {
  outline: 2px solid var(--color-accent-strong);
  outline-offset: 2px;
}

.books-search-clear-btn {
  position: absolute;
  right: 6px;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  padding: 0;
  line-height: 1;
  font-size: 18px;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.books-search-clear-btn:hover,
.books-search-clear-btn:focus-visible {
  color: var(--color-text-main);
  border-color: var(--color-border-mid);
  background: var(--color-surface-2);
}

.section-header h2 {
  margin: 0;
  font-size: clamp(22px, 3.4vw, 30px);
  font-family: var(--font-secondary);
}

.books-sort-btn {
  border: 1px solid var(--color-border-mid);
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-surface-1), var(--color-surface-2));
  color: var(--color-text-main);
  box-shadow: var(--shadow-card);
  width: auto;
  min-width: 0;
  height: auto;
  min-height: 38px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-secondary);
  line-height: 1.2;
  white-space: nowrap;
  text-align: right;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.books-sort-btn:hover,
.books-sort-btn:focus-visible {
  transform: translateY(-1px);
  border-color: var(--color-accent-strong);
  box-shadow: 0 10px 24px rgb(16 24 40 / 0.14);
}

.books-sort-btn:focus-visible {
  outline: 2px solid var(--color-accent-strong);
  outline-offset: 2px;
}

.books-sort-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

#booksSortBtnLabel {
  display: inline-block;
  line-height: 1.2;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.category-block {
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-soft);
  border-radius: 14px;
  padding: 16px;
}

.category-title {
  margin: 0 0 12px;
  font-size: 18px;
  font-family: var(--font-secondary);
}

.cards-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.card {
  text-decoration: none;
  color: inherit;
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 12px;
  border: 1px solid var(--color-border-mid);
  border-radius: 12px;
  padding: 10px;
  background: var(--color-surface-2);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--color-accent-strong);
  box-shadow: var(--shadow-card);
}

.card.is-unavailable {
  opacity: 0.58;
  cursor: not-allowed;
}

.card.is-unavailable:hover,
.card.is-unavailable:focus-visible {
  transform: none;
  border-color: var(--color-border-mid);
  box-shadow: none;
}

.due-date-card {
  cursor: pointer;
}

.due-date-card:focus-visible {
  outline: 2px solid var(--color-accent-strong);
  outline-offset: 2px;
}

.card-thumb {
  width: 100px;
  height: 140px;
  border-radius: 8px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-3);
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.link-card .card-thumb {
  width: 140px;
  height: 140px;
}

.link-card {
  grid-template-columns: 140px 1fr;
}

.card-thumb canvas,
.card-thumb img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-thumb-badges {
  position: absolute;
  top: 5px;
  left: 5px;
  z-index: 3;
  display: inline-flex;
  flex-direction: row;
  gap: 4px;
  pointer-events: none;
}

.card-thumb-badge {
  position: relative;
  width: 23px;
  height: 29px;
  display: inline-block;
}

.card-thumb-badge svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.35));
}

.card-thumb-badge .share-square {
  position: absolute;
  top: 4px;
  left: 1px;
  width: 21px;
  height: 21px;
  border-radius: 5px;
  background: var(--badge-color, #a6a6b0);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
}

.card-thumb-badge path {
  fill: var(--badge-color, #a6a6b0);
  stroke: var(--badge-color, #a6a6b0);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.card-thumb-badge .count {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.thumb-fallback {
  color: var(--color-text-muted);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

.card-title {
  margin: 1px 0 6px;
  font-size: 16px;
  font-family: var(--font-secondary);
}

.card-description {
  margin: 0;
  font-size: 14px;
  color: var(--color-text-muted);
}

.card-meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.status {
  padding: 16px;
  border-radius: 10px;
  border: 1px dashed var(--color-border-mid);
  color: var(--color-text-muted);
  background: var(--color-surface-1);
}

.floating-actions {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 15;
  display: grid;
  gap: 10px;
}

/* old floating question button removed, related styles can stay for now */
.home-questions-wrap {
  position: relative;
}

.action-btn {
  cursor: pointer;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  color: var(--color-text-main);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
}

.action-btn:hover {
  border-color: var(--color-accent-strong);
}

.action-btn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.action-btn.small {
  width: 36px;
  height: 36px;
}

.icon {
  width: 18px;
  height: 18px;
  color: currentColor;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* floating tray styles remain but no longer triggered */
.home-questions-tray {
  position: absolute;
  left: calc(100% + 10px);
  bottom: 0;
  width: min(360px, calc(100vw - 86px));
  max-height: min(70vh, 560px);
  overflow: hidden;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 160ms ease, transform 160ms ease;
}

/* leave open styles */
.home-questions-tray.is-open,
.home-questions-wrap:hover .home-questions-tray,
.home-questions-wrap:focus-within .home-questions-tray {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* new unanswered section styling */
#unansweredSection .section-header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-badge {
  background: var(--color-surface-2);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 12px;
  color: var(--color-text-muted);
}
#unansweredDetails summary {
  cursor: pointer;
  font-weight: 500;
  margin-bottom: 4px;
}
#unansweredList {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  /* make marker cards wider to keep metadata/text readable */
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* when rendered inside the grid we already tag cards with this class */
.unanswered-question-card {
  width: 100%;
}

.home-questions-title {
  padding: 2px 2px 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
}

.home-questions-list {
  display: grid;
  gap: 8px;
  max-height: min(66vh, 510px);
  overflow-y: auto;
  padding-right: 2px;
}

.home-question-card {
  display: grid;
  grid-template-columns: 1fr 32px;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-2);
}

.home-question-open {
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.home-question-book {
  font-size: 12px;
  font-family: var(--font-secondary);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-question-page {
  margin-top: 2px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.home-question-text {
  margin-top: 4px;
  font-size: 11px;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.home-question-delete {
  width: 32px;
  min-width: 32px;
  height: 32px;
  border-radius: 8px;
  padding: 0;
}

.home-question-delete .icon {
  width: 15px;
  height: 15px;
}

.home-questions-empty {
  border: 1px dashed var(--color-border-mid);
  border-radius: 10px;
  background: var(--color-surface-2);
  padding: 10px;
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
}

.due-dates-overlay {
  position: fixed;
  inset: 0;
  z-index: 34;
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: rgb(14 18 28 / 0.56);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.due-dates-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.due-dates-popup {
  width: min(940px, calc(100vw - 20px));
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--color-surface-1);
  border-left: 1px solid var(--color-border-mid);
  border-right: 1px solid var(--color-border-mid);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.05), 0 18px 48px rgb(0 0 0 / 0.32);
}

.due-dates-popup-header {
  min-height: 56px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-mid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--color-surface-1);
}

.due-dates-popup-header h2 {
  margin: 0;
  font-size: 18px;
  font-family: var(--font-secondary);
}

.due-dates-popup-body {
  min-height: 0;
  overscroll-behavior: contain;
}

#dueDatesPopupFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgb(14 18 28 / 0.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 25;
  padding: 0;
}

.settings-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.settings-island {
  width: min(460px, calc(100vw - 32px));
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-mid);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-card);
  margin: 24px;
}

body.dark-mode.invert-pdfs .card-thumb canvas,
body.dark-mode.invert-pdfs .card-thumb img {
  filter: invert(1) hue-rotate(180deg) contrast(1.08);
}

.settings-island-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.settings-island-header h2 {
  margin: 0;
  font-size: 22px;
  font-family: var(--font-secondary);
}

.settings-group {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-soft);
  border-radius: 10px;
  padding: 12px;
}

.settings-group h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-family: var(--font-secondary);
}

.settings-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
}

.settings-footer-link {
  margin-top: 14px;
  text-align: center;
}

.settings-footer-link a {
  color: var(--color-text-muted);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.settings-footer-link a:hover {
  color: var(--color-text-main);
}

.home-footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0;
  margin: 8px auto 24px;
  width: min(720px, calc(100vw - 32px));
}

.home-footer-link {
  position: relative;
  padding: 0 12px;
  color: var(--color-text-muted);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.home-footer-link + .home-footer-link::before {
  content: "\2022";
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  line-height: 1;
  pointer-events: none;
}

.home-footer-link:hover {
  color: var(--color-text-main);
}

.about-copy {
  margin: 0;
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.45;
}

@media (max-width: 720px) {
  .home-shell {
    width: calc(100vw - 20px);
    margin-top: 10px;
  }

  .hero {
    height: clamp(250px, 70vw, 390px);
    border-radius: 14px;
  }

  .category-block {
    padding: 12px;
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .card {
    grid-template-columns: 86px 1fr;
    padding: 9px;
  }

  .card-thumb {
    width: 86px;
    height: 122px;
  }

  .link-card .card-thumb {
    width: 122px;
    height: 122px;
  }

  .link-card {
    grid-template-columns: 122px 1fr;
  }

  .home-footer-links {
    justify-content: center;
    gap: 8px;
  }

  .section-header-with-action {
    align-items: flex-start;
    flex-direction: column;
  }

  .books-controls {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .books-search-wrap {
    width: 100%;
  }

  .books-search-input {
    width: 100%;
  }

  .books-sort-btn {
    align-self: flex-start;
  }

  .due-dates-popup {
    width: 100vw;
    height: 100dvh;
    border-left: 0;
    border-right: 0;
  }

  .home-footer-link {
    padding: 0;
  }

  .home-footer-link + .home-footer-link::before {
    content: none;
  }
}
