:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef2f9;
    --border: #dbe2ef;
    --ink: #112d4e;
    --ink-2: #5b6b84;
    --primary: #3f72af;
    --primary-ink: #ffffff;
    --primary-soft: #e6eef8;
    --ok: #158a5b;
    --ok-soft: #e3f5ec;
    --bad: #c0392b;
    --bad-soft: #fdecea;
    --warn: #b7791f;
    --warn-soft: #fdf3e0;
    --shadow: 0 1px 2px rgb(17 45 78 / 6%), 0 8px 24px rgb(17 45 78 / 8%);
    --radius: 14px;
    --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1526;
        --surface: #161f33;
        --surface-2: #1d2842;
        --border: #2a3752;
        --ink: #e8eef9;
        --ink-2: #9aabc6;
        --primary: #6ea8fe;
        --primary-ink: #0e1526;
        --primary-soft: #1d2b47;
        --ok: #4ade80;
        --ok-soft: #16301f;
        --bad: #f87171;
        --bad-soft: #34191a;
        --warn: #fbbf24;
        --warn-soft: #33270e;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 35%);
    }
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo',
        'Segoe UI', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    font-size: 16px;
    line-height: 1.6;
    word-break: keep-all;
}

.screen {
    display: block;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 24px 20px 64px;
    animation: fade-in 0.25s ease;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

h1,
h2,
h3 {
    line-height: 1.3;
    margin: 0;
}

.muted {
    color: var(--ink-2);
    font-size: 0.9rem;
}

button {
    font: inherit;
    font-weight: 600;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

button:hover:not(:disabled) {
    border-color: var(--primary);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-ink);
}

button.primary:hover:not(:disabled) {
    filter: brightness(1.08);
}

button.block {
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
}

:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

select,
input[type='number'],
input[type='text'] {
    font: inherit;
    width: 100%;
    padding: 11px 12px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--ink-2);
    margin-bottom: 6px;
}

.field + .field {
    margin-top: 16px;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 520px) {
    .row {
        grid-template-columns: 1fr;
    }
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    padding: 7px 13px;
    font-size: 0.9rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid transparent;
}

.chip[aria-pressed='true'] {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

.hero {
    text-align: center;
    padding: 32px 0 28px;
}

.hero img {
    width: min(240px, 70%);
    height: auto;
}

.hero h1 {
    font-size: 1.5rem;
    margin-top: 12px;
}

.hero p {
    color: var(--ink-2);
    margin: 8px 0 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.brand {
    font-weight: 800;
    color: var(--primary);
    background: none;
    border: 0;
    padding: 0;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.topbar-actions button {
    font-size: 0.85rem;
    padding: 7px 12px;
}

.page-title {
    font-size: 1.4rem;
    margin: 4px 0 16px;
}

.progress-track {
    height: 8px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 24px;
}

.progress-fill {
    height: 100%;
    width: 0;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.question-text {
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0 0 20px;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    font-weight: 500;
    padding: 14px 16px;
    background: var(--surface);
}

.option .key {
    flex: 0 0 28px;
    height: 28px;
    display: grid;
    place-items: center;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--ink-2);
    background: var(--surface-2);
    border-radius: 8px;
}

.option[aria-pressed='true'] {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.option[aria-pressed='true'] .key {
    background: var(--primary);
    color: var(--primary-ink);
}

.confidence {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px dashed var(--border);
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 24px;
}

button.ghost {
    background: transparent;
    color: var(--ink-2);
}

.score {
    text-align: center;
    padding: 28px 20px;
}

.score .big {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1;
    color: var(--primary);
}

.insight {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.insight div {
    padding: 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.insight strong {
    display: block;
    font-size: 1.4rem;
}

.insight.risk div.danger {
    background: var(--bad-soft);
    color: var(--bad);
}

.insight div.lucky {
    background: var(--warn-soft);
    color: var(--warn);
}

.insight div.solid {
    background: var(--ok-soft);
    color: var(--ok);
}

.result-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.result-item {
    padding: 16px;
}

.result-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 700;
}

.badge {
    flex: 0 0 auto;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 999px;
}

.badge.ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.badge.bad {
    background: var(--bad-soft);
    color: var(--bad);
}

.answers {
    margin: 10px 0 0;
    font-size: 0.92rem;
    color: var(--ink-2);
}

.answers span {
    font-weight: 600;
    color: var(--ink);
}

.result-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.result-actions button {
    font-size: 0.9rem;
    padding: 8px 12px;
}

.ai-box {
    margin-top: 12px;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border-left: 3px solid var(--primary);
    white-space: pre-wrap;
    font-size: 0.95rem;
}

.ai-box.error {
    border-left-color: var(--bad);
    color: var(--bad);
}

.badge:not(.ok):not(.bad) {
    background: var(--surface-2);
    color: var(--ink-2);
}

.feedback {
    margin-top: 16px;
}

.feedback h2 {
    font-size: 1.05rem;
    color: var(--primary);
    margin-bottom: 12px;
}

.feedback h3 {
    font-size: 0.95rem;
    margin: 18px 0 6px;
}

.feedback-summary {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0 0 10px;
}

.feedback-detail {
    margin: 0;
    white-space: pre-wrap;
}

.twin {
    margin-top: 12px;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border-left: 3px solid var(--ok);
}

.twin-title {
    font-weight: 700;
    margin: 0 0 10px;
}

.twin-options {
    margin: 0 0 10px;
    padding-left: 22px;
}

.twin-options li {
    margin-bottom: 4px;
}

.twin details summary {
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--ink-2);
    display: inline;
}

.twin details[open] summary {
    font-weight: 700;
    color: var(--ok);
}

.history-item {
    display: block;
    width: 100%;
    text-align: left;
    font-weight: 400;
    padding: 16px;
}

.history-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.history-range {
    font-weight: 700;
}

.history-score {
    flex: 0 0 auto;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
}

.history-item .muted {
    margin: 6px 0 0;
}

.history-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 10px 0 0;
}

.history-tags:empty {
    display: none;
}

.empty {
    text-align: center;
}

.empty p {
    margin-top: 0;
    color: var(--ink-2);
}

.explanation:empty {
    display: none;
}

button.ask-toggle {
    margin-top: 10px;
    font-size: 0.9rem;
    padding: 8px 12px;
}

.chat {
    margin-top: 12px;
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.chat[hidden] {
    display: none;
}

.chat-heading {
    margin: 0 0 12px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--ink-2);
}

.chat-log {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-log:empty {
    display: none;
}

.chat-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    white-space: pre-wrap;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--primary);
    color: var(--primary-ink);
    border-bottom-right-radius: 4px;
}

.chat-message.assistant {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-message.pending {
    color: var(--ink-2);
    font-style: italic;
}

.chat-message.error {
    background: var(--bad-soft);
    color: var(--bad);
}

.chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-top: 12px;
}

.chat-form textarea {
    font: inherit;
    flex: 1;
    min-height: 44px;
    max-height: 160px;
    padding: 11px 12px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    resize: vertical;
}

.chat-form button {
    flex: 0 0 auto;
    height: 44px;
}

.inline-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ink-2);
    font-size: 0.95rem;
}

.spinner.small {
    width: 18px;
    height: 18px;
    border-width: 2px;
    flex: 0 0 auto;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 80px 20px;
    text-align: center;
    color: var(--ink-2);
}

.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.dots::after {
    content: '';
    animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
    to {
        content: '...';
    }
}

.error-box {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    background: var(--bad-soft);
    color: var(--bad);
    font-size: 0.92rem;
}
