/* Flexoki Light Theme */
:root {
  --paper: #FFFCF0;
  --base-50: #F2F0E5;
  --base-100: #E6E4D9;
  --base-150: #DAD8CE;
  --base-200: #CECDC3;
  --base-300: #B7B5AC;

  --tx: #100F0F;
  --tx-2: #6F6E69;
  --tx-3: #878580;

  --red: #AF3029;
  --orange: #BC5215;
  --yellow: #AD8301;
  --green: #66800B;
  --cyan: #24837B;
  --blue: #205EA6;
  --purple: #5E409D;
  --magenta: #A02F6F;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(16, 15, 15, 0.06), 0 1px 2px rgba(16, 15, 15, 0.04);
  --shadow-lg: 0 4px 12px rgba(16, 15, 15, 0.08), 0 2px 4px rgba(16, 15, 15, 0.04);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 17px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--tx);
  line-height: 1.6;
  min-height: 100vh;
}

/* Color utility classes (for ASCII art in HTML) */
.c-red { color: var(--red); }
.c-orange { color: var(--orange); }
.c-yellow { color: var(--yellow); }
.c-green { color: var(--green); }
.c-cyan { color: var(--cyan); }
.c-blue { color: var(--blue); }
.c-purple { color: var(--purple); }
.c-magenta { color: var(--magenta); }

/* Header */

#header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--base-100);
}

#header-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--tx);
}

.header-spacer {
  flex: 1;
}

.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--base-150);
  border-radius: var(--radius);
  background: var(--base-50);
  color: var(--tx-2);
  cursor: pointer;
  transition: all 0.15s ease;
}

.back-btn:hover {
  background: var(--base-100);
  color: var(--tx);
}

.back-btn.visible {
  display: flex;
}

/* Rules Button in Header */

.rules-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--base-150);
  border-radius: var(--radius);
  background: var(--base-50);
  color: var(--tx-2);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.rules-btn:hover {
  background: var(--base-100);
  color: var(--tx);
  border-color: var(--base-200);
}

.rules-btn.hidden {
  display: none;
}

/* Views */

.view {
  max-width: 1200px;
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

/* Library */

.library-intro {
  text-align: center;
  padding: 48px 24px 32px;
}

.ascii-hero {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--purple);
  margin-bottom: 16px;
  display: inline-block;
}

.library-subtitle {
  color: var(--tx-2);
  font-size: 1rem;
}

.adventures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  padding: 0 24px 48px;
}

/* Adventure Card */

.adventure-card {
  background: var(--base-50);
  border: 1px solid var(--base-100);
  border-radius: var(--radius-lg);
  padding: 28px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.adventure-card:hover {
  border-color: var(--base-200);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-ascii-icon {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--purple);
  margin-bottom: 12px;
  background: none !important;
  border: none !important;
  padding: 0 !important;
}

.card-ascii-icon code {
  background: none !important;
  padding: 0 !important;
  color: inherit;
}

.adventure-card h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--tx);
}

.adventure-card .card-description {
  color: var(--tx-2);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 16px;
}

.adventure-card .card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--tx-3);
}

.card-meta .tag {
  background: var(--base-100);
  padding: 3px 10px;
  border-radius: 20px;
}

/* Adventure View */

.adventure-layout {
  display: flex;
  min-height: calc(100vh - 65px);
}

/* Chapter Sidebar (left) */

.chapter-sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--base-100);
  padding: 20px 0;
  overflow-y: auto;
  height: calc(100vh - 65px);
  position: sticky;
  top: 65px;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.88rem;
  color: var(--tx-2);
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}

.chapter-item:hover {
  background: var(--base-50);
  color: var(--tx);
}

.chapter-item.active {
  background: var(--base-100);
  color: var(--tx);
  font-weight: 500;
}

.chapter-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--base-100);
  color: var(--tx-2);
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.chapter-item.active .chapter-number {
  background: var(--purple);
  color: var(--paper);
}

.chapter-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chapter Content */

.chapter-content-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chapter-content {
  flex: 1;
  max-width: 740px;
  margin: 0 auto;
  padding: 40px 32px 24px;
  width: 100%;
}

/* Rules Drawer (right side) */

.rules-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 15, 15, 0.2);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

.rules-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 90vw;
  height: 100vh;
  background: var(--paper);
  z-index: 400;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(16, 15, 15, 0.1);
}

.rules-drawer.open {
  transform: translateX(0);
}

.rules-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--base-100);
  flex-shrink: 0;
}

.rules-drawer-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--tx);
}

