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

@font-face {
  font-family: 'Ravi';
  src: url('Ravi-VF.ttf') format('truetype');
}

:root {
  --theme-bg: #ffffff;
  --theme-text: #000000;
}

body {
  font-family: 'Ravi', 'Arial', sans-serif;
  background: var(--theme-bg);
  color: var(--theme-text);
  direction: rtl;
  text-align: right;
  line-height: 2;
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

/* --- Header --- */
header { border-bottom: 2px solid var(--theme-text); padding-bottom: 20px; margin-bottom: 40px; }
.header-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
header h1 { font-size: 2.5em; margin-bottom: 10px; color: var(--theme-text); }
header h1 a { color: var(--theme-text); text-decoration: none; }
header h1 a:hover { text-decoration: underline; }
.subtitle { font-size: 1.1em; color: var(--theme-text); opacity: 0.8; }

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  position: relative;
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: 1px solid var(--theme-text);
  border-radius: 4px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--theme-text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  opacity: 0.7;
}
.theme-toggle:hover {
  opacity: 1;
  background-color: color-mix(in srgb, var(--theme-text) 10%, transparent);
}

/* Color picker */
.color-picker {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 10px;
  background: var(--theme-bg);
  border: 1px solid var(--theme-text);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--theme-text) 20%, transparent);
  z-index: 1000;
  min-width: 200px;
  opacity: 0.95;
}

.color-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-align: right;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  color: inherit;
  font-family: inherit;
  font-size: 0.95em;
}

.color-option:hover {
  background-color: color-mix(in srgb, var(--theme-text) 10%, transparent);
}

.color-option.active {
  background-color: color-mix(in srgb, var(--theme-text) 15%, transparent);
  border-color: var(--theme-text);
}

.color-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  display: block;
}

.color-label {
  flex: 1;
}

.favorites-link {
  color: var(--theme-text);
  text-decoration: none;
  font-size: 0.95em;
  padding: 6px 12px;
  border: 1px solid var(--theme-text);
  border-radius: 4px;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
  opacity: 0.7;
}
.favorites-link:hover {
  opacity: 1;
  background-color: color-mix(in srgb, var(--theme-text) 10%, transparent);
}

/* --- Main / breadcrumb --- */
main { min-height: 60vh; }
.breadcrumb { margin-bottom: 30px; font-size: 0.95em; color: var(--theme-text); opacity: 0.7; }
.breadcrumb a { color: var(--theme-text); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; opacity: 1; }
.breadcrumb span { margin: 0 8px; }

/* --- Index page styles --- */
.poet-section {
  margin-bottom: 50px;
}
.poet-name {
  font-size: 1.8em;
  margin-bottom: 20px;
  color: var(--theme-text);
}
.book-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
}
.book-card {
  display: block;
  padding: 18px 22px;
  border: 1px solid color-mix(in srgb, var(--theme-text) 20%, transparent);
  border-radius: 10px;
  text-decoration: none;
  color: var(--theme-text);
  min-width: 220px;
  flex: 1 1 220px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 18px color-mix(in srgb, var(--theme-text) 15%, transparent);
  border-color: var(--theme-text);
}
.book-card__title {
  font-size: 1.15em;
  margin-bottom: 8px;
}
.book-card__meta {
  font-size: 0.85em;
  opacity: 0.65;
  margin: 0;
}

/* --- Book (sections) page --- */
.book {
  margin-bottom: 40px;
}
.book h2 {
  font-size: 1.8em;
  margin-bottom: 12px;
  color: var(--theme-text);
}
.book .poet {
  color: var(--theme-text);
  opacity: 0.7;
  margin-bottom: 24px;
  font-size: 0.95em;
}
.section-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.section-item a {
  display: block;
  padding: 10px 14px;
  border-radius: 6px;
  color: var(--theme-text);
  text-decoration: none;
  background-color: color-mix(in srgb, var(--theme-text) 6%, transparent);
  transition: background-color 0.15s ease;
}
.section-item a:hover {
  background-color: color-mix(in srgb, var(--theme-text) 12%, transparent);
}

/* --- Poem --- */
.poem { margin-top: 40px; }
.poem h2 { font-size: 2em; margin-bottom: 35px; color: var(--theme-text); }

.couplets { 
  max-width: 800px; 
  margin: 0 auto;
  padding-right: 50px; /* Space for star button on desktop */
}

