:root {
    --bg-color: #f0f2f5;
    --container-bg: #ffffff;
    --card-bg: #f8f9fa;
    --text-color: #333333;
    --text-secondary: #666666;
    --number-bg: #eeeeee;
    --btn-bg: #007bff;
    --ai-btn-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --shadow: rgba(0, 0, 0, 0.1);
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --dog-color: #ff9f43;
    --cat-color: #54a0ff;
    --input-border: #dddddd;
    --input-bg: #ffffff;
}

[data-theme="dark"] {
    --bg-color: #121212;
    --container-bg: #1e1e1e;
    --card-bg: #2d2d2d;
    --text-color: #f0f2f5;
    --text-secondary: #aaaaaa;
    --number-bg: #404040;
    --btn-bg: #375a7f;
    --shadow: rgba(0, 0, 0, 0.5);
    --input-bg: #2d2d2d;
    --input-border: #444444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    transition: background-color 0.3s;
}

.container {
    position: relative;
    width: 100%;
    max-width: 500px;
    background-color: var(--container-bg);
    padding: 1.5rem;
    border-radius: 28px;
    box-shadow: 0 20px 50px var(--shadow);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--input-border);
}
.app-logo { font-size: 1rem; font-weight: 900; color: #764ba2; letter-spacing: -0.5px; cursor: pointer; }
.theme-toggle { font-size: 1.25rem; cursor: pointer; background: none; border: none; color: var(--text-color); }

/* Nav & Tabs */
.main-nav, .mode-selector {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background-color: var(--card-bg);
    padding: 0.4rem;
    border-radius: 14px;
}
.nav-btn, .mode-btn {
    flex: 1;
    padding: 0.6rem;
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: 10px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}
.nav-btn.active, .mode-btn.active {
    background-color: var(--container-bg);
    color: var(--text-color);
    box-shadow: 0 2px 8px var(--shadow);
}

.tab-content { display: none; text-align: center; }
.tab-content.active { display: block; }

.main-card {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 20px;
    margin-bottom: 1rem;
    position: relative; /* For positioning stats */
}

.lotto-result-stats {
    position: absolute;
    top: 0.75rem;
    right: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary);
    opacity: 0.8;
    line-height: 1.2;
}

#lotto-total-count {
    color: #764ba2;
    font-size: 1.1rem;
}

/* Lotto Ball Fix */
.lotto-numbers { display: flex; justify-content: center; margin-bottom: 1.5rem; gap: 0.4rem; flex-wrap: wrap; }
.number { 
    width: 42px; height: 42px; border-radius: 50%; 
    background: var(--number-bg); 
    display: flex; align-items: center; justify-content: center; 
    font-weight: 900; font-size: 1rem; color: #333;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.1);
    line-height: 1;
}

/* Animal Test Result UI */
.result-area { 
    margin-top: 2rem; 
    animation: slideUp 0.5s cubic-bezier(0.22, 1, 0.36, 1); 
}

.result-box {
    padding: 1.5rem;
    border-radius: 20px;
    background: var(--container-bg);
    box-shadow: 0 10px 30px rgba(118, 75, 162, 0.15);
    border: 1px solid rgba(118, 75, 162, 0.1);
}

.result-header { 
    margin-bottom: 1.5rem; 
    font-size: 1.1rem; 
    font-weight: 700;
    color: var(--text-secondary);
}

.result-name { 
    display: block;
    margin-top: 0.5rem;
    font-size: 2.25rem;
    font-weight: 900;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 20px rgba(118, 75, 162, 0.2);
}

.gauge-container { margin-bottom: 2rem; display: flex; flex-direction: column; gap: 1rem; }
.gauge-bar { 
    height: 44px; 
    background-color: var(--number-bg); 
    border-radius: 22px; 
    position: relative; 
    overflow: hidden; 
    display: flex; 
    align-items: center; 
    padding: 0 1.5rem;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}
