:root {
    --bg: #f0f0f0;
    --surface: #fafafa;
    --surface-alt: #f5f5f5;
    --border: #e0e0e0;
    --text: #333;
    --text-secondary: #888;
    --text-muted: #aaa;
    --accent: #4a7c94;
    --accent-hover: #3d6a80;
    --accent-light: #e8f0f4;
    --block: #555;
    --block-light: #d5d5d5;
    --answer-idx: #c44;
    --danger: #c0392b;
    --success: #27ae60;
    --warning: #e67e22;
    --word-border: #999;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Rubik', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.app {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    width: 420px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px 12px 16px 20px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    flex-shrink: 0;
}

.sidebar-footer a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9em;
}

.sidebar-footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.15em;
    font-weight: 600;
    color: var(--text);
}

.sidebar-content {
    padding: 16px 20px;
    flex: 1;
}

.section-title {
    font-size: 1em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 10px;
    margin-top: 18px;
}

details.sidebar-section {
    border-left: 3px solid var(--text-secondary);
    padding-left: 1em;
    margin-top: 1em;
}

.sidebar-section > summary.section-title {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0;
    user-select: none;
}

.sidebar-section > summary.section-title::-webkit-details-marker {
    display: none;
}

.sidebar-section[open] > summary.section-title {
    margin-bottom: 10px;
}

.section-toggle {
    display: inline-block;
    font-size: 0.75em;
    transition: transform 0.15s;
}

.sidebar-section[open] > summary .section-toggle {
    transform: rotate(90deg);
}

.section-body {
    /* no extra spacing needed; controlled by form-group margins */
}

.section-title:first-child {
    margin-top: 0;
}

