:root {
    --bg: #f2f2f7; --card-bg: #ffffff; --text: #1c1c1e;
    --primary: #007aff; --result-panel: #1c1c1e; --border-color: #ddd;
}
body.dark-mode {
    --bg: #121212; --card-bg: #1e1e1e; --text: #ffffff;
    --primary: #0a84ff; --result-panel: #2c2c2e; --border-color: #444;
}

body { font-family: 'Apple SD Gothic Neo', sans-serif; background: var(--bg); color: var(--text); margin: 0; padding: 20px; transition: 0.3s; display: flex; flex-direction: column; align-items: center; }

.top-bar { display: flex; justify-content: space-between; width: 100%; max-width: 900px; margin-bottom: 10px; }

.main-nav-btns { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; background: var(--card-bg); padding: 15px; border-radius: 20px; box-shadow: 0 8px 30px rgba(0,0,0,0.05); width: 100%; max-width: 900px; }
.main-nav-btns a { padding: 10px 18px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--card-bg); color: var(--text); cursor: pointer; font-weight: 700; transition: 0.2s; text-decoration: none; }
.main-nav-btns a.active { background: var(--primary); color: white; border-color: var(--primary); }

.controls { background: var(--card-bg); padding: 25px; border-radius: 20px; box-shadow: 0 8px 30px rgba(0,0,0,0.05); width: 100%; max-width: 900px; margin-bottom: 20px; text-align: center; }

.nav-btns { display: flex; justify-content: center; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.nav-btns button { padding: 10px 18px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--card-bg); color: var(--text); cursor: pointer; font-weight: 700; transition: 0.2s; }
.nav-btns button.active { background: var(--primary); color: white; border-color: var(--primary); }

.search-group { display: flex; justify-content: center; gap: 10px; padding-top: 15px; border-top: 1px solid var(--border-color); }
input { padding: 12px; width: 250px; border: 2px solid var(--border-color); border-radius: 10px; outline: none; background: var(--card-bg); color: var(--text); }

/* 5*9 그리드 설정 */
.grid { 
    display: grid; 
    grid-template-columns: repeat(9, 1fr); /* 9열 */
    grid-template-rows: repeat(5, 1fr);    /* 5행 */
    gap: 10px; 
    width: 100%; 
    max-width: 900px; 
    background: var(--card-bg); 
    padding: 20px; 
    border-radius: 20px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.08); 
}

.item { aspect-ratio: 1/1; border-radius: 10px; overflow: hidden; cursor: pointer; position: relative; border: 3px solid transparent; background: #8882; transition: 0.2s; }
.item:hover { transform: scale(1.05); border-color: #ff3b30; z-index: 5; }
.item img { width: 100%; height: 100%; object-fit: cover; }
.item .num-label { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; }

.result-panel { margin-top: 30px; width: 100%; max-width: 600px; text-align: center; padding: 25px; background: var(--result-panel); border-radius: 20px; color: white; }
.balls { display: flex; justify-content: center; gap: 12px; margin: 20px 0; min-height: 55px; }
.ball { width: 55px; height: 55px; line-height: 55px; border-radius: 50%; background: linear-gradient(135deg, #ffcc00, #ff9500); color: #000; font-weight: bold; font-size: 1.4rem; }

.util-btn { padding: 8px 15px; border-radius: 8px; border: 1px solid var(--border-color); cursor: pointer; font-size: 13px; background: var(--card-bg); color: var(--text); font-weight: bold; }
.reset-btn { background: #ff3b30; color: white; border: none; padding: 12px 40px; border-radius: 10px; cursor: pointer; font-weight: bold; }


/* Contact Form Styles */
.contact-form-container {
    margin-top: 30px;
    width: 100%;
    max-width: 600px;
    background: var(--card-bg);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.05);
    text-align: center;
}

.contact-form-container h3 {
    color: var(--text);
    margin-bottom: 20px;
}

.contact-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.form-group {
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--text);
}

.contact-form input[type="text"],
.contact-form input[type="email"],
.contact-form textarea {
    width: calc(100% - 24px); /* Account for padding */
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    outline: none;
    background: var(--card-bg); /* Use card-bg for inputs for consistency */
    color: var(--text);
    box-sizing: border-box; /* Include padding in element's total width and height */
    transition: border-color 0.2s;
}

.contact-form input[type="text"]:focus,
.contact-form input[type="email"]:focus,
.contact-form textarea:focus {
    border-color: var(--primary);
}

.contact-form textarea {
    resize: vertical; /* Allow vertical resizing */
}

.submit-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 40px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    margin-top: 10px;
    transition: background-color 0.2s;
}

.submit-btn:hover {
    background-color: #0056b3; /* Darker shade for hover */
}

.content-section {
    margin-top: 30px;
    width: 100%;
    max-width: 900px;
    background: var(--card-bg);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.05);
    text-align: center; /* Center content within these sections */
}
.content-section p {
    text-align: left; /* Ensure paragraphs are left-aligned */
    margin-bottom: 1em;
    line-height: 1.6;
}
.article {
    margin-bottom: 20px;
    text-align: left;
}
.article h3 {
    color: var(--text);
}
footer {
    margin-top: 30px;
    text-align: center;
    width: 100%;
    max-width: 900px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.05);
}
footer a {
    color: var(--primary);
    text-decoration: none;
}

/* Tab Content Styles */
.tab-content {
    display: none; /* Hidden by default */
    width: 100%;
    max-width: 900px; /* Align with other main containers */
    margin-top: 20px; /* Space between nav and content */
}

.tab-content.active {
    display: block; /* Show active tab */
}

.description {
    margin-bottom: 20px;
    line-height: 1.6;
    color: var(--text);
    text-align: center;
}


@media screen and (max-width: 768px) {
    body {
        padding: 10px;
    }

    .top-bar, .controls, .grid, .result-panel, .contact-form-container, .content-section, footer, .main-nav-btns {
        max-width: 100%;
        padding: 15px;
        border-radius: 10px;
    }

    .main-nav-btns {
        gap: 5px;
        justify-content: space-around;
    }

    .main-nav-btns a {
        padding: 8px 12px;
        font-size: 0.9rem;
        border-radius: 8px;
    }
    
    .nav-btns {
        gap: 5px;
        justify-content: space-around;
    }

    .nav-btns button {
        padding: 8px 12px;
        font-size: 0.9rem;
        border-radius: 8px;
    }

    .search-group {
        flex-direction: column;
        gap: 8px;
    }

    input {
        width: calc(100% - 24px); /* Account for padding */
        padding: 10px;
        font-size: 1rem;
    }
    
    .search-group button {
        width: 100%;
        padding: 10px;
    }

    .grid {
        grid-template-columns: repeat(4, 1fr); /* 4열로 변경 */
        gap: 8px;
        padding: 15px;
    }

    .item .num-label {
        font-size: 18px;
    }

    .balls {
        gap: 8px;
    }

    .ball {
        width: 45px;
        height: 45px;
        line-height: 45px;
        font-size: 1.2rem;
    }

    .reset-btn, .submit-btn {
        padding: 10px 30px;
        font-size: 0.9rem;
    }

    h2, h3 {
        font-size: 1.3rem;
    }

    .top-bar {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    .util-btn {
        width: 100%;
    }
}
