:root {
    --bg: #f5f7fb;
    --panel: rgba(255, 255, 255, 0.92);
    --text: #14213d;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #3157d5;
    --primary-2: #6d7df2;
    --soft: #edf1ff;
    --success: #0f8f66;
    --warning: #b7791f;
    --shadow: 0 18px 50px rgba(44, 62, 120, 0.10);
    --radius: 24px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at 10% 0%, rgba(109, 125, 242, .16), transparent 28%),
        radial-gradient(circle at 90% 10%, rgba(49, 87, 213, .12), transparent 24%),
        var(--bg);
    min-height: 100vh;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
    height: 78px;
    padding: 0 5vw;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(229, 231, 235, .8);
    background: rgba(245, 247, 251, .76);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 14px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: white; font-weight: 800; font-size: 20px;
    box-shadow: 0 10px 25px rgba(49, 87, 213, .25);
}
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

.page-shell { width: min(1180px, 92vw); margin: 42px auto 70px; }
.panel {
    background: var(--panel);
    border: 1px solid rgba(229, 231, 235, .9);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
}

.hero {
    min-height: 620px;
    padding: 64px;
    display: grid;
    grid-template-columns: 1.05fr .95fr;
    gap: 50px;
    align-items: center;
    overflow: hidden;
    position: relative;
}
.hero::after {
    content: "";
    position: absolute;
    width: 380px; height: 380px;
    border-radius: 50%;
    background: rgba(109,125,242,.08);
    right: -110px; top: -100px;
}
.eyebrow {
    display: inline-block;
    font-size: 12px;
    letter-spacing: .12em;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 16px;
}
.hero h1 {
    font-size: clamp(42px, 5.5vw, 72px);
    line-height: 1.02;
    margin: 0 0 24px;
    letter-spacing: -0.045em;
}
.hero h1 em { color: var(--primary); font-style: normal; }
.hero p {
    color: var(--muted);
    font-size: 18px;
    line-height: 1.75;
    max-width: 680px;
}
.primary-btn, .ghost-btn {
    border: 0;
    border-radius: 14px;
    padding: 14px 20px;
    transition: .2s ease;
}
.primary-btn {
    color: white;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    box-shadow: 0 12px 26px rgba(49, 87, 213, .24);
    font-weight: 700;
}
.primary-btn:hover { transform: translateY(-2px); }
.primary-btn.small { padding: 12px 16px; }
.ghost-btn {
    color: var(--text);
    background: white;
    border: 1px solid var(--line);
}
.ghost-btn:hover { background: #f8fafc; }

.hero-card {
    height: 410px;
    position: relative;
    border-radius: 32px;
    background: linear-gradient(145deg, #eef2ff, #ffffff);
    border: 1px solid #e1e6ff;
}
.center-node, .mini-node {
    position: absolute;
    border-radius: 18px;
    background: white;
    border: 1px solid #dfe5ff;
    box-shadow: 0 12px 30px rgba(49, 87, 213, .12);
    display: grid;
    place-items: center;
    font-weight: 700;
}
.center-node {
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: 180px; height: 90px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: white;
    border: 0;
}
.mini-node { width: 120px; height: 58px; font-size: 13px; }
.n1 { left: 28px; top: 46px; }
.n2 { right: 28px; top: 58px; }
.n3 { left: 42px; bottom: 52px; }
.n4 { right: 34px; bottom: 46px; }
.hero-card::before {
    content: "";
    position: absolute;
    inset: 20%;
    border: 1px dashed #bfc9ff;
    border-radius: 50%;
}

.quiz-wrap {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
    align-items: stretch;
}
.sidebar { padding: 28px; min-height: 560px; }
.step-kicker, .question-tag {
    font-size: 11px;
    letter-spacing: .12em;
    color: var(--primary);
    font-weight: 800;
}
.progress-track {
    margin-top: 16px;
    height: 8px;
    background: #edf0f6;
    border-radius: 99px;
    overflow: hidden;
}
.progress-bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    transition: width .35s ease;
}
.progress-text { margin-top: 10px; color: var(--muted); font-size: 13px; }
.sidebar-divider { height: 1px; background: var(--line); margin: 28px 0; }
.sidebar h3 { margin: 0 0 14px; font-size: 15px; }
.check-list { padding: 0; margin: 0; list-style: none; }
.check-list li {
    padding: 10px 0;
    color: var(--muted);
    border-bottom: 1px dashed #e8eaf0;
    font-size: 14px;
}
.check-list li::before { content: "✓"; color: var(--success); margin-right: 8px; font-weight: 800; }

.question-panel { padding: 44px; min-height: 560px; display: flex; flex-direction: column; }
.question-head h2 { font-size: clamp(28px, 4vw, 42px); letter-spacing: -.03em; margin: 12px 0 10px; }
.question-head p { color: var(--muted); margin: 0; }
.options-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 34px 0;
}
.option-btn {
    min-height: 86px;
    text-align: left;
    padding: 18px 20px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: white;
    color: var(--text);
    font-weight: 650;
    transition: .18s ease;
}
.option-btn:hover {
    border-color: #b8c3f8;
    background: var(--soft);
    transform: translateY(-2px);
}
.option-btn { position: relative; padding-right: 52px; }
.option-btn::after {
    content: "";
    position: absolute;
    right: 18px;
    top: 50%;
    width: 20px;
    height: 20px;
    margin-top: -10px;
    border: 2px solid #c3cae0;
    border-radius: 6px;
    background: white;
    transition: .18s ease;
}
.option-btn.selected {
    border-color: var(--primary);
    background: var(--soft);
    box-shadow: 0 0 0 2px rgba(49, 87, 213, .14);
}
.option-btn.selected::after {
    content: "✓";
    display: flex;
    align-items: center;
    justify-content: center;
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    font-size: 14px;
    font-weight: 800;
}
.option-btn.limit-reached { opacity: .55; }
#nextBtn { white-space: nowrap; }
#nextBtn:disabled { opacity: .5; cursor: not-allowed; }
#nextBtn.hidden { display: none; }
.question-footer {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    color: var(--muted);
    font-size: 13px;
}

