html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}


body {
    margin: 0;
    padding: 0;
    font-family: 'Lora', serif;
    color: #3D352A;
    background-color: #D3C4B3;
    background-image: linear-gradient(rgba(0,0,0,0.02) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(0,0,0,0.02) 1px, transparent 1px);
    background-size: 20px 20px;
}

.background-image {
    display: none;
}


.book {
    max-width: 850px;
    margin: 50px auto;
    padding: 50px 60px;
    background-color: #FDFCF7;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    box-shadow: 0 10px 35px rgba(0, 0, 0, 0.3), 0 0 0 10px rgba(0,0,0,0.1);
}


.book-header {
    text-align: center;
    border-bottom: 3px double #D1C7B8;
    padding-bottom: 20px;
    margin-bottom: 40px;
}

.book-header h1 {
    font-size: 3em;
    font-weight: 700;
    color: #3D352A;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.book-header h2 {
    font-size: 1.3em;
    color: #8A795D;
    font-style: italic;
    font-weight: 400;
    letter-spacing: 1px;
    margin-top: 5px;
}

.book h3 {
    font-size: 1.6em;
    font-weight: 700;
    color: #5C4033;
    border-bottom: 1px solid #D1C7B8;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.book h4 {
    font-size: 1.2em;
    font-weight: 700;
    color: #8A795D;
    margin-top: -10px;
    margin-bottom: 20px;
}


.how-to-play {
    background-color: #F9F6F0;
    border: 1px dashed #D1C7B8;
    padding: 20px 25px;
    margin: 40px 0;
    border-radius: 3px;
}
.how-to-play h3 {
    border-bottom: none;
    color: #8A795D;
    font-size: 1.4em;
    text-align: center;
}
.how-to-play li {
    margin-bottom: 10px;
    line-height: 1.8;
    color: #5C5243;
}

.book-display {
    border: 1px solid #EAE6E0;
    background-color: #FFFFFF;
    border-radius: 2px;
    padding: 30px 40px;
    margin-top: 20px;
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.08);
}

.page-entry {
    padding: 20px 0;
    border-bottom: 1px solid #EAE6E0;
}
.page-entry:last-child {
    border-bottom: none;
}
.page-entry p {
    font-size: 1.1em;
    line-height: 1.8;
    color: #333;
    white-space: pre-wrap;
    margin: 0 0 10px 0;
    overflow-wrap: break-word;
    word-wrap: break-word;
}
.page-meta {
    font-size: 0.9em;
    color: #999;
    font-style: italic;
    text-align: right;
}

.writing-area {
    margin-top: 30px;
}
.writing-area textarea {
    width: 100%;
    min-height: 180px;
    background-color: #FDFCF7;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    padding: 15px;
    font-size: 1.1em;
    font-family: 'Lora', serif;
    color: #3D352A;
    line-height: 1.8;
    resize: vertical;
    transition: border-color 0.3s, box-shadow 0.3s;
}
.writing-area textarea:focus {
    outline: none;
    border-color: #8A795D;
    box-shadow: 0 0 5px rgba(138, 121, 93, 0.3);
}

.button {
    font-family: 'Open Sans', sans-serif;
    display: inline-block;
    background-color: #5C4033;
    color: #FDFCF7;
    padding: 12px 30px;
    border: none;
    border-radius: 3px;
    font-size: 1em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
}
.button:hover {
    background-color: #3D352A;
    transform: translateY(-1px);
}
.button.secondary {
     background-color: #A99985;
}
.button.secondary:hover {
     background-color: #8A795D;
}
.action-buttons {
    text-align: center;
    margin-top: 20px;
}
.action-buttons button { margin: 0 10px; }

.footer {
    text-align: center;
    margin-top: 50px;
    padding-top: 20px;
    border-top: 1px solid #EAE6E0;
    font-family: 'Open Sans', sans-serif;
}
.footer a, .footer p {
    font-size: 0.9em;
    color: #8A795D;
    text-decoration: none;
}
.footer a:hover {
    text-decoration: underline;
}
.footer ul { list-style: none; padding: 0; margin: 10px 0 0 0; }
.footer ul li { display: inline-block; margin: 0 10px; }


.library-main { min-height: 400px; }
.initial-cta-container { padding: 50px 0; }
.status-message { margin: 20px auto 0; padding: 12px; border-radius: 3px; max-width: 80%; }
.status-message.success { background-color: #D4EDDA; color: #155724; border: 1px solid #C3E6CB; }
.status-message.error { background-color: #F8D7DA; color: #721C24; border: 1px solid #F5C6CB; }
.loading-spinner { border: 5px solid #EAE6E0; border-top: 5px solid #8A795D; border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 50px auto; display: none; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.create-book-section {
    margin-top: 60px;
}

.feature-box {
    background-color: #F9F6F0;
    border: 1px dashed #D1C7B8;
    padding: 30px 40px;
    border-radius: 3px;
    text-align: center;
}

.create-book-form {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.create-book-form input[type="text"] {
    width: 100%;
    max-width: 500px;
    padding: 12px 15px;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    font-family: 'Lora', serif;
    font-size: 1.1em;
    color: #3D352A;
    text-align: center;
}

.create-book-form input[type="text"]::placeholder {
    color: #aaa;
}

.create-book-form .button {
    margin-top: 0;
}

.author-input-container {
    margin-bottom: 15px;
    text-align: left;
}

.author-input-container label {
    font-family: 'Open Sans', sans-serif;
    font-weight: 700;
    color: #8A795D;
    font-size: 0.9em;
    margin-right: 10px;
}

.author-input-container input[type="text"] {
    display: inline-block;
    width: auto;
    min-width: 250px;
    padding: 8px 10px;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    font-family: 'Lora', serif;
    font-size: 1em;
    color: #3D352A;
}

.page-meta {
    font-size: 0.9em;
    color: #999;
    font-style: italic;
    text-align: right;
    margin-top: 15px;
}

.page-meta .timestamp {
    display: block;
    margin-top: 5px;
    color: #B0A08D;
}

.back-to-home-link {
    text-align: left;
    margin-top: 20px;
    margin-bottom: 30px;
    padding-left: 10px;
}

.back-to-home-link a {
    font-family: 'Open Sans', sans-serif;
    color: #8B4513;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1em;
    padding: 8px 15px;
    border: 1px solid #D1C7B8;
    border-radius: 3px;
    background-color: #F9F6F0;
    transition: background-color 0.3s, color 0.3s;
}

.back-to-home-link a:hover {
    background-color: #D1C7B8;
    color: #3D352A;
}

.char-counter-container {
    text-align: right;
    margin-top: 5px;
}
.char-counter {
    font-family: 'Open Sans', sans-serif;
    font-size: 0.85em;
    color: #8A795D;
}
.char-counter.limit-exceeded {
    color: #9c3c3c;
    font-weight: bold;
}

.create-book-form .char-counter-container {
    width: 100%;
    max-width: 500px;
    text-align: right;
    margin-top: -10px;
    padding-right: 5px;
}