/* ======= REVERTED ALIGNMENT: original two-verse layout ======= */
.couplet {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2em;
  gap: 30px;
  /* keep full width and natural sizing */
  width: 100%;
  box-sizing: border-box;
  position: relative;
}

/* Favorite star button */
.favorite-btn {
  position: absolute;
  right: -40px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}
.favorite-btn:hover {
  opacity: 0.8;
  transform: translateY(-50%) scale(1.1);
}
.favorite-btn.favorited {
  opacity: 1;
}
.favorite-btn:active {
  transform: translateY(-50%) scale(0.95);
}
.star-icon {
  width: 24px;
  height: 24px;
  color: #999;
  stroke: #999;
  stroke-width: 1.5;
  fill: none;
  transition: fill 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              stroke 0.3s ease,
              transform 0.2s ease;
}
.star-icon path {
  fill: none;
  transition: fill 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.favorite-btn.favorited .star-icon {
  color: #999;
  stroke: #999;
}
.favorite-btn.favorited .star-icon path {
  fill: #999;
}
.favorite-btn:hover .star-icon {
  color: #777;
  stroke: #777;
}
.favorite-btn.favorited:hover .star-icon {
  color: #777;
  stroke: #777;
}
.favorite-btn.favorited:hover .star-icon path {
  fill: #777;
}

/* Hide favorite buttons during selection mode */
body.selecting-mode .favorite-btn {
  display: none;
}

/* Each verse uses natural flow (no fixed widths), justified text like original */
.verse {
  font-size: 1.3em;
  line-height: 2.5;
  margin: 0;
  text-align: justify;          /* justify the lines */
  text-align-last: center;     /* center last line */
  hyphens: auto;
}

/* explicit directions like the original */
.verse-first { text-align: right; }
.verse-second { text-align: left; }

/* --- Controls (buttons) --- */
.screenshot-controls { display: flex; gap: 10px; margin-bottom: 25px; }
.screenshot-controls button {
  background: var(--theme-bg);
  border: 1.5px solid var(--theme-text);
  color: var(--theme-text);
  padding: 10px 18px;
  font-family: inherit;
  font-size: 0.95em;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  min-width: 120px;
}

/* Floating done button */
#finish-selection {
  background: var(--theme-text);
  color: var(--theme-bg);
  position: fixed;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--theme-text) 30%, transparent);
}

