/* 
 (c)Copyright 2025. Knowledge Share LLC. All rights reserved
*/

/* Base Styles: Reset default margins and padding for consistency. 
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
*/

/* Body: Sets the default font, colors, and a dark background to simulate a chalkboard. 
body {
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-size: 0.875rem;
    line-height: 1.6;
    color: #000000;
    background-color: #2F4F4F; /* Dark slate grey chalkboard background */
}
*/


/* Top Banner: A sticky header that holds the logo. 
    background-color: #CCCCCC;
    padding: 10px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #999;
}

.banner-content {
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
}
*/

/* Logo: Styled with a classic, italic serif font. 
.logo {
    font-family: Palatino, "Times New Roman", serif;
    font-style: italic;
    font-weight: 700;
    font-size: 2.75rem;
    color: red;
}

.logo-trademark {
    font-family: Arial, sans-serif;
    font-size: 0.5rem;
    font-style: normal;
    vertical-align: super;
}
*/


/* Main Container: The main content area with a "chalkboard frame" border. 
.container {
    max-width: 600px;
    margin: 10px auto;
    background-color: #FFFFFF;
    border: 10px ridge #A52A2A; /* Brownish red chalkboard frame */
    padding: 15px;
    min-height: calc(100vh - 100px);
}

/* Chalk Scribble Decoration: A purely decorative element for aesthetic purposes. */
.chalk-scribble {
    position: absolute;
    top: 80px;
    left: 20px;
    font-family: 'Chalkduster', cursive;
    color: white;
    font-size: 1.25rem;
    letter-spacing: 2px;
    transform: rotate(-25deg);
    z-index: 1;
    pointer-events: none;
}
*/

/* Headers: Defines styles for h1, h2, and h3 tags.
h1 {
    font-family: Palatino, "Times New Roman", serif;
    font-style: italic;
    font-weight: 700;
    font-size: 2.5rem;
    color: red;
    text-align: center;
    margin-bottom: 20px;
} */

h2 {
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-weight: bold;
    font-size: 1.25rem;
    color: #000000;
    margin-bottom: 15px;
    text-align: left;
}

h3 {
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-weight: bold;
    font-size: 1.1rem;
    color: #000000;
    margin-bottom: 10px;
}

/* Word Input Section: Styles for the area where users add words. */
.word-input-section {
   /* margin-bottom: 20px; */
    padding: 15px;
    background-color: #FAFAFA;
    border: 1px solid #CCCCCC;
}

.input-group {
    margin-bottom: 15px;
}

.input-field {
    margin-bottom: 10px;
}

.input-field label {
    display: block;
    margin-bottom: 5px;
    font-weight: normal;
    color: #000000;
}

.input-field input {
    width: 300px;
    height: 25px;
    background-color: #FFFFFF;
    border: 1px solid #666;
    padding: 3px 5px;
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-size: 0.875rem;
    color: #000000;
}

.input-field input:focus {
    outline: none;
    border-color: #333;
}

/* Input Hint: Provides feedback to the user, like word length. */
.input-hint {
    margin-top: 4px;
    font-size: 0.75rem;
    color: #555;
}

.input-hint.warning {
    color: #B22222; /* firebrick */
    font-weight: bold;
}

.input-field input.max-reached {
    border-color: #B22222;
    background-color: #FFF5F5;
}

/* Buttons: General styling for all buttons. */
button {
    background-color: #E0E0E0;
    border: 1px solid #999;
    padding: 8px 15px;
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-size: 0.875rem;
    color: #000000;
    cursor: pointer;
    margin-right: 10px;
    margin-bottom: 10px;
}

button:hover:not(:disabled) {
    background-color: #D0D0D0;
}

button:disabled {
    background-color: #F0F0F0;
    color: #999;
    cursor: not-allowed;
}


.nav-btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: bold;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.nav-btn.active {
    background: #667eea;
    color: white;
}

.nav-btn:hover:not(.active) {
    background: #f0f4ff;
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}





