/* =========================================
   Global styles & color palette
   ========================================= */
:root {
  /* Soft pink primary with light-blue accent */
  --color-bg: #fff8f7;
  --color-card: #ffffff;
  --color-primary: #ff8fa3;          /* Main pink */
  --color-primary-dark: #ff6b85;     /* Darker pink for hover/active */
  --color-accent: #9ec8ff;           /* Light blue accent */
  --color-text: #4a3b46;             /* Warm gray text */
  --color-muted: #8a7a82;
  --color-border: #ffe4e9;
  --color-tag-bg: #ffe9ee;
  --color-tag-text: #c2185b;
  --color-star: #ffc857;
  --color-star-off: #e8d9bf;
  --shadow-card: 0 4px 14px rgba(255, 143, 163, 0.12);
  --shadow-card-hover: 0 8px 22px rgba(255, 143, 163, 0.22);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* =========================================
   Header
   ========================================= */
.site-header {
  text-align: center;
  padding: 28px 16px 12px;
}

.site-header h1 {
  margin: 0;
  font-size: 28px;
  color: var(--color-primary-dark);
  letter-spacing: 1px;
}

.site-header .subtitle {
  margin: 4px 0 0;
  color: var(--color-muted);
  font-size: 14px;
}

/* =========================================
   App layout: video grid + sidebar dashboard
   -----------------------------------------
   Two-column grid on wide viewports. On
   narrow viewports the dashboard stacks on
   top of the grid so progress is visible
   without scrolling.
   ========================================= */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 24px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 16px 24px;
  align-items: start;
}
.app-main {
  min-width: 0;       /* lets the inner grid actually shrink */
}
.dashboard {
  position: sticky;
  top: 16px;
  align-self: start;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 16px;
  padding: 18px 18px 22px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  font-size: 14px;
}
@media (max-width: 900px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .dashboard {
    position: static;
    max-height: none;
    order: -1;           /* show progress above the video grid on mobile */
  }
}

/* =========================================
   Filter bar
   ========================================= */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;                    /* roomy spacing between buttons */
  padding: 16px 20px 28px;
  max-width: 1200px;
  margin: 0 auto;
}

.filter-btn {
  border: 2px solid var(--color-border);
  background: var(--color-card);
  color: var(--color-text);
  padding: 11px 24px;           /* bigger touch target, more breathing room */
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  min-width: 110px;             /* every button gets at least this width */
  text-align: center;
  white-space: nowrap;          /* labels stay on one line per button */
}

.filter-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
  transform: translateY(-1px);
}

/* Active filter button */
.filter-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 4px 10px rgba(255, 143, 163, 0.35);
}

/* =========================================
   Video grid
   Responsive: 1 col on mobile, 2 on tablet, 3-4 on desktop
   ========================================= */
.video-grid {
  display: grid;
  grid-template-columns: 1fr;          /* mobile: 1 column */
  gap: 18px;
  padding: 0 16px 40px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 600px) {
  .video-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .video-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (min-width: 1200px) {
  .video-grid { grid-template-columns: repeat(4, 1fr); }
}

/* =========================================
   Video card
   ========================================= */
.video-card {
  position: relative;            /* anchor for user-video badge / delete btn */
  background: var(--color-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

/* User-added marker — a small pink star in the top-left of the card */
.user-video-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 3;
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-primary-dark);
  font-size: 14px;
  line-height: 1;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Delete button — only on user-added cards, fades in on hover */
.user-video-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--color-muted);
  font-size: 18px;
  line-height: 1;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 150ms ease, background 150ms ease, color 150ms ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.video-card.user-added:hover .user-video-delete,
.user-video-delete:focus { opacity: 1; }
.user-video-delete:hover {
  background: #c0392b;
  color: #fff;
}

/* =========================================
   "Add a video" panel — full-width, lives
   below the video grid (not inside it)
   ========================================= */
.add-video-section {
  margin-top: 32px;
  padding: 22px 24px 24px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.add-section-header {
  margin-bottom: 16px;
}
.add-section-title {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-primary-dark);
}
.add-section-desc {
  margin: 0;
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.5;
}

/* Form layout for the wider panel: stacked fields with a few
   side-by-side rows for compact controls (difficulty + checkbox). */
.add-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.add-form-wide .add-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.add-form-wide .add-row > .add-field {
  flex: 0 0 auto;
}
.add-form-wide .add-row > .add-field-grow {
  flex: 1 1 200px;
  min-width: 0;
}
.add-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-muted);
}
.add-field input {
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
}
.add-field input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  border-color: transparent;
}
/* Visible red ring when a field fails validation */
.add-field input[aria-invalid="true"] {
  border-color: #c0392b;
  background: #fff6f5;
}
.add-field input[aria-invalid="true"]:focus {
  outline-color: #c0392b;
}

