/* ============================================
   Quiz Frontend Styles
   ============================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Prompt', sans-serif;
    background: var(--ink);
    min-height: 100vh;
    color: #1e293b;
    overflow-x: hidden;
}

/* ============================================
   Landing Page
   ============================================ */
.landing {
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Fixed BG image — responsive (PC/Mobile) */
.landing-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image: url('../images/bg_pc.webp');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-color: var(--ink); /* fallback ระหว่างโหลดรูป */
}

@media (max-width: 768px) {
    .landing-bg {
        background-image: url('../images/bg_mobile.webp');
    }
}

/* iOS Safari ไม่รองรับ background-attachment: fixed บน mobile แบบ smooth
   → ใช้ position fixed แทน เพื่อให้ bg ไม่เลื่อนตาม scroll */
@supports (-webkit-touch-callout: none) {
    .landing-bg {
        background-attachment: scroll;
    }
}

/* ลบ shape เก่าออก (ไม่จำเป็นแล้ว เพราะใช้ bg image) */
.bg-shape { display: none; }

.landing-content {
    position: relative;
    z-index: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 20px;
}

.hero {
    text-align: center;
    padding: 80px 0 60px;
    color: white;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    border-radius: 24px;
    font-size: 14px;
    margin-bottom: 24px;
    border: 1px solid rgba(255,255,255,0.3);
}

.hero-title {
    font-size: clamp(32px, 6vw, 56px);
    font-weight: 800;
    margin-bottom: 20px;
    line-height: 1.2;
    text-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.hero-subtitle {
    font-size: clamp(16px, 2vw, 20px);
    opacity: 0.95;
    max-width: 600px;
    margin: 0 auto 28px;
    line-height: 1.6;
}

.hero-intro {
    max-width: 700px;
    margin: 0 auto 36px;
    padding: 20px 28px;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    line-height: 1.7;
    border: 1px solid rgba(255,255,255,0.2);
}

.btn-start {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 18px 40px;
    background: white;
    color: var(--brand);
    text-decoration: none;
    border-radius: 50px;
    font-size: 18px;
    font-weight: 600;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    transition: all 0.3s;
}

.btn-start:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 50px rgba(0,0,0,0.3);
}

.btn-start i { transition: transform 0.3s; }
.btn-start:hover i { transform: translateX(4px); }

.section-title {
    color: white;
    font-size: 28px;
    margin-bottom: 30px;
    text-align: center;
}

.groups-section { margin-bottom: 60px; }

.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.group-card {
    background: white;
    border-radius: 20px;
    padding: 28px 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s;
}

.group-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: var(--group-color, var(--brand));
}

.group-card:hover { transform: translateY(-6px); }

.group-icon-wrap {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    background: var(--group-color, var(--brand));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    color: white;
    font-size: 32px;
}

.group-image {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    object-fit: cover;
    margin: 0 auto 16px;
    display: block;
}

.group-card h3 {
    font-size: 18px;
    margin-bottom: 10px;
    color: #1e293b;
}

.group-card p {
    color: #64748b;
    font-size: 14px;
    line-height: 1.6;
    min-height: 42px;
    margin-bottom: 12px;
}

.group-meta {
    font-size: 13px;
    color: var(--group-color, var(--brand));
    font-weight: 600;
}

.features-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin: 60px 0;
}

.feature {
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.feature-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.9;
}

.feature h4 { font-size: 16px; margin-bottom: 6px; }
.feature p { font-size: 13px; opacity: 0.85; }

.landing-footer {
    text-align: center;
    color: rgba(255,255,255,0.8);
    padding: 30px 0;
    font-size: 14px;
}

/* ============================================
   Quiz Page
   ============================================ */
.quiz-body {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
}

/* ภายใน <main class="site-main"> ของ quiz page → จัด center */
body.quiz-body main.site-main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    min-height: calc(100vh - 64px); /* minus header */
}
body.quiz-body.has-mobile-bottom main.site-main {
    min-height: calc(100vh - 64px - 64px); /* minus header + mobile bottom */
    padding-bottom: 80px;
}

