/* ============================================================
   Ruang Belajar Abah - Custom Styles
   ============================================================ */

:root {
    --rba-indigo: #4f46e5;
    --rba-pink: #ec4899;
    --rba-amber: #f59e0b;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

.font-fredoka {
    font-family: 'Fredoka', cursive;
}

/* Fokus keyboard yang jelas */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
}

/* Navigasi & Tombol Aktif */
.nav-btn.active {
    background-color: rgba(255, 255, 255, 0.3) !important;
    border: 2px solid #fde047;
    font-weight: 800;
}

.phase-btn.active {
    background-color: #6366f1;
    color: #fff;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.subject-card:hover {
    transform: translateY(-6px) rotate(1deg);
}

.subject-card:active {
    transform: translateY(-2px) scale(0.99);
}

/* Scrollbar ramah anak */
.nav-scroll::-webkit-scrollbar,
#chat-window::-webkit-scrollbar,
#gen-questions-list::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.nav-scroll::-webkit-scrollbar-thumb,
#chat-window::-webkit-scrollbar-thumb,
#gen-questions-list::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.35);
    border-radius: 999px;
}

/* Navigasi horizontal: geser, panah, dan petunjuk */
.nav-scroll {
    scroll-behavior: smooth;
    scroll-padding-inline: 48px;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}

#nav-scroll:focus-visible {
    outline: 3px solid #fde047;
    outline-offset: -3px;
    border-radius: 16px;
}

.nav-scroll.nav-fade-start {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px);
    mask-image: linear-gradient(to right, transparent 0, #000 28px);
}

