/* flashcard-specific styles (see common.css for shared) */

body {
    color: #eee;
}

.app {
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
}

h1 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: #e2b96f;
}

.title {
    text-align: center;
    color: #aaa;
    font-size: 0.9rem;
}

.title-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 0.2rem;
    flex-wrap: wrap;
}

.start-challenge-btn {
    flex-shrink: 0;
    margin-left: 1rem;
    background: #e2b96f33;
}

.title-row .ruleset-select {
    padding: 0.4rem 2rem 0.4rem 0.6rem;
    background: #1a1a2e;
    color: #ccc;
    border: 1px solid #e2b96f44;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
}

.title-row .ruleset-select:focus {
    outline: none;
    border-color: #e2b96f;
}

/* --- Floating Search Button --- */
.search-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 3.125rem;
    height: 3.125rem;
    border-radius: 50%;
    background: #e2b96fee;
    border: none;
    color: #1a1a2e;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
}

.search-fab:hover {
    transform: scale(1.05);
    background: #d4a85a;
}

.search-fab:active {
    transform: scale(0.95);
}

.search-fab.active {
    background: #4fc3f7;
}

/* Challenge FAB (when embedded without header) */
.challenge-fab {
    position: fixed;
    bottom: 5rem;
    right: 1.5rem;
    width: 3.125rem;
    height: 3.125rem;
    border-radius: 50%;
    background: #e2b96fee;
    border: none;
    color: #1a1a2e;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
}

.challenge-fab:hover {
    transform: scale(1.05);
    background: #d4a85a;
}

.challenge-fab:active {
    transform: scale(0.95);
}

/* --- Search Popup --- */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 950;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
}

.search-popup {
    background: #1a1a2e;
    border: 1px solid #e2b96f;
    border-radius: 12px;
    padding: 1rem;
    width: 90%;
    max-width: 25rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.search-container {
    display: flex;
    align-items: center;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    background: #16213e;
    border: 1px solid #e2b96f55;
    border-radius: 8px;
    color: #eee;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
    border-color: #e2b96f;
    box-shadow: 0 0 0 2px rgba(226, 185, 111, 0.2);
}

.search-input::placeholder {
    color: #666;
}

.search-clear {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: #888;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    transition: color 0.2s ease;
}

.search-clear:hover {
    color: #e2b96f;
}

.search-results-count {
    text-align: center;
    color: #888;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.search-active-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    background: #e2b96f22;
    border: 1px solid #e2b96f55;
    border-radius: 20px;
    color: #e2b96f;
    font-size: 0.8rem;
    margin-bottom: 1rem;
}

.search-active-indicator button {
    background: none;
    border: none;
    color: #e2b96f;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    line-height: 1;
}

.category-section { margin-bottom: 3rem; }

.category-label {
    font-size: 1.3rem;
    color: #e2b96f;
    border-bottom: 2px solid #e2b96f44;
    padding-bottom: 0.5rem;
    margin-bottom: 1.25rem;
}

.card-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    width: 100%;
}

/* --- Flip card --- */
@keyframes flip-fade-out {
    0%   { opacity: 1; }
    50%  { opacity: 0; }
    100% { opacity: 0; }
}

@keyframes flip-fade-in {
    0%   { opacity: 0; }
    50%  { opacity: 0; }
    100% { opacity: 1; }
}

.flashcard-container {
    perspective: 1000px;
    width: 45vw;
    height: 37.5rem;
    cursor: pointer;
    flex-shrink: 0;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s ease-in-out;
    border-radius: 10px;
}

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

.flashcard-container:hover .flashcard {
    box-shadow: 0 4px 20px rgba(79, 195, 247, 0.15);
}

.flashcard-container:hover .flashcard:not(.flipped) {
    box-shadow: 0 4px 20px rgba(226, 185, 111, 0.2);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    gap: 0.35rem;
    text-align: center;
    overflow: hidden;
}

.flashcard-front {
    background-color: #16213e;
    border: 1px solid #e2b96f55;
    gap: 0.4rem;
}

.flashcard-back {
    background-color: #0f3460;
    border: 1px solid #4fc3f7aa;
    transform: rotateY(180deg);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #4fc3f766 transparent;
    opacity: 0;
}

.flashcard:not(.flipped) .flashcard-front {
    animation: flip-fade-in 0.6s ease-in-out forwards;
}

.flashcard:not(.flipped) .flashcard-back {
    opacity: 0;
}

.flashcard.flipped .flashcard-front {
    animation: flip-fade-out 0.6s ease-in-out forwards;
}