.rules-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--base-150);
  border-radius: var(--radius);
  background: var(--base-50);
  color: var(--tx-2);
  cursor: pointer;
  transition: all 0.15s ease;
}

.rules-close-btn:hover {
  background: var(--base-100);
  color: var(--tx);
}

.rules-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px;
}

/* Markdown styles shared between chapter-content and rules-content */

.chapter-content h1,
.rules-content h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--tx);
  line-height: 1.3;
}

.chapter-content h2,
.rules-content h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-top: 40px;
  margin-bottom: 16px;
  color: var(--tx);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--base-100);
}

.chapter-content h3,
.rules-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 12px;
  color: var(--tx);
}

.chapter-content h4,
.rules-content h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 8px;
  color: var(--tx-2);
}

.chapter-content p,
.rules-content p {
  margin-bottom: 16px;
  color: var(--tx);
}

.chapter-content strong,
.rules-content strong {
  font-weight: 600;
}

.chapter-content em,
.rules-content em {
  font-style: italic;
}

.chapter-content ul,
.chapter-content ol,
.rules-content ul,
.rules-content ol {
  margin-bottom: 16px;
  padding-left: 24px;
}

.chapter-content li,
.rules-content li {
  margin-bottom: 6px;
}

.chapter-content hr,
.rules-content hr {
  border: none;
  height: 1px;
  background: var(--base-150);
  margin: 32px 0;
}

/* ASCII Art / Code Blocks */

.chapter-content pre,
.rules-content pre {
  background: var(--base-50);
  border: 1px solid var(--base-100);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  overflow-x: auto;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--purple);
}

.chapter-content code,
.rules-content code {
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  background: var(--base-50);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--magenta);
}

.chapter-content pre code,
.rules-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

/* Tables */

.chapter-content table,
.rules-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 0.92rem;
}

.chapter-content thead,
.rules-content thead {
  background: var(--base-50);
}

.chapter-content th,
.rules-content th {
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--base-150);
  color: var(--tx);
}

.chapter-content td,
.rules-content td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--base-100);
  color: var(--tx);
}

.chapter-content tr:last-child td,
.rules-content tr:last-child td {
  border-bottom: none;
}

/* Blockquotes */

.chapter-content blockquote,
.rules-content blockquote {
  border-left: 3px solid var(--cyan);
  background: var(--base-50);
  padding: 14px 20px;
  margin-bottom: 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--tx-2);
  font-size: 0.92rem;
}

.chapter-content blockquote p:last-child,
.rules-content blockquote p:last-child {
  margin-bottom: 0;
}

/* Chapter Navigation */

.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px 40px;
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
}

.nav-btn {
  padding: 10px 20px;
  border: 1px solid var(--base-150);
  border-radius: var(--radius);
  background: var(--base-50);
  color: var(--tx);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 500;
}

.nav-btn:hover {
  background: var(--base-100);
  border-color: var(--base-200);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-btn:disabled:hover {
  background: var(--base-50);
  border-color: var(--base-150);
}

.chapter-indicator {
  font-size: 0.82rem;
  color: var(--tx-3);
}

/* Loading */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px;
  color: var(--tx-3);
  font-size: 0.95rem;
}

/* Mobile sidebar toggle */

.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--purple);
  color: var(--paper);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

/* Responsive */

@media (max-width: 768px) {
  html {
    font-size: 16px;
  }

  #header {
    padding: 12px 16px;
  }

  .rules-btn span {
    display: none;
  }

  .rules-btn {
    padding: 8px;
  }

  .library-intro {
    padding: 32px 16px 24px;
  }

  .ascii-hero {
    font-size: 0.55rem;
  }

  .adventures-grid {
    grid-template-columns: 1fr;
    padding: 0 16px 32px;
  }

  .adventure-card {
    padding: 20px;
  }

  .adventure-layout {
    flex-direction: column;
  }

  .chapter-sidebar {
    width: 100%;
    height: auto;
    position: relative;
    top: 0;
    border-right: none;
    border-bottom: 1px solid var(--base-100);
    padding: 12px 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .chapter-sidebar.open {
    max-height: 600px;
    overflow-y: auto;
  }

  .sidebar-toggle {
    display: flex;
  }

  .chapter-content {
    padding: 24px 16px 16px;
  }

  .chapter-nav {
    padding: 16px 16px 32px;
  }

  .chapter-content h1 {
    font-size: 1.5rem;
  }

  .chapter-content h2 {
    font-size: 1.2rem;
  }

  .chapter-content pre,
  .rules-content pre {
    padding: 14px 16px;
    font-size: 0.72rem;
  }

  .rules-drawer {
    width: 100vw;
    max-width: 100vw;
  }
}
