:root {
  --bg: #f7f4ef;
  --bg-card: #fff;
  --text: #1a1a1a;
  --muted: #6b6560;
  --accent: #2d6a4f;
  --accent-light: #d8f3dc;
  --border: #e8e2d9;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  --topbar-h: 56px;
  --font-serif: "Souvenir", Georgia, "Times New Roman", serif;
  --font-arabic: "ShaikhHamdullahMushaf", "UthmanTaha", serif;
  --font-osmanlica: "hasenat", serif;
  --reader-scale: 1;
  --page-bg: #fbf0cb;
  --page-text: rgba(0, 0, 0, 0.87);
  --page-accent: rgba(0, 0, 0, 0.87);
  --menu-bg: #5c3d2e;
  --oku-menu-h: 56px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  line-height: 1.65;
}

.hidden { display: none !important; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
}

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

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar p {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.85;
}

.icon-btn {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.search-panel {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.search-panel input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.search-results {
  max-height: 280px;
  overflow-y: auto;
  margin-top: 8px;
}

.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
}

.search-hit strong {
  display: block;
  color: var(--text);
}

.search-hit span {
  font-size: 0.8rem;
  color: var(--muted);
}

.search-hit:hover {
  background: var(--accent-light);
}

#main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
}

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #40916c 100%);
  color: #fff;
  padding: 28px 24px;
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.hero-tag {
  font-size: 0.75rem;
  opacity: 0.9;
  margin: 0 0 8px;
}

.hero h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.hero p {
  margin: 0;
  opacity: 0.9;
}

.nesriyat-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nesriyat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
}

.nesriyat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.nesriyat-logo {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.nesriyat-card strong {
  display: block;
  font-size: 1rem;
}

.nesriyat-card span {
  font-size: 0.8rem;
  color: var(--muted);
}

.shelf {
  margin-bottom: 32px;
}

.shelf-header h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  color: var(--accent);
}

.shelf-header p {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

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

.book-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  position: relative;
  transition: transform 0.15s;
}

.book-card:hover {
  transform: scale(1.03);
  border-color: var(--accent);
}

.book-cover {
  width: 64px;
  height: 88px;
  border-radius: 4px 8px 8px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 1.4rem;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
}

.book-cover-img {
  width: 64px;
  height: 88px;
  object-fit: cover;
  border-radius: 4px 8px 8px 4px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.15);
}

.book-cover.fallback {
  display: flex;
}

.book-name {
  font-size: 0.75rem;
  text-align: center;
  line-height: 1.3;
  color: var(--text);
}

.book-progress {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.65rem;
  background: var(--accent-light);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
}

#main {
  flex: 1;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
}

#view-reader {
  padding: 0 !important;
  max-width: 100% !important;
}

#main.reader-active {
  padding: 0;
  max-width: 100%;
}

#view-reader:not(.hidden) {
  display: block;
  min-height: calc(100vh - var(--topbar-h));
}

#view-home #main,
#view-shelves {
  max-width: 960px;
  margin: 0 auto;
}

/* --- Risaleoku reader layout --- */
.reader-layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
  position: relative;
}

.reader-center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--oku-menu-h);
  align-items: center;
  background: #e8e0d0;
}

.okucerceve {
  flex: 1;
  width: 100%;
  max-width: 900px;
  font-family: Souvenir, var(--font-serif);
  min-height: calc(100vh - var(--topbar-h) - var(--oku-menu-h));
  padding: 40px 50px 60px;
  background: var(--page-bg);
  color: var(--page-text);
  box-shadow: 0 0 13px rgba(74, 3, 3, 0.84);
  text-align: justify;
  font-size: calc(19px * var(--reader-scale));
  line-height: calc(1.3 * var(--reader-scale));
  overflow-y: auto;
  transition: background 0.25s, color 0.25s;
}

.okucerceve.page-mode {
  overflow-y: auto;
}

.okucerceve.page-mode .page-marker {
  display: none;
}

#btn-read-mode.active,
#btn-tefekkur.active {
  background: rgba(255, 181, 0, 0.2) !important;
  border-color: #ffb500 !important;
}

