/* Cryptogram Viewer Styles */

/* Quote Grid - horizontal layout for quote text */
.cryptogram-grid {
    display: grid;
    gap: 1px;
    background-color: #363636;
    padding: 10px;
    border-radius: 8px;
    max-width: none;
    margin: 0;
    width: max-content;
}

/* Scroll container should use full width */
.cryptogram-scroll-container {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0.5rem;
    padding-bottom: 5px;
    position: relative;
}

.cryptogram-cell {
    width: 28px;
    height: 28px;
    background-color: white;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
}

.cryptogram-cell:hover {
    background-color: #f5f5f5;
    border-color: #3273dc;
}

.cryptogram-cell.active {
    background-color: #e3f2fd;
    border-color: #3273dc;
    box-shadow: 0 0 0 2px rgba(50, 115, 220, 0.2);
}

.cryptogram-cell.highlighted {
    background-color: #fff3cd;
    border-color: #ffc107;
}

.cryptogram-cell.blocked {
    background-color: #000000 !important;
    border-color: #000000 !important;
    cursor: default;
}

.cryptogram-cell.space {
    background-color: #e8e8e8;
    border-color: #d0d0d0;
    cursor: default;
}

.cryptogram-cell.punctuation {
    background-color: #f5f5f5;
    border-color: #ddd;
    cursor: default;
    color: #666;
}

.cryptogram-cell.revealed {
    background-color: #e8f5e8;
    color: #2e7d32;
}

.cryptogram-cell.incorrect {
    background-color: #ffebee;
    color: #c62828;
    animation: shake 0.3s ease-in-out;
}

.cryptogram-cell.correct {
    background-color: #e8f5e8;
    color: #2e7d32;
}

/* Cell numbers - standard acrostic format */
.cryptogram-cell-number {
    position: absolute;
    top: 1px;
    font-size: 7px;
    font-weight: normal;
    color: #666;
    line-height: 1;
    pointer-events: none;
}

/* Top-left: Sequential quote position (1, 2, 3...) */
.cryptogram-cell-pos {
    left: 2px;
}

/* Top-right: Clue letter (A, B, C...) */
.cryptogram-cell-clue {
    right: 2px;
}

/* Input styling for acrostic cells */
.cryptogram-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
    outline: none;
    text-transform: uppercase;
}

.cryptogram-input:focus {
    background-color: transparent;
}

/* Clue list styling - bright white text for dark theme */
.clue-list {
    max-height: 500px;
    overflow-y: auto;
}

.clue-item {
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-left: 3px solid transparent;
    background-color: rgba(255, 255, 255, 0.05);
}

.clue-item:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.clue-item.active {
    background-color: rgba(50, 115, 220, 0.3);
    border-left: 3px solid #3273dc;
}

.clue-item.completed {
    background-color: rgba(72, 199, 116, 0.2);
    border-left: 3px solid #48c774;
}

.clue-item.is-acrostic {
    border-left: 3px solid #ffdd57;
}

.clue-item.is-acrostic.active {
    border-left: 3px solid #3273dc;
}

.clue-number {
    font-weight: bold;
    color: #ffdd57;
    margin-right: 8px;
    display: inline-block;
    min-width: 24px;
}

.clue-text {
    color: #ffffff;
    font-weight: 600;
    line-height: 1.4;
}

