/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

#app {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: #1a1a1a;
}

/* ===== Steps ===== */
.step {
    display: none;
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.step.active {
    display: block;
}

/* ===== Gallery ===== */
.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.btn-create-new {
    text-decoration: none;
    display: inline-block;
    font-size: 0.9rem;
    white-space: nowrap;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.gallery-card {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.gallery-card:hover {
    border-color: #2B579A;
    box-shadow: 0 2px 8px rgba(43, 87, 154, 0.15);
}

.gallery-card-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 8px;
    color: #1a1a1a;
    word-break: break-word;
}

.gallery-card-meta {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 4px;
}

.gallery-card-date {
    font-size: 0.8rem;
    color: #999;
}

.gallery-empty {
    text-align: center;
    padding: 40px 20px;
    color: #888;
}

.gallery-empty p {
    margin-bottom: 8px;
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.radio-group {
    display: flex;
    gap: 16px;
}

.radio-group label {
    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

input[type="text"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
}

textarea {
    resize: vertical;
}

select {
    width: auto;
    min-width: 80px;
}

.password-wrapper {
    display: flex;
    gap: 8px;
}

.password-wrapper input {
    flex: 1;
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

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

.btn-primary {
    background: #2B579A;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #1e3f6f;
}

.btn-secondary {
    background: #e0e0e0;
    color: #333;
}

.btn-secondary:hover:not(:disabled) {
    background: #d0d0d0;
}

.btn-icon {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.btn-small {
    padding: 4px 12px;
    border: none;
    border-radius: 4px;
    background: #e0e0e0;
    cursor: pointer;
    font-size: 0.85rem;
    margin-left: 8px;
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* ===== Error & Warning ===== */
.error-msg {
    color: #c0392b;
    font-size: 0.9rem;
    margin-top: 8px;
    min-height: 1.4em;
}

.warning-box {
    background: #fff8e1;
    border: 1px solid #f9a825;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* ===== Spinner ===== */
.spinner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 0.9rem;
    color: #666;
}

.spinner-icon {
    width: 20px;
    height: 20px;
    border: 3px solid #ddd;
    border-top-color: #2B579A;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.spinner-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 100;
    font-size: 1rem;
    color: #333;
}

.spinner-overlay .spinner-icon {
    width: 36px;
    height: 36px;
    border-width: 4px;
}

/* ===== Editor Table ===== */
#editor-table-wrapper {
    overflow-x: auto;
}

#editor-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 8px;
}

#editor-table th,
#editor-table td {
    padding: 6px 8px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: middle;
}

#editor-table th {
    font-size: 0.85rem;
    color: #666;
    font-weight: 600;
}

.col-num { width: 36px; text-align: center; }
.col-word { width: 160px; }
.col-clue { }
.col-del { width: 36px; text-align: center; }

#editor-table input[type="text"] {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.9rem;
}

#editor-table .word-input {
    text-transform: uppercase;
}

.row-error {
    background: #fff0f0;
}

.row-error input {
    border-color: #e74c3c;
}

.btn-delete-row {
    background: none;
    border: none;
    color: #999;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-delete-row:hover {
    background: #fee;
    color: #c0392b;
}

.row-hint {
    font-size: 0.75rem;
    color: #c0392b;
    display: block;
    margin-top: 2px;
}

/* ===== Crossword Grid ===== */
#grid-wrapper {
    overflow-x: auto;
    margin: 0 auto 20px;
    text-align: center;
}

.crossword-grid {
    border-collapse: collapse;
    margin: 0 auto;
}

.grid-cell {
    width: 36px;
    height: 36px;
    min-width: 36px;
    position: relative;
    text-align: center;
    vertical-align: middle;
    padding: 0;
}

.grid-cell.black {
    background: transparent;
    border: none;
}

.grid-cell.white {
    background: #fff;
    border: 1px solid #333;
}

.cell-number {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 10px;
    line-height: 1;
    color: #333;
    pointer-events: none;
    white-space: nowrap;
}

.arrow-right {
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    border-left: 4px solid #333;
    margin-left: 1px;
    vertical-align: middle;
}

.arrow-down {
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 4px solid #333;
    margin-left: 1px;
    vertical-align: middle;
}

.cell-letter {
    font-size: 18px;
    font-weight: bold;
    color: #000;
    line-height: 1;
}

/* ===== Clue Container ===== */
#clue-container {
    display: flex;
    gap: 24px;
    margin-top: 16px;
}

.clue-column {
    flex: 1;
}

.clue-column h3 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: #1a1a1a;
}

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

.clue-column li {
    font-size: 0.9rem;
    margin-bottom: 4px;
    padding: 2px 0;
}

.clue-number {
    font-weight: 600;
    margin-right: 4px;
}

/* ===== Preview Header ===== */
.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.preview-controls label {
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
    #app {
        padding: 12px;
    }

    .step {
        padding: 16px;
    }

    .grid-cell {
        width: 28px;
        height: 28px;
    }

    .cell-number {
        font-size: 8px;
    }

    .cell-letter {
        font-size: 14px;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
    }

    #clue-container {
        flex-direction: column;
        gap: 12px;
    }

    .preview-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .preview-controls {
        flex-wrap: wrap;
    }
}

/* ===== Print Styles ===== */
.print-only {
    display: none;
}

@media print {
    body {
        background: #fff;
        font-size: 9pt;
    }

    #app {
        max-width: none;
        padding: 0;
        margin: 0;
    }

    .no-print,
    .preview-header,
    .warning-box,
    .btn-row {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    .step {
        box-shadow: none;
        padding: 0;
        border-radius: 0;
    }

    #print-title {
        text-align: center;
        font-size: 16pt;
        margin-bottom: 10mm;
    }

    .grid-cell.black {
        background: transparent !important;
        border: none !important;
    }

    .grid-cell.white {
        border: 1px solid #000 !important;
    }

    .cell-number {
        font-size: 6pt;
        color: #000;
    }

    .arrow-right {
        border-left-color: #000;
        border-top-width: 2px;
        border-bottom-width: 2px;
        border-left-width: 3px;
    }

    .arrow-down {
        border-top-color: #000;
        border-left-width: 2px;
        border-right-width: 2px;
        border-top-width: 3px;
    }

    .cell-letter {
        font-size: 10pt;
        color: #000;
    }

    #clue-container {
        margin-top: 8mm;
    }

    .clue-column h3 {
        font-size: 10pt;
    }

    .clue-column li {
        font-size: 9pt;
    }

    @page {
        size: A4 portrait;
        margin: 15mm;
    }
}
