:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #1d2025;
  --panel-2: #292d34;
  --text: #f4f2ee;
  --muted: #a9adb5;
  --accent: #d94832;
  --accent-2: #f0b44c;
  --line: #3a3f49;
  --shadow: rgb(0 0 0 / 32%);
}

:root.light {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #e9edf2;
  --text: #20242a;
  --muted: #66707d;
  --accent: #bd311f;
  --accent-2: #a56312;
  --line: #d8dee7;
  --shadow: rgb(30 38 54 / 14%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px minmax(120px, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

p,
#subtitle {
  margin-top: 4px;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: color-mix(in srgb, var(--accent) 62%, var(--line));
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border-radius: 8px;
  font-size: 20px;
}

.text-button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 700;
  white-space: nowrap;
}

.text-button.secondary {
  color: var(--muted);
}

.text-button.active {
  border-color: var(--accent);
  color: var(--accent-2);
}

main {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
}

.account-panel,
.collections-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.collections-panel {
  display: block;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.auth-form {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
}

.auth-form input {
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-error {
  grid-column: 1 / -1;
  color: var(--accent-2);
  font-size: 14px;
}

.section-tabs,
.folder-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.folder-tabs {
  margin-top: -4px;
  margin-bottom: 22px;
}

.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 22px;
  align-items: start;
}

.library.compact {
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 16px;
}

.issue-card {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 46px var(--shadow);
}

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

.progress-bar {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 5px;
  background: rgb(0 0 0 / 42%);
}

.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent-2);
}

.issue-title {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.issue-meta {
  color: var(--muted);
  font-size: 13px;
}

.reader {
  display: grid;
  justify-items: center;
  gap: 18px;
}

.pages {
  display: grid;
  width: 100%;
  justify-items: center;
  gap: 18px;
}

.reader-toolbar {
  position: sticky;
  top: 82px;
  z-index: 10;
  display: flex;
  width: min(100%, 980px);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  color: var(--muted);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(12px);
}

.reader-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.page {
  width: min(100%, 980px);
  height: auto;
  border-radius: 4px;
  background: var(--panel-2);
  box-shadow: 0 20px 80px var(--shadow);
  cursor: zoom-in;
}

.reader.fit-height .page {
  width: auto;
  max-width: 100%;
  max-height: calc(100vh - 108px);
}

.reader.carousel .pages {
  display: flex;
  justify-content: flex-start;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  padding-bottom: 12px;
}

.reader.carousel .page {
  width: min(92vw, 980px);
  flex: 0 0 auto;
  scroll-snap-align: center;
}

.lightbox {
  width: min(96vw, 1280px);
  height: min(96vh, 960px);
  padding: 0;
  overflow: hidden;
  background: #08090b;
  border: 1px solid #3a3f49;
  border-radius: 8px;
}

.lightbox::backdrop {
  background: rgb(0 0 0 / 82%);
}

.lightbox img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 160ms ease;
}

.lightbox img.zoomed {
  cursor: zoom-out;
  transform: scale(2);
  transform-origin: center;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  z-index: 3;
  background: rgb(8 9 11 / 72%);
  border-color: rgb(255 255 255 / 22%);
}

.lightbox-close {
  top: 12px;
  right: 12px;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-prev {
  left: 12px;
}

.lightbox-next {
  right: 12px;
}

.collection + .collection {
  margin-top: 28px;
}

.collection h3 {
  margin-bottom: 12px;
}

.hidden {
  display: none;
}

.empty {
  grid-column: 1 / -1;
  padding: 32px 0;
  color: var(--muted);
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 40px 1fr;
  }

  .actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .auth-form {
    grid-template-columns: 1fr;
  }

  .reader-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 20px;
  }

  .library {
    grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
    gap: 16px;
  }
}