.clue-answer-boxes {
    display: flex;
    gap: 3px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.clue-answer-box {
    width: 22px;
    height: 22px;
    border: 1px solid #ddd;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: bold;
    background-color: #fafafa;
}

.clue-answer-box.filled {
    background-color: #e3f2fd;
    border-color: #3273dc;
}

.clue-answer-box.correct {
    background-color: #e8f5e8;
    border-color: #48c774;
    color: #2e7d32;
}

/* Acrostic clue inputs - the letter boxes next to each clue */
.cryptogram-word-inputs {
    display: flex;
    gap: 2px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* Container for each letter input + position number */
.cryptogram-letter-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.cryptogram-letter-input {
    width: 26px;
    height: 26px;
    border: 1px solid #666;
    border-radius: 2px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: bold;
    text-transform: uppercase;
    background-color: #ffffff;
    padding: 0;
    color: #000;
}

.cryptogram-letter-input:focus {
    outline: 2px solid #3273dc;
    background-color: #e3f2fd;
    border-color: #3273dc;
}

.cryptogram-letter-input.correct {
    background-color: #e8f5e8;
    border-color: #48c774;
    color: #2e7d32;
}

/* Position number underneath each letter box */
.cryptogram-position-num {
    display: block;
    font-size: 10px;
    color: #ffdd57;
    font-weight: 700;
    line-height: 1.2;
    font-family: 'Courier New', monospace;
    text-align: center;
    min-height: 12px;
}

/* Per-clue clear button */
.cryptogram-clue-clear {
    width: 24px;
    height: 24px;
    border: 1px solid #666;
    border-radius: 3px;
    background-color: #444;
    color: #ccc;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    padding: 0;
    transition: all 0.2s ease;
}

.cryptogram-clue-clear:hover {
    background-color: #f14668;
    border-color: #f14668;
    color: #fff;
}

.cryptogram-clue-clear i {
    font-size: 10px;
}

.cryptogram-clue-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}

/* Clue letter styling (A., B., C., etc.) */
.clue-letter {
    display: inline-block;
    font-weight: bold;
    color: #ffdd57;
    font-size: 14px;
    min-width: 20px;
}

/* Sticky Clue Bar */
#sticky-clue-bar {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    border-radius: 4px;
    background-color: #e3f2fd;
    border: 1px solid #3273dc;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.sticky-clue-line {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
}

.sticky-clue-label {
    font-weight: 600;
    color: #3273dc;
}

.sticky-clue-text {
    font-weight: 600;
    color: #1f2d3d;
}

/* Timer styling */
#timer-display {
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    background-color: #ffffff;
    color: #000000;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background-color: #3273dc;
    color: white;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.3s ease;
    max-width: 300px;
    word-wrap: break-word;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.success {
    background-color: #48c774;
}

.toast.error {
    background-color: #f14668;
}

.toast.warning {
    background-color: #ffdd57;
    color: #363636;
}

