/* =================================================================
   SENTENCE BUILDER MODULE STYLES
   Version 1.0 - November 2025
   ================================================================= */

.module-sentence-builder {
    animation: fadeIn 0.3s ease;
}

.module-sentence-builder h1 {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.module-sentence-builder h1 i {
    color: var(--primary);
}

.module-sentence-builder .controls {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    justify-content: center;
}

/* =================================================================
   SENTENCE AREA - Middle 50% of screen
   ================================================================= */

.sentence-area {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 24px 0;
    min-height: 300px;
}

#sentenceRow {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: clamp(8px, 1.5vw, 20px);
    align-items: flex-start;
    justify-content: center;
}

/* =================================================================
   SENTENCE FRAMES - 110x165px (2:3 ratio matching image dimensions)
   ================================================================= */

.sentence-frame {
    width: clamp(80px, 8vw, 140px);
    aspect-ratio: 2 / 3;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    perspective: 1000px;
}

.sentence-frame:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Empty frame styling */
.sentence-frame.empty-frame {
    border-style: dashed;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sentence-frame.empty-frame:hover {
    background: var(--bg-secondary);
}

.add-card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.add-card-content i {
    font-size: 32px;
    color: var(--primary);
}

.add-card-content span {
    font-size: 14px;
    font-weight: 500;
}

/* =================================================================
   FUNCTION WORD FRAMES - Smaller cards for words without pictures
   ================================================================= */

.sentence-frame.function-word {
    width: clamp(45px, 5vw, 70px);
    aspect-ratio: 1 / 1;
    border-style: dashed;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
}

.sentence-frame.function-word:hover {
    background: var(--bg-secondary);
}

.sentence-frame.function-word .function-word-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    word-break: break-word;
    padding: 4px;
}

body.mobile-phone .sentence-frame.function-word {
    /* Fluid sizing handles this - kept for specificity override if needed */
}

body.mobile-phone .sentence-frame.function-word .function-word-text {
    font-size: 12px;
}

/* =================================================================
   FRAME CARD (has content)
   ================================================================= */

.sentence-frame.has-card {
    border-style: solid;
}

.frame-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

.sentence-frame.flipped .frame-card {
    transform: rotateY(180deg);
}

.frame-card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.frame-card-front {
    background: var(--bg-primary);
}

.frame-card-front img,
.frame-card-front video {
    width: 90%;
    height: 90%;
    object-fit: contain;
    border-radius: 6px;
}

.frame-card-back {
    background: var(--bg-secondary);
    transform: rotateY(180deg);
    flex-direction: column;
    padding: 12px;
    text-align: center;
}

.frame-word {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    word-break: break-word;
}

.frame-english {
    font-size: 14px;
    color: var(--text-secondary);
    word-break: break-word;
}

/* Speaker icon on frames */
.frame-speaker {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
}

.frame-speaker:hover {
    transform: scale(1.1);
    background: var(--primary-dark);
}

.frame-speaker i {
    color: white;
    font-size: 14px;
}

/* Delete button on frames */
.frame-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: var(--error);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    opacity: 0;
}

.sentence-frame:hover .frame-delete {
    opacity: 1;
}

.frame-delete:hover {
    transform: scale(1.1);
    background: #c0392b;
}

.frame-delete i {
    color: white;
    font-size: 12px;
}

/* Edit button - pencil icon to change card */
.frame-edit {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    opacity: 0;
}

.sentence-frame:hover .frame-edit {
    opacity: 1;
}

.frame-edit:hover {
    transform: scale(1.1);
    background: var(--primary-dark, #4a47a3);
}

.frame-edit i {
    color: white;
    font-size: 10px;
}

/* =================================================================
   SORTABLE DRAG AND DROP STATES
   ================================================================= */

.sortable-ghost {
    opacity: 0.4;
    background: var(--bg-secondary);
}

.sortable-chosen {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    transform: scale(1.05);
}

.sortable-drag {
    opacity: 1;
}

/* Cursor for draggable cards */
.sentence-frame.has-card .frame-card {
    cursor: grab;
}

.sentence-frame.has-card .frame-card:active {
    cursor: grabbing;
}

/* =================================================================
   WORD TYPE MODAL
   ================================================================= */

.word-type-modal {
    max-width: 600px;
}

.word-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 8px;
}

.word-type-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 12px;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 100px;
    text-align: center;
}