/* Checkbox field — sits horizontally instead of stacked */
.add-field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
}
.add-field-checkbox .add-practice {
  width: 16px;
  height: 16px;
  accent-color: var(--color-primary);
  cursor: pointer;
  margin: 0;
}
.add-checkbox-label {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.add-checkbox-label em {
  font-style: normal;
  font-size: 11px;
  color: var(--color-muted);
  margin-top: 1px;
}
.add-field em {
  font-style: normal;
  text-transform: none;
  opacity: 0.7;
  margin-left: 4px;
  font-size: 11px;
}
.add-hint {
  font-style: italic;
  color: var(--color-primary);
}

.add-diff-picker {
  display: flex;
  gap: 2px;
}
.add-diff-star {
  flex: 1;
  border: 1px solid var(--color-border);
  background: #fff;
  font-size: 14px;
  color: var(--color-star-off);
  padding: 4px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: color 100ms ease, background 100ms ease;
}
.add-diff-star.active { color: var(--color-star); background: #fffaef; }
.add-diff-star:hover  { background: #fffaef; }

.add-error {
  color: #c0392b;
  font-size: 12px;
  margin: 2px 0;
}

.add-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
}
.add-reset,
.add-submit {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 150ms ease;
}
.add-reset {
  background: rgba(0, 0, 0, 0.05);
  color: var(--color-muted);
}
.add-submit {
  background: var(--color-primary);
  color: #fff;
  min-width: 140px;
}
.add-submit:disabled {
  opacity: 0.6;
  cursor: progress;
}
.add-reset:hover,
.add-submit:hover:not(:disabled) { filter: brightness(1.05); }

.video-card:hover {
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}

/* Thumbnail wrapper: enforces 16:9 aspect ratio */
.thumb-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #f3eaec;
}

.thumb-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

/* Slight zoom on hover */
.video-card:hover .thumb-wrapper img {
  transform: scale(1.05);
}

/* Play icon overlay that fades in on hover */
.play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.18);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;       /* clicks pass through to the link */
}

.video-card:hover .play-icon { opacity: 1; }

.play-icon::before {
  content: "";
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  position: relative;
}

.play-icon::after {
  content: "";
  position: absolute;
  width: 0; height: 0;
  border-left: 18px solid var(--color-primary-dark);
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  margin-left: 4px;   /* nudge for optical centering */
}

/* Card body */
.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-title {
  position: relative;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  /* The two-line clamp lives on the inner span so the edit ✏️ button
     is free to overflow the line box without being clipped. */
  display: block;
  padding-right: 22px;  /* leave room for the pencil */
}
.card-title .title-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: text;
}
/* Pencil button — only visible on hover/focus, sits at the right edge */
.card-title .title-edit {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  border: none;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
  transition: opacity 150ms ease;
}
.video-card:hover .title-edit,
.title-edit:focus { opacity: 0.75; }
.title-edit:hover  { opacity: 1; }

/* Editing state — input + ✓/✕ replace the static title */
.card-title.editing {
  display: flex;
  gap: 4px;
  padding-right: 0;
  align-items: center;
}
.card-title .title-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  padding: 4px 8px;
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  background: #fff;
  outline: none;
}
.card-title .title-save,
.card-title .title-cancel {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.card-title .title-save  { background: var(--color-primary); color: #fff; }
.card-title .title-cancel{ background: rgba(0,0,0,0.06);    color: var(--color-muted); }
.card-title .title-save:hover, .card-title .title-cancel:hover { filter: brightness(1.05); }

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.category-tag {
  display: inline-block;
  background: var(--color-tag-bg);
  color: var(--color-tag-text);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.difficulty {
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--color-star);
}

.difficulty .star-off { color: var(--color-star-off); }

.notes {
  margin: 0;
  font-size: 13px;
  color: var(--color-muted);
  background: #fff5f7;
  padding: 6px 10px;
  border-radius: 8px;
  border-left: 3px solid var(--color-accent);
  line-height: 1.4;
}

/* =========================================
   Playback speed buttons + Practice button
   (under each card)
   ---------------------------------------------------------
   margin-top: auto pushes this row (and the Practice button
   that follows) to the bottom of the card. Combined with
   CSS Grid's default row-height stretching, this means the
   speed buttons line up horizontally across every card in
   the same row, even when titles or notes vary in length.
   ========================================================= */
.speed-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: auto;
}

.speed-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  background: #fff4f6;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  padding: 6px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.speed-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
  transform: translateY(-1px);
}

