@import url('https://fonts.googleapis.com/css2?family=Spectral:wght@400;500;600;700&family=Spectral+SC:wght@400;500&display=swap');

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

:root {
    --paper: #f5f0e1;
    --paper-dark: #e8e0cc;
    --paper-edge: #d4c9b0;
    --ink: #2d2416;
    --ink-light: #5c4d38;
    --ink-faded: #8a7a62;
    --red: #8b3a3a;
    --red-faded: #a65d5d;
    --accent: #4a5d3a;
    --bg: #3d3428;
}

body {
    font-family: 'Spectral', Georgia, serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--ink);
    font-size: 16px;
    line-height: 1.7;
}

.app {
    min-height: 100vh;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Header container */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    width: 100%;
    max-width: 1100px;
}

/* Style selector */
.style-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: var(--paper-dark);
    border: 1px solid var(--paper-edge);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    position: relative;
    top: 1px;
}

.style-selector label {
    font-family: 'Spectral SC', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
    letter-spacing: 0.05em;
}

.style-selector select {
    padding: 0.25rem 1.5rem 0.25rem 0.5rem;
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    color: var(--ink);
    font-family: 'Spectral', serif;
    font-size: 0.9rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' fill='%235c4d38'%3E%3Cpath d='M0 0l4 5 4-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.style-selector select:hover {
    border-color: var(--ink-faded);
}

.style-selector select:focus {
    outline: none;
    border-color: var(--red);
}

.style-selector select option {
    background: var(--paper);
    color: var(--ink);
}

/* Navigation - journal tabs */
nav {
    display: flex;
    gap: 0;
    margin-bottom: 0;
}

nav a {
    font-family: 'Spectral SC', serif;
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--ink-faded);
    padding: 0.6rem 1.5rem;
    background: var(--paper-dark);
    border: 1px solid var(--paper-edge);
    border-bottom: none;
    margin-right: -1px;
    position: relative;
    top: 1px;
    transition: all 0.15s;
}

nav a:first-child {
    border-radius: 4px 0 0 0;
}

nav a:last-child {
    border-radius: 0 4px 0 0;
}

nav a:hover {
    color: var(--ink);
    background: var(--paper);
}

nav a.active {
    color: var(--ink);
    background: var(--paper);
    border-bottom-color: var(--paper);
    z-index: 1;
}

/* Journal pages container */
.journal {
    background: var(--paper);
    width: 100%;
    max-width: 1100px;
    border: 1px solid var(--paper-edge);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    display: grid;
    grid-template-columns: 340px 1fr;
    position: relative;
}

.journal::before {
    content: '';
    position: absolute;
    left: 340px;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(90deg,
        rgba(0,0,0,0.08) 0%,
        transparent 50%,
        rgba(0,0,0,0.03) 100%
    );
    pointer-events: none;
    z-index: 1;
}

.page {
    padding: 2rem;
    position: relative;
}

.page-left {
    background-image: repeating-linear-gradient(
        var(--paper) 0px,
        var(--paper) 27px,
        var(--paper-dark) 28px
    );
    border-right: 1px solid var(--paper-edge);
}

.page-header {
    font-family: 'Spectral SC', serif;
    font-size: 1rem;
    font-weight: 500;
    color: var(--red);
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--red-faded);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--paper-edge);
    padding-bottom: 0.5rem;
}