/* ซ่อน footer ในหน้า quiz เพราะมันรกตอนทำเทส */
body.quiz-body .site-footer { display: none; }

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    color: white;
    padding: 40px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.quiz-container {
    width: 100%;
    max-width: 760px;
    background: white;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
}

.quiz-header {
    padding: 24px 32px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #eee;
}

.progress-info {
    text-align: center;
    font-size: 14px;
    color: #64748b;
    margin-bottom: 10px;
    font-weight: 500;
}

.progress-info span { color: var(--brand); font-weight: 700; }

.progress-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand) 0%, var(--brand-2) 100%);
    border-radius: 10px;
    transition: width 0.4s ease;
    width: 0%;
}

.question-screen {
    padding: 30px;
}

.question-card {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.question-number {
    display: inline-block;
    padding: 6px 14px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    color: white;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 16px;
}

.question-text {
    font-size: clamp(20px, 2.4vw, 26px);
    font-weight: 600;
    color: #1e293b;
    line-height: 1.5;
    margin-bottom: 20px;
}

.question-image-wrap {
    margin-bottom: 20px;
    text-align: center;
}

.question-image-wrap img {
    max-width: 100%;
    max-height: 300px;
    width: auto;
    height: auto;
    border-radius: 12px;
    object-fit: contain;
}

/* ===== Answer hint (checkbox mode) ===== */
.answer-hint {
    background: #eef2ff;
    color: #4338ca;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.answer-hint i { color: var(--brand); }

/* ===== Answers wrap ===== */
.answers-wrap {
    display: grid;
    gap: 12px;
    margin-bottom: 24px;
}

/* Text-only: 1 column (stacked rows) */
.answers-wrap.text-only {
    grid-template-columns: 1fr;
}

/* Has images: responsive 3 → 2 → 1 */
.answers-wrap.has-images {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 900px) {
    .answers-wrap.has-images {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 560px) {
    .answers-wrap.has-images {
        grid-template-columns: 1fr;
    }
}

/* ===== Answer card ===== */
.answer-card {
    position: relative;
    padding: 16px 20px;
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
    font-family: inherit;
    font-size: 15px;
    color: #374151;
    line-height: 1.5;
    display: flex;
    align-items: center;
    gap: 12px;
    user-select: none;
}

.answer-card:hover {
    border-color: #a5b4fc;
    background: #f5f3ff;
}

.answers-wrap.text-only .answer-card:hover {
    transform: translateX(4px);
}

.answer-card.selected {
    border-color: var(--brand);
    background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
    box-shadow: 0 4px 16px rgba(102,126,234,0.2);
}

/* ===== Answer indicator (checkbox/radio visual) ===== */
.answer-indicator {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid #d1d5db;
    background: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    font-size: 12px;
    color: transparent;
}

.indicator-checkbox {
    border-radius: 6px;
}

.answer-card:hover .answer-indicator {
    border-color: #a5b4fc;
}

.answer-card.selected .answer-indicator {
    background: var(--brand);
    border-color: var(--brand);
    color: white;
}

/* Hide radio "circle" icon (selected shows with bg color only); show check icon for checkbox */
.answer-card.selected .indicator-radio i {
    color: white;
    font-size: 8px;
}

.answer-card.selected .indicator-checkbox i {
    color: white;
    font-size: 14px;
}

/* ===== Has image layout ===== */
.answer-card.has-image {
    flex-direction: column;
    text-align: center;
    padding: 0;
    overflow: hidden;
    align-items: stretch;
}

.answer-card.has-image .answer-indicator {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
    background: white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.answer-card.has-image.selected .answer-indicator {
    background: var(--brand);
}

.answer-image-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #f3f4f6;
    position: relative;
}

.answer-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
}

.answer-card.has-image:hover .answer-image-wrap img {
    transform: scale(1.05);
}

.answer-card.has-image .answer-text {
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    line-height: 1.4;
}

/* Text-only card text */
.answers-wrap.text-only .answer-text {
    flex: 1;
}

.question-nav {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid #f1f5f9;
}

.btn-nav {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-nav-prev {
    background: #f1f5f9;
    color: #64748b;
}

.btn-nav-prev:hover:not(:disabled) { background: #e2e8f0; }

.btn-nav-next {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    color: white;
    margin-left: auto;
}

.btn-nav-next:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102,126,234,0.4);
}

.btn-nav:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Info Screen */
.info-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.info-card {
    background: white;
    border-radius: 24px;
    padding: 40px 32px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
    width: 100%;
    text-align: center;
}

.info-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    color: white;
    font-size: 40px;
}

.info-card h2 {
    font-size: 24px;
    margin-bottom: 10px;
    color: #1e293b;
}

.info-card > p {
    color: #64748b;
    margin-bottom: 24px;
    font-size: 15px;
}

.info-card .form-group { margin-bottom: 16px; text-align: left; }

.info-card label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
    color: #374151;
    font-weight: 500;
}