.flashcard.flipped .flashcard-back {
    animation: flip-fade-in 0.6s ease-in-out forwards;
}

.flashcard-back::-webkit-scrollbar {
    width: 0.375rem;
}

.flashcard-back::-webkit-scrollbar-track {
    background: transparent;
}

.flashcard-back::-webkit-scrollbar-thumb {
    background: #4fc3f766;
    border-radius: 3px;
}

.card-name {
    font-weight: 700;
    color: #e2b96f;
    line-height: 1.2;
    max-width: 100%;
    word-wrap: break-word;
}

.flashcard-back .card-name {
    color: #4fc3f7;
}

.card-aka {
    font-size: 0.75rem;
    color: #aaa;
    font-style: italic;
}

.card-points {
    font-size: 0.85rem;
    color: #e2b96f;
    margin-top: 0.3rem;
}

.card-description {
    font-size: 1.8rem;
    color: #ddd;
    line-height: 1.4;
    max-width: 100%;
}

.card-note {
    font-size: 0.72rem;
    color: #90caf9;
    margin-top: 0.2rem;
    line-height: 1.35;
    max-width: 100%;
}

/* --- Buttons --- */
.btn {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #e2b96f;
    color: #1a1a2e;
}

.btn-primary:hover {
    background: #d4a85a;
}

.btn-secondary {
    background: #3a3a5a;
    color: #eee;
}

.btn-secondary:hover {
    background: #4a4a6a;
}

.btn-correct {
    background: #4caf50;
    color: white;
    font-size: 1.1rem;
}

.btn-correct:hover {
    background: #43a047;
}

.btn-wrong {
    background: #f44336;
    color: white;
    font-size: 1.1rem;
}

.btn-wrong:hover {
    background: #e53935;
}

/* --- Config Modal --- */
.config-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