/* Last-used speed across all cards stays highlighted */
.speed-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 2px 6px rgba(255, 143, 163, 0.35);
}

/* The Practice button sits on its own row, full width */
.practice-btn {
  margin-top: 6px;
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #9ec8ff 0%, #b8a4ff 100%);
  border: none;
  border-radius: 8px;
  padding: 8px 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.practice-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(158, 200, 255, 0.45);
  filter: brightness(1.05);
}

/* =========================================
   Practice panel inside the modal
   ---------------------------------------------------------
   Slim layout: one header row with loop times + speed −/+,
   then the full-width loop range bar.
   ========================================================= */
.practice-panel {
  margin-top: 8px;
  padding: 6px 0 6px;            /* tight padding — no wasted space at bottom */
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Grid layout: 1fr | auto | 1fr keeps the speed control centered
   while loop info sits at the left edge. */
.practice-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  margin-bottom: 6px;
}

.practice-info  { justify-self: start;  }
.speed-control  { justify-self: center; }
.practice-hint  { justify-self: end;    }

.practice-info,
.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Discoverability hint that auto-fades after a few seconds. It lives
   in the empty right column of the practice-header grid so it never
   competes with the loop info or speed control. */
.practice-hint {
  font-size: 12px;
  font-style: italic;
  opacity: 0;
  color: rgba(255, 255, 255, 0.85);
  transition: opacity 400ms ease;
  pointer-events: none;
  white-space: nowrap;
}
.practice-hint.visible {
  opacity: 0.9;
}
/* On narrow screens the practice-header gets tight — drop the hint
   so the speed control isn't squeezed. */
@media (max-width: 640px) {
  .practice-hint { display: none; }
}

.practice-label {
  opacity: 0.7;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 1px;
  font-weight: 500;
}

.practice-times,
.practice-value {
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.practice-value {
  min-width: 54px;
  text-align: center;
}

.practice-arrow {
  margin: 0 6px;
  opacity: 0.6;
}

/* Small circular −/+ buttons for speed */
.speed-step-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.speed-step-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.5);
  transform: scale(1.06);
}

.speed-step-btn:active {
  transform: scale(0.94);
}

.speed-step-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* ---- Dual-thumb range slider ----
   Horizontal inset (28px each side) matches YouTube's own progress
   bar margins, so the two timelines visually line up.
   No bottom margin — the panel's padding handles spacing. */
.range-slider {
  position: relative;
  height: 36px;
  margin: 0 28px;
}

.range-slider .range-track {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 5px;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.18);
  border-radius: 3px;
}

.range-slider .range-fill {
  position: absolute;
  top: 50%;
  height: 5px;
  transform: translateY(-50%);
  background: var(--color-primary);
  border-radius: 3px;
  pointer-events: none;
}

/* Two overlapping range inputs */
.range-slider input[type="range"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 36px;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none;
  outline: none;
}

.range-slider input[type="range"]::-webkit-slider-runnable-track {
  background: transparent;
  height: 36px;
}

.range-slider input[type="range"]::-moz-range-track {
  background: transparent;
  height: 36px;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid #fff;
  pointer-events: all;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  margin-top: -8px;
}

.range-slider input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-primary);
  border: 2px solid #fff;
  pointer-events: all;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.range-slider input[type="range"]:active::-webkit-slider-thumb { cursor: grabbing; }
.range-slider input[type="range"]:active::-moz-range-thumb    { cursor: grabbing; }

/* Floating timestamp tooltip above each thumb */
.range-tooltip {
  position: absolute;
  bottom: calc(100% - 4px);
  background: var(--color-primary-dark);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.range-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-primary-dark);
}

.range-tooltip.visible { opacity: 1; }


/* =========================================
   Empty state
   ========================================= */
.empty-hint {
  text-align: center;
  color: var(--color-muted);
  padding: 40px 16px;
  font-size: 15px;
}

/* =========================================
   Modal player overlay
   ========================================= */
.player-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.player-modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
  animation: fadeIn 0.2s ease;
}

/* Modal sizing logic:
   - Take as much width as possible, but cap at 95vw
   - And cap at whatever width still fits 16:9 within the available
     vertical space (100vh minus the close button area, minus the
     practice panel when it's showing)
   - And cap at 1600px absolute max on huge monitors */