#oku_menusu {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--oku-menu-h);
  background: #f4f4f4;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 100;
  padding: 6px 12px;
  flex-wrap: wrap;
}

.zoom-controls {
  display: inline-flex;
  gap: 6px;
}

.zoom-btn {
  padding: 8px 10px;
  font-size: 15px;
  border: none;
  border-radius: 6px;
  background: #f3f3f5;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.zoom-btn:hover {
  background: #e7e7ea;
}

.nav-circle.ui.button {
  background: #fff !important;
}

.sh_label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: rgba(0, 0, 0, 0.6);
  font-size: 16px;
  margin: 0 6px;
}

.page-input-wrap.ui.input {
  width: 56px !important;
}

.page-input-wrap input {
  text-align: center !important;
  padding: 8px !important;
}

#oku_menusu_butonlar {
  display: inline-flex;
  gap: 6px;
  margin-left: 8px;
}

#oku_menusu_butonlar .ui.basic.button {
  font-size: 14px !important;
  padding: 10px 12px !important;
}

#oku_menusu_butonlar .ui.basic.button.active,
#btn-tefekkur.active {
  background: #fff3cd !important;
  border-color: #ffb500 !important;
}

#btn-tefekkur .icon {
  color: #ffb500;
}

/* Side menus */
.side-menu {
  width: 260px;
  flex-shrink: 0;
  background: linear-gradient(180deg, #6b4423 0%, #4a2f1a 100%);
  color: #fff;
  position: relative;
  z-index: 20;
}

.side-menu.hidden {
  display: none;
}

.side-menu-inner {
  padding: 16px 12px;
  height: 100%;
  overflow-y: auto;
}

.side-menu-inner h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: #ffd100;
}

.side-tab {
  position: absolute;
  right: -28px;
  top: 56px;
  width: 28px;
  height: 56px;
  border: none;
  background: #6b4423;
  color: #ffd100;
  cursor: pointer;
  border-radius: 0 6px 6px 0;
}

.side-menu-right {
  position: fixed;
  right: 0;
  top: var(--topbar-h);
  bottom: var(--oku-menu-h);
  width: 52px;
  background: linear-gradient(180deg, #6b4423 0%, #4a2f1a 100%);
  z-index: 90;
  transition: width 0.2s;
  overflow: hidden;
}

.side-menu-right.open {
  width: 220px;
}

.side-tab-right {
  position: absolute;
  left: 0;
  top: 56px;
  width: 52px;
  height: 56px;
  border: none;
  background: transparent;
  color: #ffd100;
  cursor: pointer;
  font-size: 1.2rem;
}

.side-menu-right.open .side-tab-right i {
  transform: rotate(180deg);
}

#sagmenuic {
  padding-top: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.side-menu-right.open #sagmenuic {
  opacity: 1;
  pointer-events: auto;
}

.sagmenu-list {
  list-style: none;
  margin: 0;
  padding: 0 0 0 52px;
}

.sagmenu-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 15px;
}

.sagmenu-list li:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sagmenu-list li i {
  color: #ffd100;
  width: 22px;
}

.fihrist-tree button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  color: #fff;
}

.fihrist-tree button:hover {
  color: #ffd100;
}

.fihrist-root {
  font-weight: 600;
  color: #ffd100 !important;
}

/* Lugat / meal popups (risaleoku style) */
#markmenu {
  position: fixed;
  background: #f5f5f5;
  border: 1px solid #dcdcdc;
  border-radius: 5px;
  padding: 4px 8px;
  cursor: pointer;
  z-index: 9999;
  font-size: 12px;
  font-weight: 700;
}

#lugat-popup {
  position: fixed;
  display: none;
  background: #fff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.35);
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  color: #765c5c;
  z-index: 9998;
  max-width: 320px;
}

#lugat-popup:before {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  transform: rotate(225deg);
  top: -5px;
  left: 50%;
  margin-left: -5px;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2);
}

.lugat-popup-inner {
  padding: 12px 14px;
  max-height: 360px;
  overflow: auto;
}