/* Predefined Sets: Styles for the word set dropdown. 
.predefined-sets {
    margin-top: 15px;
}

.predefined-sets label {
    display: block;
    margin-bottom: 5px;
    color: #000000;
}

.predefined-sets select {
    width: 300px;
    height: 25px;
    background-color: #FFFFFF;
    border: 1px solid #666;
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-size: 0.875rem;
    color: #000000;
}
*/


/* Word List Section: Styles for the container that displays the added words. */

.crossword-layout .word-list-section {
    margin-bottom: 0;
    padding: 15px;
    background-color: #FAFAFA;
    border: 1px solid #CCCCCC;
}

.crossword-layout .word-list {
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #CCCCCC;
    padding: 10px;
    background-color: #FFFFFF;
    margin-bottom: 10px;
    display: block !important;
}


.crossword-layout .word-list::after {
  content: '↓ More words below ↓';
  position: sticky;
  bottom: 0;
  display: block;
  text-align: center;
  font-size: 12px;
  color: #666;
  background: rgba(255, 255, 255, 0.95);
  padding: 0;
  margin-top:auto;
}



/* Word Item: Styles for a single entry in the word list. */
.crossword-layout .word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin-bottom: 8px;
    background-color: #F8F8F8;
    border: 1px solid #DDD;
}

.crossword-layout .word-details {
    flex-grow: 1;
}

.crossword-layout .word-text {
    font-weight: bold;
    color: #000000;
    margin-bottom: 2px;
    text-align: left;
}

.crossword-layout .word-definition {
    color: #000000;
    font-size: 0.8rem;
    text-align: left;
}

.crossword-layout .delete-btn {
    background-color: #E0E0E0;
    border: 1px solid #999;
    padding: 4px 8px;
    font-size: 0.75rem;
    margin: 0;
    /* other properties */
    flex-shrink: 0 !important;
    white-space: nowrap !important;  /* Prevent text wrapping */
}

.crossword-layout .delete-btn:hover {
    background-color: #D0D0D0;
}

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

.word-count {
    font-weight: bold;
    color: #000000;
}

/* Controls Section: Styles for the main action buttons (Generate, Print, etc.). */
.controls-section {
    margin-bottom: 0;
    margin-top: 0;
    text-align: center;
    padding: 15px;
    background-color: white;
}

.controls-section button {
    width: 120px;
    padding: 10px;
    margin: 0 5px;
}

/*
#generate-btn {
    background-color: #E0E0E0;
}
*/
#generate-btn {
    background: linear-gradient(45deg, #4caf50, #45a049);
    color: white;
}

#generate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}

/*
#generate-btn:hover:not(:disabled) {
    background-color: #D0D0D0;
}
*/

#toggle-answers-btn {
    background-color: #E0E0E0;
}

#toggle-answers-btn:hover {
    background-color: #D0D0D0;
}

#print-btn {
    background-color: #E0E0E0;
}

#print-btn:hover {
    background-color: #D0D0D0;
}

/* Reset Button */
#reset-btn {
    background-color: #E0E0E0;
}

#reset-btn:hover {
    background-color: #D0D0D0;
}

/* Crossword Section: Container for the generated puzzle and clues. */
.crossword-section {
    margin-bottom: 20px;
}

/* Puzzle ID Display: Styles for the unique puzzle identifier shown on screen. */
.puzzle-id-display {
    text-align: center;
    margin-bottom: 0;
    padding: 8px;
    background-color: white;
/*    border: 1px solid #CCCCCC; */
    font-size: 0.875rem;
}

.puzzle-id-label {
    font-weight: bold;
    color: #000000;
    margin-right: 8px;
}

.puzzle-id-value {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    color: #0000FF;
    font-size: 1rem;
}

/* Print Puzzle ID - hidden on screen, shown only when printing */
.print-puzzle-id {
    display: none;
    margin-bottom: 0;
}