.info-card input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 15px;
    font-family: inherit;
    transition: border 0.2s;
}

.info-card input:focus {
    outline: none;
    border-color: var(--brand);
}

.btn-submit {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    transition: transform 0.2s;
}

.btn-submit:hover { transform: translateY(-2px); }

.form-error {
    margin-top: 16px;
    padding: 12px;
    background: #fee;
    color: #c33;
    border-radius: 8px;
    font-size: 14px;
}

/* Result Screen */
.result-screen {
    width: 100%;
    max-width: 820px;
    margin: 0 auto;
    padding: 20px 0;
}

.result-container {
    background: white;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.3);
    animation: fadeIn 0.6s ease;
}

.result-header {
    padding: 40px 30px 30px;
    text-align: center;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    color: white;
}

.result-celebrate { font-size: 56px; margin-bottom: 10px; }
.result-header h1 { font-size: 28px; margin-bottom: 10px; }
.result-intro { opacity: 0.95; font-size: 14px; }

.top-char-label {
    display: inline-block;
    padding: 4px 14px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* ===== Top Character Card (ใช้ใน result.php) ===== */
.top-character-display {
    padding: 30px;
    background: #f8fafc;
    border-bottom: 1px solid #eee;
}

.top-char-card {
    display: grid;
    grid-template-columns: 8fr 4fr;
    gap: 24px;
    align-items: center;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 24px;
    border-radius: 20px;
    color: #fff;
    box-shadow: 0 16px 40px rgba(0,0,0,0.15);
    background: linear-gradient(135deg, var(--brand), var(--brand-2)); /* fallback */
}

.top-char-card .top-char-image {
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    border-radius: 16px;
    overflow: hidden;
    margin: 0;
    background: rgba(255,255,255,0.15);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.top-char-card .top-char-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.top-char-info {
    min-width: 0;
    text-align: center;
}

.top-char-card .top-char-group {
    display: inline-block;
    padding: 5px 14px;
    background: rgba(0,0,0,0.25);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #fff;
    margin-bottom: 16px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.top-char-card .top-char-name {
    font-size: 32px;
    font-weight: 800;
    color: #fff;
    margin: 0 0 10px;
    line-height: 1.15;
    text-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.top-char-card .top-char-percent {
    font-size: 48px;
    font-weight: 800;
    color: #fff;
    background: none;
    -webkit-background-clip: initial;
    -webkit-text-fill-color: #fff;
    background-clip: initial;
    margin-bottom: 0;
    line-height: 1;
    text-shadow: 0 3px 10px rgba(0,0,0,0.25);
}

/* ข้อความ short desc แบบแยกออกมา (สีเข้มบนพื้นขาว) */
.top-char-short-desc {
    width: 100%;
    max-width: 960px;
    margin: 16px auto 0;
    padding: 16px 20px;
    background: #f8fafc;
    border-left: 4px solid var(--brand);
    border-radius: 8px;
    color: #475569;
    font-size: 14px;
    line-height: 1.7;
}

@media (max-width: 768px) {
    .top-character-display { padding: 20px; }
    .top-char-card {
        grid-template-columns: 1fr;
        text-align: center;
        padding: 20px;
        gap: 20px;
    }
    .top-char-card .top-char-image {
        aspect-ratio: 16 / 9;
    }
    .top-char-card .top-char-name { font-size: 26px; }
    .top-char-card .top-char-percent { font-size: 40px; }
}

/* ===== Top Character (original — ใช้ใน quiz.php) ===== */
.top-char-image {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: block;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    background: #f3f4f6;
}

.top-char-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.top-char-icon-wrap {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 54px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.top-char-name {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
    color: #1e293b;
}

.top-char-group {
    font-size: 15px;
    color: #64748b;
    margin-bottom: 16px;
}

.top-char-percent {
    font-size: 48px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.top3-section { padding: 30px; }

.top3-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
    text-align: center;
    color: #1e293b;
}

.top3-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.top3-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: #f9fafb;
    border-radius: 14px;
    border-left: 4px solid var(--item-color);
    transition: transform 0.2s;
}

.top3-item:hover { transform: translateX(4px); }

.top3-rank {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #1e293b;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.top3-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #f3f4f6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.top3-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.top3-info { flex: 1; min-width: 0; }

.top3-name {
    font-weight: 600;
    font-size: 15px;
    color: #1e293b;
    margin-bottom: 4px;
}

.top3-group { font-size: 12px; color: #64748b; }

.top3-progress,
.top3-bar {
    margin-top: 8px;
    height: 6px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.top3-progress-fill,
.top3-bar-fill {
    height: 100%;
    background: var(--item-color);
    border-radius: 4px;
    transition: width 1s ease;
}

.top3-percent {
    font-size: 24px;
    font-weight: 700;
    color: var(--item-color);
    flex-shrink: 0;
}

.character-desc,
.char-desc-card {
    padding: 30px;
    border-top: 1px solid #f1f5f9;
}

.character-desc h3,
.char-desc-card h3 {
    margin-bottom: 14px;
    color: #1e293b;
}

.character-desc-content,
.char-desc-content {
    color: #475569;
    line-height: 1.7;
}

.character-desc-content img,
.char-desc-content img {
    max-width: 100%;
    border-radius: 8px;
}

.result-actions {
    padding: 20px 30px 30px;
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-home, .btn-share {
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: all 0.2s;
}

.btn-home {
    background: #f1f5f9;
    color: #64748b;
}

.btn-home:hover { background: #e2e8f0; }

.btn-share {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-2) 100%);
    color: white;
}

.btn-share:hover { transform: translateY(-2px); }

/* Mobile */
@media (max-width: 640px) {
    .quiz-container { border-radius: 16px; }
    .question-screen { padding: 20px; }
    .question-text { font-size: 18px; }
    .answer-card { padding: 14px 16px; font-size: 14px; }
    .answer-card.has-image { padding: 0; }
    .answers-wrap.has-images {
        grid-template-columns: repeat(2, 1fr);
    }
    .question-nav { flex-wrap: wrap; }
    .btn-nav { padding: 10px 16px; font-size: 14px; }
    .result-header { padding: 30px 20px 20px; }
    .result-header h1 { font-size: 22px; }
    .top-char-name { font-size: 22px; }
    .top-char-percent { font-size: 36px; }
    .top-character-display { padding: 30px 20px; }
    .top3-section, .character-desc { padding: 20px; }
    .top3-item { padding: 12px; gap: 10px; }
    .top3-percent { font-size: 20px; }
    .info-card { padding: 30px 20px; }
    .hero { padding: 40px 0 30px; }
}