.loading { padding: 72px; text-align: center; }
.loader {
    width: 52px; height: 52px; margin: 0 auto 24px;
    border: 5px solid #e7ebf8;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 30px; }
.result-heading h2 { font-size: clamp(32px, 4vw, 48px); margin: 4px 0 8px; letter-spacing: -.035em; }
.result-heading p { color: var(--muted); margin: 0; }
.section-title { font-weight: 800; font-size: 18px; margin: 24px 0 14px; }
.secondary-title { margin-top: 34px; }
.cards-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.cards-grid.secondary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.major-card {
    background: white;
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 24px;
    box-shadow: 0 10px 28px rgba(27, 40, 85, .07);
}
.major-card h3 { margin: 8px 0 10px; font-size: 21px; }
.major-card p { color: var(--muted); line-height: 1.6; font-size: 14px; }
.score-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.score-pill { font-size: 12px; font-weight: 800; color: var(--primary); background: var(--soft); padding: 7px 10px; border-radius: 99px; }
.score-bar { height: 7px; background: #edf0f6; border-radius: 99px; overflow: hidden; margin: 12px 0 18px; }
.score-bar > div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.detail-title { margin-top: 18px; font-size: 12px; font-weight: 800; letter-spacing: .05em; }
.reason-list, .caution-list, .school-list { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.reason-list li::marker { color: var(--success); }
.caution-list li::marker { color: var(--warning); }
.tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.tag { padding: 6px 8px; background: #f4f6fb; border-radius: 8px; color: #4b5563; font-size: 12px; }
.disclaimer { padding: 18px 20px; margin-top: 26px; color: var(--muted); font-size: 14px; }
.disclaimer strong { color: var(--text); }

.hidden { display: none !important; }

@media (max-width: 900px) {
    .hero { grid-template-columns: 1fr; padding: 36px; }
    .hero-card { min-height: 340px; }
    .quiz-wrap { grid-template-columns: 1fr; }
    .sidebar { min-height: 0; }
    .cards-grid, .cards-grid.secondary { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .page-shell { width: min(94vw, 1180px); margin-top: 18px; }
    .topbar { padding: 0 3vw; }
    .brand span { display: none; }
    .hero { padding: 28px 22px; min-height: auto; }
    .hero-card { display: none; }
    .question-panel { padding: 28px 20px; }
    .options-grid { grid-template-columns: 1fr; }
    .question-footer { align-items: flex-start; flex-direction: column; }
    .result-heading { align-items: flex-start; flex-direction: column; }
}

/* ==========================================================
   HOMEPAGE HERO V2
   ========================================================== */
.hero-v2 {
    min-height: 650px;
    grid-template-columns: 1.08fr .92fr;
    gap: 64px;
    padding: 68px 70px;
    isolation: isolate;
}
.hero-v2::after {
    width: 460px;
    height: 460px;
    right: -180px;
    top: -190px;
    background: radial-gradient(circle, rgba(88, 108, 236, .12), rgba(88, 108, 236, 0) 70%);
    z-index: -1;
}
.hero-v2::before {
    content: "";
    position: absolute;
    width: 320px;
    height: 320px;
    left: -180px;
    bottom: -220px;
    border-radius: 50%;
    background: rgba(49, 87, 213, .05);
    z-index: -1;
}
.hero-badge {
    width: fit-content;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 8px 12px;
    border-radius: 999px;
    background: #f2f5ff;
    border: 1px solid #dfe5ff;
    color: #3d55b8;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .02em;
    margin-bottom: 20px;
}
.hero-badge > span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 5px rgba(49, 87, 213, .10);
}
.hero-v2 h1 {
    max-width: 760px;
    font-size: clamp(44px, 5.1vw, 68px);
    line-height: 1.035;
    margin-bottom: 22px;
}
.hero-v2 h1 em {
    background: linear-gradient(110deg, #3157d5, #6d7df2);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.hero-lead {
    max-width: 700px !important;
    font-size: 17px !important;
    line-height: 1.72 !important;
    margin: 0 !important;
}
.hero-actions {
    margin-top: 30px;
    display: flex;
    align-items: center;
    gap: 22px;
}
.hero-start {
    min-height: 54px;
    padding: 15px 22px;
    display: inline-flex;
    align-items: center;
    gap: 14px;
}
.hero-start span {
    font-size: 20px;
    line-height: 1;
}
.hero-note strong {
    color: var(--text);
    font-size: 12px;
}
.hero-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-top: 38px;
}
.stat-item {
    min-height: 92px;
    padding: 14px 15px;
    border: 1px solid #e7eaf3;
    border-radius: 16px;
    background: rgba(250, 251, 255, .86);
}
.stat-item strong {
    display: block;
    font-size: 13px;
    margin-bottom: 7px;
}
.stat-item span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}
.hero-visual {
    min-height: 468px;
    align-self: center;
    padding: 26px;
    border-radius: 30px;
    border: 1px solid #dfe5ff;
    background:
        radial-gradient(circle at 85% 0%, rgba(109,125,242,.16), transparent 34%),
        linear-gradient(160deg, #f9faff 0%, #eef2ff 100%);
    box-shadow: 0 22px 55px rgba(49, 87, 213, .12);
    position: relative;
    overflow: hidden;
}
.hero-visual::after {
    content: "";
    position: absolute;
    width: 170px;
    height: 170px;
    border-radius: 50%;
    border: 1px dashed rgba(49, 87, 213, .22);
    right: -55px;
    bottom: -60px;
}
.visual-topline {
    display: flex;
    align-items: center;
    gap: 9px;
    color: #53607f;
    font-size: 12px;
    font-weight: 700;
    padding-bottom: 18px;
    border-bottom: 1px solid rgba(207, 215, 245, .8);
}
.visual-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #16a47a;
    box-shadow: 0 0 0 5px rgba(22, 164, 122, .10);
}
.adaptive-flow {
    padding: 24px 4px 18px;
}
.flow-step {
    display: grid;
    grid-template-columns: 46px 1fr;
    align-items: center;
    gap: 13px;
}
.flow-index {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: white;
    border: 1px solid #dfe5ff;
    color: #5e6a8c;
    font-size: 11px;
    font-weight: 900;
    box-shadow: 0 8px 18px rgba(49,87,213,.07);
}
.flow-step.active .flow-index {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: white;
    border-color: transparent;
}
.flow-step strong {
    display: block;
    font-size: 14px;
    margin-bottom: 4px;
}
.flow-step span {
    color: var(--muted);
    font-size: 12px;
}
.flow-line {
    width: 1px;
    height: 24px;
    margin: 4px 0 4px 22px;
    background: linear-gradient(#bec9f4, #dfe4fa);
}
.match-preview {
    margin-top: 7px;
    padding: 18px;
    border-radius: 20px;
    background: rgba(255,255,255,.82);
    border: 1px solid rgba(215,222,249,.95);
    box-shadow: 0 12px 30px rgba(49, 87, 213, .08);
}
.match-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-size: 11px;
    color: var(--muted);
}
.match-preview-head b {
    color: var(--primary);
    font-size: 12px;
}
.match-bar {
    height: 7px;
    background: #e8ecf9;
    border-radius: 99px;
    margin: 14px 0 13px;
    overflow: hidden;
}
.match-bar span {
    display: block;
    width: 78%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
}
.match-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.match-tags span {
    padding: 6px 8px;
    border-radius: 9px;
    background: #f3f5fb;
    color: #59627a;
    font-size: 10px;
    font-weight: 700;
}
@media (max-width: 900px) {
    .hero-v2 { grid-template-columns: 1fr; padding: 42px; gap: 34px; }
    .hero-visual { min-height: 430px; }
}
@media (max-width: 620px) {
    .hero-v2 { padding: 30px 22px; }
    .hero-v2 h1 { font-size: 42px; }
    .hero-actions { align-items: flex-start; flex-direction: column; }
    .hero-stats { grid-template-columns: 1fr; }
    .stat-item { min-height: auto; }
    .hero-visual { display: block; min-height: auto; padding: 20px; }
    .match-preview { margin-bottom: 8px; }
}
.card-actions {
    display: flex;
    gap: 10px;
    margin: 16px 0 4px;
}
.detail-btn {
    border: 1px solid rgba(99, 102, 241, .28);
    background: rgba(99, 102, 241, .08);
    color: inherit;
    border-radius: 12px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform .18s ease, background .18s ease, border-color .18s ease;
}
.detail-btn:hover {
    transform: translateY(-1px);
    background: rgba(99, 102, 241, .14);
    border-color: rgba(99, 102, 241, .46);
}
body.modal-open {
    overflow: hidden;
}
.detail-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
}
.detail-modal.hidden {
    display: none;
}
.detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 15, 30, .62);
    backdrop-filter: blur(8px);
}
.detail-dialog {
    position: relative;
    z-index: 1;
    width: min(920px, 100%);
    max-height: min(88vh, 900px);
    overflow: auto;
    border-radius: 24px;
    border: 1px solid rgba(148, 163, 184, .22);
    background: #fff;
    color: #172033;
    box-shadow: 0 30px 80px rgba(15, 23, 42, .28);
}
.detail-close {
    position: sticky;
    top: 14px;
    float: right;
    z-index: 2;
    margin: 14px 14px 0 0;
    width: 40px;
    height: 40px;
    border: 1px solid #e2e8f0;
    border-radius: 50%;
    background: #fff;
    color: #475569;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(15, 23, 42, .08);
}
#detailContent {
    padding: 34px;
}
.detail-summary {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: flex-start;
    padding-right: 46px;
}
.detail-kicker {
    display: inline-block;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
    color: #6366f1;
    margin-bottom: 8px;
}
.detail-summary h2 {
    margin: 0 0 10px;
    font-size: clamp(26px, 4vw, 40px);
    line-height: 1.08;
}
.detail-summary p {
    margin: 0;
    color: #64748b;
    line-height: 1.65;
}
.detail-score-ring {
    flex: 0 0 auto;
    width: 112px;
    height: 112px;
    border-radius: 50%;
    display: grid;
    place-content: center;
    text-align: center;
    background: linear-gradient(145deg, #eef2ff, #f8fafc);
    border: 8px solid #c7d2fe;
}
.detail-score-ring strong {
    font-size: 30px;
    line-height: 1;
}
.detail-score-ring span {
    color: #64748b;
    font-size: 13px;
    margin-top: 3px;
}
.detail-section {
    margin-top: 30px;
    padding-top: 26px;
    border-top: 1px solid #e8edf5;
}
.detail-section h3 {
    margin: 0 0 16px;
    font-size: 18px;
}
.detail-section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
     margin-bottom: 16px;
}
.detail-section-head h3 {
    margin: 0;
}
.detail-section-head span,
.detail-muted {
    color: #64748b;
    font-size: 14px;
}
.detail-factors {
    display: grid;
    gap: 18px;
}
.detail-factor-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 8px;
}
.detail-factor-head b {
    color: #4f46e5;
}
.detail-factor-bar {
    height: 9px;
    background: #eef2f7;
    border-radius: 999px;
    overflow: hidden;
}
.detail-factor-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
}
.detail-evidence {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 9px;
}
.detail-evidence span {
    padding: 5px 9px;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #475569;
    font-size: 12px;
}
.trait-list {
    display: grid;
    gap: 10px;
}
.trait-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    padding: 13px 15px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #fbfdff;
}
.trait-row > div {
    display: grid;
    gap: 3px;
}
.trait-row span {
    color: #64748b;
    font-size: 13px;
}
.trait-row .trait-ok {
    color: #047857;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 5px 9px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 12px;
}
.detail-gap-list {
    margin: 0;
    padding-left: 20px;
    color: #475569;
    line-height: 1.65;
}
.detail-gap-list li + li {
    margin-top: 8px;
}
.detail-explain-note {
    display: grid;
    gap: 6px;
    margin-top: 28px;
    padding: 16px 18px;
    border-radius: 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #475569;
    line-height: 1.55;
}
.detail-explain-note small {
    color: #64748b;
}
@media (max-width: 680px) {
    .detail-modal { padding: 10px; }
    .detail-dialog { max-height: 94vh; border-radius: 18px; }
    #detailContent { padding: 24px 18px 28px; }
    .detail-summary { display: grid; padding-right: 42px; }
    .detail-score-ring { width: 92px; height: 92px; border-width: 6px; }
    .detail-score-ring strong { font-size: 25px; }
    .detail-section-head { display: grid; gap: 4px; }
    .trait-row { align-items: flex-start; }
}

