/**
 * C214 Flashcard Styles
 * 3D card flip animations and adaptive UI
 */

/* ============================================
   Container and Layout
   ============================================ */

#flashcard-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: 0.5rem 1rem 1rem;
}

#flashcard-panel.active {
    display: flex;
}

#flashcard-container {
    display: flex;
    flex-direction: column;
    max-width: 580px;
    margin: 0 auto;
    width: 100%;
    gap: clamp(0.75rem, 2vw, 1.25rem);
}

/* ============================================
   Header Stats Bar
   ============================================ */

.flashcard-header {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 1.25rem);
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    flex-shrink: 0;
    gap: clamp(0.5rem, 2vw, 1rem);
    flex-wrap: wrap;
}

#flashcard-streak {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 1.25rem;
    font-weight: bold;
}

#flashcard-streak.pulse {
    animation: pulse 0.3s ease;
}

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

.streak-icon {
    font-size: 1.4rem;
}

.streak-count {
    color: #ff6b35;
    min-width: 1.5ch;
    text-align: center;
}

#flashcard-stats {
    display: flex;
    gap: clamp(0.75rem, 2vw, 1.25rem);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 45px;
}

.stat-value {
    font-size: clamp(0.95rem, 2.5vw, 1.2rem);
    font-weight: bold;
    color: #00bcd4;
}

.stat-label {
    font-size: 0.65rem;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Progress Ring */
#flashcard-progress-ring {
    width: 50px;
    height: 50px;
    display: none; /* Hidden for cleaner layout */
}

#flashcard-progress-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.progress-ring-bg {
    fill: none;
    stroke: #333;
    stroke-width: 8;
}

.progress-ring-fill {
    fill: none;
    stroke: #4caf50;
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.3s ease;
}

.progress-ring-text {
    fill: #fff;
    font-size: 18px;
    font-weight: bold;
    transform: rotate(90deg);
    transform-origin: center;
}

/* Difficulty Meter */
#flashcard-difficulty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.difficulty-label {
    font-size: 0.6rem;
    color: #999;
}

.difficulty-bar {
    display: flex;
    gap: 2px;
}

.difficulty-segment {
    width: 10px;
    height: 5px;
    border-radius: 2px;
    background: #444;
    transition: background 0.3s ease;
}

.difficulty-name {
    font-size: 0.7rem;
    font-weight: bold;
    color: #ccc;
}

/* ============================================
   Topic Selector
   ============================================ */

.flashcard-controls {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

#flashcard-topic-select {
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.85rem;
    font-family: 'Share Tech Mono', monospace;
    cursor: pointer;
    min-width: 160px;
    transition: all 0.2s ease;
}

#flashcard-topic-select:hover {
    background: rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.25);
}

#flashcard-topic-select:focus {
    outline: none;
    border-color: #00bcd4;
    box-shadow: 0 0 0 2px rgba(0, 188, 212, 0.2);
}

/* ============================================
   Card Stage and 3D Container
   ============================================ */

#flashcard-stage {
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
    position: relative;
    min-height: clamp(280px, 45vh, 420px);
    padding: 0.5rem 0;
}

#flashcard {
    width: 100%;
    max-width: min(90%, 450px);
    min-height: 280px;
    height: auto;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s ease;
    cursor: pointer;
}

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

/* ============================================
   Card Faces
   ============================================ */

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 14px;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

#flashcard-front {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border: 2px solid #00bcd4;
}

#flashcard-back {
    background: linear-gradient(135deg, #0f3460 0%, #1a1a2e 100%);
    border: 2px solid #4caf50;
    transform: rotateY(180deg);
    overflow-y: auto;
}

/* ============================================
   Card Content
   ============================================ */

.card-badges {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.card-type-badge,
.card-topic-badge {
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: bold;
    text-transform: uppercase;
}

.card-type-badge {
    color: #fff;
}

.card-topic-badge {
    background: rgba(255, 255, 255, 0.1);
    color: #aaa;
}

.card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0;
    margin: auto 0;
}

