/**
 * study-companion.css — Styles for AI Study Companion
 * Uses CSS variables from the theme for automatic theming
 *
 * TO WIRE UP: add <script src='/assets/study-companion.js'> and <link rel='stylesheet' href='/assets/study-companion.css'> to learn.php for non-editor mode
 */

/* ──────────────────────────────────────────────────────
   Floating Study Tools Button
   ────────────────────────────────────────────────────── */

.study-companion-btn {
  position: fixed;
  bottom: 120px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent, #f5c518);
  color: #000;
  border: none;
  font-size: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(245, 197, 24, 0.3);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 99;
}

.study-companion-btn:hover {
  transform: scale(1.12);
  box-shadow: 0 12px 32px rgba(245, 197, 24, 0.5);
}

.study-companion-btn:active {
  transform: scale(0.95);
}

@media (max-width: 600px) {
  .study-companion-btn {
    bottom: 100px;
    right: 16px;
    width: 48px;
    height: 48px;
    font-size: 24px;
  }
}

/* ──────────────────────────────────────────────────────
   Study Panel (Flashcards, Quiz, Summary)
   ────────────────────────────────────────────────────── */

.study-companion-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 360px;
  max-height: 600px;
  background: var(--bg-secondary, #111128);
  border: 1px solid rgba(245, 197, 24, 0.2);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 98;
  overflow: hidden;
}

.study-companion-panel.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.study-panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(245, 197, 24, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.study-panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #fff);
  letter-spacing: 0.5px;
}

.study-panel-close {
  background: none;
  border: none;
  color: var(--text-muted, rgba(255, 255, 255, 0.5));
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.study-panel-close:hover {
  color: var(--accent, #f5c518);
}

.study-panel-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(245, 197, 24, 0.1);
  flex-wrap: wrap;
}

.study-tab-btn {
  flex: 1;
  min-width: 80px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(245, 197, 24, 0.15);
  border-radius: 6px;
  color: var(--text-muted, rgba(255, 255, 255, 0.6));
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
}

.study-tab-btn:hover {
  background: rgba(245, 197, 24, 0.08);
  border-color: rgba(245, 197, 24, 0.3);
  color: var(--text, #fff);
}

.study-tab-btn.active {
  background: var(--accent, #f5c518);
  border-color: var(--accent, #f5c518);
  color: #000;
}

.study-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.study-tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.study-tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.study-load-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--accent, #f5c518);
  border: none;
  border-radius: 8px;
  color: #000;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.25s;
  margin-bottom: 12px;
}

.study-load-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(245, 197, 24, 0.3);
}

.study-load-btn:active {
  transform: translateY(0);
}

/* ──────────────────────────────────────────────────────
   Flashcards Grid
   ────────────────────────────────────────────────────── */

.flashcards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.flashcard {
  perspective: 1000px;
  cursor: pointer;
  height: 160px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

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

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid rgba(245, 197, 24, 0.2);
  text-align: center;
}

.flashcard-front {
  background: linear-gradient(135deg, rgba(245, 197, 24, 0.1), rgba(245, 197, 24, 0.05));
  z-index: 2;
}

.flashcard-back {
  background: linear-gradient(135deg, rgba(233, 69, 96, 0.1), rgba(233, 69, 96, 0.05));
  transform: rotateY(180deg);
}

.flashcard-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted, rgba(255, 255, 255, 0.5));
  margin-bottom: 8px;
  font-weight: 700;
}

.flashcard-text {
  font-size: 14px;
  color: var(--text, #fff);
  line-height: 1.5;
  font-weight: 500;
  flex: 1;
  display: flex;
  align-items: center;
}

.flashcard-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted, rgba(255, 255, 255, 0.4));
  font-style: italic;
}

/* ──────────────────────────────────────────────────────
   Summary Content
   ────────────────────────────────────────────────────── */

.study-summary-content {
  color: var(--text, #fff);
  font-size: 13px;
  line-height: 1.7;
}

.study-summary-content p {
  margin: 0 0 12px 0;
}

.study-summary-content p:last-child {
  margin-bottom: 0;
}

/* ──────────────────────────────────────────────────────
   Text Selection Tooltip — "Explain this"
   ────────────────────────────────────────────────────── */

.explain-tooltip {
  position: fixed;
  background: rgba(10, 10, 26, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 197, 24, 0.3);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.8);
  z-index: 10001;
  animation: tooltipIn 0.25s ease;
}

