:root {
  --bg-dark: #070115;
  --card-bg: #181125;
  --accent: #71b340;
  --border-color: #2a2a2b;
  --text: #c9e4ca;
  /* Responsive typography: 16px on mobile up to 20px on desktop */
  --font-size-base: clamp(16px, 1vw + 12px, 20px);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
  background-color: var(--bg-dark);
  color: var(--text);
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
  text-align: center;
}

header {
  padding: 2rem 1rem;
  color: var(--accent);
}

.header-link {
  text-decoration: none;
  color: inherit;
}

/* Navigation container */
.nav-container {
  display: flex;
  justify-content: center;
  gap: 1.25rem; /* 20px */
  margin-bottom: 1.25rem;
}

.nav-link {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  opacity: 0.8;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: opacity 0.2s;
  cursor: pointer;
}

.nav-link:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Search and Buttons */
.search-box {
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem; /* 10px */
}

input,
select {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text);
  padding: 0.75rem; /* 12px */
  border-radius: 0.375rem; /* 6px */
  font-size: 1rem;
  width: 100%;
  text-align: center;
}

.btn-group {
  display: flex;
  gap: 0.625rem;
  justify-content: center;
  width: 100%;
}

.btn {
  flex: 1;
  background: var(--accent);
  color: var(--bg-dark);
  font-weight: bold;
  border: none;
  padding: 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 1rem;
  transition:
    transform 0.2s,
    filter 0.2s;
}

.btn:hover {
  transform: translateY(-3px);
  filter: brightness(1.2);
}

.btn-home,
.btn-cancel {
  background: var(--border-color);
  color: var(--text);
}

.btn-danger {
  background: #ff6b6b;
  color: white;
}
.btn-edit-card {
  background: var(--border-color);
  color: var(--accent);
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition:
    transform 0.2s,
    filter 0.2s;
}
/* Grid System: 1 col mobile, 2 col rest */
#app-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 0.7rem;
  max-width: 500px;
  margin: 0 auto;
}

/* Categories */
.category-item {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: 0.75rem; /* 12px */
  border: 1px solid var(--border-color);
  cursor: pointer;
  /* Added opacity and adjusted transform for cascade animation */
  transition:
    transform 0.4s ease-out,
    opacity 0.4s ease-out,
    filter 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.category-item:hover {
  transform: translateY(-5px);
  filter: brightness(1.3);
}

/* Flashcards Adaptive Height */
.flashcard {
  perspective: 1000px;
  width: 100%;
  /* Added opacity and adjusted transform for cascade animation */
  transition:
    height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s ease,
    opacity 0.4s ease-out;
}

.flashcard:hover {
  transform: translateY(-5px);
  filter: brightness(1.2);
}

/* Accessibility: Visible focus for keyboard navigation */
.flashcard:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 0.75rem;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  cursor: pointer;
  display: block;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.front,
.back {
  backface-visibility: hidden;
  padding: 3rem 1.25rem 1.2rem 1.25rem; /* Dynamic padding */
  border-radius: 0.75rem;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  width: 100%;
  top: 0;
  left: 0;
  font-weight: 200;
}

.front {
  position: relative;
  z-index: 2;
  transform: rotateY(0deg);
}
.back {
  transform: rotateY(180deg);
  border-color: var(--accent);
  z-index: 1;
  text-align: left;
  position: absolute;
  border-left: 0.4rem solid var(--accent);
}

.flashcard.flipped .front {
  position: absolute;
}

.flashcard.flipped .back {
  position: relative;
}

.card-label {
  position: absolute;
  top: 1rem;
  left: 1.25rem;
  font-size: 0.65rem;
  color: #3a5f1f;
  text-transform: uppercase;
  font-weight: bold;
}

/* Styles for Tags on the card */
.card-tags {
  margin-top: auto; /* Push tags to the bottom */
  padding-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  background: var(--bg-dark);
  color: var(--accent);
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 200;
  letter-spacing: 0.5px;
}

/* Favorite Button (Star) */
.card-favorite-btn {
  position: absolute;
  top: 0.625rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.8rem; /* 28.8px */
  cursor: pointer;
  color: var(--border-color); /* Color para estado vacío (☆) */
  z-index: 10;
  padding: 0;
  line-height: 1;
  transition:
    transform 0.2s,
    color 0.2s;
}

.card-favorite-btn:hover {
  transform: scale(1.2);
  filter: brightness(1.5);
}

.card-favorite-btn.active {
  color: #ffd700; /* Gold for filled state (★) */
}

.card-favorite-btn.pop {
  animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

.front h3 {
  margin: 0.625rem 0;
  color: var(--accent);
  text-align: center;
  font-weight: 600;
}
.front-content,
.back-content {
  text-align: left;
  /* margin-top: 0.625rem; */
}

/* Responsive images in cards and editor */
.front-content img,
.back-content img,
.ql-editor img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.625rem auto;
  border-radius: 0.25rem;
}

/* Admin & Modals */
.admin-container {
  width: 95%;
  max-width: 700px;
  margin: 0 auto;
  padding-bottom: 2.5rem;
}
.admin-container h2 {
  color: var(--accent);
}
.form-section {
  display: flex;
  flex-direction: column;
  background: var(--border-color);
  padding: 1.25rem;
  border-radius: 0.5rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.form-error-msg {
  color: #ff6b6b;
  display: none;
  margin-bottom: 15px;
  font-weight: bold;
}

.login-input {
  max-width: 280px;
  margin-bottom: 10px;
}

.login-btn-group {
  width: 280px;
}

label {
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 1rem;
}

#login-overlay,
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 1);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#login-overlay h2 {
  color: var(--accent);
  margin-bottom: 1.5rem;
}
#modal-overlay {
  display: none;
  background: rgba(0, 0, 0, 0.8);
}

