/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Arial', sans-serif;
  background: linear-gradient(180deg, #001c0e, #007838);
  color: white;
  text-align: center;
  overflow-y: scroll;
  scrollbar-width: none;
  -ms-overflow-style: none;
  display: flex;
  flex-direction: column;
}

body {
  min-height: 100vh;
  background: linear-gradient(180deg, #001c0e, #007838);
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

/* Header */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  background: #005430;
  border-bottom: 4px solid #00311c;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  padding: 1rem 2vw;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  user-select: none;
  font-size: clamp(1.5rem, 5vw, 3rem);
  font-weight: bold;
  color: #ffffff;
  margin: 0;
  white-space: nowrap;
  transition: all 0.3s ease;
  text-decoration: none;
  transition: none;
}

.header-buttons {
  display: flex;
  gap: 4rem; /* control spacing between buttons */
  align-items: center;
  justify-content: center;
  margin-left: auto;
  margin-right: auto;
}

@media (max-width: 768px) {
  header h1,
  #siteTitle {
    font-size: clamp(1rem, 3vw, 1.5rem); /* Smaller font for tablets */
  }
}

@media (max-width: 480px) {
  header h1,
  #siteTitle {
    font-size: clamp(1rem, 8vw, 1.6rem);
    margin-bottom: 0.5rem;
    flex-basis: 100%;
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  header {
    /* Your special iPad styles here */
    flex-direction: row;
    gap: 0.2rem;
    padding: 0.7rem 1vw;
    font-size: clamp(1rem, 2vw, 1.5rem);
    /* Add or override any other styles */
  }
  .header-buttons {
    gap: 0.2rem;
  }
}

header h1,
#siteTitle {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: bold;
  color: #ffffff;
  margin: 0;
  white-space: nowrap;
  transition: all 0.3s ease;
  text-decoration: none;
  font-size: clamp(1.5rem, 5vw, 3rem);
  font-weight: bold;
  color: #ffffff;
  margin: 0;
  white-space: nowrap;
  transition: all 0.3s ease;
  text-decoration: none;
  transition: none;
}

#siteTitle:hover {
  text-shadow: 0 0 20px rgb(11, 231, 88);
  transform: scale(1.02);
}

/* Search bar and buttons */
.search-container {
  position: fixed;
  bottom: 75px;          /* distance from bottom */
  left: 50%;             /* position horizontally at 50% */
  transform: translateX(-50%);  /* center exactly by shifting half its width */
  padding: 0.5rem 1rem;
  border-radius: 100rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 10000;        /* make sure it’s above other content */
  width: fit-content;    /* shrink-wrap to content width */
  max-width: 90vw;       /* max width responsive */
  background: rgb(255, 255, 255);
}

/* Move hover and focus styles here */
.search-container:hover,
.search-container:focus-within {
  background-color: #dffbf3;
  box-shadow: 0 0 10px 2px rgb(15, 185, 75);
}

/* Reset #searchBar background and remove its hover/focus */
#searchBar {
  width: 100%;
  max-width: 100vw;
  font-size: 1.1rem;
  padding: 0.7rem 5vw;
  border-radius: 1.5rem;
  border: none;
  background: transparent; /* make input background transparent */
  color: #00422e;
  text-align: center;
  caret-color: transparent !important;
  direction: rtl;
  flex: 1;
  outline: none;  /* Remove default focus outline */
  transition: none;
}


/* Toggle switches */
#tagToggleContainer label,
#resetToggleContainer label,
#sentenceToggleContainer label,
#wordToggleContainer label {
  display: flex;
  align-items: center;
  cursor: pointer;
  gap: 0.5rem;
  direction: rtl;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
  direction: rtl;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  right: 4px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.4s ease;
  transform: translateX(0);
}

input:checked + .slider:before {
  transform: translateX(-24px);
}

input:checked + .slider {
  background-color: #4caf50;
}

.slider:hover {
  box-shadow: 0 0 10px 2px rgb(15, 185, 75);
}

/* Toggle containers */
#tagToggleContainer,
#resetToggleContainer,
#sentenceToggleContainer,
#wordToggleContainer {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  font-weight: bold;
  font-size: 1.1rem;
  color: #ffffff;
  user-select: none;
  direction: rtl;
}

/* Wrapper */
.wrapper {
  flex: 1;
  padding: 1rem;
  padding-top: 4.5rem; /* was 6rem, now less */
}

/* Flashcard grid */
.flashcard-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); /* was 220px, now wider */
  gap: 1.2rem;
  max-width: 100vw;
  margin: 1.5rem auto 0;
  padding: 4.5rem 2vw 0 2vw;
  padding-top: 1.5rem; /* was 4.5rem, now less */
  padding-left: 1.5vw;
  padding-right: 1.5vw;
}

/* Flashcard */
.flashcard {
  width: 100%;
  max-width: 100vw;
  aspect-ratio: 320 / 420;
  min-width: 340px;      /* was 260px, now wider */
  height: 420px;
  cursor: pointer;
  perspective: 1000px;
  position: relative;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.8s ease;
  border-radius: 14px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.5);
  border: 3px solid #00311c;
  background: #005430;
  transition: all 0.4s ease;
}

