/**
 * study.css
 * Styles for the study toolkit (Phase 2): the Study panel, its dialogs
 * (review, highlight review, making cards), the floating focus timer and the
 * reading calendar. Every selector targets ts-study-* classes only, so this
 * file cannot change the look of anything that existed before it.
 */

/* ============================================
   PANEL
   ============================================ */
.ts-study-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.ts-study-secondary,
.ts-study-danger {
  padding: 0.45rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  color: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  cursor: pointer;
}

.ts-study-secondary:hover:not(:disabled),
.ts-study-secondary:focus-visible {
  border-color: rgba(34, 197, 94, 0.55);
  outline: none;
}

.ts-study-danger {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
}

.ts-study-danger:hover,
.ts-study-danger:focus-visible {
  background: rgba(248, 113, 113, 0.12);
  outline: none;
}

.ts-study-secondary:disabled,
.ts-study-mini-btn:disabled,
.ts-study-grade:disabled {
  opacity: 0.45;
  cursor: default;
}

.ts-study-decks,
.ts-study-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ts-study-deck {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}

.ts-study-deck-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ts-study-deck-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ts-study-deck-meta {
  font-size: 0.78rem;
  opacity: 0.7;
}

.ts-study-timer-clock {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.ts-study-timer-status,
.ts-study-goal-today,
.ts-study-streak {
  margin: 0.25rem 0;
}

.ts-study-streak {
  font-weight: 600;
}

/* ============================================
   PROGRESS BAR
   ============================================ */
.ts-study-progress {
  height: 6px;
  margin: 0.35rem 0;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  overflow: hidden;
}

.ts-study-progress-bar {
  width: 0;
  height: 100%;
  background: #22c55e;
  border-radius: inherit;
  transition: width 0.25s ease;
}

.ts-study-progress-text {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  opacity: 0.75;
}

/* ============================================
   READING CALENDAR (one hue; the level also shows in each cell's tooltip)
   ============================================ */
.ts-study-heatmap {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  max-width: 320px;
}

.ts-study-cell {
  display: block;
  aspect-ratio: 1;
  min-width: 8px;
  max-width: 100%;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.07);
}

.ts-study-cell[data-level="1"] { background: rgba(34, 197, 94, 0.28); }
.ts-study-cell[data-level="2"] { background: rgba(34, 197, 94, 0.5); }
.ts-study-cell[data-level="3"] { background: rgba(34, 197, 94, 0.75); }
.ts-study-cell[data-level="4"] { background: #22c55e; }
.ts-study-cell.is-future { background: transparent; }
.ts-study-cell.is-today { outline: 1.5px solid currentColor; outline-offset: 1px; }

.ts-study-legend {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  opacity: 0.8;
}

.ts-study-legend .ts-study-cell {
  width: 10px;
  min-width: 10px;
}

.ts-study-legend span:first-child { margin-right: 0.25rem; }
.ts-study-legend span:last-child { margin-left: 0.25rem; }

/* ============================================
   DIALOG
   ============================================ */
.ts-study-dialog {
  position: fixed;
  inset: 0;
  z-index: 1000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.6);
  font-family: 'Inter', 'DM Sans', system-ui, sans-serif;
}

.ts-study-dialog [hidden] {
  display: none !important;
}

.ts-study-dialog-box {
  width: min(560px, 100%);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  color: #e9edeb;
  background: #121513;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.ts-study-dialog-box.is-wide {
  width: min(760px, 100%);
}

.ts-study-dialog-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem 0.7rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ts-study-dialog-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.ts-study-dialog-close {
  padding: 0.3rem 0.55rem;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.ts-study-dialog-close:hover,
.ts-study-dialog-close:focus-visible {
  border-color: rgba(255, 255, 255, 0.25);
  outline: none;
}

.ts-study-dialog-body {
  padding: 1rem 1.1rem 1.2rem;
  overflow-y: auto;
  line-height: 1.5;
}

.ts-study-dialog button:focus-visible,
.ts-study-dialog select:focus-visible,
.ts-study-dialog textarea:focus-visible,
.ts-study-dialog input:focus-visible {
  outline: 2px solid #22c55e;
  outline-offset: 2px;
}

/* ============================================
   CARDS
   ============================================ */
.ts-study-card {
  padding: 1.2rem;
  font-size: 1.15rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
}

.ts-study-card-back-wrap {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
}

.ts-study-blank {
  display: inline-block;
  min-width: 3.5em;
  color: transparent;
  border-bottom: 2px solid currentColor;
  border-bottom-color: #22c55e;
}

.ts-study-answer {
  padding: 0 0.15em;
  color: inherit;
  background: rgba(34, 197, 94, 0.3);
  border-radius: 3px;
}

.ts-study-reveal {
  margin-top: 0.8rem;
}

.ts-study-grades {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
  margin-top: 0.8rem;
}

.ts-study-grade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.55rem 0.3rem;
  font: inherit;
  color: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  cursor: pointer;
}

