/* ========================================================================
 V15 — Seven themes & mobile finishing layer (CSS only, no business logic)
 Loaded LAST so mobile polish does not erase selected theme personalities.
 Safeguards: no global button/body rewrites, no pet features, no API changes.
 ========================================================================= */
:root{--v15-tap:44px}
/* Content safety: image, embeds, long unbroken URLs, and table scrolling. */
#lesson-view :is(.lesson-article,#lesson-rich-text),
#course-details-view :is(.course-details-header,.lesson-card),
#student-dashboard :is(.main-content,.v2-card){min-width:0;overflow-wrap:anywhere}
#lesson-rich-text :is(img,video,canvas,svg,iframe){max-width:100%!important}
#lesson-rich-text img{height:auto!important}
#lesson-rich-text iframe{width:100%!important;display:block}
#lesson-rich-text table{max-width:100%;border-collapse:collapse}
#lesson-rich-text :is(pre,code){overflow-wrap:anywhere;white-space:pre-wrap}
#lesson-rich-text blockquote{max-width:100%;margin-inline:0}
/* Visible keyboard focus on app-specific cards and controls. */
:is(#student-dashboard,#main-dashboard-wrapper) :is(button,a,input,select,textarea,[role="button"],.option-card,.v2-theme-preview):focus-visible{
  outline:3px solid var(--main-theme,#2563eb)!important;
  outline-offset:3px!important;
}
/* Avoid hover decorations shifting tap targets on touch screens. */
@media(hover:none){
  html[data-platform-theme] :is(.course-card,.lesson-card,.dash-info-card):hover{transform:none!important}
}
/* Quiz choices use comfortable readable line-height across 7 visual identities. */
#quiz-view .option-card{min-height:52px;overflow-wrap:anywhere;line-height:1.7}
#quiz-result-view :is(.quiz-result-card,.quiz-review-panel){max-width:100%}
.quiz-review-panel :is(.qr-question h4,.qr-answer strong,.qr-explanation p){overflow-wrap:anywhere}

/* Admin appearance selector: actually show seven distinct micro-previews. */
#v2-appearance-view .v2-theme-preview{
  height:auto;min-height:138px;position:relative;isolation:isolate;
  display:flex;flex-direction:column;justify-content:flex-end;align-items:flex-start;
  gap:7px;overflow:hidden;padding:48px 17px 15px!important;
  text-align:right;white-space:normal;line-height:1.7;
  border:2px solid transparent;transition:border-color .16s ease,transform .16s ease,box-shadow .16s ease;
}
#v2-appearance-view .v2-theme-preview strong{position:relative;z-index:2;font-weight:900;font-size:17px;line-height:1.3}
#v2-appearance-view .v2-theme-preview span{position:relative;z-index:2;font-size:11px;line-height:1.65;opacity:.88}
#v2-appearance-view .v2-theme-preview::before{
  content:'';position:absolute;right:16px;top:14px;width:85px;height:24px;
  background:var(--v15-mini,#2563eb);border-radius:var(--v15-radius,14px);
  box-shadow:32px 16px 0 -5px var(--v15-mini-accent,rgba(37,99,235,.22));
  pointer-events:none;z-index:1;
}
#v2-appearance-view .v2-theme-preview.modern{--v15-mini:#2563eb;--v15-mini-accent:#c4b5fd;--v15-radius:14px;border-radius:24px}
#v2-appearance-view .v2-theme-preview.academy{--v15-mini:#c49945;--v15-mini-accent:#1b477a;--v15-radius:4px;border-radius:9px}
#v2-appearance-view .v2-theme-preview.minimal{--v15-mini:#0f766e;--v15-mini-accent:#d6eee9;--v15-radius:2px;border-radius:3px}
#v2-appearance-view .v2-theme-preview.premium{--v15-mini:#8052d9;--v15-mini-accent:#26bdd3;--v15-radius:12px;border-radius:25px 8px 25px 8px}
#v2-appearance-view .v2-theme-preview.girls{--v15-mini:#c2529a;--v15-mini-accent:#eac0de;--v15-radius:999px;border-radius:33px;background:linear-gradient(145deg,#fffafd,#f5e9ff,#e8f9f3);color:#56314e}
#v2-appearance-view .v2-theme-preview.action{--v15-mini:#16b8ff;--v15-mini-accent:#ff751a;--v15-radius:0;border-radius:0;clip-path:polygon(0 0,calc(100% - 16px) 0,100% 16px,100% 100%,16px 100%,0 calc(100% - 16px));background:linear-gradient(135deg,#05101e,#0d2944);color:#e8f5ff}
#v2-appearance-view .v2-theme-preview.horror{--v15-mini:#87304f;--v15-mini-accent:#563140;--v15-radius:0;border-radius:0;background:radial-gradient(circle at 85% 10%,#29141e,#0d090e);color:#f1e3e9}
#v2-appearance-view .v2-theme-preview.action strong{color:#f2faff}
#v2-appearance-view .v2-theme-preview.horror strong{color:#f1e3e9}
#v2-appearance-view .v2-theme-preview.selected{outline:3px solid var(--admin-accent,#3b82f6);outline-offset:2px;box-shadow:0 0 0 6px rgba(59,130,246,.13)}
#v2-appearance-view .v2-theme-preview[role="button"]{cursor:pointer}
#v2-appearance-view .v2-theme-preview[aria-pressed="true"]::after{
  content:'✓';position:absolute;left:13px;top:12px;width:25px;height:25px;
  display:grid;place-items:center;border-radius:50%;font-weight:900;font-size:14px;
  background:#fff;color:#1465ad;box-shadow:0 4px 12px rgba(0,0,0,.15);z-index:3;
}