/* Scroll fade indicator */
.card-face::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(to top, var(--card-bg-end, #1a1a2e), transparent);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.card-face.has-overflow::after {
    opacity: 1;
}

#flashcard-front {
    --card-bg-end: #16213e;
}

#flashcard-back {
    --card-bg-end: #1a1a2e;
}

/* Custom Scrollbar for Cards */
.card-face::-webkit-scrollbar,
.card-content::-webkit-scrollbar {
    width: 6px;
}

.card-face::-webkit-scrollbar-track,
.card-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.card-face::-webkit-scrollbar-thumb,
.card-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.card-face::-webkit-scrollbar-thumb:hover,
.card-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Firefox scrollbar */
.card-face,
.card-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
}

.card-question {
    font-size: clamp(0.9rem, 2.5vw, 1.15rem);
    line-height: 1.5;
    color: #fff;
    text-align: center;
}

.card-hint {
    font-size: 0.8rem;
    color: #ffc107;
    text-align: center;
    font-style: italic;
}

.card-answer {
    font-size: clamp(0.85rem, 2.2vw, 1.05rem);
    line-height: 1.5;
    color: #4caf50;
    text-align: center;
    font-weight: 500;
}

.card-formula {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.6rem;
    border-radius: 6px;
    text-align: center;
    color: #00bcd4;
    white-space: pre-wrap;
}

.card-explanation {
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    color: #bbb;
    line-height: 1.4;
    text-align: center;
}

.card-example {
    font-size: 0.75rem;
    color: #888;
    border-left: 2px solid #666;
    padding-left: 0.5rem;
    margin-top: 0.25rem;
}

.card-footer {
    text-align: center;
    padding-top: 0.5rem;
}

.tap-hint {
    font-size: 0.75rem;
    color: #666;
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ============================================
   Swipe Indicators
   ============================================ */

.swipe-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.swipe-indicator-left {
    left: -80px;
    background: rgba(244, 67, 54, 0.8);
    color: #fff;
}

.swipe-indicator-right {
    right: -80px;
    background: rgba(76, 175, 80, 0.8);
    color: #fff;
}

/* ============================================
   Response Buttons
   ============================================ */

#flashcard-responses {
    display: flex;
    justify-content: center;
    gap: clamp(0.4rem, 1.5vw, 0.75rem);
    padding: 0.5rem 1rem;
    transition: opacity 0.3s ease;
    flex-shrink: 0;
    min-height: 50px;
    max-width: 400px;
    margin: 0 auto;
}

#flashcard-responses.hidden {
    opacity: 0;
    pointer-events: none;
    min-height: 60px;
}

.response-btn {
    flex: 1 1 70px;
    max-width: 95px;
    min-height: 44px;
    padding: 0.5rem 0.3rem;
    border: none;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.response-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

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

.response-btn.again {
    background: linear-gradient(135deg, #f44336, #d32f2f);
    color: #fff;
}

.response-btn.hard {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: #fff;
}

.response-btn.good {
    background: linear-gradient(135deg, #4caf50, #388e3c);
    color: #fff;
}

.response-btn.easy {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    color: #fff;
}

.response-label {
    font-size: 0.7rem;
}

.response-key {
    font-size: 0.6rem;
    opacity: 0.7;
}

/* ============================================
   Celebration Popup
   ============================================ */

.celebration-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    z-index: 1000;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.celebration-popup.show {
    transform: translate(-50%, -50%) scale(1);
}

.celebration-content {
    background: linear-gradient(135deg, #ff6b35, #ff8c42);
    padding: 2rem 3rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(255, 107, 53, 0.4);
}

.celebration-streak {
    font-size: 3rem;
    font-weight: bold;
    color: #fff;
    animation: bounce 0.5s ease infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.celebration-message {
    font-size: 1.2rem;
    color: #fff;
    margin-top: 0.5rem;
}

/* ============================================
   Mastery Panel
   ============================================ */

#flashcard-mastery-panel {
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
}

#flashcard-mastery-panel:empty {
    display: none;
}

#flashcard-mastery-panel h3 {
    margin: 0 0 1rem 0;
    color: #00bcd4;
    font-size: 1rem;
}

.mastery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
}

.mastery-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem;
    border-radius: 8px;
}

