/* ===== ROOT & RESET ===== */

:root {
  --base-font-size: 16px;

  --bg-body: #050608;
  --bg-elevated: #111319;
  --bg-elevated-soft: #151822;
  --text-main: #f5f5f7;
  --text-muted: #9ca0af;
  --accent: #ffb74d;
  --accent-soft: rgba(255, 183, 77, 0.16);
  --accent-strong: #ff9800;
  --border-subtle: rgba(255, 255, 255, 0.06);

  --nav-width: 270px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--base-font-size);
}

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

/* ===== THEME VARIANTS ===== */

body.theme-light {
  --bg-body: #f4f5f9;
  --bg-elevated: #ffffff;
  --bg-elevated-soft: #f0f1f7;
  --text-main: #111318;
  --text-muted: #646978;
  --border-subtle: rgba(0, 0, 0, 0.06);
}

body.theme-dark {
  --bg-body: #050608;
}

body.theme-warm {
  --bg-body: #1c1511;
  --bg-elevated: #241812;
  --bg-elevated-soft: #2b1d15;
  --accent: #ffcc80;
  --accent-soft: rgba(255, 204, 128, 0.2);
  --accent-strong: #ffb74d;
}

/* ===== APP LAYOUT ===== */

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

/* Header */

.app-header {
  padding: 0.8rem 1.4rem 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(4, 6, 10, 0.96);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

body.theme-light .app-header {
  background: rgba(245, 245, 250, 0.94);
}

.app-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.app-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.app-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.app-header-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
}

.toggle-group {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.18rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
}

.toggle-group-label {
  font-size: 0.75rem;
  padding-inline: 0.45rem 0.25rem;
  color: var(--text-muted);
}

.toggle-group button {
  border: none;
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  font-size: 0.75rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle-group button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.font-size-control {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
}

.font-size-control input[type="range"] {
  width: 90px;
}

/* Tabs + TTS row */

.app-header-bottom {
  margin-top: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.section-tabs {
  display: inline-flex;
  gap: 0.25rem;
  border-radius: 999px;
  padding: 0.2rem;
  background: rgba(255, 255, 255, 0.04);
}

.section-tabs button {
  border-radius: 999px;
  border: none;
  padding: 0.3rem 0.9rem;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
}

.section-tabs button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tts-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tts-controls button {
  border-radius: 999px;
  border: none;
  padding: 0.22rem 0.5rem;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
}

.tts-controls button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

/* Main area */

.app-main {
  flex: 1;
  display: flex;
  gap: 0.9rem;
  padding: 0.9rem 1.4rem 1.4rem;
}

.nav-panel {
  width: var(--nav-width);
  min-width: 230px;
  max-width: 310px;
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.content-panel {
  flex: 1;
  background: var(--bg-elevated-soft);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

/* Nav panel */

.nav-panel-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

#navPanelTitle {
  font-size: 0.85rem;
  font-weight: 600;
}

#navToolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

#storySearch {
  flex: 1;
  font-size: 0.76rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
  color: var(--text-main);
}

#storySearch::placeholder {
  color: var(--text-muted);
}

#partFilter {
  font-size: 0.76rem;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
  color: var(--text-main);
}

.nav-panel-body {
  flex: 1;
  overflow-y: auto;
}

/* Story list generic */

#storyList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.story-item {
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}

.story-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.story-item.active {
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px rgba(255, 183, 77, 0.4);
}

.story-item-part {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.story-item-title {
  margin: 0.1rem 0;
  font-size: 0.8rem;
  font-weight: 500;
}

.story-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Content panel */

.content-panel-header {
  margin-bottom: 0.5rem;
}

#slideHeading {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 600;
}

#slideMeta {
  margin-top: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.content-panel-main {
  flex: 1;
  overflow-y: auto;
}

.slide-columns {
  display: grid;
  gap: 0.75rem;
}

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

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

.slide-block {
  padding: 0.7rem 0.8rem;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

.slide-block-title {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--accent-strong);
}

.slide-text {
  font-size: 0.85rem;
  line-height: 1.9;
}

.slide-text-small {
  font-size: 0.78rem;
  line-height: 1.7;
}

.empty-placeholder {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Extra area */

#slideExtra {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border-subtle);
}

.tags-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}

.tags-row--column {
  flex-direction: column;
}

.tags-row-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  min-width: 90px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.75rem;
}

/* Story nav row */

.story-nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
  margin-top: 0.3rem;
}

/* Buttons */

.btn-primary {
  border-radius: 999px;
  border: none;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--accent-strong);
  color: #111;
}

.btn-secondary {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  background: transparent;
  color: var(--text-main);
}

.btn-ghost {
  border: none;
  background: transparent;
  cursor: pointer;
  color: inherit;
}

/* Vocab list styling */

.vocab-item {
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.vocab-item.open {
  background: rgba(255, 255, 255, 0.06);
}

.vocab-header {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0.35rem 0.55rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  color: var(--text-main);
}

.vocab-word {
  font-size: 0.85rem;
  font-weight: 500;
}

.vocab-pos {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.vocab-details {
  display: none;
  padding: 0 0.6rem 0.45rem;
  border-top: 1px solid var(--border-subtle);
}

.vocab-item.open .vocab-details {
  display: block;
}

.vocab-meaning,
.vocab-definition,
.vocab-example {
  font-size: 0.78rem;
  line-height: 1.7;
  margin-top: 0.25rem;
}

/* Word highlight for TTS */

.word-highlight {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 3px;
  padding-inline: 2px;
}

/* Muted */

.muted {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Reading overlay ===== */

.reading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.reading-overlay.visible {
  display: block;
}

.reading-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
}

.reading-overlay-panel {
  position: relative;
  max-width: 900px;
  max-height: 90vh;
  margin: 3vh auto;
  background: var(--bg-elevated-soft);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.reading-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.reading-header h2 {
  margin: 0;
  font-size: 1rem;
}

.reading-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.reading-body {
  margin-top: 0.6rem;
  margin-bottom: 0.6rem;
  overflow-y: auto;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.5rem 0.4rem 0.5rem 0.6rem;
}

.reading-text {
  font-size: 0.9rem;
  line-height: 2;
  margin-bottom: 0.7rem;
}

.reading-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.reading-footer-left,
.reading-footer-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* ===== RESPONSIVE (Mobile) ===== */

@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
    padding-inline: 0.8rem;
  }

  .nav-panel {
    width: 100%;
    max-width: 100%;
    min-height: 130px;
    max-height: 210px;
  }

  .content-panel {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .app-header {
    padding-inline: 0.8rem;
  }

  .app-header-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .app-header-controls {
    justify-content: flex-start;
  }

  .app-header-bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  /* في الموبايل: نخفي أدوات البحث/الفلترة لتصغير الشاشة */
  #navToolbar {
    display: none !important;
  }

  .nav-panel {
    min-height: auto;
    max-height: 180px;
  }

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

  .reading-overlay-panel {
    max-width: 95vw;
    margin: 2vh auto;
  }

  .reading-body {
    max-height: 60vh;
  }

  .reading-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .reading-footer-left,
  .reading-footer-right {
    justify-content: space-between;
  }
}