.tab-btn {
    font-family: 'Spectral SC', serif;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 0.4rem 0.75rem;
    background: transparent;
    border: 1px solid transparent;
    color: var(--ink-faded);
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover {
    color: var(--ink);
}

.tab-btn.active {
    color: var(--red);
    border-color: var(--paper-edge);
    border-bottom-color: var(--paper);
    background: var(--paper);
    position: relative;
    top: 1px;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Form fields */
.field {
    margin-bottom: 0.9rem;
}

.field label {
    display: block;
    font-family: 'Spectral SC', serif;
    font-size: 0.75rem;
    color: var(--ink-faded);
    margin-bottom: 0.25rem;
    letter-spacing: 0.05em;
}

.field select {
    width: 100%;
    padding: 0.5rem 0.6rem;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--ink-faded);
    color: var(--ink);
    font-family: 'Spectral', serif;
    font-size: 1rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' fill='%235c4d38'%3E%3Cpath d='M0 0l4 5 4-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0 center;
    transition: border-color 0.15s;
}

.field select:hover {
    border-bottom-color: var(--ink-light);
}

.field select:focus {
    outline: none;
    border-bottom-color: var(--red);
}

.field select option {
    background: var(--paper);
    color: var(--ink);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.note {
    font-size: 0.85rem;
    color: var(--ink-faded);
    font-style: italic;
    margin: 1.25rem 0;
    padding-left: 0.75rem;
    border-left: 2px solid var(--red-faded);
}

/* Buttons */
.actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.btn {
    flex: 1;
    padding: 0.65rem 1rem;
    font-family: 'Spectral SC', serif;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--ink);
    color: var(--paper);
}

.btn-primary:hover:not(:disabled) {
    background: var(--red);
}

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

.btn-secondary {
    background: var(--paper-dark);
    color: var(--ink);
    border: 1px solid var(--paper-edge);
}

.btn-secondary:hover {
    border-color: var(--ink-faded);
}

/* Preview/Illustration panel */
.page-right {
    display: flex;
    flex-direction: column;
    background: var(--paper);
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.illustration-frame {
    width: 512px;
    height: 512px;
    min-width: 512px;
    min-height: 512px;
    max-width: 100%;
    margin: 1rem auto;
    border: 1px solid var(--ink-faded);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper-dark);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.illustration-frame::before,
.illustration-frame::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    z-index: 2;
}

.illustration-frame::before {
    top: -1px;
    left: -1px;
    border-top: 2px solid var(--ink);
    border-left: 2px solid var(--ink);
}

.illustration-frame::after {
    bottom: -1px;
    right: -1px;
    border-bottom: 2px solid var(--ink);
    border-right: 2px solid var(--ink);
}

.illustration-frame img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.placeholder {
    position: absolute;
    text-align: center;
    color: var(--ink-faded);
}

.loading {
    position: absolute;
    text-align: center;
    color: var(--ink-faded);
}

.placeholder svg {
    width: 48px;
    height: 48px;
    stroke: var(--ink-faded);
    fill: none;
    stroke-width: 1;
    margin-bottom: 0.75rem;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.placeholder p {
    font-style: italic;
    font-size: 0.95rem;
}

.caption {
    text-align: center;
    font-family: 'Spectral SC', serif;
    font-size: 0.8rem;
    color: var(--ink-faded);
    padding: 0.5rem;
    flex-shrink: 0;
}

.illustration-actions {
    display: flex !important;
    gap: 0.5rem;
    padding: 0 1rem 1rem;
    flex-shrink: 0;
    visibility: visible !important;
}

.illustration-actions .btn {
    flex: 1;
    padding: 0.5rem;
    font-size: 0.8rem;
    background: var(--paper);
    color: var(--ink-faded);
    border: 1px solid var(--paper-edge);
}

.illustration-actions .btn:hover {
    color: var(--ink);
    border-color: var(--ink-faded);
}

.illustration-actions .btn.active {
    color: var(--red);
    border-color: var(--red-faded);
}

/* Loading state - positioned absolutely in illustration frame */

.spinner {
    width: 40px;
    height: 40px;
    border: 2px solid var(--paper-edge);
    border-top-color: var(--red);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.status-text {
    font-style: italic;
    font-size: 0.9rem;
}

.status-text.error {
    color: var(--red);
}

/* Prompt display */
.prompt-display {
    margin: 0 1rem 1rem;
    padding: 0.75rem;
    background: var(--paper-dark);
    border: 1px solid var(--paper-edge);
    min-height: 120px;
    overflow: hidden;
    flex-shrink: 0;
}

#prompt-display.hidden {
    display: block !important;
    visibility: hidden;
}

.prompt-display h3 {
    font-family: 'Spectral SC', serif;
    font-size: 0.75rem;
    color: var(--ink-faded);
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.prompt-display p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--ink-light);
}

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

/* ==================== GALLERY PAGE ==================== */

.gallery-container {
    background: var(--paper);
    width: 100%;
    max-width: 1100px;
    border: 1px solid var(--paper-edge);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    padding: 2rem;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--red-faded);
}

