* {
  box-sizing: border-box;
}

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1d2430;
  --panel-3: #111823;
  --border: #2a3140;
  --text: #e6edf3;
  --muted: #9aa4b2;
  --accent: #ffd369;
  --accent-2: #f7b801;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  --radius: 20px;
}

html,
body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #0d1117 0%, #0a0f14 100%);
  color: var(--text);
  font-family: Arial, sans-serif;
}

body {
  min-height: 100vh;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* OVERLAY */
.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  transition: 0.25s ease;
}

.mobile-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* SIDEBAR */
.sidebar {
  width: 360px;
  background: rgba(22, 27, 34, 0.98);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  backdrop-filter: blur(10px);
  z-index: 100;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  margin-bottom: 18px;
}

.brand h1 {
  margin: 0 0 6px;
  font-size: 28px;
  color: var(--accent);
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

#searchInput {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #0f141b;
  color: var(--text);
  outline: none;
  margin: 18px 0 20px;
  font-size: 15px;
  transition: 0.2s ease;
}

#searchInput:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(247, 184, 1, 0.12);
}

.story-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* STORY CARD */
.story-card {
  background: linear-gradient(180deg, var(--panel-2) 0%, #1a2130 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.story-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.story-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.story-arrow {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #101720;
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 14px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.story-card.open .story-arrow {
  transform: rotate(90deg);
}

.story-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--accent);
  line-height: 1.45;
  word-break: break-word;
}

.story-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-3);
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.chapter-list {
  margin-top: 14px;
  display: none;
  animation: fadeSlide 0.2s ease;
}

.story-card.open .chapter-list {
  display: block;
}

.chapter-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  margin-bottom: 8px;
  background: #101720;
  border: 1px solid #2b3545;
  color: var(--text);
  border-radius: 14px;
  cursor: pointer;
  transition: 0.2s ease;
  font-size: 14px;
  line-height: 1.55;
}

.chapter-btn:hover {
  background: #16202d;
}

.chapter-btn.active {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, #1b2633 0%, #1a2330 100%);
  box-shadow: 0 0 0 2px rgba(247, 184, 1, 0.1);
}

/* MAIN */
.main {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.topbar h2,
.mobile-header h2 {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 30px;
  line-height: 1.25;
}

.topbar p,
.mobile-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.nav-buttons,
.mobile-nav-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.nav-buttons button,
.mobile-nav-buttons button,
.pagination-box button,
.icon-btn {
  padding: 11px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #1a202b 0%, #151b24 100%);
  color: var(--text);
  cursor: pointer;
  transition: 0.2s ease;
  font-size: 14px;
}

.nav-buttons button:hover:not(:disabled),
.mobile-nav-buttons button:hover:not(:disabled),
.pagination-box button:hover:not(:disabled),
.icon-btn:hover {
  border-color: var(--accent-2);
}

.nav-buttons button:disabled,
.mobile-nav-buttons button:disabled,
.pagination-box button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* READER */
.reader {
  background: linear-gradient(180deg, #161b22 0%, #121821 100%);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 34px 30px;
  min-height: 60vh;
  box-shadow: var(--shadow);
}

.reader-content {
  font-size: 18px;
  line-height: 2.05;
  color: var(--text);
}

.reader-content p {
  margin: 0 0 1.35em;
  text-align: justify;
}

.reader-content p:last-child {
  margin-bottom: 0;
}

.empty-reader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 45vh;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  font-size: 44px;
  margin-bottom: 14px;
}

.empty-reader h3 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 22px;
}

.empty-reader p {
  margin: 0;
  max-width: 420px;
  line-height: 1.7;
}

.empty-state {
  color: var(--muted);
  padding: 20px 0;
}

.pagination-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

#storyPageInfo {
  color: var(--muted);
  font-size: 14px;
}

.footer-note {
  margin-top: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

/* MOBILE HEADER */
.mobile-header {
  display: none;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.mobile-header-text {
  min-width: 0;
}

.mobile-header h2 {
  font-size: 22px;
  margin-bottom: 6px;
}

.mobile-header p {
  font-size: 14px;
}

.mobile-nav-buttons {
  display: none;
  margin-top: 18px;
}

.mobile-nav-buttons button {
  flex: 1;
}

.mobile-only {
  display: none;
}

/* ANIMATION */
@keyframes fadeSlide {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* MOBILE */
@media (max-width: 980px) {
  .app {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(88vw, 360px);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 0.28s ease;
    border-right: 1px solid var(--border);
    border-bottom: none;
    box-shadow: var(--shadow);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .main {
    padding: 16px;
  }

  .desktop-topbar {
    display: none;
  }

  .mobile-header {
    display: flex;
  }

  .mobile-nav-buttons {
    display: flex;
  }

  .mobile-only {
    display: inline-flex;
  }

  .reader {
    padding: 22px 18px;
    border-radius: 22px;
    min-height: 58vh;
  }

  .reader-content {
    font-size: 17px;
    line-height: 2;
  }

  .reader-content p {
    text-align: left;
  }

  .brand h1 {
    font-size: 24px;
  }

  .story-title {
    font-size: 15px;
  }

  .chapter-btn {
    font-size: 14px;
    padding: 12px 13px;
  }

  .pagination-box {
    flex-wrap: wrap;
  }

  .pagination-box button {
    flex: 1;
  }

  .icon-btn {
    min-width: 46px;
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}