:root {
  color-scheme: dark;
  --bg: #121417;
  --panel: #1a1d21;
  --panel-2: #20252b;
  --ink: #f6f2eb;
  --muted: #a9adb4;
  --line: #323841;
  --accent: #e05d44;
  --accent-2: #2aa198;
  --accent-3: #ffbe55;
  --danger: #ff6b70;
  --ok: #6ee7a8;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid transparent;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input,
select {
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--ink);
  background: #111317;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(42, 161, 152, 0.16);
}

.app-shell {
  width: 100vw;
  height: 100dvh;
  background:
    linear-gradient(180deg, rgba(255, 190, 85, 0.07), transparent 28%),
    var(--bg);
}

.layout {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  height: 100dvh;
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: rgba(18, 20, 23, 0.96);
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
}

.brand {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: #f2efe8;
  color: #121417;
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-scroll {
  overflow: auto;
  min-height: 0;
  padding-right: 2px;
}

.nav-title {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.nav-button,
.library-button,
.recent-button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: left;
}

.nav-button:hover,
.library-button:hover,
.recent-button:hover,
.nav-button.is-active,
.library-button.is-active {
  background: var(--panel-2);
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: #262c33;
  color: var(--accent-3);
  font-size: 14px;
  font-weight: 800;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-meta {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-foot {
  display: grid;
  gap: 8px;
  padding-top: 12px;
}

.main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: rgba(18, 20, 23, 0.86);
  backdrop-filter: blur(18px);
}

.topbar-title {
  min-width: 0;
}

.topbar h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.inline-actions,
.reader-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.content {
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.content-narrow {
  max-width: 980px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(26, 29, 33, 0.82);
  box-shadow: var(--shadow);
}

.connect-panel {
  display: grid;
  gap: 18px;
  max-width: 760px;
  padding: 18px;
}

.button {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 700;
}

.button:hover {
  border-color: #49515c;
  background: #293039;
}

.button.primary {
  border-color: rgba(224, 93, 68, 0.6);
  background: var(--accent);
  color: white;
}

.button.secondary {
  border-color: rgba(42, 161, 152, 0.58);
  color: #dff8f5;
}

.button.ghost {
  background: transparent;
}

.button.icon {
  width: 44px;
  padding: 0;
}

.status-line {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.status-line.error {
  color: var(--danger);
}

.status-line.ok {
  color: var(--ok);
}

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

.series-card,
.book-card {
  display: grid;
  grid-template-rows: auto minmax(54px, auto);
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  text-align: left;
}

.series-card:hover,
.book-card:hover {
  border-color: #4a5360;
  transform: translateY(-1px);
}

.poster {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background:
    linear-gradient(135deg, rgba(224, 93, 68, 0.25), transparent 42%),
    linear-gradient(315deg, rgba(42, 161, 152, 0.28), transparent 48%),
    #242a31;
  overflow: hidden;
}

.poster.wide {
  aspect-ratio: 16 / 10;
}

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

.poster.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(100%);
  }
}

.card-body {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.card-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.progress-track {
  height: 4px;
  overflow: hidden;
  background: #343b44;
}

.progress-bar {
  width: var(--progress, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent-3));
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 320px;
  color: var(--muted);
  text-align: center;
}

.reader {
  position: fixed;
  z-index: 50;
  inset: 0;
  overflow: hidden;
  background: var(--reader-bg, #050608);
  color: var(--ink);
}

.reader-toolbar {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 62px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.74), rgba(0, 0, 0, 0.2));
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.reader-title {
  min-width: 0;
  text-align: center;
}

.reader-title strong,
.reader-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-title span {
  color: var(--muted);
  font-size: 12px;
}

.reader-stage {
  position: absolute;
  inset: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}

.page-view {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0;
  transition: padding 0.18s ease;
}

.page-spread {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, auto);
  gap: 10px;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.page-frame {
  display: grid;
  place-items: center;
  min-width: 0;
  width: 100%;
  height: 100%;
}

.page-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
  user-select: none;
  -webkit-user-drag: none;
}

.page-image.fit-width {
  width: 100%;
  height: auto;
  max-height: none;
}

.page-image.fit-height {
  height: 100%;
  width: auto;
  max-width: none;
}

.tap-zone {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 0;
  width: 38%;
}

.tap-zone.left {
  left: 0;
}

.tap-zone.right {
  right: 0;
}

.tap-zone.center {
  left: 38%;
  right: 38%;
  width: auto;
}

.webtoon-stage {
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 0;
  transition: padding 0.18s ease;
}

.webtoon-strip {
  display: grid;
  justify-items: center;
  gap: var(--webtoon-gap, 0px);
  width: 100%;
}

.webtoon-page {
  width: min(100%, var(--webtoon-width, 980px));
  min-height: 220px;
  background: #0d0f12;
}

.webtoon-page img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.reader-footer {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0.16));
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.reader.chrome-visible .page-view {
  padding: calc(74px + env(safe-area-inset-top)) 12px calc(76px + env(safe-area-inset-bottom));
}

.reader.chrome-visible .webtoon-stage {
  padding: calc(74px + env(safe-area-inset-top)) 0 calc(86px + env(safe-area-inset-bottom));
}

.reader.chrome-hidden .reader-toolbar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-100%);
}

.reader.chrome-hidden .reader-footer {
  opacity: 0;
  pointer-events: none;
  transform: translateY(100%);
}

.reader-progress {
  display: grid;
  gap: 6px;
}

.reader-progress input {
  width: 100%;
  min-height: 28px;
  accent-color: var(--accent-2);
}

.reader-progress span {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: #20252b;
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 14px;
}

.mobile-menu {
  display: none;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(326px, 88vw);
    transform: translateX(-104%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    visibility: hidden;
    pointer-events: none;
  }

  .sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  .mobile-menu {
    display: inline-grid;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar-title {
    grid-column: auto;
  }

  .content {
    padding: 12px;
  }

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

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

  .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .reader-actions {
    max-width: 50vw;
    justify-content: flex-end;
  }

  .reader-actions select,
  .reader-actions .button:not(.icon) {
    max-width: 92px;
  }

  .reader-footer {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .page-view {
    padding: 8px;
  }
}

@media (max-width: 540px) {
  .topbar {
    min-height: 64px;
  }

  .topbar h2 {
    font-size: 17px;
  }

  .topbar-actions .button:not(.icon) {
    display: none;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .reader-actions select {
    max-width: 82px;
    padding: 0 6px;
  }

  .reader-footer .button:not(.icon) {
    display: none;
  }
}