/* ========== Chatbot ========== */
.chat-toggle {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 40;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 10px 28px rgba(37, 99, 235, 0.35);
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease;
}
.chat-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(37, 99, 235, 0.42);
}
.chat-toggle-icon { display: flex; align-items: center; font-size: 18px; line-height: 1; }
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-badge.hidden { display: none; }

.chat-panel {
    position: fixed;
    right: 22px;
    bottom: 86px;
    z-index: 41;
    width: min(400px, calc(100vw - 28px));
    height: min(520px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    box-shadow: 0 22px 50px rgba(15, 23, 42, 0.18);
    overflow: hidden;
}
.chat-panel.hidden { display: none; }

.chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: #0f172a;
    color: #f8fafc;
}
.chat-header strong {
    display: block;
    font-size: 15px;
}
.chat-header span {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.4;
}
.chat-close {
    border: none;
    background: transparent;
    color: #cbd5e1;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}
.chat-close:hover { color: #fff; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f8fafc;
}
.chat-bubble {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-bubble.bot {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e2e8f0;
    color: #0f172a;
}
.chat-bubble.user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
}
.chat-bubble.system {
    align-self: center;
    background: #eef2ff;
    color: #3730a3;
    font-size: 12px;
    border-radius: 10px;
}
.chat-bubble.typing {
    opacity: .75;
    font-style: italic;
}

.chat-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}
.chat-form input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
}
.chat-form input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.chat-form .primary-btn {
    flex-shrink: 0;
}