.config-modal {
    background: #1a1a2e;
    border: 1px solid #e2b96f55;
    border-radius: 12px;
    padding: 2rem;
    max-width: 31.25rem;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.config-modal h2 {
    color: #e2b96f;
    margin-bottom: 1.5rem;
    text-align: center;
}

.config-section {
    margin-bottom: 1.5rem;
}

.config-section h3 {
    color: #e2b96f;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.config-hint {
    color: #888;
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
}

.config-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.config-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.config-option:hover {
    background: #2a2a4e;
}

.config-option input[type="radio"] {
    accent-color: #e2b96f;
}

.config-value-select {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.config-value-select select {
    background: #2a2a4e;
    color: #eee;
    border: 1px solid #e2b96f55;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

.config-number-select {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.number-btn {
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid #e2b96f55;
    border-radius: 6px;
    background: #2a2a4e;
    color: #eee;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.number-btn:hover {
    background: #3a3a5e;
}

.number-btn.selected {
    background: #e2b96f;
    color: #1a1a2e;
    border-color: #e2b96f;
}

.config-buttons {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
}

/* --- Advanced Dropdown --- */
.config-advanced {
    margin-bottom: 1.5rem;
}

.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.5rem 0;
    transition: color 0.2s ease;
}

.advanced-toggle:hover {
    color: #e2b96f;
}

.advanced-arrow {
    display: inline-block;
    font-size: 0.7rem;
    transition: transform 0.2s ease;
}

.advanced-arrow.open {
    transform: rotate(90deg);
}

.advanced-content {
    display: none;
    padding-left: 1rem;
    border-left: 2px solid #e2b96f33;
    margin-top: 0.75rem;
}

.advanced-content.open {
    display: block;
}

/* --- Challenge Mode --- */
.challenge-mode {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
}

.challenge-header {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 0.2rem;
}

.challenge-stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.btn-exit-challenge {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    color: red;
}

.stat {
    font-size: 0.95rem;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
}

.stat.correct {
    color: #4caf50;
}

.stat.wrong {
    color: #f44336;
}

.stat.remaining {
    color: #aaa;
}

.stat.mastered {
    color: #e2b96f;
}

.challenge-card-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.challenge-card-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
}

.challenge-card.flashcard-container {
    width: 100%;
    height: auto;
    min-height: 12.5rem;
}

.challenge-card .flashcard-back {
    position: relative;
    height: fit-content;
    transform: rotateY(180deg);
}

.challenge-front {
    background: linear-gradient(135deg, #16213e, #1a2744);
}

.challenge-front-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: 100%;
    height: 100%;
}

.challenge-card-image {
    max-height: 40vh;
    overflow: hidden;
}

.challenge-points {
    font-size: 0.85rem;
    color: #888;
    margin-top: 0.5rem;
}

.challenge-buttons {
    display: flex;
    flex-direction: row;
    gap: 1.5rem;
}

.challenge-hint {
    color: #888;
    font-size: 0.9rem;
    text-align: center;
}

.challenge-complete {
    text-align: center;
    padding: 3rem;
}

.challenge-complete h2 {
    color: #e2b96f;
    margin-bottom: 1.5rem;
}

.final-stats {
    margin-bottom: 2rem;
}

.final-stats p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.struggled-cards {
    margin: 2rem auto;
    max-width: 25rem;
    text-align: left;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 1.5rem;
}

.struggled-cards h3 {
    color: #e2b96f;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    text-align: center;
}

.struggled-cards ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.struggled-cards li {
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    color: #ccc;
}

.struggled-cards li:last-child {
    border-bottom: none;
}

.struggled-cards .card-name {
    flex: 1;
}

.struggled-cards .wrong-count {
    color: #e57373;
    font-weight: 600;
    min-width: 1.5rem;
    text-align: right;
}

.struggled-cards li.clickable {
    cursor: pointer;
    transition: background 0.2s;
}

.struggled-cards li.clickable:hover {
    background: rgba(255, 255, 255, 0.1);
}

.review-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.review-modal {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.review-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
    z-index: 1;
}

.review-modal-close:hover {
    color: #e2b96f;
}

/* --- Responsive --- */

/* Tablet landscape and smaller desktops */
@media (max-width: 1024px) {
    .app {
        padding: 1.5rem 1rem;
    }

    .card-grid {
        gap: 0.85rem;
    }
}

/* Tablet portrait */
@media (max-width: 768px) {
    h1 {
        font-size: 1.75rem;
    }

    .category-label {
        font-size: 1.15rem;
    }

    .card-description {
        font-size: 1.3rem;
        color: #ddd;
        line-height: 1.4;
        max-width: 100%;
    }
    
    .card-grid {
        gap: 0.75rem;
    }

    .challenge-header {
        gap: 0.75rem;
    }

    .challenge-stats {
        justify-content: center;
        gap: 1rem;
    }

    .config-modal {
        padding: 1.5rem;
        margin: 0.5rem;
    }
}

/* Large phones */
@media (max-width: 480px) {
    .app {
        padding: 1rem 0.75rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .title {
        font-size: 0.85rem;
    }

    .flashcard-container {
        width: 95vw;
        height: 30rem;
    }

    .category-section {
        margin-bottom: 2rem;
    }

    .category-label {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }

    .card-grid {
        gap: 0.6rem;
    }

    .card-aka {
        font-size: 0.65rem;
    }

    .card-note {
        font-size: 0.65rem;
    }

    .challenge-buttons {
        width: 90vw;
        max-width: 20rem;
    }

    .challenge-card-area {
        gap: 1.5rem;
    }

    .stat {
        font-size: 0.85rem;
        padding: 0.25rem 0.4rem;
    }

    .challenge-stats {
        gap: 0.6rem;
    }

    .config-modal {
        padding: 1.25rem;
        border-radius: 10px;
    }

    .config-modal h2 {
        font-size: 1.25rem;
        margin-bottom: 1.25rem;
    }

    .config-section h3 {
        font-size: 0.95rem;
    }

    .config-hint {
        font-size: 0.75rem;
    }

    .config-buttons {
        flex-direction: column;
        gap: 0.75rem;
    }

    .config-buttons .btn {
        width: 100%;
    }

    .number-btn {
        width: 2.25rem;
        height: 2.25rem;
        font-size: 0.9rem;
    }

    .btn {
        font-size: 0.85rem;
    }

    .btn-correct,
    .btn-wrong {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        width: 45%;
    }
}

/* Small phones */
@media (max-width: 360px) {
    .app {
        padding: 0.75rem 0.5rem;
    }

    h1 {
        font-size: 1.3rem;
    }

    .flashcard-container {
        width: 95vw;
        height: 25rem;
    }

    .challenge-stats {
        gap: 0.4rem;
    }

    .stat {
        font-size: 0.75rem;
        padding: 0.2rem 0.3rem;
    }

    .config-modal {
        padding: 1rem;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .flashcard-container:hover .flashcard {
        box-shadow: none;
    }

    .flashcard-container:active .flashcard {
        box-shadow: 0 4px 20px rgba(226, 185, 111, 0.3);
    }

    .btn:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
    }

    .config-option:hover {
        background: transparent;
    }

    .config-option:active {
        background: #2a2a4e;
    }
}
