/* Crossword Editor Page Stylesheet
   All rules scoped to .crossword-editor-page (the page root div).
   Exceptions kept global:
   - .crossword-editor-page itself (it IS the scope root)
   - .drag-ghost (rendered OUTSIDE the scope div for DnD overlay) */

/* Neutralize body zoom for the editor page */
.crossword-editor-page {
    zoom: calc(1 / 1.1);
}

.crossword-editor-page .editor-main-container {
    width: 100%;
    max-width: 1100px;
    background-color: #e9e9e9;
    border-radius: 16px;
    border: 1px solid #dcdcdc;
    padding: 25px 30px 40px 30px;
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    margin: 20px auto;
    animation: fadeIn 0.3s ease-out;
}

.crossword-editor-page .content-columns {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

/* --- Left Column (Board) --- */
.crossword-editor-page .left-column {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0; /* Prevents overflow inside flex */
}

.crossword-editor-page h2.section-title {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 16px;
    color: #1a1a1a;
    text-align: center;
    letter-spacing: 0.5px;
}

.crossword-editor-page .crossword-board-wrapper {
    background-color: #ffffff;
    border: 1.5px solid #888;
    padding: 20px;
    width: 100%;
    max-height: 480px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
    overflow: auto; /* Enable scrollbars for larger grids */
    position: relative;
}

/* The Grid */
.crossword-editor-page .crossword-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-cols, 15), 22px);
    grid-template-rows: repeat(var(--grid-rows, 15), 22px);
    padding: 1px 0 0 1px; /* Compensate for negative margins */
    user-select: none;
}

.crossword-editor-page .crossword-grid.drag-active .cell {
    cursor: crosshair;
}

.crossword-editor-page .cell {
    width: 22px;
    height: 22px;
    border: 1px solid #c5c5e0;
    margin-top: -1px;
    margin-left: -1px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    position: relative;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
    text-transform: uppercase;
}

/* Unoccupied/Empty space cell */
.crossword-editor-page .cell.empty {
    background: #fdfdfd;
    border: 1px dashed #ccc;
    color: #bbb;
}

.crossword-editor-page .cell.empty:hover {
    background-color: #f0f2ff;
    border-color: #4d49fc;
}

/* Placed word cells */
.crossword-editor-page .cell.occupied {
    background: #ffffff;
    border: 1px solid #333;
    color: #111;
}

/* Highlighted lane corresponding to active selected cell + orientation */
.crossword-editor-page .cell.highlighted-lane {
    background-color: #f0f2ff;
}

/* Currently selected editing coordinate */
.crossword-editor-page .cell.selected {
    background-color: #cbd2ff !important;
    border: 1.5px solid #4d49fc !important;
    z-index: 2;
}

.crossword-editor-page .cell .num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 7px;
    font-weight: 400;
    line-height: 1;
    color: #333;
    pointer-events: none;
}

/* Word placement preview — dimmed letters */
.crossword-editor-page .cell.preview {
    background: #eef0ff;
    border: 1px dashed #8888cc;
    color: #999;
    font-weight: 500;
}

/* Preview intersection — green highlight */
.crossword-editor-page .cell.preview-intersection {
    background: #d4f5d4 !important;
    border-color: #4caf50 !important;
    color: #2e7d32 !important;
    font-weight: 700;
}

/* Preview conflict — red highlight */
.crossword-editor-page .cell.preview-conflict {
    background: #ffebee !important;
    border-color: #f44336 !important;
    color: #c62828 !important;
    font-weight: 700;
}

.crossword-editor-page .left-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.crossword-editor-page .btn-blue {
    background-color: #4d49fc;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.crossword-editor-page .btn-blue:hover {
    background-color: #28209c;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(77,73,252,0.25);
}

.crossword-editor-page .btn-blue:active {
    transform: translateY(0);
}

.crossword-editor-page .btn-blue:disabled {
    background-color: #a8a8cf;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.crossword-editor-page .hint-text {
    font-size: 13.5px;
    color: #444;
    text-align: center;
}

/* --- Right Column (Parameters & Dictionary) --- */
.crossword-editor-page .right-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Params Form */
.crossword-editor-page .params-form {
    display: grid;
    grid-template-columns: auto minmax(140px, 1fr) auto auto;
    justify-content: start;
    gap: 12px;
    align-items: center;
    margin-bottom: 25px;
    padding-top: 5px;
}

.crossword-editor-page .form-label {
    font-size: 13.5px;
    color: #333;
    font-weight: 500;
    text-align: right;
}

.crossword-editor-page .form-label.col-3 {
    text-align: left;
}

.crossword-editor-page .form-input,
.crossword-editor-page .form-select {
    width: 100%;
    padding: 6px 10px;
    border: 1.5px solid #bbb;
    border-radius: 6px;
    font-size: 13.5px;
    outline: none;
    background-color: #fff;
    transition: border-color 0.2s;
    font-family: 'Inter', sans-serif;
}