.crossword-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background-color: white;
    margin-top: 0;
    margin-bottom: 0;
    padding-top: 10px;
    padding-bottom: 10px;
}

/* Crossword Grid: The main grid structure, dynamically sized by JavaScript. */
.crossword-grid {
    display: grid;
    grid-template-columns: repeat(15, 40px);
    grid-template-rows: repeat(15, 40px);
    gap: 0;
    background-color: #FFFFFF;
    border: 2px solid #000;
    margin: 0 auto;
}

/* Grid Cell: Individual cells within the crossword grid. */
.grid-cell {
    width: 40px;
    height: 40px;
    background-color: #FFFFFF;
    border: 1px solid #CCCCCC;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Open Sans', Verdana, Arial, sans-serif;
    font-weight: bold;
    font-size: 16px;
    color: #000000;
    position: relative;
    text-transform: uppercase;
}

.grid-cell.black {
    background-color: #A9A9A9; /* dark gray */
    border: 1px solid #000000;
}

.grid-cell.invisible {
    background-color: #FFFFFF;
    border: none;
}

.grid-cell.letter-cell {
    background-color: #FFFFFF;
    border: 1px solid #CCCCCC;
}

/* Numbered Cell: Uses a pseudo-element to display the clue number. */
.grid-cell.numbered::before {
    content: attr(data-number);
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 10px;
    font-weight: bold;
    color: #000000;
    line-height: 1;
}

.grid-cell.filled {
    color: #000000;
    background-color: #FFFFFF;
}

/* Clues Container: Holds the 'Across' and 'Down' clue columns. */
.clues-container {
    width: 100%;
    max-width: 600px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.clues-column {
    background-color: #FAFAFA;
    border: 1px solid #CCCCCC;
    padding: 15px;
}

.clues-column h3 {
    color: #0000FF; /* Blue for clue headers */
    margin-bottom: 10px;
    font-size: 1.1rem;
    border-bottom: 1px solid #CCCCCC;
    padding-bottom: 5px;
}

.clues-list {
    list-style: none;
    padding-left: 10px;
    margin: 0;
}

.clues-list li {
    margin-bottom: 6px;
    font-size: 0.875rem;
    line-height: 1.4;
}

.clues-list li strong {
    color: #0000FF; /* Blue for clue numbers */
    margin-right: 5px;
}

/* Definition/Clue styling to match SuperKids Word Challenge */
.clue-definition {
    color: red; /* Red for the actual clue text */
}

/* Message Styles: For displaying errors, successes, and warnings. */
.error-message, .success-message, .warning-message {
    border: 1px solid #CCCCCC;
    padding: 10px;
    margin-top: 10px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: #FFFFFF;
}

.error-message {
    border-left: 3px solid red;
    color: red;
}

.success-message {
    border-left: 3px solid #008000;
    color: #008000;
}

.warning-message {
    border-left: 3px solid #FFA500;
    color: #FFA500;
}

.error-reasons {
    margin-top: 5px;
}

.error-reasons ul {
    margin: 5px 0;
    padding-left: 20px;
}

.error-reasons li {
    margin-bottom: 3px;
}


/* Responsive Design: Adjusts layout for smaller screens. */
@media (max-width: 768px) {
    .container {
        margin: 5px;
        padding: 10px;
        max-width: none;
    }
    
    .banner-content {
        flex-direction: column;
        gap: 10px;
    }
    
    .logo {
        font-size: 2rem;
    }
    
    .input-field input,
    .predefined-sets select {
        width: 100%;
        max-width: 300px;
    }
    
    .crossword-grid {
        /* Grid sizing will be set dynamically by JavaScript */
    }
    
    .grid-cell {
        width: 25px;
        height: 25px;
        font-size: 12px;
    }
    
    .grid-cell.numbered::before {
        font-size: 8px;
        top: 1px;
        left: 2px;
    }
    
    .clues-container {
        grid-template-columns: 1fr;
    }
    
    .chalk-scribble {
        display: none; /* Hide on mobile */
    }
    
    .crossword-layout .delete-btn {
        width: 60px !important;  /* Keep your fixed width */
        max-width: 60px !important;  /* Override the 300px max-width */
    }
}

@media (min-width: 769px) {
    .input-group {
        display: flex;
        flex-direction: row;
        gap: 1.5rem;
        align-items: flex-end; /* Better than 'end' for older browsers */
     }
    
    .input-field {
        flex: 1;
        min-width: 0; /* Prevents flex items from overflowing */
    }
    
    #add-word-btn {
        flex-shrink: 0; /* Prevents button from shrinking */
    }
}