.mastery-topic {
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

.mastery-bar-container {
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.mastery-bar {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.mastery-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: #888;
}

/* ============================================
   No Cards Message
   ============================================ */

.no-cards-message {
    text-align: center;
    padding: 2rem;
}

.no-cards-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.no-cards-message h3 {
    color: #4caf50;
    margin: 0 0 1rem 0;
}

.no-cards-message p {
    color: #888;
    margin: 0.5rem 0;
}

/* ============================================
   Tablet Responsive
   ============================================ */

@media (max-width: 768px) {
    #flashcard-container {
        max-width: 520px;
    }

    #flashcard {
        max-width: min(95%, 420px);
    }

    .stat-value {
        font-size: 1rem;
    }
}

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 600px) {
    #flashcard-panel {
        padding: 0.25rem 0.5rem 0.5rem;
    }

    #flashcard-container {
        gap: 0.6rem;
        max-width: 100%;
    }

    #flashcard-stage {
        min-height: 260px;
        padding: 0.25rem 0;
    }

    #flashcard {
        max-width: 100%;
        min-height: 260px;
    }

    .card-face {
        padding: 0.6rem 0.8rem;
    }

    .flashcard-header {
        padding: 0.5rem 0.75rem;
    }

    #flashcard-stats {
        gap: 0.6rem;
    }

    .stat-value {
        font-size: 0.95rem;
    }

    .stat-label {
        font-size: 0.6rem;
    }

    #flashcard-responses {
        min-height: 48px;
        padding: 0.4rem;
    }

    .response-btn {
        max-width: 80px;
        min-height: 44px;
    }

    .swipe-indicator {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }

    .swipe-indicator-left {
        left: -50px;
    }

    .swipe-indicator-right {
        right: -50px;
    }
}

@media (max-width: 400px) {
    #flashcard-responses {
        gap: 0.4rem;
    }

    .response-btn {
        max-width: 70px;
        font-size: 0.7rem;
    }

    .response-key {
        display: none;
    }

    #flashcard {
        min-height: 240px;
    }

    .card-question {
        font-size: 0.9rem;
    }
}

/* ============================================
   Dark Mode Adjustments
   ============================================ */

body.dark-mode #flashcard-front,
body.dark-mode #flashcard-back {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

body.light-mode .card-face {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

body.light-mode #flashcard-front {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    border-color: #00838f;
    --card-bg-end: #e0e0e0;
}

body.light-mode #flashcard-back {
    background: linear-gradient(135deg, #e8f5e9 0%, #f5f5f5 100%);
    border-color: #2e7d32;
    --card-bg-end: #f5f5f5;
}

body.light-mode .card-question {
    color: #333;
}

body.light-mode .card-answer {
    color: #2e7d32;
}

body.light-mode .card-explanation {
    color: #555;
}

body.light-mode .card-formula {
    background: rgba(0, 0, 0, 0.1);
    color: #00838f;
}

body.light-mode .flashcard-header {
    background: rgba(0, 0, 0, 0.08);
}

body.light-mode .stat-value {
    color: #0097a7;
}

body.light-mode .stat-label {
    color: #666;
}

body.light-mode .streak-count {
    color: #e65100;
}

body.light-mode .difficulty-label,
body.light-mode .difficulty-name {
    color: #666;
}

body.light-mode .difficulty-segment {
    background: #ddd;
}

body.light-mode #flashcard-topic-select {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border-color: #ccc;
}

body.light-mode #flashcard-topic-select:hover {
    background: #fff;
    border-color: #aaa;
}

/* Light mode scrollbar */
body.light-mode .card-face::-webkit-scrollbar-track,
body.light-mode .card-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

body.light-mode .card-face::-webkit-scrollbar-thumb,
body.light-mode .card-content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}

body.light-mode .card-face::-webkit-scrollbar-thumb:hover,
body.light-mode .card-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
}

body.light-mode .card-face,
body.light-mode .card-content {
    scrollbar-color: rgba(0, 0, 0, 0.2) rgba(0, 0, 0, 0.05);
}
