:root {
    --bg-color: #f8f9fa;
    --text-color: #212529;
    --card-bg: #ffffff;
    --header-bg: #212529;
    --header-text: #ffffff;
    --accent-color: #4a90e2;
    --accent-hover: #357abd;
    --shadow: 0 4px 15px rgba(0,0,0,0.08);
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #e9ecef;
    --card-bg: #1e1e1e;
    --header-bg: #000000;
    --header-text: #ffffff;
    --accent-color: #64b5f6;
    --accent-hover: #90caf9;
    --shadow: 0 4px 15px rgba(0,0,0,0.4);
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
    margin: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.6;
}

header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
}

header h1 { margin: 0; font-size: 1.3rem; }

#themeToggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--header-text);
    padding: 0.4rem;
    cursor: pointer;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

main {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1.5rem 6rem 1.5rem;
}

.intro { text-align: center; margin-bottom: 2rem; }
.intro p { font-size: 1rem; opacity: 0.8; }

/* Improved User Info Styling */
.user-info-v2 {
    display: flex;
    justify-content: center;
    margin-bottom: 2.5rem;
}

.info-card {
    background: var(--card-bg);
    padding: 2rem 3rem;
    border-radius: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 3rem;
    border: 1px solid rgba(0,0,0,0.05);
}

.info-card .divider {
    width: 1px;
    height: 40px;
    background: rgba(0,0,0,0.1);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.input-group label {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gender-btn-group {
    display: flex;
    gap: 0.5rem;
    background: var(--bg-color);
    padding: 0.4rem;
    border-radius: 12px;
}

.gender-btn {
    cursor: pointer;
    position: relative;
}

.gender-btn input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.gender-btn span {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.2s;
    background: transparent;
    color: var(--text-color);
}

.gender-btn input:checked + span {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.3);
}

.age-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.age-input-wrapper input {
    padding: 0.6rem;
    width: 80px;
    border: 2px solid var(--bg-color);
    border-radius: 10px;
    background: var(--bg-color);
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: bold;
    text-align: center;
    transition: border-color 0.2s;
}

.age-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.age-input-wrapper .unit {
    font-weight: bold;
    opacity: 0.7;
}

.unified-upload-section {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 2.5rem;
    border: 3px dashed var(--accent-color);
}

.upload-btn-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.custom-file-upload, .camera-btn {
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
    border: none;
    display: inline-block;
}

.custom-file-upload {
    background: var(--accent-color);
    color: white;
}

.camera-btn {
    background: #2c3e50;
    color: white;
}

.reset-btn {
    margin-top: 1.5rem;
    padding: 0.6rem 1.2rem;
    background: #e74c3c;
    color: white;
    border-radius: 8px;
    border: none;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.reset-btn:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

.custom-file-upload:hover { background: var(--accent-hover); }
.camera-btn:hover { background: #34495e; }

.unified-upload-section input[type="file"] { display: none; }
.upload-hint { font-size: 0.8rem; margin-top: 1rem; opacity: 0.6; }

/* Analysis Container Size Control */
.analysis-container {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.analysis-box {
    background: var(--card-bg);
    border-radius: 15px;
    box-shadow: var(--shadow);
    overflow: hidden;
    width: 100%;
    max-width: 300px; /* Limits the size of the palm photo display */
}

.box-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 0.5rem;
    text-align: center;
    font-weight: bold;
    font-size: 0.85rem;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 4/5;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    object-fit: contain;
    z-index: 2;
}

.preview-placeholder {
    color: white; font-size: 0.8rem; opacity: 0.4; z-index: 1;
}

.action-section { text-align: center; margin-bottom: 3rem; }
.primary-btn { padding: 1rem 3rem; background: var(--accent-color); color: white; border: none; border-radius: 12px; font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: all 0.2s; }
.primary-btn:hover { background: var(--accent-hover); transform: translateY(-2px); }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; background: #999; }

.unified-upload-section.drag-over { background: rgba(74, 144, 226, 0.05); }

/* Camera Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 2.5rem;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    position: relative;
    box-shadow: var(--shadow);
}

.close-modal {
    position: absolute;
    right: 20px; top: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    opacity: 0.5;
}

.camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/5;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 80%; height: 80%;
    border: 2px dashed rgba(255,255,255,0.4);
    border-radius: 30px;
    pointer-events: none;
}

.capture-btn {
    position: absolute;
    bottom: 20px; left: 50%;
    transform: translateX(-50%);
    padding: 1rem 2rem;
    background: var(--accent-color);
    color: white;
    border-radius: 50px;
    border: none;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.camera-hint { font-size: 0.9rem; opacity: 0.7; }

/* Overhauled Result Section */
.result-section h2 {
    text-align: center;
    font-size: 2.2rem;
    margin-bottom: 2rem;
    font-weight: 800;
    color: var(--accent-color);
}

.summary-card {
    background: rgba(74, 144, 226, 0.08);
    padding: 2rem;
    border-radius: 18px;
    margin-bottom: 2.5rem;
    border: 2px solid rgba(74, 144, 226, 0.1);
    font-size: 1.15rem;
    line-height: 1.7;
    text-align: center;
}

.summary-card strong { color: var(--accent-color); }

.reading-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.reading-card {
    padding: 2rem;
    border-radius: 18px;
    background: var(--bg-color);
    border: 1px solid rgba(0,0,0,0.04);
}

.reading-card h3 {
    margin-top: 0; margin-bottom: 1.2rem;
    font-size: 1.2rem; font-weight: 800;
    display: flex; align-items: center; gap: 0.5rem;
}

.line-label {
    font-weight: 800; font-size: 0.75rem;
    padding: 3px 8px; border-radius: 5px;
}

/* Redesigned Advice Section */
.advice-section {
    margin-top: 3.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.total-review-box {
    background: #ffffff;
    padding: 2rem;
    border-radius: 20px;
    border-left: 8px solid var(--accent-color);
    box-shadow: var(--shadow);
}

body.dark-mode .total-review-box {
    background: #2d2d2d;
}

.total-review-box h3 {
    margin-top: 0; color: var(--accent-color);
    font-size: 1.4rem; font-weight: 800;
    display: flex; align-items: center; gap: 0.6rem;
}

.destiny-advice-box {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    color: white;
    padding: 2.5rem;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(52, 152, 219, 0.2);
}

.destiny-advice-box h3 {
    margin-top: 0; font-size: 1.6rem; font-weight: 800;
    margin-bottom: 1.2rem;
}

.destiny-advice-box p {
    font-size: 1.15rem; line-height: 1.8;
}

.loader {
    border: 5px solid rgba(0,0,0,0.05);
    border-top: 5px solid var(--accent-color);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 0.8s cubic-bezier(0.42, 0, 0.58, 1) infinite;
    margin: 2rem auto;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

footer { position: fixed; bottom: 0; width: 100%; background: var(--header-bg); color: var(--header-text); padding: 0.8rem; text-align: center; font-size: 0.75rem; }

@media (max-width: 768px) {
    .analysis-container { grid-template-columns: 1fr; }
    .reading-grid { grid-template-columns: 1fr; }
}