.word-type-btn:hover {
    border-color: var(--primary);
    background: var(--bg-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.word-type-btn .word-type-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.word-type-btn .word-count {
    font-size: 13px;
    font-weight: 500;
    color: var(--primary);
}

.word-type-btn .word-preview {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 4px;
}

/* =================================================================
   CARD SELECTOR MODAL
   ================================================================= */

.card-selector-modal {
    max-width: 900px;
    max-height: 80vh;
}

.card-selector-modal .modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-selector-modal .modal-header h2 {
    flex: 1;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.back-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--primary);
}

.card-selector-modal .modal-body {
    overflow-y: auto;
    max-height: 60vh;
}

.card-selector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(clamp(100px, 10vw, 160px), 1fr));
    gap: clamp(8px, 1.5vw, 16px);
    padding: 8px;
}

/* Selector card - fluid with flip and select button */
.selector-card {
    width: clamp(80px, 8vw, 140px);
    position: relative;
    perspective: 1000px;
}

.selector-card-inner {
    width: 100%;
    aspect-ratio: 2 / 3;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
}

.selector-card.flipped .selector-card-inner {
    transform: rotateY(180deg);
}

.selector-card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.selector-card-front img,
.selector-card-front video {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

.selector-card-back {
    transform: rotateY(180deg);
    flex-direction: column;
    padding: 12px;
    text-align: center;
    background: var(--bg-secondary);
}

.selector-word {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    word-break: break-word;
}

.selector-english {
    font-size: 13px;
    color: var(--text-secondary);
    word-break: break-word;
}

/* Speaker icon on selector cards */
.selector-speaker {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
}

.selector-speaker:hover {
    transform: scale(1.1);
    background: var(--primary-dark);
}

.selector-speaker i {
    color: white;
    font-size: 12px;
}

/* Select button below card */
.selector-select-btn {
    width: 100%;
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.selector-select-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.selector-card:hover .selector-card-inner {
    border-color: var(--primary);
}

.selector-card:hover .selector-card-face {
    border-color: var(--primary);
}

/* No image placeholder */
.no-image {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

/* =================================================================
   MOBILE RESPONSIVE
   ================================================================= */

body.mobile-phone .module-sentence-builder h1 {
    font-size: 18px;
}

body.mobile-phone #sentenceRow {
    width: 90%;
    min-width: unset;
}

body.mobile-phone .sentence-frame {
    /* Fluid sizing with clamp() handles responsive - kept for override specificity */
}

body.mobile-phone .frame-word {
    font-size: 14px;
}

body.mobile-phone .frame-english {
    font-size: 12px;
}

body.mobile-phone .frame-speaker {
    width: 28px;
    height: 28px;
}

body.mobile-phone .frame-speaker i {
    font-size: 12px;
}

/* Always show edit/delete buttons on mobile (no hover) */
body.mobile-phone .frame-edit,
body.mobile-phone .frame-delete {
    opacity: 1;
}

body.mobile-phone .frame-edit,
body.mobile-phone .frame-delete {
    width: 28px;
    height: 28px;
}

/* Touch device - show buttons always */
@media (hover: none) {
    .frame-edit,
    .frame-delete {
        opacity: 1;
    }
}

body.mobile-phone .word-type-grid {
    grid-template-columns: repeat(2, 1fr);
}

body.mobile-phone .card-selector-grid {
    grid-template-columns: repeat(2, 1fr);
}

body.mobile-phone .selector-card {
    /* Fluid sizing handles responsive */
}

body.mobile-phone .selector-card-inner {
    /* Fluid sizing with aspect-ratio handles this */
}

body.mobile-phone .controls {
    flex-wrap: wrap;
}

/* Tablet responsive - fluid sizing handles most cases */
body.mobile-tablet #sentenceRow {
    width: 85%;
}

body.mobile-tablet .sentence-frame {
    /* Fluid sizing with clamp() handles responsive */
}

@media (max-width: 768px) {
    #sentenceRow {
        width: 90%;
    }

    /* Fluid sizing handles card dimensions automatically */

    .card-selector-modal {
        max-width: 95%;
    }

    .word-type-modal {
        max-width: 95%;
    }
}

/* =================================================================
   ANIMATIONS
   ================================================================= */

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

.sentence-frame {
    animation: fadeIn 0.3s ease;
}

/* Pulse animation for empty frames */
.sentence-frame.empty-frame .add-card-content i {
    animation: pulse 2s infinite;
}

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