.gallery-header h1 {
    font-family: 'Spectral SC', serif;
    font-size: 1rem;
    font-weight: 500;
    color: var(--red);
    letter-spacing: 0.1em;
}

.gallery-filters label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--ink-faded);
}

.gallery-filters input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--red);
}

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

.gallery-card {
    position: relative;
    aspect-ratio: 1;
    border: 1px solid var(--ink-faded);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--paper-dark);
}

.gallery-card::before,
.gallery-card::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    z-index: 2;
    transition: all 0.15s;
}

.gallery-card::before {
    top: -1px;
    left: -1px;
    border-top: 2px solid var(--ink-light);
    border-left: 2px solid var(--ink-light);
}

.gallery-card::after {
    bottom: -1px;
    right: -1px;
    border-bottom: 2px solid var(--ink-light);
    border-right: 2px solid var(--ink-light);
}

.gallery-card:hover::before,
.gallery-card:hover::after {
    border-color: var(--red);
}

.gallery-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.5rem;
    background: linear-gradient(transparent, rgba(45, 36, 22, 0.9));
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.favorite-indicator {
    color: var(--paper-edge);
    font-size: 1.1rem;
}

.favorite-indicator.active {
    color: var(--red);
}

.card-date {
    font-family: 'Spectral SC', serif;
    font-size: 0.7rem;
    color: var(--paper-dark);
    letter-spacing: 0.05em;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: var(--ink-faded);
    font-style: italic;
}

.empty-state a {
    color: var(--red);
    text-decoration: none;
}

.empty-state a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(45, 36, 22, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 2rem;
}

.modal-content {
    background: var(--paper);
    border: 1px solid var(--paper-edge);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    max-width: 900px;
    max-height: 90vh;
    overflow: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--paper-dark);
    border: 1px solid var(--paper-edge);
    color: var(--ink);
    font-size: 1.25rem;
    width: 36px;
    height: 36px;
    border-radius: 0;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--red);
    color: var(--paper);
    border-color: var(--red);
}

.modal-body {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 1.5rem;
    padding: 1.5rem;
}

#modal-image {
    width: 100%;
    border: 1px solid var(--ink-faded);
}

.modal-info h3 {
    font-family: 'Spectral SC', serif;
    font-size: 0.9rem;
    color: var(--red);
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--red-faded);
}

.modal-info h4 {
    font-family: 'Spectral SC', serif;
    font-size: 0.75rem;
    color: var(--ink-faded);
    letter-spacing: 0.05em;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

#modal-attributes {
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--ink);
}

#modal-prompt-text {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--ink-faded);
    font-style: italic;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.modal-actions button {
    width: 100%;
    padding: 0.6rem;
    font-family: 'Spectral SC', serif;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
    background: var(--paper-dark);
    color: var(--ink);
    border: 1px solid var(--paper-edge);
    cursor: pointer;
    transition: all 0.15s;
}

.modal-actions button:hover {
    border-color: var(--ink-faded);
}

.modal-actions button.danger {
    color: var(--red);
}

.modal-actions button.danger:hover {
    background: var(--red);
    color: var(--paper);
    border-color: var(--red);
}

/* Responsive */
@media (max-width: 850px) {
    .journal {
        grid-template-columns: 1fr;
    }

    .journal::before {
        display: none;
    }

    .page-left {
        border-right: none;
        border-bottom: 1px solid var(--paper-edge);
    }

    .modal-body {
        grid-template-columns: 1fr;
    }
}