.gauge-bar .label, .gauge-bar .percent { 
    position: relative;
    z-index: 1; 
    font-weight: 900; 
    font-size: 0.95rem; 
    color: #ffffff; 
    text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 2px rgba(0,0,0,1); 
}
.gauge-bar .percent { margin-left: auto; }
.gauge-bar .fill { position: absolute; left: 0; top: 0; height: 100%; transition: width 0.8s ease; }
.gauge-bar.dog .fill { background-color: var(--dog-color); }
.gauge-bar.cat .fill { background-color: var(--cat-color); }

.result-description-box {
    background-color: var(--card-bg);
    padding: 1.25rem; 
    border-radius: 12px; 
    border-left: 5px solid #764ba2;
    margin-bottom: 1.5rem; 
    text-align: left; 
    line-height: 1.6; 
    font-size: 0.95rem;
    color: var(--text-secondary);
    display: none; /* 내용이 없을 땐 숨김 */
}

.result-description-box.active {
    display: block; /* 내용이 있을 때만 표시 */
}

/* Modal Fixes */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--modal-overlay); z-index: 1000;
    align-items: center; justify-content: center; backdrop-filter: blur(4px);
    padding: 1rem;
}

.modal-content {
    background-color: var(--container-bg);
    width: 100%; max-width: 420px;
    border-radius: 24px; padding: 1.5rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-height: 90vh; overflow-y: auto;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.close-btn { font-size: 1.5rem; background: none; border: none; color: var(--text-secondary); cursor: pointer; line-height: 1; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-bottom: 1rem; }
.stat-item { 
    background: var(--card-bg); 
    padding: 1rem 0.75rem; 
    border-radius: 12px; 
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    justify-content: center;
}
.stat-label { font-size: 0.8rem; color: var(--text-secondary); font-weight: 600; }
.stat-value { font-size: 1.4rem; font-weight: 900; color: #764ba2; }

.history-list { max-height: 250px; overflow-y: auto; margin-bottom: 1rem; padding-right: 5px; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem; background: var(--card-bg); border-radius: 10px; margin-bottom: 0.4rem; font-size: 0.75rem; }
.history-numbers { display: flex; gap: 3px; }
.history-num { width: 22px; height: 22px; border-radius: 50%; font-size: 0.6rem; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #333; }

/* Form Elements Fix */
.contact-form { text-align: left; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.75rem; font-weight: 600; margin-bottom: 0.3rem; color: var(--text-secondary); }
.form-group input, .form-group textarea {
    width: 100%; padding: 0.75rem; border-radius: 10px;
    border: 1px solid var(--input-border); background: var(--input-bg);
    color: var(--text-color); font-size: 0.9rem;
    display: block; outline: none;
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* Buttons */
.button-group { display: flex; flex-direction: column; gap: 0.6rem; }
button { padding: 0.85rem; border: none; border-radius: 12px; font-weight: bold; cursor: pointer; transition: 0.2s; font-size: 0.9rem; }
#generator-btn { background: var(--btn-bg); color: #fff; }
.ai-btn { background: var(--ai-btn-bg); color: #fff; }
.secondary-btn { background: none; border: 1px solid var(--input-border); color: var(--text-secondary); width: 100%; }
.submit-btn { width: 100%; background: var(--ai-btn-bg); color: #fff; margin-top: 0.5rem; }
.link-btn { background: none; color: var(--text-secondary); text-decoration: underline; margin-top: 1rem; font-size: 0.8rem; cursor: pointer; border: none; width: 100%; }
.clear-btn { width: 100%; background: #ff4757; color: #fff; padding: 0.75rem; border-radius: 10px; margin-top: 0.5rem; }

.ai-status { height: 20px; font-size: 0.8rem; font-weight: bold; color: #667eea; margin-bottom: 0.5rem; }
.loading { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Analysis UI */
.analysis-container { margin-bottom: 1rem; }
.upload-area, .webcam-wrapper {
    width: 100%; aspect-ratio: 1/1; border: 2px dashed var(--input-border); border-radius: 16px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background-color: #000; overflow: hidden;
}
.upload-area { background-color: var(--card-bg); }
#face-preview, canvas { width: 100% !important; height: 100% !important; object-fit: cover; }