.nav-scroll.nav-fade-end {
    -webkit-mask-image: linear-gradient(to left, transparent 0, #000 28px);
    mask-image: linear-gradient(to left, transparent 0, #000 28px);
}

.nav-scroll.nav-fade-start.nav-fade-end {
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 28px, #000 calc(100% - 28px), transparent 100%);
}

.nav-arrow {
    position: absolute;
    top: 50%;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.92);
    color: #4338ca;
    font-size: 12px;
    box-shadow: 0 6px 16px rgba(30, 27, 75, 0.35);
    transform: translateY(-50%);
    transition: transform 0.15s ease, background-color 0.15s ease;
    cursor: pointer;
}

.nav-arrow:hover {
    background: #fff;
    transform: translateY(-50%) scale(1.08);
}

.nav-arrow:active {
    transform: translateY(-50%) scale(0.96);
}

.nav-arrow[hidden] {
    display: none;
}

.nav-arrow-prev {
    left: 2px;
}

.nav-arrow-next {
    right: 2px;
}

.nav-arrow.is-nudging {
    animation: navArrowNudge 1.1s ease-in-out 3;
}

.nav-hint {
    display: none;
    position: absolute;
    right: 10px;
    top: calc(100% + 10px);
    z-index: 30;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 999px;
    background: #fff;
    border: 2px solid #fde047;
    color: #3730a3;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 12px 28px rgba(49, 46, 129, 0.28);
}

.nav-hint.is-visible {
    display: flex;
    animation: navHintIn 0.35s ease-out both;
}

.nav-hint::before {
    content: "";
    position: absolute;
    top: -7px;
    right: 20px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-left: 2px solid #fde047;
    border-top: 2px solid #fde047;
    transform: rotate(45deg);
}

@keyframes navHintIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes navArrowNudge {
    0%, 100% {
        transform: translateY(-50%) translateX(0);
    }
    50% {
        transform: translateY(-50%) translateX(4px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .nav-scroll {
        scroll-behavior: auto;
    }

    .nav-arrow.is-nudging,
    .nav-hint.is-visible {
        animation: none;
    }
}

@media (pointer: coarse) {
    .nav-arrow {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
}

/* Chip saran pertanyaan */
.suggestion-chip {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    color: #9d174d;
    background: #fff;
    border: 1px solid #fbcfe8;
    border-radius: 999px;
    padding: 6px 12px;
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.suggestion-chip:hover {
    background: #fdf2f8;
    transform: translateY(-1px);
}

/* ==========================================
   EFEK ANIMASI BERMAIN & CERIA
   ========================================== */

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-12px) rotate(4deg); }
}

.float-anim {
    animation: float 4s ease-in-out infinite;
}

@keyframes spinSlow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spin-slow {
    animation: spinSlow 12s linear infinite;
}

@keyframes pulseSlow {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse-anim {
    animation: pulseSlow 3s ease-in-out infinite;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.toast-item {
    animation: toastIn 0.2s ease-out;
    box-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.35);
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-panel {
    animation: modalIn 0.18s ease-out;
}

@keyframes resultPop {
    0% { transform: scale(0.85); opacity: 0; }
    70% { transform: scale(1.04); }
    100% { transform: scale(1); opacity: 1; }
}

.result-pop {
    animation: resultPop 0.35s ease-out;
}

/* Materi */
#materi-body {
    line-height: 1.85;
}

.materi-topic-btn {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.materi-topic-btn.active {
    background: #eef2ff;
    color: #3730a3;
    border-color: #a5b4fc;
    font-weight: 800;
}

/* Opsi kuis */
.quiz-opt-btn {
    transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
}

.quiz-opt-btn:hover:not(:disabled) {
    transform: translateX(2px);
}

.quiz-opt-btn:disabled {
    cursor: default;
}

/* Loading shimmer */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.ai-loading {
    background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease infinite;
}

/* Prose sederhana untuk hasil modul ajar */
.prose h1,
.prose h2,
.prose h3 {
    color: #312e81;
    font-weight: 800;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    line-height: 1.35;
}

.prose h1 { font-size: 1.35rem; }
.prose h2 { font-size: 1.2rem; }
.prose h3 { font-size: 1.05rem; }

.prose p {
    margin-bottom: 0.6rem;
    line-height: 1.75;
}

.prose ul,
.prose ol {
    margin: 0.4rem 0 0.8rem 1.25rem;
}

.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li { margin-bottom: 0.25rem; }

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0 1rem;
    font-size: 0.8rem;
}

.prose th,
.prose td {
    border: 1px solid #c7d2fe;
    padding: 0.45rem 0.6rem;
    text-align: left;
    vertical-align: top;
}

.prose th {
    background: #eef2ff;
    font-weight: 800;
}

.prose strong { font-weight: 800; }

.prose blockquote {
    border-left: 4px solid #f9a8d4;
    padding-left: 0.8rem;
    color: #475569;
    font-style: italic;
}

/* Ruang chat */
.chat-bubble-ai,
.chat-bubble-user {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-bubble-ai {
    white-space: pre-wrap;
}

.chat-bubble-user {
    white-space: pre-wrap;
}

/* Print area: tidak terlihat di layar */
#print-area {
    display: none;
}

/* ==========================================
   FORMAT KHUSUS CETAK (PRINT RULES)
   ========================================== */
@media print {
    @page {
        size: A4;
        margin: 12mm;
    }

    html,
    body {
        background: #fff !important;
        color: #000 !important;
        font-size: 12px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Sembunyikan seluruh UI saat print-area digunakan */
    body.printing > *:not(#print-area) {
        display: none !important;
    }

    #print-area {
        display: block !important;
        width: 100%;
    }

    #print-area .no-print,
    #print-area button {
        display: none !important;
    }

    #print-area .rapor-paper,
    #print-area .print-sheet {
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    #print-area .print-sheet {
        page-break-after: avoid;
    }

    #print-area .prose {
        font-size: 11.5px;
        line-height: 1.6;
    }

    #print-area .prose h1,
    #print-area .prose h2,
    #print-area .prose h3 {
        page-break-after: avoid;
    }

    #print-area .prose table {
        page-break-inside: auto;
    }

    #print-area .prose tr {
        page-break-inside: avoid;
    }

    /* Fallback jika user menekan Ctrl+P tanpa tombol aplikasi */
    body:not(.printing) .no-print {
        display: none !important;
    }

    body:not(.printing) header,
    body:not(.printing) footer,
    body:not(.printing) nav,
    body:not(.printing) #toast-container,
    body:not(.printing) #modal-siswa,
    body:not(.printing) #modal-apikey,
    body:not(.printing) #modal-remedial {
        display: none !important;
    }
}