@keyframes tooltipIn {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.explain-tooltip-btn {
  padding: 8px 14px;
  background: var(--accent, #f5c518);
  border: none;
  border-radius: 6px;
  color: #000;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.explain-tooltip-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(245, 197, 24, 0.4);
}

.explain-tooltip-btn:active {
  transform: scale(0.95);
}

/* ──────────────────────────────────────────────────────
   Explanation Modal
   ────────────────────────────────────────────────────── */

.study-explanation-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10002;
  animation: fadeIn 0.25s ease;
}

.study-explanation-content {
  background: var(--bg-secondary, #111128);
  border: 1px solid rgba(245, 197, 24, 0.2);
  border-radius: 12px;
  max-width: 600px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}

.study-explanation-header {
  padding: 20px;
  border-bottom: 1px solid rgba(245, 197, 24, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.study-explanation-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text, #fff);
  font-weight: 700;
}

.study-close-btn {
  background: none;
  border: none;
  color: var(--text-muted, rgba(255, 255, 255, 0.6));
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}

.study-close-btn:hover {
  color: var(--accent, #f5c518);
}

.study-explanation-body {
  padding: 20px;
  color: var(--text, #fff);
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ──────────────────────────────────────────────────────
   Loading & Error States
   ────────────────────────────────────────────────────── */

.explain-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10, 10, 26, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 197, 24, 0.3);
  border-radius: 12px;
  padding: 24px 40px;
  color: var(--accent, #f5c518);
  font-weight: 600;
  font-size: 14px;
  z-index: 10001;
  animation: fadeIn 0.25s ease;
}

.study-error-msg {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(220, 38, 38, 0.9);
  color: #fff;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 10001;
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ──────────────────────────────────────────────────────
   Responsive adjustments
   ────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .study-companion-panel {
    width: calc(100vw - 32px);
    max-height: 70vh;
    right: 16px;
    bottom: 80px;
  }

  .study-panel-tabs {
    flex-direction: column;
  }

  .study-tab-btn {
    min-width: 100%;
  }

  .flashcards-grid {
    gap: 10px;
  }

  .flashcard {
    height: 140px;
  }

  .study-explanation-content {
    width: 95%;
    max-height: 80vh;
  }
}

/* ──────────────────────────────────────────────────────
   Scrollbar styling (webkit browsers)
   ────────────────────────────────────────────────────── */

.study-companion-panel::-webkit-scrollbar,
.study-explanation-content::-webkit-scrollbar {
  width: 6px;
}

.study-companion-panel::-webkit-scrollbar-track,
.study-explanation-content::-webkit-scrollbar-track {
  background: rgba(245, 197, 24, 0.05);
  border-radius: 3px;
}

.study-companion-panel::-webkit-scrollbar-thumb,
.study-explanation-content::-webkit-scrollbar-thumb {
  background: rgba(245, 197, 24, 0.3);
  border-radius: 3px;
}

.study-companion-panel::-webkit-scrollbar-thumb:hover,
.study-explanation-content::-webkit-scrollbar-thumb:hover {
  background: rgba(245, 197, 24, 0.5);
}

/* ── Student Quiz Me — interactive 5-question MCQ ────────────────── */
.study-quiz {
  padding: 8px 4px;
}
.study-quiz-counter {
  font-size: 12px;
  color: var(--text-muted, #6b7280);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.study-quiz-q {
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text, #1f2937);
}
.study-quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}
.study-quiz-opt {
  text-align: left;
  padding: 10px 14px;
  background: var(--card-bg, #fff);
  border: 1.5px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background-color 0.15s, border-color 0.15s;
}
.study-quiz-opt:hover:not(:disabled) {
  background: rgba(245, 197, 24, 0.08);
  border-color: rgba(245, 197, 24, 0.4);
}
.study-quiz-opt:disabled {
  cursor: default;
  opacity: 0.85;
}
.study-quiz-opt.is-correct {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgb(34, 197, 94);
  color: rgb(21, 128, 61);
  font-weight: 600;
}
.study-quiz-opt.is-wrong {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgb(239, 68, 68);
  color: rgb(153, 27, 27);
}
.study-quiz-explain {
  margin: 12px 0;
  padding: 12px 14px;
  background: rgba(59, 130, 246, 0.08);
  border-left: 3px solid rgb(59, 130, 246);
  border-radius: 4px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text, #1f2937);
}
.study-quiz-result {
  text-align: center;
  padding: 24px 8px;
}
.study-quiz-score {
  font-size: 28px;
  font-weight: 700;
  color: var(--text, #1f2937);
  margin-bottom: 8px;
}