@media (max-width: 680px) {
    .chat-toggle { right: 14px; bottom: 14px; }
    .chat-panel {
        right: 10px;
        bottom: 72px;
        width: calc(100vw - 20px);
        height: min(70vh, 520px);
    }
    .chat-toggle-label { display: none; }
}


/* Responsive layouts: keep questions, results and conversations usable on touch screens. */
.hero-copy, .hero-visual, .quiz-wrap > *, .result-heading > *,
.major-card, .detail-summary > *, .chat-header > div {
    min-width: 0;
}
button { touch-action: manipulation; }
button:focus-visible, .chat-panel:focus-visible {
    outline: 3px solid #3157d5;
    outline-offset: 3px;
}
.question-head h2, .major-card h3, .detail-summary h2,
.reason-list, .school-list, .detail-evidence, .trait-row {
    overflow-wrap: anywhere;
}
.chat-header, .chat-form { flex-shrink: 0; }
.chat-messages { min-height: 0; overscroll-behavior: contain; }
.chat-form input { min-width: 0; }
.chat-close, .detail-close { min-width: 44px; min-height: 44px; }
.detail-dialog { overscroll-behavior: contain; }

@media (min-width: 681px) and (max-width: 1024px) {
    .page-shell { width: calc(100% - 40px); margin-top: 28px; }
    .hero-v2 { padding: 36px; gap: 32px; grid-template-columns: 1fr; min-height: auto; }
    .hero-v2 h1 { font-size: clamp(40px, 6vw, 56px); }
    .hero-visual { min-height: auto; }
    .quiz-wrap { grid-template-columns: 1fr; }
    .sidebar { min-height: 0; padding: 22px; }
    .sidebar-divider, .sidebar h3, .sidebar .check-list { display: none; }
    .question-panel { padding: 32px; min-height: auto; }
    .cards-grid, .cards-grid.secondary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    :root { --radius: 20px; --mobile-header-height: 64px; }
    body { min-height: 100dvh; }
    .topbar {
        height: auto;
        min-height: 64px;
        padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
    }
    .brand strong { font-size: 14px; line-height: 1.45; max-width: min(320px, calc(100vw - 96px)); }
    .brand span { display: none; }
    .page-shell {
        width: auto;
        margin: 16px max(12px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    }
    .hero-v2 { padding: 28px 20px; min-height: auto; display: block; }
    .hero-v2 h1 { font-size: clamp(30px, 8.4vw, 42px); line-height: 1.16; letter-spacing: -.035em; }
    .hero-lead { font-size: 15px !important; line-height: 1.7 !important; }
    .hero-actions { margin-top: 24px; }
    .hero-start { width: 100%; justify-content: space-between; min-height: 52px; }
    .hero-stats { grid-template-columns: 1fr; gap: 0; margin-top: 26px; border-top: 1px solid var(--line); }
    .stat-item {
        display: grid;
        grid-template-columns: 95px minmax(0, 1fr);
        align-items: center;
        gap: 12px;
        min-height: 58px;
        padding: 12px 0;
        border: 0;
        border-bottom: 1px solid var(--line);
        border-radius: 0;
        background: transparent;
    }
    .stat-item strong { margin: 0; }
    .stat-item span { font-size: 12px; }
    .hero-visual { display: none; }
    .quiz-wrap { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .sidebar {
        position: sticky;
        top: calc(var(--mobile-header-height) + 8px);
        z-index: 15;
        min-height: 0;
        padding: 14px 16px;
        border-radius: 16px;
        background: #fff;
        box-shadow: 0 5px 18px rgba(27, 40, 85, .07);
    }
    .sidebar-divider, .sidebar h3, .sidebar .check-list { display: none; }
    .sidebar .progress-track { margin-top: 9px; height: 6px; }
    .sidebar .progress-text { margin-top: 8px; font-size: 12px; line-height: 1.5; }
    .question-panel { padding: 24px 18px; min-height: 0; }
    .question-head h2 { font-size: clamp(23px, 6vw, 30px); line-height: 1.35; margin-top: 12px; }
    .question-head p { font-size: 14px; line-height: 1.6; }
    .question-tag { display: block; line-height: 1.6; }
    .options-grid { grid-template-columns: minmax(0, 1fr); margin: 24px 0; gap: 10px; }
    .option-btn { min-height: 60px; padding: 16px; border-radius: 14px; font-size: 15px; line-height: 1.55; }
    .option-btn:active { border-color: var(--primary); background: var(--soft); }
    .question-footer { flex-direction: column; align-items: stretch; gap: 12px; }
    .question-footer .ghost-btn { align-self: flex-start; min-height: 46px; }
    #adaptiveHint { line-height: 1.6; font-size: 12px; }
    .loading { padding: 40px 20px; }
    .loading h2 { font-size: 23px; line-height: 1.4; }
    .loading p { font-size: 14px; line-height: 1.7; }
    .result-heading { display: flex; flex-direction: column; align-items: stretch; gap: 18px; margin-bottom: 24px; }
    .result-heading h2 { font-size: 30px; line-height: 1.2; }
    .result-heading p { font-size: 14px; line-height: 1.7; }
    .result-heading .primary-btn { align-self: flex-start; min-height: 46px; }
    .cards-grid, .cards-grid.secondary { grid-template-columns: minmax(0, 1fr); gap: 14px; }
    .major-card { padding: 20px 18px; border-radius: 18px; }
    .major-card h3 { font-size: 21px; line-height: 1.4; }
    .score-row { flex-wrap: wrap; gap: 8px; }
    .score-pill { max-width: 100%; }
    .card-actions .detail-btn { width: 100%; min-height: 46px; }
    .reason-list, .caution-list, .school-list { font-size: 14px; }
    .detail-modal { padding: 0; align-items: end; }
    .detail-dialog {
        width: 100%;
        max-height: 94vh;
        max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 12px);
        border-radius: 22px 22px 0 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    #detailContent { padding: 24px 18px 28px; }
    .detail-summary { display: flex; flex-direction: column; gap: 18px; padding-right: 38px; }
    .detail-summary h2 { font-size: 26px; line-height: 1.25; }
    .detail-summary p { font-size: 14px; }
    .detail-close { top: 10px; margin: 10px 10px 0 0; }
    .detail-section { margin-top: 24px; padding-top: 22px; }
    .detail-factor-head { gap: 10px; line-height: 1.5; font-size: 14px; }
    .detail-factor-head b { flex-shrink: 0; }
    .trait-row { flex-wrap: wrap; padding: 12px; gap: 10px; }
    .trait-row > div { min-width: 0; }
    .detail-evidence span { max-width: 100%; border-radius: 12px; }
    .chat-toggle {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
        right: max(16px, env(safe-area-inset-right, 0px));
        top: calc(var(--mobile-header-height) / 2 - 22px);
        bottom: auto;
    }
    .chat-toggle-label { display: none; }
    body.chat-open { overflow: hidden; }
    body.chat-open .chat-toggle { visibility: hidden; }
    .chat-panel {
        top: calc(var(--chat-viewport-top, 0px) + env(safe-area-inset-top, 0px) + 8px);
        bottom: auto;
        right: max(10px, env(safe-area-inset-right, 0px));
        left: max(10px, env(safe-area-inset-left, 0px));
        width: auto;
        height: calc(var(--chat-viewport-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
        max-height: none;
        border-radius: 20px;
    }
    .chat-header { padding: 12px 12px 12px 16px; align-items: center; }
    .chat-close { display: grid; place-items: center; padding: 0; }
    .chat-messages { padding: 14px 12px; }
    .chat-bubble { font-size: 15px; line-height: 1.65; max-width: 94%; }
    .chat-form { padding: 10px; gap: 8px; }
    .chat-form input { font-size: 16px; min-height: 48px; padding: 10px; }
    .chat-form .primary-btn { min-height: 48px; padding: 12px 14px; }
}

@media (hover: none) {
    .option-btn:hover, .primary-btn:hover, .detail-btn:hover, .chat-toggle:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .progress-bar, .option-btn, .primary-btn, .detail-btn, .chat-toggle { transition: none; }
}

.adjacent-label { display: inline-block; padding: 7px 10px; margin: 2px 0 8px; border-radius: 10px; background: #fff7ed; color: #9a3412; font-size: 12px; font-weight: 700; line-height: 1.5; }
.adjacent-reason { margin-top: 4px; }

.question-head .question-context { margin: 14px 0 8px; padding: 10px 12px; border-left: 3px solid #a5b4fc; background: #f5f7ff; border-radius: 0 10px 10px 0; color: #475569; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
