/* RESET & GLOBAL - MINIMAL & CLEAN */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  transition: background-color 0.6s ease, color 0.5s ease;
  font-family: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  font-weight: 900;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0;
  line-height: 1.4;
  min-height: 100vh;
}

.main-wrapper {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 100vh;
  padding: 5rem 1.5rem;
}

.text-display {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100%;
  flex: 1 1 auto;
  padding: 2rem 0.5rem;
  margin: auto 0;
}

.quote-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.5rem 0;
  max-height: none;
  overflow: visible;
}

.persian-quote {
  font-size: clamp(2.2rem, 10vw, 5.5rem);
  font-weight: 900;
  line-height: 1.5;
  letter-spacing: -0.01em;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
  width: 100%;
  transition: opacity 0.65s ease-in-out, transform 0.5s ease;
  opacity: 1;
  transform: scale(1);
  text-rendering: optimizeLegibility;
  padding: 0.25rem 0;
  margin: 0;
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
  display: block;
  max-height: none;
  height: auto;
}

.fade-out {
  opacity: 0 !important;
  transform: scale(0.98);
}

/* THEME TOGGLE */
.theme-toggle-wrapper {
  position: fixed;
  bottom: 1.8rem;
  left: 1.8rem;
  z-index: 90;
}

#theme-toggle {
  background: transparent;
  border: 2px solid currentColor;
  border-radius: 3rem;
  padding: 0.7rem 1.8rem;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: "Vazirmatn", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(6px);
  background-color: rgba(255, 255, 255, 0.04);
  border-color: currentColor;
  color: inherit;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

#theme-toggle:hover {
  background-color: rgba(128, 128, 128, 0.08);
  transform: scale(0.97);
}

#theme-toggle img {
  filter: invert(0);
  transition: filter 0.3s ease;
}

/* SHARE COMPONENT */
.share-wrapper {
  position: fixed;
  bottom: 1.8rem;
  right: 1.8rem;
  z-index: 100;
}

.share-button {
  background: transparent;
  border: 2px solid currentColor;
  border-radius: 3rem;
  padding: 0.7rem 1.8rem;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: "Vazirmatn", sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(6px);
  background-color: rgba(255, 255, 255, 0.04);
  border-color: currentColor;
  color: inherit;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.share-button:hover {
  background-color: rgba(128, 128, 128, 0.08);
  transform: scale(0.97);
}

/* Share Menu - IMPROVED FOR LANDSCAPE & SCROLLABLE */
.share-menu {
  position: absolute;
  bottom: calc(100% + 1rem);
  right: 0;
  width: 320px;
  max-width: 90vw;
  max-height: 70vh; /* Prevent overflow in landscape */
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 1.8rem;
  padding: 1.4rem;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(128, 128, 128, 0.12);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 1;
  transform: translateY(0);
  display: flex;
  flex-direction: column;
}

.share-menu.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

.share-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.2rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: inherit;
  border-bottom: 1px solid rgba(128, 128, 128, 0.15);
  padding-bottom: 0.8rem;
  flex-shrink: 0; /* Prevent header from shrinking */
}

.close-share {
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 0.5rem;
  border-radius: 2rem;
  transition: background-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-share:hover {
  background-color: rgba(128, 128, 128, 0.1);
}

.close-share img {
  display: block;
  width: 16px;
  height: 16px;
}

.share-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto; /* Make options scrollable when needed */
  overflow-x: hidden;
  padding-right: 0.2rem;
  padding-left: 0.2rem;
  flex: 1 1 auto; /* Allow scrolling */
}

/* Custom scrollbar for share options */
.share-options::-webkit-scrollbar {
  width: 4px;
}

.share-options::-webkit-scrollbar-track {
  background: rgba(128, 128, 128, 0.05);
  border-radius: 10px;
}

.share-options::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.2);
  border-radius: 10px;
}

.share-options::-webkit-scrollbar-thumb:hover {
  background: rgba(128, 128, 128, 0.3);
}

.share-option {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-radius: 2rem;
  text-decoration: none;
  color: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: right;
  font-family: "Vazirmatn", sans-serif;
  cursor: pointer;
  flex-shrink: 0; /* Prevent options from shrinking */
}

.share-option:hover {
  background-color: rgba(128, 128, 128, 0.08);
  transform: translateX(-2px);
}

.share-option-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}

.copy-link {
  border-top: 1px solid rgba(128, 128, 128, 0.2);
  margin-top: 0.6rem;
  padding-top: 1rem;
}

.native-share {
  background-color: rgba(0, 122, 255, 0.08);
  border-radius: 2rem;
  color: #007aff;
}

.native-share:hover {
  background-color: rgba(0, 122, 255, 0.15);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 6rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 30, 30, 0.9);
  backdrop-filter: blur(8px);
  color: white;
  padding: 0.8rem 2rem;
  border-radius: 3rem;
  font-size: 0.95rem;
  font-weight: 500;
  z-index: 200;
  transition: opacity 0.3s ease;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* =========================================== */
/* DARK MODE FIXES - ALL ICONS TURN WHITE */
/* =========================================== */
body.dark .share-menu {
  background: rgba(26, 29, 33, 0.95);
  backdrop-filter: blur(20px);
  border-color: rgba(255, 255, 255, 0.1);
}

body.dark .native-share {
  background-color: rgba(10, 132, 255, 0.2);
  color: #0a84ff;
}

body.dark .toast {
  background: rgba(250, 250, 250, 0.9);
  color: #1a1d21;
}

/* CRITICAL: Force all icons to white in dark mode */
body.dark #theme-toggle img,
body.dark .share-button img,
body.dark .share-option img,
body.dark .close-share img {
  filter: brightness(0) invert(1) !important;
}