/* V13 & V12 pagination: usable controls on small displays, no clipped labels. */
#main-dashboard-wrapper :is(.v13-controls,.pc-page-controls,.pc12-controls){min-width:0;max-width:100%}
#main-dashboard-wrapper :is(.v13-controls,.pc-page-controls) :is(button,input,select){min-height:44px}
#main-dashboard-wrapper :is(.v13-controls,.pc-page-controls) :is(input,select){min-width:0}
#main-dashboard-wrapper :is(.v13-table,.admin-table,.v2-table){border-collapse:separate;border-spacing:0}

@media(max-width:992px){
  /* Forms and help drawers always fit viewport. */
  #main-dashboard-wrapper :is(.v2-card,.pc-card,.comp-card,.settings-container,.stat-card){min-width:0;max-width:100%}
  #main-dashboard-wrapper :is(.v2-grid,.v2-form-grid,.comp-form-grid){min-width:0}
  #main-dashboard-wrapper :is(.v13-controls,.pc-page-controls){gap:8px;flex-wrap:wrap}
  #main-dashboard-wrapper :is(.v13-controls,.pc-page-controls) input{flex:1 1 160px;min-width:0}
  #main-dashboard-wrapper :is(.v13-controls,.pc-page-controls) button{min-height:44px}
  #main-dashboard-wrapper .admin-v3-quick-pop{max-height:min(75dvh,630px);overflow-y:auto;overscroll-behavior:contain}
  #main-dashboard-wrapper .ql-toolbar.ql-snow{max-width:100%;overflow-x:auto!important}
  #main-dashboard-wrapper .ql-editor{overflow-wrap:anywhere}
  /* Active modal doesn't clip action buttons. */
  .modal-overlay.active .modal-content{overscroll-behavior:contain}
}

