:root {
    --primary-color: #6c63ff;
    --light-grey: #f2f2f2;
    --dark-grey: #333;
    --text-color: #555;
    --font-family: 'Pretendard', sans-serif;
}

@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css');

body {
    font-family: var(--font-family);
    margin: 0;
    background-color: var(--light-grey);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

#app {
    width: 100%;
    max-width: 420px;
    margin: 2rem;
    position: relative; /* Stacking context for modal */
}

.screen {
    background-color: white;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s ease-in-out;
}

.hidden {
    display: none;
}

/* Login Screen */
.login-container {
    padding: 3rem 2.5rem;
    text-align: center;
}

.login-container h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-weight: 900;
}

.login-container p {
    margin-bottom: 2rem;
    color: var(--text-color);
    font-size: 1.1rem;
}

#login-form .input-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

#login-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--dark-grey);
}

#login-form input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

#login-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2);
}

.login-button {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    background-color: var(--primary-color);
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 4px 15px rgba(108, 99, 255, 0.4);
}

.login-button:hover {
    background-color: #5a52e0;
}

.login-button:active {
    transform: translateY(2px);
}

/* Main Screen */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.profile-greeting {
    display: flex;
    align-items: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.profile-picture {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid white;
    margin-right: 1rem;
    object-fit: cover;
}

main {
    padding: 2rem;
}

#entry-form-container {
    margin-bottom: 2rem;
}

#entry-form .form-group {
    margin-bottom: 1.5rem;
}

#entry-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

#entry-form input[type="date"],
#entry-form textarea,
#entry-form input[type="file"] {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    box-sizing: border-box;
}

#entry-form textarea {
    resize: vertical;
}

#photo-preview {
    width: 100%;
    max-height: 200px;
    margin-top: 1rem;
    border-radius: 8px;
    object-fit: cover;
}

.submit-button, .action-button {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.submit-button {
    background-color: #28a745;
    color: white;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.4);
}

.submit-button:hover {
    background-color: #218838;
}

.action-button {
    background-color: var(--primary-color);
    color: white;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 15px rgba(108, 99, 255, 0.4);
}

.action-button:hover {
    background-color: #5a52e0;
}

#entries-container .entry {
    background-color: #f9f9f9;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    border-left: 5px solid var(--primary-color);
}

#entries-container .entry img {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 1rem;
}

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden; /* Start hidden */
    pointer-events: none; /* Ignore clicks when hidden */
    transition: opacity 0.3s ease-in-out, visibility 0s 0.3s;
}

/* [BUG FIX] This is the crucial part. */
.modal.hidden {
    display: flex; /* Override display:none */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal:not(.hidden) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.3s ease-in-out;
}

.modal-content {
    background-color: #fff;
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    transform: scale(0.95);
    transition: transform 0.3s ease-in-out;
}

.modal:not(.hidden) .modal-content {
    transform: scale(1);
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s;
}

.close-button:hover,
.close-button:focus {
    color: #333;
    text-decoration: none;
}

#essay-output {
    margin-top: 1.5rem;
    margin-bottom: 2rem;
    padding: 1rem;
    min-height: 200px;
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Responsive */
@media (max-width: 480px) {
    #app {
        margin: 1rem;
    }
    .login-container {
        padding: 2rem 1.5rem;
    }
    .login-container h1 {
        font-size: 2rem;
    }
    main {
        padding: 1.5rem;
    }
    .modal-content {
        padding: 2rem;
    }
}