/* Override for native share icon - keep blue tint but white icon */
body.dark .native-share img {
  filter: brightness(0) invert(0.8) sepia(1) hue-rotate(180deg) !important;
}

/* LIGHT THEME */
body.light {
  background-color: #faf9f7;
  color: #1a1c1e;
}

body.light .persian-quote {
  color: #0b0c0e;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

body.light #theme-toggle,
body.light .share-button {
  color: #1e1e24;
  border-color: #2d2f33;
}

/* DARK THEME */
body.dark {
  background-color: #1a1d21;
  color: #efeeea;
}

body.dark .persian-quote {
  color: #f2efea;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
}

body.dark #theme-toggle,
body.dark .share-button {
  color: #f0ebe5;
  border-color: #b9b3a6;
}

/* =========================================== */
/* RESPONSIVE FIXES - INCLUDING LANDSCAPE */
/* =========================================== */

/* Mobile phones portrait */
@media (max-width: 600px) {
  .main-wrapper {
    padding: 5rem 1.2rem;
  }

  .persian-quote {
    font-size: clamp(2rem, 8.5vw, 3.2rem);
    line-height: 1.6;
    padding: 1rem 0;
  }

  .theme-toggle-wrapper,
  .share-wrapper {
    bottom: 1.2rem;
  }

  .theme-toggle-wrapper {
    left: 1.2rem;
  }

  .share-wrapper {
    right: 1.2rem;
  }

  #theme-toggle,
  .share-button {
    padding: 0.6rem 1.4rem;
    font-size: 0.95rem;
  }

  .share-menu {
    width: 300px;
    max-width: 85vw;
    max-height: 70vh;
    right: 0;
    padding: 1.2rem;
  }

  .toast {
    font-size: 0.85rem;
    padding: 0.7rem 1.5rem;
    white-space: normal;
    width: 80%;
    text-align: center;
  }
}

/* Very small devices */
@media (max-width: 380px) {
  .share-menu {
    width: 280px;
    max-width: 90vw;
  }

  #theme-toggle span:last-child,
  .share-button span:last-child {
    display: none;
  }

  #theme-toggle,
  .share-button {
    padding: 0.7rem;
    border-radius: 50%;
  }
}

/* =========================================== */
/* LANDSCAPE MODE FIXES - CRITICAL */
/* =========================================== */
@media (orientation: landscape) and (max-height: 600px) {
  .main-wrapper {
    padding: 3rem 1.5rem;
    min-height: 100vh;
  }

  .persian-quote {
    font-size: clamp(1.8rem, 7vw, 3.5rem);
    line-height: 1.4;
    padding: 0.5rem 0;
  }

  .text-display {
    padding: 1rem 0.5rem;
  }

  .theme-toggle-wrapper,
  .share-wrapper {
    bottom: 0.8rem;
  }

  .theme-toggle-wrapper {
    left: 0.8rem;
  }

  .share-wrapper {
    right: 0.8rem;
  }

  #theme-toggle,
  .share-button {
    padding: 0.5rem 1.2rem;
    font-size: 0.9rem;
  }

  /* CRITICAL: Share menu in landscape - make it scrollable and positioned properly */
  .share-menu {
    bottom: calc(100% + 0.8rem);
    max-height: 60vh; /* Limit height in landscape */
    width: 300px;
    padding: 1rem;
  }

  .share-options {
    max-height: calc(60vh - 4rem); /* Ensure scrolling */
    overflow-y: auto;
  }

  .share-option {
    padding: 0.5rem 0.8rem;
  }
}

/* Extra small landscape devices */
@media (orientation: landscape) and (max-height: 450px) {
  .main-wrapper {
    padding: 2rem 1rem;
  }

  .persian-quote {
    font-size: clamp(1.5rem, 6vw, 2.8rem);
    line-height: 1.3;
  }

  .theme-toggle-wrapper,
  .share-wrapper {
    bottom: 0.5rem;
  }

  .share-menu {
    max-height: 70vh;
    width: 280px;
    padding: 0.8rem;
  }

  .share-options {
    max-height: calc(70vh - 3.5rem);
  }

  .share-option {
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
  }

  .share-option-icon {
    width: 20px;
    height: 20px;
  }
}

/* Tablets and medium screens */
@media (min-width: 601px) and (max-width: 1024px) {
  .main-wrapper {
    padding: 6rem 2.5rem;
  }

  .persian-quote {
    font-size: clamp(2.8rem, 7vw, 4.5rem);
    line-height: 1.5;
  }
}

/* Large screens */
@media (min-width: 1025px) {
  .main-wrapper {
    padding: 7rem 3rem;
  }

  .persian-quote {
    font-size: clamp(3.5rem, 6vw, 5.5rem);
    line-height: 1.5;
  }
}

/* Safe area insets */
@supports (padding: max(0px)) {
  .theme-toggle-wrapper {
    bottom: max(1.8rem, env(safe-area-inset-bottom));
    left: max(1.8rem, env(safe-area-inset-left));
  }

  .share-wrapper {
    bottom: max(1.8rem, env(safe-area-inset-bottom));
    right: max(1.8rem, env(safe-area-inset-right));
  }

  @media (orientation: landscape) and (max-height: 600px) {
    .theme-toggle-wrapper {
      bottom: max(0.8rem, env(safe-area-inset-bottom));
      left: max(0.8rem, env(safe-area-inset-left));
    }

    .share-wrapper {
      bottom: max(0.8rem, env(safe-area-inset-bottom));
      right: max(0.8rem, env(safe-area-inset-right));
    }
  }
}