/* Hormati preferensi pengguna yang mengurangi animasi */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ==========================================
   GAMIFIKASI & KONFETI
   ========================================== */
.confetti-piece {
    position: fixed;
    top: -12px;
    width: 10px;
    height: 16px;
    border-radius: 3px;
    z-index: 90;
    pointer-events: none;
    animation: confettiFall 2.2s ease-in forwards;
}

@keyframes confettiFall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(105vh) rotate(720deg); opacity: 0; }
}

.adventure-card {
    isolation: isolate;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ==========================================
   BELAJAR FOKUS
   ========================================== */
#focus-timer-display {
    letter-spacing: 0.04em;
    line-height: 1;
}

#focus-progress-bar {
    transition: width 0.4s linear;
}

/* ==========================================
   MODE PROYEKTOR
   ========================================== */
#modal-proyektor #projector-body {
    font-size: 22px;
}

#modal-proyektor #projector-body .print-sheet {
    max-width: 1100px;
    margin: 0 auto;
}

#modal-proyektor #projector-body h1,
#modal-proyektor #projector-body h2,
#modal-proyektor #projector-body h3 {
    color: #312e81;
}

#modal-proyektor #projector-body table {
    font-size: 0.8em;
}

/* ==========================================
   AKSESIBILITAS
   ========================================== */
html.a11y-large-text {
    font-size: 18px;
}

.a11y-large-text body {
    line-height: 1.7;
}

html.a11y-dyslexia body,
html.a11y-dyslexia .font-fredoka,
body.a11y-dyslexia,
body.a11y-dyslexia .font-fredoka {
    font-family: 'Comic Sans MS', 'Verdana', 'Trebuchet MS', sans-serif !important;
    letter-spacing: 0.02em;
    word-spacing: 0.08em;
}

html.a11y-high-contrast body {
    filter: contrast(1.12) saturate(1.15);
}

html.a11y-high-contrast button,
html.a11y-high-contrast a,
html.a11y-high-contrast select,
html.a11y-high-contrast input,
html.a11y-high-contrast textarea {
    border-width: 2px !important;
}

html.a11y-high-contrast .text-slate-400,
html.a11y-high-contrast .text-slate-500,
html.a11y-high-contrast .text-slate-600 {
    color: #1e293b !important;
}

html.a11y-high-contrast .nav-btn:focus-visible,
html.a11y-high-contrast button:focus-visible,
html.a11y-high-contrast a:focus-visible {
    outline: 4px solid #f59e0b !important;
    outline-offset: 3px;
}

html.a11y-reduce-motion *,
html.a11y-reduce-motion *::before,
html.a11y-reduce-motion *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

html.a11y-auto-read #btn-read-materi {
    box-shadow: 0 0 0 4px rgba(236, 72, 153, 0.2);
}

/* Tombol rentang laporan orang tua */
.parent-range-btn.active {
    background: #4f46e5;
    color: #fff;
}

/* Scrollbar untuk panel baru */
#journal-list::-webkit-scrollbar,
#item-analysis::-webkit-scrollbar,
#profile-content::-webkit-scrollbar,
#projector-body::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#journal-list::-webkit-scrollbar-thumb,
#item-analysis::-webkit-scrollbar-thumb,
#profile-content::-webkit-scrollbar-thumb,
#projector-body::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.35);
    border-radius: 999px;
}

/* ==========================================
   TAMBAHAN CETAK UNTUK FITUR BARU
   ========================================== */
@media print {
    body:not(.printing) #modal-profil,
    body:not(.printing) #modal-petualangan,
    body:not(.printing) #modal-fokus,
    body:not(.printing) #modal-aksesibilitas,
    body:not(.printing) #modal-donasi,
    body:not(.printing) #modal-proyektor,
    body:not(.printing) #offline-banner {
        display: none !important;
    }
}