.modal-overlay-container {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--accent);
  padding: 2rem;
  border-radius: 0.75rem;
  max-width: 400px;
  width: 90%;
}

/* Admin Dashboard Styles */
.hidden {
  display: none !important;
}

.admin-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
  margin-bottom: 2.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.admin-header-title {
  margin: 0;
  cursor: pointer;
}

.btn-logout {
  padding: 8px 15px;
  font-size: 0.8rem;
  flex: initial; /* Override flex: 1 from .btn */
}

.dashboard-menu {
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.dashboard-card {
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 0.75rem;
  padding: 2rem;
  width: 200px;
  cursor: pointer;
  transition:
    transform 0.2s,
    background 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
}

.dashboard-card:hover {
  transform: translateY(-5px);
  background: var(--border-color);
}

.dashboard-card h3 {
  margin: 0;
  color: var(--accent);
}

/* Admin Lists / Tables */
.admin-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-top: 1.25rem;
}

.admin-card-item {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 2.5rem 1.25rem 1.25rem 1.25rem; /* Top space for the label */
  border-radius: 0.75rem;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
}

.card-title-truncate {
  font-weight: bold;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 1rem;
  flex: 1;
  color: var(--text);
}

.admin-list-item {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 1rem;
  border-radius: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font-size: 0.9rem;
}

.admin-list-item div {
  flex: 1;
}

.search-stats {
  display: none;
  margin-top: 10px;
  color: var(--accent);
  font-style: italic;
}

.ql-editor {
  min-height: 150px;
  font-size: 16px;
  resize: vertical;
  overflow-y: auto;
}

/* Quill Toolbar Customization */
.ql-toolbar.ql-snow {
  background-color: var(--accent);
  border-color: var(--accent);
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
}

.ql-toolbar.ql-snow .ql-stroke {
  stroke: var(--bg-dark);
}

.ql-toolbar.ql-snow .ql-fill {
  fill: var(--bg-dark);
}

.ql-toolbar.ql-snow .ql-picker {
  color: var(--bg-dark);
}

/* Editor Styles to match dark theme (Cards) */
#editor-front,
#editor-back {
  background-color: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent); /* Coincide con el borde del toolbar */
  border-top: none;
  border-bottom-left-radius: 0.5rem;
  border-bottom-right-radius: 0.5rem;
}

/* Helper class for cascade-in animation */
.will-cascade-in {
  opacity: 0;
  transform: translateY(20px);
}

/* --- MOBILE OPTIMIZATION --- */
@media (max-width: 600px) {
  .admin-container {
    width: 100%;
    padding: 0 0.5rem 2rem 0.5rem;
  }

  .form-section {
    padding: 0.4rem; /* Reduce padding for more editor space */
  }

  .admin-card-item {
    padding: 2.5rem 0.8rem 0.8rem 0.8rem;
  }
}