/* Animation for incorrect answers */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Loading state */
.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3273dc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive design */
@media (max-width: 768px) {
    .cryptogram-cell {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .cryptogram-grid {
        padding: 5px;
        gap: 1px;
    }

    .columns {
        flex-direction: column;
    }

    .column.is-8,
    .column.is-4 {
        width: 100%;
        max-width: 100%;
    }

    .field.is-grouped {
        flex-direction: column;
        align-items: stretch;
    }

    .control {
        margin-bottom: 8px;
    }

    .clue-answer-boxes {
        gap: 2px;
    }

    .clue-answer-box {
        width: 18px;
        height: 18px;
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .cryptogram-cell {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }

    .cryptogram-cell-number {
        font-size: 6px;
    }

    .title.is-2 {
        font-size: 1.5rem;
    }

    .title.is-4 {
        font-size: 1.25rem;
    }
}

/* Desktop sizing improvements */
@media (min-width: 1024px) {
    .cryptogram-cell {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .cryptogram-cell-number {
        font-size: 8px;
    }
}

/* Web-wrapped grid styles */
.cryptogram-grid.web-wrapped {
    width: auto !important;
    max-width: none !important;
    transform: none !important;
    display: grid !important;
}

.cryptogram-scroll-container.wrapped-mode {
    overflow-x: auto !important;
    overflow-y: visible !important;
    height: auto !important;
    min-height: 0 !important;
}

/* Ensure cells in wrapped grid scale with the grid template columns */
.cryptogram-grid.web-wrapped .cryptogram-cell {
    /* Size is controlled by grid-template-columns (fixed pixel values from JS) */
    width: 100% !important;
    height: auto !important;
    min-width: 0 !important;  /* Allow shrinking below default */
    min-height: 0 !important;
    aspect-ratio: 1;
}

/* Scale inputs and cell numbers with the cell size (using CSS variable from JS) */
.cryptogram-grid.web-wrapped .cryptogram-input {
    font-size: var(--cell-font-size, 14px);
    font-weight: bold;
}

.cryptogram-grid.web-wrapped .cryptogram-cell-number {
    font-size: calc(var(--cell-font-size, 14px) * 0.5);
}

.cryptogram-grid.web-wrapped .cryptogram-cell.empty-pad {
    visibility: hidden;
    border: none !important;
    background: transparent !important;
}

/* Accessibility improvements */
.cryptogram-cell:focus {
    outline: 3px solid #3273dc;
    outline-offset: 2px;
}

.clue-item:focus {
    outline: 2px solid #3273dc;
    outline-offset: 1px;
}

/* Print styles - Portrait (default) */
@media print {
    @page {
        margin: 0.5cm;
        size: letter portrait;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background-color: white !important;
        padding-top: 0 !important;
        color: black !important;
        margin: 0 !important;
    }

    .navbar,
    .buttons,
    .field,
    .toast-container,
    .modal,
    #sticky-clue-bar,
    #author-reveal-box,
    #viewer-controls {
        display: none !important;
    }

    .section {
        padding: 0 !important;
    }

    .box {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin-bottom: 1rem !important;
        background-color: transparent !important;
    }

    #puzzle-header {
        margin-bottom: 1rem !important;
        border-bottom: 2px solid #000 !important;
        padding-bottom: 1rem !important;
    }

    #puzzle-title {
        font-size: 24pt !important;
        margin-bottom: 0.5rem !important;
        color: black !important;
    }

    .cryptogram-grid {
        background-color: transparent !important;
        border: 2px solid #000 !important;
        gap: 0 !important;
        page-break-inside: avoid;
        margin: 0 auto 1.5rem auto !important;
        padding: 0 !important;
        /* Scale grid to fill available width */
        width: 100% !important;
        max-width: 100% !important;
        transform: none !important;
    }

    .cryptogram-cell {
        background-color: #fff !important;
        border: 1px solid #000 !important;
        color: transparent !important;
        box-shadow: none !important;
        /* Larger cells for better legibility */
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
    }

    /* Position numbers in grid cells - black for print */
    .cryptogram-cell-number {
        color: #000 !important;
        font-size: 6px !important;
    }

    .cryptogram-cell.blocked,
    .cryptogram-cell.space {
        background-color: #ccc !important;
    }

    .cryptogram-cell.punctuation {
        color: #000 !important;
    }

    .cryptogram-input {
        display: none !important;
    }

    .clue-list {
        max-height: none !important;
        overflow: visible !important;
    }

    .clue-item {
        margin-bottom: 0.25rem !important;
        padding: 0 !important;
        background-color: transparent !important;
        page-break-inside: avoid;
        font-size: 10pt !important;
    }

    /* Hide per-clue clear buttons in print */
    .cryptogram-clue-clear {
        display: none !important;
    }

    /* Show answers when print-with-answers class is on body */
    body.print-with-answers .cryptogram-cell {
        color: #000 !important;
    }

    body.print-with-answers .cryptogram-input {
        display: block !important;
        color: #000 !important;
    }
}

/* Additional print styles */
@media print {
    .clue-number {
        color: #000 !important;
    }

    .clue-text {
        color: #000 !important;
    }

    .clue-answer-boxes {
        display: none !important;
    }

    /* Clue letter styling for print */
    .clue-letter {
        color: #000 !important;
        font-weight: bold !important;
    }

    /* Position numbers under clue letter boxes - BLACK for print visibility */
    .cryptogram-position-num {
        color: #000 !important;
        font-weight: bold !important;
    }

    /* Letter input boxes for clues */
    .cryptogram-letter-input {
        border: 1px solid #000 !important;
        background-color: #fff !important;
    }

    /* Clue item layout for print */
    .cryptogram-clue-label {
        margin-bottom: 4px !important;
    }

    .cryptogram-word-inputs {
        margin-top: 4px !important;
        margin-bottom: 8px !important;
    }

    .cryptogram-letter-box {
        margin-right: 2px !important;
    }

    /* Wrapped grid for print - allow natural flow */
    .cryptogram-grid.print-wrapped {
        width: auto !important;
        max-width: 100% !important;
        display: grid !important;
    }

    /* Hide empty padding cells in print */
    .cryptogram-cell.empty-pad {
        display: none !important;
    }

    /* Landscape print mode - slightly smaller cells to fit more per row */
    body.print-landscape .cryptogram-cell {
        width: 22px !important;
        height: 22px !important;
        min-width: 22px !important;
        min-height: 22px !important;
    }

    body.print-landscape .cryptogram-cell-number {
        font-size: 5px !important;
    }
}