@media(max-width:768px){
  #student-dashboard .main-content{min-width:0;max-width:100%}
  #student-dashboard .dashboard-header-cards{min-width:0;gap:10px!important}
  #student-dashboard .dash-info-card{min-width:0;overflow-wrap:anywhere}
  .student-mobile-bottom-nav{max-width:calc(100vw - 12px);box-sizing:border-box}
  .student-mobile-bottom-nav button{min-width:0!important;min-height:48px!important;flex:1 1 0}
  .student-mobile-bottom-nav button span{overflow:hidden;text-overflow:ellipsis;max-width:100%;white-space:nowrap}
  #lesson-view .video-wrapper,#lesson-view iframe{max-width:100%}
  #lesson-view .lesson-article{max-width:100%;box-sizing:border-box}
  #quiz-view .quiz-header{flex-wrap:wrap!important;min-width:0}
  #quiz-view .quiz-question{overflow-wrap:anywhere}
  #quiz-view .quiz-footer{max-width:100%}
  #quiz-result-view .qr-filters{scrollbar-width:thin}
  #quiz-result-view .qr-tool-row{min-width:0}
  #v2-quizzes-container{max-width:100%;min-width:0}
  #v2-quizzes-container .v2-card{max-width:100%}
  :is(.team-student-actions,.challenge-card-actions,.season-admin-actions) button{overflow-wrap:anywhere;white-space:normal}
}

/* Tiny phones: 2-up header/stat buttons cause overlap. */
@media(max-width:390px){
  #student-dashboard .dashboard-header-cards{grid-template-columns:minmax(0,1fr)!important}
  #student-dashboard .dash-info-card{min-width:0}
  #main-dashboard-wrapper .top-header .welcome-text h1{font-size:16px!important;white-space:normal!important;line-height:1.45!important}
  #main-dashboard-wrapper .top-header{gap:6px!important}
  #main-dashboard-wrapper .admin-v3-header-actions{gap:3px!important}
  #main-dashboard-wrapper .admin-v3-page-help,#main-dashboard-wrapper .admin-v3-help-center-btn{width:40px!important;min-width:40px!important;height:40px!important}
  #main-dashboard-wrapper .pc-page-controls button{flex:1 1 auto}
}

/* V15: guard against parent card & inputs in narrow/student dark views. */
@media(max-width:560px){
  .v14-parent-access-card{flex-direction:column;align-items:stretch!important}
  .v14-parent-access-card .v14-parent-access-btn{width:100%;min-height:46px}
  #v14-parent-access-modal .modal-content{width:100%!important;max-width:100%!important}
  #main-dashboard-wrapper #v2-appearance-view .v2-grid{grid-template-columns:1fr!important}
}