.ts-study-grade:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.ts-study-grade.is-again { border-color: rgba(248, 113, 113, 0.5); }
.ts-study-grade.is-good { border-color: rgba(34, 197, 94, 0.55); }
.ts-study-grade-label { font-weight: 600; }
.ts-study-grade-when { font-size: 0.75rem; opacity: 0.7; }

.ts-study-source {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  opacity: 0.7;
}

.ts-study-summary-big {
  font-size: 1.2rem;
  font-weight: 600;
}

.ts-study-summary-counts {
  margin: 0.4rem 0;
  padding-left: 1.2rem;
}

/* ============================================
   HIGHLIGHT REVIEW AND CARD MAKER
   ============================================ */
.ts-study-quote {
  margin: 0;
  padding: 0.9rem 1rem;
  font-size: 1.1rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(250, 204, 21, 0.08);
  border-left: 4px solid #facc15;
  border-radius: 0 10px 10px 0;
}

.ts-study-note {
  margin: 0.5rem 0 0;
  font-style: italic;
}

.ts-study-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.6rem 0;
  font-size: 0.85rem;
}

.ts-study-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.95rem;
  color: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  resize: vertical;
}

.ts-study-inline {
  display: flex;
  gap: 0.45rem;
}

.ts-study-deck-picker .ts-study-input {
  margin-top: 0.35rem;
}

.ts-study-words {
  padding: 0.7rem;
  line-height: 2.1;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
}

.ts-study-word {
  padding: 0.05rem 0.2rem;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  cursor: pointer;
}

.ts-study-word[aria-pressed="true"] {
  color: #0b0d0c;
  background: #22c55e;
  border-style: solid;
  border-color: #22c55e;
}

.ts-study-cloze-preview {
  margin: 0.2rem 0 0;
  padding: 0.6rem 0.7rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
}

.ts-study-list-item {
  padding: 0.6rem 0.7rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}

.ts-study-list-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ts-study-list-item .ts-study-danger {
  margin-top: 0.4rem;
}

.ts-study-error {
  margin: 0.5rem 0 0;
  color: #fca5a5;
  font-weight: 600;
}

.ts-study-ai-save {
  margin-left: 0.5rem;
}

/* ============================================
   FLOATING FOCUS TIMER
   ============================================ */
.ts-study-mini {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.35rem 0.3rem 0.7rem;
  color: #e9edeb;
  font-family: 'Inter', 'DM Sans', system-ui, sans-serif;
  font-size: 0.85rem;
  background: rgba(18, 21, 19, 0.94);
  border: 1px solid rgba(34, 197, 94, 0.45);
  border-radius: 99px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.ts-study-mini[hidden] {
  display: none;
}

.ts-study-mini[data-phase="short"],
.ts-study-mini[data-phase="long"] {
  border-color: rgba(96, 165, 250, 0.55);
}

.ts-study-mini-phase {
  opacity: 0.75;
}

.ts-study-mini-clock {
  min-width: 3.2em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ts-study-mini-btn {
  pointer-events: auto;
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  font: inherit;
  color: inherit;
  background: rgba(255, 255, 255, 0.07);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.ts-study-mini-btn:hover,
.ts-study-mini-btn:focus-visible {
  background: rgba(34, 197, 94, 0.3);
  outline: none;
}

@media (max-width: 480px) {
  .ts-study-mini-phase { display: none; }
  .ts-study-grades { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .ts-study-progress-bar { transition: none; }
}

/* ============================================
   LIGHT MODE
   ============================================ */
body.light-mode .ts-study-dialog-box,
body.light-mode .ts-study-mini {
  color: #14201b;
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .ts-study-mini {
  border-color: rgba(22, 163, 74, 0.5);
}

body.light-mode .ts-study-dialog-head {
  border-bottom-color: rgba(0, 0, 0, 0.08);
}

body.light-mode .ts-study-card,
body.light-mode .ts-study-words,
body.light-mode .ts-study-deck,
body.light-mode .ts-study-list-item,
body.light-mode .ts-study-input,
body.light-mode .ts-study-grade,
body.light-mode .ts-study-secondary,
body.light-mode .ts-study-mini-btn {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.14);
}

body.light-mode .ts-study-word {
  border-color: rgba(0, 0, 0, 0.3);
}

body.light-mode .ts-study-card-back-wrap {
  border-top-color: rgba(0, 0, 0, 0.2);
}

body.light-mode .ts-study-progress,
body.light-mode .ts-study-cell {
  background: rgba(0, 0, 0, 0.08);
}

body.light-mode .ts-study-cell[data-level="1"] { background: rgba(22, 163, 74, 0.3); }
body.light-mode .ts-study-cell[data-level="2"] { background: rgba(22, 163, 74, 0.52); }
body.light-mode .ts-study-cell[data-level="3"] { background: rgba(22, 163, 74, 0.76); }
body.light-mode .ts-study-cell[data-level="4"] { background: #16a34a; }
body.light-mode .ts-study-cell.is-future { background: transparent; }

body.light-mode .ts-study-danger,
body.light-mode .ts-study-error {
  color: #b91c1c;
}