.crossword-editor-page .form-input:focus,
.crossword-editor-page .form-select:focus {
    border-color: #4d49fc;
}

.crossword-editor-page .size-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.crossword-editor-page .custom-number-wrapper {
    position: relative;
    width: 58px;
    height: 31px;
}

.crossword-editor-page .custom-number-input {
    width: 100%;
    height: 100%;
    padding: 6px 16px 6px 8px;
    border: 1.5px solid #bbb;
    border-radius: 6px;
    font-size: 13.5px;
    outline: none;
    background-color: #fff;
    transition: border-color 0.2s;
    font-family: 'Inter', sans-serif;
    text-align: left;
    -moz-appearance: textfield;
}

.crossword-editor-page .custom-number-input:focus {
    border-color: #4d49fc;
}

.crossword-editor-page .custom-number-input::-webkit-outer-spin-button,
.crossword-editor-page .custom-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.crossword-editor-page .custom-number-controls {
    position: absolute;
    right: 2px;
    top: 2px;
    bottom: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 14px;
}

.crossword-editor-page .custom-number-controls button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 13px;
    color: #888;
    transition: color 0.15s, background-color 0.15s;
    border-radius: 3px;
}

.crossword-editor-page .custom-number-controls button:hover {
    color: #333;
    background-color: #e6e6e6;
}

.crossword-editor-page .custom-number-controls button svg {
    width: 10px;
    height: 10px;
}

/* Dictionary Section */
.crossword-editor-page h2.section-title.dict {
    margin-top: 15px;
    border-top: 1px solid #ccc;
    padding-top: 20px;
}

.crossword-editor-page .dict-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.crossword-editor-page .search-wrapper {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1.5px solid #bbb;
    border-radius: 6px;
    width: 150px;
    height: 32px;
    overflow: hidden;
}

.crossword-editor-page .search-wrapper input {
    border: none;
    outline: none;
    padding: 4px 8px;
    width: 100%;
    font-size: 13.5px;
}

.crossword-editor-page .search-icon-btn {
    padding: 0 8px;
    height: 100%;
    display: flex;
    align-items: center;
    border-left: 1px solid #bbb;
    background: #f0f0f0;
    cursor: pointer;
}

.crossword-editor-page .search-icon-btn:hover {
    background: #e0e0e0;
}

/* Dictionary Panels */
.crossword-editor-page .dict-panels-wrapper {
    position: relative;
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
}

.crossword-editor-page .panel-box {
    background: #ffffff;
    border: 1.5px solid #777;
    border-radius: 8px;
    height: 200px;
    flex: 1;
    padding: 8px;
    font-size: 13.5px;
    overflow-y: auto;
}

.crossword-editor-page .term-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.crossword-editor-page .term-item {
    padding: 6px 12px;
    border-radius: 12px;
    cursor: grab;
    font-size: 13.5px;
    transition: all 0.15s ease;
    word-break: break-all;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.crossword-editor-page .term-item:hover {
    background-color: #f0eeff;
}

.crossword-editor-page .term-item.active {
    background-color: #4d49fc;
    color: white;
}

.crossword-editor-page .term-item.on-grid {
    opacity: 0.45;
    cursor: default;
    text-decoration: line-through;
    pointer-events: auto;
}

.crossword-editor-page .term-item.on-grid:hover {
    background-color: #f5f5f5;
}

.crossword-editor-page .term-item.on-grid.active {
    background-color: #9795c8;
    color: white;
}

.crossword-editor-page .term-item.dragging {
    background-color: #4d49fc22;
    outline: 2px dashed #4d49fc;
    outline-offset: -2px;
    transform: scale(0.97);
    opacity: 0.7;
}

/* Active word display under grid or panels */
.crossword-editor-page .active-word-info {
    background-color: #e2e8f0;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Action Buttons Bottom */
.crossword-editor-page .dict-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.crossword-editor-page .action-group {
    display: flex;
    gap: 6px;
}

.crossword-editor-page .btn-small {
    background-color: #4d49fc;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.crossword-editor-page .btn-small:hover {
    background-color: #28209c;
}

.crossword-editor-page .btn-small.btn-icon {
    padding: 6px;
    width: 32px;
    height: 28px;
}

.crossword-editor-page .btn-small.btn-icon svg {
    width: 14px;
    height: 14px;
}

/* Bottom Global Button */
.crossword-editor-page .bottom-action-wrapper {
    display: flex;
    justify-content: center;
    margin-top: 25px;
    border-top: 1px solid #ccc;
    padding-top: 20px;
}


/* GLOBAL: drag-ghost renders OUTSIDE .crossword-editor-page (sibling of root)
   so it must NOT be scoped. Name is unique and won't conflict. */
.drag-ghost {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    background: #4d49fc;
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    white-space: nowrap;
    opacity: 0.9;
    text-transform: uppercase;
}