/* --- Selection visuals (only on page, not in screenshot) --- */
.couplet.selectable {
  border: 2px dotted #bbb;
  border-radius: 10px;
  padding: 5px;
  outline-offset: 6px;
  transition: border-color 0.18s ease, background 0.18s ease;
  cursor: pointer;
}
.couplet.selectable:hover { border-color: #999; }

.couplet.selected {
  outline: 1px solid rgba(0,0,0,0.08);
  background: #dbdbdb; /* keep white */
  border-radius: 10px;
}

/* --- Hint text --- */
.selection-hint {
  text-align: center;
  color: var(--theme-text);
  font-size: 0.95em;
  margin-bottom: 20px;
  background: color-mix(in srgb, var(--theme-text) 5%, transparent);
  padding: 8px 15px;
  border-radius: 6px;
  display: inline-block;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.selection-hint.fade-in { opacity: 1; }
.selection-hint.fade-out { opacity: 0; }

/* --- Screenshot container (offscreen, dynamic size) --- */
.screenshot-container {
  position: fixed;
  top: -10000px;    /* offscreen */
  right: 0;
  background: #fff;
  padding: 60px 40px;
  font-family: 'Ravi', sans-serif;
  display: inline-block;            /* shrink to content (dynamic) */
  text-align: center;
  color: #000;
  overflow: visible;
  box-shadow: none;
}

/* Ensure inside screenshot couplets keep the same original layout (no borders, no padding from selection) */
.screenshot-container .couplet {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 30px;
  margin-bottom: 1.5em;
  border: none !important;     /* remove any selection borders */
  background: transparent !important;
  padding: 0 !important;
}

.screenshot-container .verse {
  font-size: 1.3em;
  line-height: 2.5;
  margin: 0;
  text-align: justify;
  text-align-last: center;
  hyphens: auto;
  color: #000;
}

/* Footer in screenshot */
.screenshot-footer {
  margin-top: 40px;
  border-top: 1px solid #eee;
  padding-top: 10px;
  font-size: 0.9em;
  color: #555;
  text-align: left;
}
.screenshot-footer .poet-name {
  font-weight: bold;
  margin-bottom: 4px;
}

/* --- Responsive: on small screens keep readable stacked view on page ---- */
@media (max-width: 600px) {
  body { padding: 15px; }
  header h1 { font-size: 2em; }
  .poem h2 { font-size: 1.5em; }

  /* keep on-page couplets stacked (original behavior) */
  .couplet { flex-direction: column; gap: 0; }
  .verse { text-align: center; }

  .screenshot-container .couplet {
    flex-direction: column;
    margin-bottom: 4em; /* 👈 more space between couplets */
  }

  .screenshot-container .verse {
    text-align: justify;
    text-align-last: center;
    line-height: 2;
  }

  .screenshot-container .verse + .verse {
    margin-top: 0.2em; /* 👈 small gap between the two verses inside each couplet */
  }
  
  /* Mobile: adjust couplets container and star positioning */
  .couplets {
    padding-right: 0; /* No extra padding on mobile */
  }
  
  .couplet {
    padding-right: 45px; /* Make room for star button to sit outside text */
  }
  
  .favorite-btn {
    position: absolute;
    right: 0; /* Position just outside the text area */
    top: 25px;
    transform: none;
    padding: 10px 8px;
  }
  .favorite-btn:hover {
    transform: scale(1.1);
  }
  .favorite-btn:active {
    transform: scale(0.95);
  }
  
  .header-content {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
    margin-top: 10px;
  }
  .color-picker {
    left: auto;
    right: 0;
  }
}

/* --- Favorites page --- */
main h2 {
  font-size: 2em;
  margin-bottom: 30px;
}
#favorites-container {
  margin-top: 30px;
}
.favorite-card {
  border: 1px solid var(--theme-text);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  background: var(--theme-bg);
  transition: box-shadow 0.2s ease;
  opacity: 0.8;
}
.favorite-card:hover {
  box-shadow: 0 2px 8px color-mix(in srgb, var(--theme-text) 15%, transparent);
  opacity: 1;
}
.favorite-title {
  font-size: 1.3em;
  margin-bottom: 12px;
  color: var(--theme-text);
}
.favorite-couplet {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 30px;
  margin-bottom: 15px;
}
.favorite-couplet .verse {
  font-size: 1.2em;
  line-height: 2.2;
  margin: 0;
  text-align: justify;
  text-align-last: center;
}
.favorite-couplet .verse-first {
  text-align: right;
}
.favorite-couplet .verse-second {
  text-align: left;
}
.favorite-meta {
  font-size: 0.9em;
  color: var(--theme-text);
  opacity: 0.7;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.favorite-meta .poet-name {
  font-weight: 500;
}
.favorite-meta .separator {
  opacity: 0.5;
}
.favorite-link {
  color: var(--theme-text);
  text-decoration: none;
  font-size: 0.9em;
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--theme-text);
  border-radius: 4px;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  opacity: 0.7;
}
.favorite-link:hover {
  opacity: 1;
  background-color: color-mix(in srgb, var(--theme-text) 10%, transparent);
}

@media (max-width: 600px) {
  .favorite-couplet {
    flex-direction: column;
    gap: 10px;
  }
  .favorite-couplet .verse {
    text-align: center;
  }
}

/* Poem navigation */
.poem-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 40px;
  margin-bottom: 30px;
}
.poem-nav__link {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--theme-text) 25%, transparent);
  border-radius: 10px;
  text-decoration: none;
  color: var(--theme-text);
  gap: 6px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  min-width: 0;
}
.poem-nav__link--next {
  align-items: flex-end;
  text-align: left;
}
.poem-nav__link:hover {
  transform: translateY(-3px);
  border-color: var(--theme-text);
  box-shadow: 0 6px 14px color-mix(in srgb, var(--theme-text) 12%, transparent);
}
.poem-nav__primary {
  font-size: 1em;
  font-weight: 600;
}
.poem-nav__secondary {
  font-size: 0.9em;
  opacity: 0.75;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

@media (max-width: 600px) {
  .poem-nav {
    flex-direction: column;
  }
  .poem-nav__link,
  .poem-nav__link--next {
    align-items: center;
    text-align: center;
  }
  .poem-nav__secondary {
    width: 100%;
  }
}