/* Optimized Print Layout for Crossword Puzzle */
@media print {
    /* Base print setup */
    body {
        background-color: white !important;
        color: black !important;
        font-size: 11pt;
        line-height: 1.3;
        margin: 0;
        padding: 0;
    }
    
    .main-content {
        margin-top: 0;
        margin-bottom: 0;
    }
    
    /* Hide non-essential UI elements during printing */
    .top-banner,
    .word-input-section,
    .word-list-section,
    .controls-section,
    .chalk-scribble {
        display: none !important;
    }
    
    .frame {
        margin:0;
        padding: 0;
    }
    
    /* Handle the real page header */
    .breadcrumbs-title {
        margin: 0 0 0 0;
        padding: 0 0 0 0;
    }
    .breadcrumbs-title h1 {
        font-size: 15pt;     /* Compact but readable */
        font-weight: bold;
        text-align: center;
        color: black !important;
        margin: 0 0 0 0 !important;
        padding: 0 !important;
        /* Total height: ~0.4" */
    }
    
    /* Expand container to fill page */
    .container {
        max-width: none;
        margin: 0;
        padding: 0.4in;
        background-color: white;
        border: none;
        min-height: auto;
    }
    
    /* Main crossword section */
    .crossword-section {
        display: block !important;
        margin: 0;
        page-break-inside: avoid;
    }
    
    /* Optimized title header - reduced from 7/8" to 1/2" */
    .crossword-section h2 {
        font-size: 14pt;
        font-weight: bold;
        margin-bottom: 0.1in;
        text-align: center;
        color: black;
        /* Total height: ~0.5" */
    }
    
    /* Top/bottom layout with flowing clues */
    .crossword-container {
        display: block !important;
        grid-template-columns: none !important;
        width: 100% !important;
        max-width: none !important;
        align-items: start !important;
        justify-content: start !important;
    }
    
    /* Generous grid sizing for readability */
    .crossword-grid {
        width: auto;
        height: auto;
/*        max-width: 4.8in; 
        max-height: 4.8in;        Removed to allow dynamic sizing */
        /* Let the grid size itself based on content */
        width: fit-content;
        height: fit-content;
        margin: 0 auto 0.15in auto;  /* Less bottom margin */
        border: 2px solid black;
        display: grid;
        gap: 0;
        justify-content: center;
        justify-self: center;
        /* NEW: Dynamic grid sizing */
        grid-template-columns: repeat(var(--grid-cols, 15), 0.32in) !important;
        grid-template-rows: repeat(var(--grid-rows, 15), 0.32in) !important;
    }
    
    /* Adjusted cells for space constraints */
    .grid-cell {
        width: 0.32in;           /* 15 × 0.32" = 4.8" */
        height: 0.32in;
        min-width: 0.32in;
        min-height: 0.32in;
        border: 1px solid black;
        font-size: 10pt;         /* Still readable */
        font-weight: bold;
        background-color: white !important;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }
    
    /* Cell styling variants */
    .grid-cell.invisible {
        background-color: white !important;
        border: none !important;
    }
    
    .grid-cell.letter-cell {
        background-color: white !important;
        border: 1px solid black !important;
    }
    
    .grid-cell.black {
        background-color: #A9A9A9 !important;
        border: 1px solid black !important;
    }
    
    .grid-cell.filled {
        color: black !important;
        font-size: 11pt;
        font-weight: bold;
        text-transform: uppercase;
    }
    
    /* Clue numbers in grid */
    .grid-cell.numbered::before {
        content: attr(data-number);
        position: absolute;
        top: 1px;
        left: 2px;
        font-size: 8pt;
        font-weight: bold;
        color: black !important;
        line-height: 1;
    }
    
    /* Dedicated Across/Down column layout - Centered and Wider */
    .clues-container {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.4in !important;                    /* Wider gap for better separation */
        margin: 0.15in auto 0 auto !important;   /* Center the container */
        max-width: 7in !important;               /* Use most of the page width */
        width: 7in !important;                   /* Fixed width for consistent centering */
        align-items: start !important;
    }
    
    /* Individual clue columns */
    .clues-column {
        display: block !important;
        width: 100% !important;
        background-color: transparent !important;
        padding: 0;
        margin-bottom: 0.12in;
        border: none;
    }
    
    /* Simplified orphan control for dedicated columns */
    .clues-column h3 {
        font-size: 12pt;
        font-weight: bold;
        margin-bottom: 0.08in;
        margin-left: 3pt;
        border-bottom: 1px solid black;
        padding-bottom: 2pt;
        color: black;
        
        /* Orphan control - simplified for grid layout */
        break-after: avoid !important;      /* Keep header with content */
        page-break-after: avoid !important; /* Older browser support */
    }
    
    /* Clue list styling */
    .clues-list {
        margin: 0;
        padding: 0;
        list-style: none;
        /* Removed column-specific properties */
    }
    
    /* Individual clue styling - tighter for space */
    .clues-list li {
        background-color: transparent !important;
        margin-bottom: 2pt;          /* Tighter spacing */
        padding: 0;
        font-size: 8.5pt;            /* Smaller to fit more */
        line-height: 1.05;           /* Tighter line height */
        break-inside: avoid;
        border: none;
    }
    
    /* Clue numbers */
    .clues-list li strong {
        font-weight: bold;
        color: black !important;
        margin-right: 4pt;
    }
    
    .clues-list ul {
        margin-bottom: 0 !important;
        padding-bottom: 0;
    }
    
    /* Clue text */
    .clue-definition {
        color: black !important;
    }
    
    /* Force all text colors to black for printing */
    h1, h2, h3, h4, h5, h6 {
        color: black !important;
    }
    
    .crossword-section * {
        color: black !important;
    }
    
    /* Ensure colors print correctly */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    /* Page setup */
    @page {
        margin: 0.4in;
        size: letter portrait;
    }
    
    /* Prevent page breaks within puzzle */
    .crossword-container,
    .crossword-grid,
    .clues-container {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    
    /* Hide on-screen puzzle ID */
    .puzzle-id-display {
        display: none !important;
    }
    
    /* Show puzzle ID at bottom - reduced from 1/2" to 1/4" */
    .print-puzzle-id {
        display: block !important;
        text-align: center;
        margin-top: 0;          /* Reduced spacing */
        padding-top: 0;         /* Reduced padding */
        font-size: 8pt;              /* Smaller font */
        font-weight: normal;
        color: black !important;
        /* Total height: ~0.20" */
    }
    
    
    .print-copyright {
        display: block !important;
        text-align: center;
        margin-top: 0.05in;
        margin-bottom: 0;
        font-size: 8pt;
        color: black !important;
        border-top: 1px solid black;
        padding-top: 0.05in;
        padding-bottom: 0;
        /* Total height: ~0.25" */
    }
    
    .print-name-date {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        margin-bottom: 0;
        margin-top: 0.1in;
        padding: 0.1in 0;
        font-size: 10pt;
        color: black !important;
    }
    
    .print-name-date div {
        color: black !important;
    }
}    
    /* Hide on screen */
    @media screen {
        .print-copyright {
            display: none;
        }
    .print-name-date {
        display: none !important;
    }

    }
