/* Crossword Puzzle Styles */

* {
    box-sizing: border-box;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    background-color: #f5f5f0;
    color: #333;
    margin: 0;
    padding: 20px;
    line-height: 1.5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

.header-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

header h1 {
    font-size: 2.5rem;
    margin: 0;
    color: #1a1a1a;
    font-weight: normal;
}

/* Database Status Indicator */
.db-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #f5f5f5;
    border-radius: 12px;
    font-size: 0.75rem;
    color: #666;
}

.status-led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    transition: background 0.3s;
}

.db-status.connected .status-led {
    background: #28a745;
    box-shadow: 0 0 6px #28a745;
}

.db-status.local .status-led {
    background: #ffc107;
    box-shadow: 0 0 6px #ffc107;
}

.db-status.error .status-led {
    background: #dc3545;
    box-shadow: 0 0 6px #dc3545;
}

.status-text {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.subtitle {
    font-style: italic;
    color: #666;
    margin-top: 5px;
}

/* Upload Section */
.upload-section {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.upload-section h2 {
    margin-top: 0;
    font-size: 1.3rem;
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
}

.upload-hint {
    font-size: 0.85rem;
    color: #666;
    margin: 0 0 15px 0;
    display: block;
}

.upload-controls {
    display: flex;
    gap: 30px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.upload-field {
    flex: 1;
    min-width: 250px;
}

.upload-field label {
    display: block;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.upload-field input[type="file"] {
    width: 100%;
    padding: 10px;
    border: 2px dashed #ccc;
    border-radius: 4px;
    background: #fafafa;
    cursor: pointer;
}

.upload-field input[type="file"]:hover {
    border-color: #999;
}

.file-name {
    display: block;
    font-size: 0.85rem;
    color: #666;
    margin-top: 5px;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    font-size: 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-primary {
    background: #2c5aa0;
    color: white;
}

.btn-primary:hover {
    background: #1e4080;
}

.btn-primary:disabled {
    background: #999;
    cursor: not-allowed;
}

.btn-check {
    background: #28a745;
    color: white;
}

.btn-check:hover {
    background: #1e7e34;
}

.btn-clear {
    background: #6c757d;
    color: white;
}

.btn-clear:hover {
    background: #545b62;
}

.btn-reveal {
    background: #dc3545;
    color: white;
}

.btn-reveal:hover {
    background: #c82333;
}

.error-message {
    color: #dc3545;
    margin-top: 15px;
    padding: 10px;
    background: #ffe6e6;
    border-radius: 4px;
    display: none;
}

.error-message.visible {
    display: block;
}

/* Validation Warnings */
.validation-warnings {
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
    display: none;
}

.validation-warnings.visible {
    display: block;
}

.validation-warnings strong {
    display: block;
    margin-bottom: 10px;
}

.validation-warnings ul {
    margin: 0;
    padding-left: 20px;
    font-size: 0.9rem;
}

.validation-warnings li {
    margin-bottom: 5px;
}

/* Reconciliation Log */
.reconciliation-log {
    margin-top: 15px;
    font-size: 0.9rem;
}

.recon-section {
    border-radius: 4px;
    padding: 12px 15px;
    margin-bottom: 10px;
}

.recon-section strong {
    display: block;
    margin-bottom: 8px;
}

.recon-section ul {
    margin: 0;
    padding-left: 20px;
}

.recon-section li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.recon-errors {
    color: #721c24;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
}

.recon-resolved {
    color: #0c5460;
    background: #d1ecf1;
    border: 1px solid #bee5eb;
}

.recon-warnings {
    color: #856404;
    background: #fff3cd;
    border: 1px solid #ffc107;
}

.recon-pdf {
    color: #6c757d;
    font-family: monospace;
    font-size: 0.85em;
}

.recon-yaml {
    color: #6c757d;
    font-family: monospace;
    font-size: 0.85em;
}

/* Puzzle Section */
.puzzle-section {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.puzzle-section.hidden {
    display: none;
}

.puzzle-layout {
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
}

/* Grid Container */
.grid-container {
    flex-shrink: 0;
    position: relative;
}

.grid-proxy-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    border: none;
    padding: 0;
    margin: 0;
    pointer-events: none;
    z-index: -1;
}

.crossword-grid {
    display: inline-grid;
    border: 1px solid #1a1a1a;
    background: #1a1a1a;
    gap: 1px;
    user-select: none;
    /* Default size for desktop - 15 cols × 40px = 600px */
    width: 616px; /* 600 + 14 gaps + 2 border */
}

.grid-controls {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.validation-result {
    margin-top: 15px;
    padding: 10px;
    border-radius: 4px;
    font-weight: bold;
}

.validation-result.success {
    background: #d4edda;
    color: #155724;
}

.validation-result.error {
    background: #f8d7da;
    color: #721c24;
}

/* Grid Cells */
.cell {
    aspect-ratio: 1;
    background: white;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, 2.5vw, 1.4rem);
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
}

.cell.black {
    background: #1a1a1a;
    cursor: default;
}

.cell.selected {
    background: #ffeb3b;
}

.cell.highlighted {
    background: #b3d9ff;
}

.cell.selected.highlighted {
    background: #ffeb3b;
}

.cell.incorrect {
    background: #ffcccc;
}

.cell.correct {
    background: #ccffcc;
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 0.6rem;
    font-weight: normal;
    color: #333;
    line-height: 1;
}

.cell-letter {
    font-family: 'Arial', sans-serif;
}

/* Clues Container */
.clues-container {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 600px;
    overflow-y: auto;
}

.clues-panel h3 {
    margin: 0 0 10px 0;
    font-size: 1.1rem;
    color: #1a1a1a;
    border-bottom: 2px solid #1a1a1a;
    padding-bottom: 5px;
}

.clue-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.clue-list li {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s;
    font-size: 0.95rem;
}

.clue-list li:hover {
    background: #f0f0f0;
}

.clue-list li.active {
    background: #b3d9ff;
}

.clue-number {
    font-weight: bold;
    margin-right: 8px;
    min-width: 25px;
    display: inline-block;
}

/* Current Clue Bar - positioned directly below grid */
.current-clue-bar {
    background: #2c5aa0;
    color: white;
    padding: 12px 15px;
    margin-top: 15px;
    border-radius: 4px;
    font-size: 1rem;
    min-height: 44px;
    max-width: 100%;
    line-height: 1.4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.clue-bar-content {
    flex: 1;
}

#current-clue-number {
    font-weight: bold;
    margin-right: 10px;
}

.btn-solve {
    background: #ffc107;
    color: #333;
    border: none;
    padding: 6px 16px;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-solve:hover:not(:disabled) {
    background: #e0a800;
}

.btn-solve:disabled {
    background: #6c8ab5;
    color: #a0b4cc;
    cursor: not-allowed;
}

/* Trainer Modal */
.trainer-modal-wrapper {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
}

.trainer-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 16px 20px;
    background: #2c5aa0;
    color: white;
    border-radius: 12px 12px 0 0;
    gap: 10px;
}

#trainer-clue-number {
    font-weight: bold;
    font-size: 1.1rem;
    flex-shrink: 0;
}

#trainer-clue-text {
    font-size: 0.95rem;
    line-height: 1.4;
    flex: 1;
}

.trainer-modal-header .btn-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    opacity: 0.8;
    flex-shrink: 0;
}

.trainer-modal-header .btn-close:hover {
    opacity: 1;
}

/* Trainer Container - where TemplateTrainer renders */
.trainer-container {
    padding: 0;
}

.trainer-answer-box.word-gap {
    width: 12px;
    border: none;
    background: transparent;
}

/* Trainer Instruction Section */
.trainer-instruction-section {
    padding: 20px;
}

.trainer-instruction {
    font-size: 1.1rem;
    color: #333;
    margin-bottom: 15px;
    font-weight: 500;
}

.trainer-clue-words {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.trainer-word {
    padding: 8px 12px;
    background: #f0f0f0;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.15s;
}

.trainer-word:hover {
    background: #e0e0e0;
}

.trainer-word.selected {
    border-color: #2c5aa0 !important;
    background: #e3f2fd !important;
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.3);
}

.trainer-word.highlight-green {
    background: #d4edda;
    border-color: #28a745;
}

.trainer-word.highlight-orange {
    background: #fff3cd;
    border-color: #ffc107;
}

.trainer-word.highlight-blue {
    background: #cce5ff;
    border-color: #007bff;
}

.trainer-word.highlight-purple {
    background: #e2d5f1;
    border-color: #6f42c1;
}

/* Trainer Input */
.trainer-input-section {
    padding: 0 20px 15px;
}

.trainer-text-input {
    width: 100%;
    padding: 12px;
    font-size: 1.1rem;
    border: 2px solid #ddd;
    border-radius: 6px;
    text-transform: uppercase;
}

.trainer-text-input:focus {
    border-color: #2c5aa0;
    outline: none;
}

/* Trainer Feedback */
.trainer-feedback {
    padding: 12px 20px;
    margin: 0 20px 15px;
    border-radius: 6px;
    font-size: 0.95rem;
}

.trainer-feedback.correct {
    background: #d4edda;
    color: #155724;
}

.trainer-feedback.incorrect {
    background: #f8d7da;
    color: #721c24;
}

.trainer-feedback.hint {
    background: #fff3cd;
    color: #856404;
}

/* Trainer Actions */
.trainer-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 15px 20px;
    border-top: 1px solid #ddd;
    background: #f9f9f9;
}

.trainer-complete {
    text-align: center;
    padding: 30px 20px;
}

.trainer-success {
    font-size: 1.5rem;
    font-weight: bold;
    color: #28a745;
    margin-bottom: 20px;
}

.trainer-complete .btn {
    font-size: 1.1rem;
    padding: 12px 30px;
}

/* Instructions */
.instructions {
    margin-top: 30px;
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.instructions h3 {
    margin-top: 0;
    font-size: 1rem;
    color: #666;
}

.instructions ul {
    margin: 0;
    padding-left: 20px;
    columns: 2;
    column-gap: 40px;
}

.instructions li {
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: #555;
}

/* Responsive */
@media (max-width: 800px) {
    .puzzle-layout {
        flex-direction: column;
    }

    .clues-container {
        flex-direction: row;
        max-height: none;
    }

    .clues-panel {
        flex: 1;
    }

    .instructions ul {
        columns: 1;
    }

    /* Grid scales to fit - no fixed cell sizes */
    .crossword-grid {
        width: 100%;
        max-width: 500px;
    }

    .cell-number {
        font-size: 0.5rem;
    }
}

/* Small mobile screens */
@media (max-width: 600px) {
    body {
        padding: 8px;
    }

    .puzzle-section {
        padding: 4px;
        border-radius: 0;
        overflow-x: hidden;
    }

    .puzzle-header {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        text-align: center;
    }

    .grid-container {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* Grid fills available width on mobile */
    /* Account for: body padding 8px×2 + section padding 4px×2 + border 2px = 26px */
    .crossword-grid {
        width: calc(100vw - 26px) !important;
        max-width: calc(100vw - 26px) !important;
    }

    .current-clue-bar {
        width: 100%;
    }

    .cell-number {
        font-size: clamp(6px, 1.5vw, 10px);
    }

    .grid-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    .grid-controls button {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* Loading state */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: 'Processing...';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 20px 40px;
    border-radius: 8px;
    font-size: 1.2rem;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
}

.nav-tab {
    padding: 12px 24px;
    font-size: 1rem;
    font-family: inherit;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    color: #666;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.nav-tab:hover {
    color: #333;
    background: #f5f5f5;
}

.nav-tab.active {
    color: #2c5aa0;
    border-bottom-color: #2c5aa0;
    font-weight: bold;
}

/* Puzzles Section */
.puzzles-section {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.puzzles-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.puzzles-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.series-filter {
    padding: 8px 12px;
    font-size: 0.95rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
    font-family: inherit;
    min-width: 180px;
}

/* Puzzle List */
.puzzle-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.puzzle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f9f9f9;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    transition: all 0.2s;
}

.puzzle-item:hover {
    background: #f0f0f0;
    border-color: #ccc;
}

.puzzle-item-info {
    flex: 1;
}

.puzzle-item-title {
    font-weight: bold;
    font-size: 1.05rem;
    color: #333;
    margin-bottom: 4px;
}

.puzzle-item-meta {
    font-size: 0.85rem;
    color: #666;
    display: flex;
    gap: 15px;
    align-items: center;
}

.puzzle-date {
    color: #555;
}

.puzzle-item-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.has-answers {
    color: #28a745;
    font-size: 0.85rem;
    font-weight: bold;
}

.no-answers {
    color: #999;
    font-size: 0.85rem;
}

.empty-message {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 40px 20px;
}

/* Small buttons */
.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

.delete-btn {
    padding: 6px 10px;
    font-size: 0.85rem;
    min-width: auto;
}

/* Puzzle Header */
.puzzle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #ddd;
}

.puzzle-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #333;
}

.btn-back {
    background: transparent;
    color: #2c5aa0;
    border: 1px solid #2c5aa0;
    padding: 8px 16px;
}

.btn-back:hover {
    background: #2c5aa0;
    color: white;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 450px;
    width: 90%;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.modal-content p {
    color: #666;
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-status {
    margin-top: 15px;
    font-size: 0.9rem;
    max-height: 300px;
    overflow-y: auto;
}

.modal-status.hidden {
    display: none;
}

.modal-status .status-importing {
    color: #2563eb;
    font-weight: 500;
}

.modal-status .status-success {
    color: #16a34a;
    font-weight: 500;
    margin-bottom: 8px;
}

.modal-status .status-error {
    color: #dc2626;
    font-weight: 500;
    margin-bottom: 8px;
}

/* Responsive adjustments for puzzle list */
@media (max-width: 600px) {
    .puzzle-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .puzzle-item-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .puzzles-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }

    .series-filter {
        width: 100%;
    }
}

/* Mobile: Trainer modal full screen */
@media (max-width: 768px) {
    .trainer-modal-wrapper {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
    }

    .trainer-modal-header {
        border-radius: 0;
        flex-shrink: 0;
        padding: 10px 12px;
        gap: 6px;
        align-items: baseline;
    }

    #trainer-clue-number {
        font-size: 0.95rem;
    }

    #trainer-clue-text {
        font-size: 0.85rem;
        line-height: 1.3;
    }

    .trainer-container {
        flex: 1;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    /* Ensure the modal overlay fills screen */
    #trainer-modal {
        padding: 0;
        align-items: stretch;
    }

    /* Answer boxes on mobile — let inline styles handle sizing */

    /* Larger clue words for easier tapping */
    .trainer-word {
        padding: 12px 16px;
        font-size: 1.1rem;
    }

    /* Larger buttons */
    .check-button,
    .trainer-button {
        padding: 14px 24px;
        font-size: 1.1rem;
    }
}