/* Theme-specific controls restored AFTER generic V7/V11 overrides. */
@media(max-width:768px){
  /* Modern: floating gradient / rounded. */
  html[data-platform-theme="modern"] :is(.course-card,.lesson-card,.quiz-container){border-radius:24px!important}
  html[data-platform-theme="modern"] :is(.course-card .primary-btn,.lesson-details button){border-radius:14px!important}
  /* Academy: stationery / gold accent. */
  html[data-platform-theme="academy"] :is(.course-card,.lesson-card,.quiz-container){border-radius:8px!important;border:1px solid #9a7d44!important}
  html[data-platform-theme="academy"] :is(.course-card .primary-btn,.lesson-details button){border-radius:5px!important}
  /* Minimal: sober flush square geometry. */
  html[data-platform-theme="minimal"] :is(.course-card,.lesson-card,.quiz-container){border-radius:4px!important;box-shadow:0 3px 12px rgba(15,23,42,.06)!important}
  html[data-platform-theme="minimal"] :is(.course-card .primary-btn,.lesson-details button){border-radius:4px!important}
  /* Premium: generous Bento cards with soft glass borders. */
  html[data-platform-theme="premium"] :is(.course-card,.lesson-card,.quiz-container){border-radius:25px!important}
  html[data-platform-theme="premium"] :is(.course-card .primary-btn,.lesson-details button){border-radius:16px!important}
  /* Girls: soft rounded/diary. */
  html[data-platform-theme="girls"] :is(.course-card,.lesson-card,.quiz-container,.lesson-article){border-radius:30px!important}
  html[data-platform-theme="girls"] :is(.course-card .primary-btn,.lesson-details button,.option-card){border-radius:999px!important}
  html[data-platform-theme="girls"] .option-card{padding:15px 18px 15px 40px!important}
  html[data-platform-theme="girls"] .option-card::before{left:12px}
  /* Action: angular screens, with no clip paths on touch (focus outline safe). */
  html[data-platform-theme="action"] :is(.course-card,.lesson-card,.quiz-container,.lesson-article){border-radius:2px!important;clip-path:none!important;border-color:#1a4b68!important}
  html[data-platform-theme="action"] :is(.course-card .primary-btn,.lesson-details button,.option-card){border-radius:2px!important;clip-path:none!important}
  html[data-platform-theme="action"] .option-card{padding:15px 48px 15px 15px!important}
  html[data-platform-theme="action"] .option-card::before{right:11px}
  html[data-platform-theme="action"] .lesson-article{border-right:4px solid #16b8ff!important}
  /* Dark Mystery: a quiet cinematic archive, NOT a white/default fallback. */
  html[data-platform-theme="horror"] :is(.course-card,.lesson-card,.quiz-container,.lesson-article){border-radius:0!important;border-color:#4e2735!important}
  html[data-platform-theme="horror"] :is(.course-card .primary-btn,.lesson-details button,.option-card){border-radius:0!important}
  html[data-platform-theme="horror"] .lesson-article{border-right:4px solid #7d2b48!important}
  /* All themes: preserve usable tappable targets and spacing. */
  html[data-platform-theme] :is(.course-card .primary-btn,.lesson-details button){min-height:44px!important}
}

/* Parent consent modal and review cards should remain theme-appropriate. */
html[data-platform-theme="girls"] .v14-parent-access-card{border-radius:30px;background:linear-gradient(135deg,#fffafd,#f7edfb);border-color:#ebd4e4}
html[data-platform-theme="girls"] .v14-parent-access-btn{border-radius:999px;background:linear-gradient(135deg,#c2529a,#8b5cc7)}
html[data-platform-theme="action"] .v14-parent-access-card{border-radius:2px;background:#0b1b29;border-color:#1a4b68}
html[data-platform-theme="action"] .v14-parent-access-btn{border-radius:2px;background:#1466c4;color:#fff}
html[data-platform-theme="horror"] .v14-parent-access-card{border-radius:0;background:#130e12;border-color:#512938}
html[data-platform-theme="horror"] .v14-parent-access-btn{border-radius:0;background:#7d2947;color:#fff}

/* Motion and printing preferences. */
@media(prefers-reduced-motion:reduce){
 #v2-appearance-view .v2-theme-preview,
 html[data-platform-theme] :is(.course-card,.lesson-card,.option-card){transition:none!important;animation:none!important}
}
@media print{
 .student-mobile-bottom-nav,.student-mobile-overlay,.mobile-theme-dock{display:none!important}
}

/* V15 visual QA fix: hero decorative pseudo elements expanded the *root*
   scrollable width by 50–180px on a 390px viewport even though content fit.
   Mobile uses painted backgrounds instead of offscreen decorative pseudo. */
@media(max-width:768px){
  html[data-platform-theme] .hero-section::before,
  html[data-platform-theme] .hero-section::after{
    content:none!important;display:none!important;
  }
}
/* V15 visual QA fix: Action X and Dark Mystery inherited black headings on
   dark hero/quiz surfaces from the older shared layout. */
html[data-platform-theme="action"] :is(.hero-section h1,.hero-section h2,.hero-section h3,.hero-section p,.section-title h2,.quiz-container h2,.quiz-container h3),
html[data-platform-theme="horror"] :is(.hero-section h1,.hero-section h2,.hero-section h3,.hero-section p,.section-title h2,.quiz-container h2,.quiz-container h3){
  color:#f2f8ff!important;
}
html[data-platform-theme="horror"] .hero-section p{color:#d5c3cd!important}
html[data-platform-theme="action"] .hero-section p{color:#bdd8eb!important}
html[data-platform-theme="action"] .quiz-container .quiz-question,
html[data-platform-theme="horror"] .quiz-container .quiz-question{color:#eef1f5!important}

/* Section labels rendered directly inside the dark student's content. */
html[data-platform-theme="action"] :is(#student-dashboard .main-content > h2,#student-dashboard .view > h2,#course-details-view > h2,#lesson-view > h2),
html[data-platform-theme="horror"] :is(#student-dashboard .main-content > h2,#student-dashboard .view > h2,#course-details-view > h2,#lesson-view > h2){
 color:#edf2f7!important;
}

/* V15.1 — Auth navigation visibility fix.
   The older mobile-polish-v7.css contains #auth-buttons{display:flex!important}
   on small screens. It overrides the login JS inline display:none and makes
   Login / Register appear even when the student is signed in.
   Honor the real login state from the existing server-backed dashboard checker:
   only hide when its JS has set an explicit display:none. Guest stays visible.
   Keep this at the end of the final loaded CSS file. */
#auth-buttons[style*="display: none"],
#auth-buttons[style*="display:none"],
#auth-buttons[hidden]{display:none!important}
#user-profile-menu[style*="display: none"],
#user-profile-menu[style*="display:none"],
#user-profile-menu[hidden]{display:none!important}


/* V15.2 — Compact course-only share button.
   The previous .primary-btn inherited the full course CTA dimensions. Keep
   the share action compact in visitor cards, enrolled cards, and stage lists;
   preserve 44px tap target and all existing course actions. */
:is(.course-card,.stage-course-row) .course-share-btn{
  box-sizing:border-box!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  flex:0 0 44px!important;
  width:44px!important;
  min-width:44px!important;
  max-width:44px!important;
  height:44px!important;
  min-height:44px!important;
  max-height:44px!important;
  padding:0!important;
  margin:0!important;
  font-size:16px!important;
  line-height:1!important;
  aspect-ratio:1 / 1;
  border-width:1.5px!important;
  border-style:solid!important;
  border-color:var(--main-theme,#2563eb)!important;
  border-radius:12px!important;
  background:var(--main-theme-light,rgba(37,99,235,.10))!important;
  color:var(--main-theme,#2563eb)!important;
  box-shadow:none!important;
  overflow:hidden!important;
}
:is(.course-card,.stage-course-row) .course-share-btn i{
  font-size:17px!important;
  line-height:1!important;
  flex:none;
  pointer-events:none;
}
:is(.course-card,.stage-course-row) .course-share-btn:hover{
  transform:translateY(-2px)!important;
  filter:brightness(1.05);
}
:is(.course-card,.stage-course-row) .course-share-btn:focus-visible{
  outline:3px solid var(--main-theme,#2563eb)!important;
  outline-offset:3px;
}
/* Preserve each V6.1/V15 theme's unique button geometry. */
html[data-platform-theme="girls"] :is(.course-card,.stage-course-row) .course-share-btn{border-radius:50%!important;padding-inline:0!important;padding:0!important}
html[data-platform-theme="academy"] :is(.course-card,.stage-course-row) .course-share-btn{border-radius:6px!important}
html[data-platform-theme="minimal"] :is(.course-card,.stage-course-row) .course-share-btn{border-radius:4px!important}
html[data-platform-theme="premium"] :is(.course-card,.stage-course-row) .course-share-btn{border-radius:15px!important}
html[data-platform-theme="action"] :is(.course-card,.stage-course-row) .course-share-btn{
  border-radius:2px!important;
  clip-path:none!important;
  background:#0b273b!important;
  border-color:#1686ba!important;
  color:#7cddff!important;
}
html[data-platform-theme="horror"] :is(.course-card,.stage-course-row) .course-share-btn{
  border-radius:0!important;
  clip-path:none!important;
  background:#201119!important;
  border-color:#7d3550!important;
  color:#e3a6ba!important;
}
/* Do not let the share icon grow with its parent CTA at any breakpoint. */
@media(max-width:768px){
  :is(.course-card,.stage-course-row) .course-share-btn{
    flex:0 0 44px!important;
    width:44px!important;
    min-width:44px!important;
    max-width:44px!important;
    height:44px!important;
    min-height:44px!important;
    max-height:44px!important;
    padding:0!important;
  }
}
@media(prefers-reduced-motion:reduce){
  :is(.course-card,.stage-course-row) .course-share-btn:hover{transform:none!important}
}