.modal-content {
  position: relative;
  z-index: 1;
  width: min(95vw, calc((100vh - 80px) * 16 / 9), 1600px);
  animation: zoomIn 0.25s ease;
}

/* When practice mode is on, reserve ~80px below the video for the
   (now slim) practice panel — header row + range slider, tight padding. */
.player-modal.practice-active .modal-content {
  width: min(95vw, calc((100vh - 80px - 80px) * 16 / 9), 1600px);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* The iframe lives here, 16:9 ratio */
.modal-player-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-player-frame iframe,
.modal-player-frame #modal-player {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* Close button (X) in the top-right of the modal */
.modal-close {
  position: absolute;
  top: -42px;
  right: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: #333;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.15s ease;
  font-family: inherit;
  padding: 0;
  font-weight: 300;
}

.modal-close:hover {
  background: #fff;
  transform: scale(1.05);
}

/* Speed indicator that briefly appears over the player */
.modal-speed-indicator {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-speed-indicator.visible { opacity: 1; }

/* On small screens, give the modal a bit more room */
@media (max-width: 600px) {
  .player-modal { padding: 12px; }
  .modal-close {
    top: -38px;
    width: 32px;
    height: 32px;
    font-size: 22px;
  }
}

/* When the modal is open, prevent the page behind from scrolling */
body.modal-open {
  overflow: hidden;
}

/* =========================================
   Practice dashboard (inline aside)
   ========================================= */

.dashboard-header {
  margin-bottom: 14px;
}
.dashboard-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--color-primary-dark);
}
.dashboard-sub {
  margin: 2px 0 0;
  color: var(--color-muted);
  font-size: 12px;
}

/* ---- Hero row: goal ring + streak side-by-side ---- */
.dashboard-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.stats-goal-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
}
.goal-ring {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}
.goal-ring-track,
.goal-ring-fill {
  fill: none;
  stroke-width: 9;
  stroke-linecap: round;
}
.goal-ring-track {
  stroke: rgba(0, 0, 0, 0.07);
}
.goal-ring-fill {
  stroke: var(--color-primary, #f48fb1);
  stroke-dasharray: 326.7;        /* 2π × 52 ≈ 326.7 */
  stroke-dashoffset: 326.7;       /* JS shrinks this */
  transition: stroke-dashoffset 600ms ease;
}
.goal-ring-text {
  position: absolute;
  text-align: center;
  line-height: 1.2;
}
.goal-ring-text strong {
  display: block;
  font-size: 22px;
  color: var(--color-primary-dark);
  font-variant-numeric: tabular-nums;
}
.goal-of {
  font-size: 12px;
  color: var(--color-muted);
}

.stats-streak-card {
  text-align: center;
}
.streak-flame {
  font-size: 32px;
  line-height: 1;
  margin-bottom: 4px;
}
.streak-current {
  font-size: 16px;
  color: var(--color-text, #333);
}
.streak-current strong {
  font-size: 22px;
  color: var(--color-primary-dark);
  margin-right: 4px;
}
.streak-best {
  font-size: 12px;
  color: var(--color-muted);
  margin-top: 2px;
}

.dashboard-label {
  display: block;
  font-size: 11px;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.goal-edit-row {
  display: flex;
  gap: 8px;
}
.goal-edit-row input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
}
.goal-edit-row button {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary, #f48fb1);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.goal-edit-row button:hover { filter: brightness(1.05); }

/* ---- Section spacing ---- */
.dashboard-section {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}
.dashboard-section:first-of-type { border-top: none; margin-top: 0; }
.dashboard-section h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: 600;
}

/* ---- Calendar heatmap ---- */
.heatmap-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 14px);
  grid-auto-flow: column;
  grid-auto-columns: 14px;
  gap: 3px;
  overflow-x: auto;
}
.hm-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: var(--hm-l0, rgba(0, 0, 0, 0.06));
  display: inline-block;
}
.hm-l0 { background: rgba(0, 0, 0, 0.06); }
.hm-l1 { background: #fce4ec; }     /* light pink */
.hm-l2 { background: #f8bbd0; }
.hm-l3 { background: #f48fb1; }
.hm-l4 { background: #ec407a; }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--color-muted);
}
.hm-legend-label {
  margin: 0 4px;
}

/* ---- Sidebar-specific tweaks ---- */
.dashboard-section canvas {
  display: block;
  max-width: 200px;
  max-height: 200px;
  margin: 0 auto;
}
.empty-note {
  color: var(--color-muted);
  font-size: 13px;
  font-style: italic;
}

.song-list,
.ranked-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.song-list li,
.ranked-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  font-size: 14px;
}
.song-list li:last-child,
.ranked-list li:last-child { border-bottom: none; }
.song-list .song-title,
.ranked-list .song-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 12px;
}
.song-list .song-sec,
.ranked-list .song-sec {
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.ranked-list { counter-reset: rank; }
.ranked-list li::before {
  counter-increment: rank;
  content: counter(rank) ".";
  width: 22px;
  flex-shrink: 0;
  color: var(--color-muted);
  font-weight: 600;
}

.dashboard-footnote {
  margin-top: 14px;
  font-size: 13px;
  color: var(--color-muted);
}
.dashboard-footnote strong {
  color: var(--color-text, #333);
}

/* Compact down the heatmap a bit so it fits the sidebar nicely */
.dashboard .heatmap {
  grid-template-rows: repeat(7, 12px);
  grid-auto-columns: 12px;
  gap: 2px;
}
.dashboard .hm-cell {
  width: 12px;
  height: 12px;
}

/* =========================================
   Login screen
   -----------------------------------------
   Full-viewport overlay shown until Firebase
   Auth resolves a signed-in user. Hidden via
   the [hidden] attribute when login succeeds.
   ========================================= */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fff0f3 0%, #e8f2ff 100%);
  padding: 24px 16px;
}
/* Class selectors normally override the user-agent [hidden] rule, so
   we have to re-establish the hide behavior explicitly. */
.login-screen[hidden],
body.signed-in .login-screen {
  display: none !important;
}

/* =========================================
   Post-login loading overlay
   -----------------------------------------
   Covers everything between "auth succeeded"
   and "data fully rendered" so the user
   never sits looking at a stale login form.
   ========================================= */
.app-loading {
  position: fixed;
  inset: 0;
  z-index: 2100;          /* above login (2000) and player (1000) */
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fff0f3 0%, #e8f2ff 100%);
}
.app-loading[hidden] { display: none !important; }
.app-loading-card {
  text-align: center;
  padding: 24px 32px;
}
.app-loading-spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 14px;
  border: 3px solid rgba(255, 143, 163, 0.25);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: app-loading-spin 0.8s linear infinite;
}
.app-loading-text {
  margin: 0;
  font-size: 14px;
  color: var(--color-primary-dark);
  font-weight: 500;
}
@keyframes app-loading-spin {
  to { transform: rotate(360deg); }
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 18px;
  padding: 28px 26px 24px;
  box-shadow: 0 10px 32px rgba(255, 143, 163, 0.18);
}
.login-title {
  margin: 0 0 6px;
  font-size: 22px;
  text-align: center;
  color: var(--color-primary-dark);
}
.login-sub {
  margin: 0 0 22px;
  text-align: center;
  color: var(--color-muted);
  font-size: 13px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--color-muted);
}
.login-field input {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: var(--color-text);
  width: 100%;
}
.login-field input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  border-color: transparent;
}