.flashcard-inner:hover {
  box-shadow: 0 0 20px 5px rgba(15, 185, 75, 0.5);
}

.flashcard-inner.flipped {
  transform: rotateY(180deg) scale(1);
}

.flashcard-inner.flipped:hover {
  transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  backface-visibility: hidden;
  top: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  color: white;
}

.flashcard-back {
  transform: rotateY(180deg);
}

/* Responsive font sizes for cards */
.word {
  font-size: clamp(2rem, 6vw, 5.5rem);
  font-weight: bold;
  margin-bottom: 1rem;
}

ul.details {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
  text-align: center;
}

ul.details li {
  margin-bottom: 1.4rem;
}

ul.details li.arabic {
  font-size: clamp(1.2rem, 5vw, 5rem);
  line-height: 1.1em;
  font-weight: bold;
  color: #ffffff;
}

ul.details li.english {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: #d0e0dc;
}

.tag-labels {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background: #00311c;
  color: white;
  font-size: clamp(1rem, 2vw, 1.1rem);
  padding: 0.6rem 0;
  border-radius: 0.5rem 0.5rem 0 0;
  font-weight: bold;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  z-index: 2;
  cursor: pointer;
  user-select: none;
  text-align: center;
  transition: opacity 0.4s ease, transform 0.4s ease;
  transform-origin: top center;
}

.tag-labels.hidden {
  opacity: 0;
  pointer-events: none;
}

.sentence-label, .word-label {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.2rem;
  font-weight: bold;
  color: #aaffaaa3;
  border-radius: 10px;
  pointer-events: none;
  z-index: 3;
}

.sentence-label.hidden, .word-label.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* Buttons */
#clearButton {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #00311c;
  color: white;
  font-weight: bold;
  font-size: 18px;
  cursor: pointer;
  line-height: 28px;
  text-align: center;
  padding: 0;
  user-select: none;
  transition: background-color 0.3s ease;
  z-index: 10;
}

#dropdownButton {
  position: absolute;
  top: 50%;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #00311c;
  color: white;
  font-weight: bold;
  font-size: 18px;
  cursor: pointer;
  line-height: 28px;
  text-align: center;
  padding: 0;
  user-select: none;
  transition: background-color 0.3s ease;
  z-index: 10;

  /* Combine both transforms here */
  transform: translateY(-50%) rotate(180deg);
}

#clearButton {
  left: 8px;
}

#dropdownButton {
  right: 8px;
}

#clearButton:hover,
#dropdownButton:hover {
  background-color: #138c3d;
}

#clearButton:focus,
#dropdownButton:focus {
  outline: 2px solid #0fb94b;
}

/* Dropdown menu */
#tagDropdownMenu label {
  margin-left: 15rem;
}

header h1,
#siteTitle {
  font-size: clamp(1rem, 2.5vw, 1.7rem); /* smaller default, scalable */
  font-weight: bold;
  color: #ffffff;
  margin: 0;
  white-space: nowrap;
  transition: all 0.3s ease;
  text-decoration: none;
}

/* Footer */
footer {
  margin-top: 2rem;
  margin-bottom: 1rem;
  width: 100%;
  text-align: center;
  font-size: clamp(0.75rem, 1vw, 0.9rem);
  color: #cccccc;
}

/* Selection */
::selection,
::-moz-selection {
  background: #138c3d;
  color: white;
}

/* Responsive media queries */
@media (max-width: 1024px) {
  .flashcard-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding-left: 1vw;
    padding-right: 1vw;
  }
  .word {
    font-size: 4vw;
  }
}

@media (max-width: 768px) {
  header {
    flex-direction: column;
    padding: 1rem 2vw;
  }
  .flashcard-container {
    grid-template-columns: 1fr;
    gap: 0.8rem;
    padding-left: 1vw;
    padding-right: 1vw;
  }
  .flashcard {
    aspect-ratio: auto;
    height: 320px;
    max-width: 100vw;
  }
  .word {
    font-size: 3rem;
  }
  ul.details li.arabic {
    font-size: 2.2rem;
  }
}

@media (max-width: 1024px) {
  header {
    padding: 0.7rem 1vw;
    gap: 0.5rem;
    flex-wrap: nowrap; /* Prevent wrapping */
  }
  #searchBar {
    font-size: 1rem;
    padding: 0.5rem 1vw;
    max-width: 100vw;
    flex-basis: 100%;
    margin-bottom: 1rem;
  }
  #tagToggleContainer {
    flex-basis: 100%;
    justify-content: center;
  }
  .flashcard-container {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-left: 1vw;
    padding-right: 1vw;
  }
  .flashcard {
    aspect-ratio: auto;
    height: 220px;
    max-width: 100vw;
  }
  .word {
    font-size: 2rem;
  }
  ul.details li.arabic {
    font-size: 1.2rem;
  }
  .dialect-options a {
    font-size: 1rem;
    padding: 0.8rem;
  }
  footer {
    font-size: 0.75rem;
  }
}

/* Sentence card tweaks */
.flashcard.sentence-card .flashcard-back li.arabic,
.sentence-card .word {
  font-size: 3rem;
  line-height: 3.4rem;
}