#meal-popup {
  position: fixed;
  display: none;
  background: #fff8e7;
  border: 1px solid #d4a574;
  border-radius: 6px;
  padding: 10px 14px;
  max-width: 360px;
  font-style: italic;
  color: #5c4033;
  z-index: 9998;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Theme panel */
.theme-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-panel-inner {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  width: min(360px, 90vw);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.theme-panel-inner h3 {
  margin: 0 0 14px;
}

.theme-swatches {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.theme-swatch {
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 16px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  text-align: center;
}

.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

/* Tefekkür — risaleoku segment renkleri */
.tefekkur-chunk {
  border-radius: 2px;
  padding: 0 1px;
}

body.tefekkur-on .book-para b,
body.tefekkur-on .book-para strong {
  color: inherit;
}

.arapca {
  font-family: ShaikhHamdullahMushaf, var(--font-arabic);
  direction: rtl;
  position: relative;
  text-align: center;
  color: red;
  margin: 0.75em 0 1em;
  display: block;
  font-size: calc(30px * var(--reader-scale));
  line-height: calc(1.65 * var(--reader-scale));
  padding: 0.2em 0 0.35em;
}

.arapca_ic {
  border-bottom: 1px dotted #c0392b;
  line-height: inherit;
}

.arapca_ikon {
  margin-right: 14px;
  padding-right: 15px;
  background: url("../assets/meal.png") no-repeat center;
  background-size: contain;
  width: 33px;
  height: 17px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.barla {
  font-family: barla, var(--font-osmanlica);
  text-align: center;
  display: block;
  font-size: calc(70px * var(--reader-scale));
  line-height: calc(1.3 * var(--reader-scale));
  margin-top: 27px;
  color: var(--page-text);
}

.ortali {
  text-align: center;
  display: block;
  font-weight: bold;
  font-size: calc(22px * var(--reader-scale));
  line-height: calc(1.3 * var(--reader-scale));
  color: var(--page-text);
}

.kalin1 {
  margin-bottom: -45px;
  display: block;
  font-weight: bold;
  font-size: calc(18px * var(--reader-scale));
  line-height: calc(1.3 * var(--reader-scale));
  color: var(--page-text);
}

.term,
.lugat-word {
  cursor: help;
  color: inherit;
  font-weight: 700;
  border-bottom: 1px dotted rgba(0, 0, 0, 0.25);
}

#selection-menu {
  position: fixed;
  z-index: 1200;
  display: flex;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

#selection-menu.hidden {
  display: none;
}

#selection-menu button {
  border: none;
  background: #fff;
  color: #333;
  padding: 0.55rem 0.9rem;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

#selection-menu button:hover {
  background: #f5f5f5;
}

#selection-menu button + button {
  border-left: 1px solid #eee;
}

.lugat-word,
.term {
  cursor: help;
}

.book-heading {
  font-size: calc(1.5rem * var(--reader-scale));
  text-align: center;
  color: var(--page-accent);
  margin: 16px 0;
  font-weight: 700;
}

.book-subheading {
  font-size: calc(1.05rem * var(--reader-scale));
  text-align: center;
  color: var(--page-text);
  opacity: 0.75;
  margin: 8px 0 20px;
}

.book-label {
  font-size: calc(0.95rem * var(--reader-scale));
  color: var(--page-accent);
  margin: 20px 0 8px;
  font-weight: 600;
}

.book-para {
  text-indent: 1.5em;
  margin: 0 0 10px;
}

.page-marker {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin: 24px 0 16px;
  padding: 4px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
  .okucerceve {
    padding: 24px 16px 48px;
  }

  #oku_menusu_butonlar {
    display: none;
  }

  .side-menu {
    position: fixed;
    left: 0;
    top: var(--topbar-h);
    bottom: var(--oku-menu-h);
    z-index: 80;
  }
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 12px;
}

.error {
  background: #fee;
  border: 1px solid #fcc;
  padding: 16px;
  border-radius: 8px;
  color: #900;
}

.book-note {
  font-size: 0.9rem;
  opacity: 0.75;
  margin: 8px 0;
}

.book-divider {
  border: none;
  border-top: 1px dashed rgba(0, 0, 0, 0.15);
  margin: 20px 0;
}

.quote {
  font-style: italic;
}
