body {
    font-family: 'Georgia', serif;
    line-height: 1.6;
    color: #333;
    margin: 0;
    padding: 0;
    background-color: #f9f9f7;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 20px;
}

#about-btn {
    justify-self: start;
    background: #f0e8dc;
    border-color: #c4a882;
    color: #5a3921;
}

#about-btn:hover {
    background: #e8ddd0;
    border-color: #b89968;
}

.random-btn-container {
    display: flex;
    justify-content: center;
}

.header-btn {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #f5f5f5;
    cursor: pointer;
    font-family: inherit;
    font-size: 1em;
    line-height: 1.4;
    color: #5a3921;
    white-space: nowrap;
}

.search-container {
    justify-self: end;
    display: flex;
    align-items: stretch;
}

#search-input {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid #ccc;
    min-width: 260px;
    font-family: inherit;
    font-size: 1em;
    color: #333;
    box-sizing: border-box;
}

#search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    margin-left: 4px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #f5f5f5;
    cursor: pointer;
    box-sizing: border-box;
}

#search-btn img {
    display: block;
    width: 22px;
    height: 22px;
}

.modal {
    position: relative;
    max-width: 560px;
    width: calc(100% - 40px);
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    margin: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: none;
    border-radius: 8px;
    padding: 36px 32px 28px;
    background: #fff;
    color: #333;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    box-sizing: border-box;
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.about-header {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e0d6c2;
}

.about-header h2 {
    color: #5a3921;
    margin: 0 0 8px;
    font-size: 1.6em;
}

.about-tagline {
    margin: 0;
    color: #9a7b59;
    font-style: italic;
    font-size: 0.95em;
    line-height: 1.5;
}

.about-lead {
    margin: 0 0 24px;
    line-height: 1.65;
    color: #444;
}

.about-section-title {
    margin: 0 0 16px;
    font-size: 1.05em;
    font-weight: bold;
    color: #5a3921;
}

.about-features {
    list-style: none;
    margin: 0 0 20px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.about-features li {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    background: #f9f9f7;
    border-radius: 6px;
    border-left: 3px solid #c4a882;
}

.about-feature-icon {
    flex-shrink: 0;
    font-size: 1.3em;
    line-height: 1.4;
}

.about-features strong {
    display: block;
    color: #5a3921;
    margin-bottom: 4px;
}

.about-features p {
    margin: 0;
    font-size: 0.92em;
    color: #666;
    line-height: 1.5;
}

.about-tip {
    padding: 12px 14px;
    background: #f5f0e8;
    border-radius: 6px;
    font-size: 0.9em;
    color: #5a3921;
    line-height: 1.5;
}

.about-tip strong {
    color: #7a5c38;
}

.about-credits {
    margin: 20px 0 0;
    padding-top: 16px;
    border-top: 1px solid #e0d6c2;
    font-size: 0.88em;
    color: #666;
    line-height: 1.65;
}

.about-credits a {
    color: #7a5c38;
    text-decoration: none;
    border-bottom: 1px solid #c4a882;
}

.about-credits a:hover {
    color: #5a3921;
    border-bottom-color: #5a3921;
}

.about-meta {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e0d6c2;
    font-size: 0.9em;
    color: #5a3921;
    line-height: 1.6;
}

.about-meta p {
    margin: 0 0 8px;
}

.about-meta p:last-child {
    margin-bottom: 0;
}

.about-meta a {
    color: #7a5c38;
    text-decoration: none;
    border-bottom: 1px solid #c4a882;
}

.about-meta a:hover {
    color: #5a3921;
    border-bottom-color: #5a3921;
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 12px;
    border: none;
    background: none;
    font-size: 1.6em;
    line-height: 1;
    color: #9a7b59;
    cursor: pointer;
}

.current-poem {
    background-color: #fff;
    padding: 30px;
    margin: 12px 0 30px 0;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    text-align: center;
    position: relative;
}

.current-poem h2 {
    color: #7a5c38;
    margin-bottom: 5px;
}

.current-poem h4 {
    color: #9a7b59;
    margin-top: 0;
    margin-bottom: 20px;
}

.poem-text {
    white-space: pre-line;
    text-align: center;
    padding: 0 20px;
}

.poem-date {
    position: absolute;
    bottom: 10px;
    right: 15px;
    color: #9a7b59;
    font-size: 1em;
    font-style: italic;
    opacity: 0.8;
}

.recommendations {
    margin-top: 40px;
}

.recommendations h3 {
    color: #5a3921;
    border-bottom: 1px solid #e0d6c2;
    padding-bottom: 5px;
}

.similar-poems {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 20px;
}

.similar-poem {
    flex: 1;
    min-width: 200px;
    background-color: #fff;
    padding: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.similar-poem:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.similar-poem h4 {
    color: #7a5c38;
    margin-top: 0;
    margin-bottom: 5px;
}

.similar-poem p {
    color: #9a7b59;
    font-style: italic;
    margin-top: 0;
    margin-bottom: 10px;
}

.similar-poem .preview-text {
    color: #666;
    font-size: 0.9em;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

.loading {
    text-align: center;
    color: #999;
    padding: 20px;
}

.page-footer {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px 24px;
    text-align: center;
}

.page-footer p {
    margin: 0;
    font-size: 0.9em;
    color: #9a7b59;
}

.page-footer a {
    color: #7a5c38;
    text-decoration: none;
    border-bottom: 1px solid #c4a882;
}

.page-footer a:hover {
    color: #5a3921;
    border-bottom-color: #5a3921;
}

@media (max-width: 800px) {
    header {
        grid-template-columns: 1fr;
        grid-template-areas:
            "about"
            "search"
            "random";
        gap: 10px;
        padding: 16px;
    }
    #about-btn {
        grid-area: about;
        justify-self: stretch;
    }
    .random-btn-container {
        grid-area: random;
    }
    .random-btn-container .header-btn {
        width: 100%;
    }
    .search-container {
        grid-area: search;
        justify-self: stretch;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
    #search-input {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }
    #search-btn {
        flex-shrink: 0;
    }
    .modal {
        width: calc(100% - 24px);
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        padding: 28px 20px 20px;
        margin: 12px auto;
    }
}

@media (max-width: 600px) {
    .similar-poems {
        flex-direction: column;
    }
}