/* Password field with show/hide toggle inside */
.login-password-wrap {
  position: relative;
}
.login-password-wrap input {
  padding-right: 44px;       /* leave room for the toggle button */
}
.login-password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  border-radius: 6px;
  opacity: 0.55;
  transition: opacity 150ms ease, background 150ms ease;
}
.login-password-toggle:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.04);
}
.login-password-toggle.showing { opacity: 1; }
.login-submit {
  margin-top: 4px;
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  background: var(--color-primary);
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 150ms ease, transform 150ms ease;
}
.login-submit:hover:not(:disabled) { filter: brightness(1.05); }
.login-submit:active:not(:disabled) { transform: scale(0.98); }
.login-submit:disabled {
  opacity: 0.65;
  cursor: progress;
}
.login-error {
  margin: 4px 0 0;
  color: #c0392b;
  font-size: 13px;
  text-align: center;
}

/* While signed-out, hide everything except the login screen. */
body:not(.signed-in) .site-header,
body:not(.signed-in) .filter-bar,
body:not(.signed-in) .app-layout,
body:not(.signed-in) .player-modal {
  display: none !important;
}

/* =========================================
   Logout button + signed-in user text in dashboard header
   ========================================= */
.dashboard-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.logout-btn {
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-muted);
  font: inherit;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.logout-btn:hover {
  background: var(--color-tag-bg);
  color: var(--color-primary-dark);
}
.dashboard-user {
  display: inline-block;
  margin-left: 6px;
  color: var(--color-muted);
  font-size: 11px;
  opacity: 0.75;
}
.dashboard-user::before { content: "· "; opacity: 0.5; }