.form-group {
    margin-bottom: 12px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.82em;
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    min-height: 90px;
    resize: vertical;
    font-family: inherit;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.range-group input[type="range"] {
    flex: 1;
    height: 3px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
}

.range-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.range-value {
    min-width: 40px;
    text-align: right;
    font-size: 0.85em;
    font-weight: 500;
    color: var(--accent);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-group input {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}

.checkbox-group label {
    margin: 0;
    cursor: pointer;
}

.error-message {
    color: var(--danger);
    font-size: 0.78em;
    margin-top: 4px;
}

.btn {
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.88em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text);
    border: 1px solid var(--border);
    margin-top: 6px;
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-small {
    padding: 5px 10px;
    font-size: 11px;
    margin-top: 0;
    margin-left: 6px;
    width: auto;
    border-radius: 5px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
}

.stats {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-value {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--text);
}

.stat-label {
    font-size: 0.78em;
    color: var(--text-secondary);
}

.grid-area {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    position: relative;
}

.grid-scaler {
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

.crossword-grid {
    display: inline-grid;
    gap: 1px;
    background: #d0d0d0;
    padding: 1px;
    border-radius: 0;
    transform-origin: top center;
    border: none;
}

.cell {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    position: relative;
    background: #fff;
    color: var(--text);
    border: none;
}

/* Word outline borders: stronger edge on word boundary — REMOVED */

.cell.block {
    background: var(--block);
    border-color: var(--block);
}

.cell.block-light {
    background: var(--block-light);
    border-color: var(--block-light);
}

.cell.clue-cell {
    background: var(--surface-alt);
    font-size: 5.5px;
    font-weight: 400;
    color: #777;
    padding: 2px;
    overflow: hidden;
    flex-direction: column;
    line-height: 1.0;
    text-align: center;
    word-break: break-word;
    border-color: var(--border);
}

/* answer — no background highlight, just the index number */

.cell-answer-index {
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: 8px;
    font-weight: 700;
    color: var(--answer-idx);
}

.cell-clue-text {
    font-size: 4.5px;
    line-height: 1.0;
    max-height: 26px;
    overflow: hidden;
}

.cell-number {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 8px;
    font-weight: normal;
    color: var(--text-secondary);
}

.cell-arrow {
    position: absolute;
    bottom: 1px;
    right: 2px;
    font-size: 10px;
    color: var(--accent);
}

.clues-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
    max-width: 800px;
    margin-top: 20px;
}

.clues-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    max-height: 300px;
    overflow-y: auto;
}

.clues-title {
    font-weight: 600;
    margin-bottom: 10px;
    font-size: 0.72em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.clue-list {
    list-style: none;
}

.clue-item {
    padding: 6px 8px;
    margin-bottom: 3px;
    background: var(--surface-alt);
    border-radius: 5px;
    font-size: 0.82em;
    line-height: 1.35;
}

.clue-number {
    color: var(--accent);
    font-weight: 600;
    margin-right: 5px;
}

.loading {
    display: none;
    text-align: center;
    padding: 14px 20px;
    background: rgba(250, 250, 250, 0.92);
    border-radius: 10px;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    border: 1px solid var(--border);
}

.loading.active {
    display: block;
}

.loading-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.loading .btn-stop {
    margin-top: 8px;
    padding: 5px 18px;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
}

.loading .btn-stop:hover {
    opacity: 0.9;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.arrow-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
    margin-top: 10px;
    font-size: 0.78em;
}

.arrow-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: var(--surface-alt);
    border-radius: 5px;
    border: 1px solid var(--border);
}

.arrow-symbol {
    font-size: 1em;
    color: var(--accent);
}

.suggest-panel {
    background: var(--surface);
    border: 1.5px solid var(--accent);
    border-radius: 10px;
    padding: 14px;
    margin-top: 12px;
}

.suggest-header {
    font-weight: 600;
    font-size: 0.88em;
    margin-bottom: 8px;
    color: var(--accent);
}

.suggest-word {
    font-size: 1.2em;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 3px;
}

.suggest-clue {
    font-size: 0.85em;
    color: #555;
    margin-bottom: 3px;
}

.suggest-info {
    font-size: 0.75em;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.suggest-actions {
    display: flex;
    gap: 6px;
}

.suggest-actions .btn {
    width: auto;
    flex: 1;
    padding: 5px 6px;
    font-size: 0.78em;
}

.cell.preview {
    background: #d4eaf7;
    color: var(--accent);
}

.cell.preview-existing {
    background: #eaf4f9;
    color: var(--accent);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.btn-accept {
    background: var(--success);
    color: #fff;
}

.btn-accept:hover {
    opacity: 0.9;
}

.btn-retry {
    background: var(--warning);
    color: #fff;
}

.btn-retry:hover {
    opacity: 0.9;
}

.btn-reject {
    background: var(--danger);
    color: #fff;
}

.btn-reject:hover {
    opacity: 0.9;
}

.btn-add-words {
    background: #6c6ea0;
    color: #fff;
    margin-top: 6px;
}

.btn-add-words:hover {
    background: #5a5c8a;
}

/* Dictionary list */
.dict-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dict-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 5px 8px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.82em;
    transition: opacity 0.15s;
}

.dict-row.dict-disabled {
    opacity: 0.5;
}

.dict-line1 {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dict-line2 {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 20px;
    font-size: 0.92em;
}

.dict-require-label {
    display: flex;
    align-items: center;
    gap: 3px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.9em;
}

.dict-actions {
    margin-left: auto;
    display: flex;
    gap: 2px;
}

.dict-row input[type="checkbox"] {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.dict-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.dict-count {
    color: var(--text-secondary);
    font-size: 0.9em;
    white-space: nowrap;
}

.dict-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
}

.dict-delete:hover {
    color: var(--danger);
}

.dict-require-cb {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    accent-color: #e67e22;
    cursor: pointer;
}

.dict-edit {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.85em;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
}

.dict-edit:hover {
    opacity: 0.7;
}

.sidebar-right {
    width: 420px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-right .sidebar-header {
    padding: 12px 16px;
    flex-shrink: 0;
}

.sidebar-right .stats {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.sidebar-right .sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    padding-bottom: 16px;
}

.sidebar-right #clues-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
    min-height: 0;
}

.sidebar-right .clues-panel {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    max-height: none;
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .app {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        max-height: 50vh;
        border-right: none;
        border-bottom: 1px solid #d2d2d7;
    }
    .sidebar-right {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
    }
    .clues-section {
        grid-template-columns: 1fr;
    }
}
