* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f4f6fa;
    color: #20242d;
    font-family: -apple-system, BlinkMacSystemFont, "Noto Sans KR",
        "Malgun Gothic", sans-serif;
}

button,
textarea,
input {
    font: inherit;
}

button,
label {
    -webkit-tap-highlight-color: transparent;
}

.page-shell {
    width: min(860px, calc(100% - 32px));
    margin: 0 auto;
    padding: 48px 0 36px;
}

.page-header {
    margin-bottom: 24px;
}

.eyebrow {
    margin: 0 0 6px;
    color: #65708a;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.page-header h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 38px);
    line-height: 1.2;
    letter-spacing: -0.04em;
}

.intro {
    margin: 12px 0 0;
    color: #687286;
    font-size: 14px;
    line-height: 1.7;
}

.panel {
    border: 1px solid #e3e7ef;
    border-radius: 20px;
    background: #ffffff;
    box-shadow: 0 14px 40px rgba(33, 45, 70, 0.06);
}

.loading-panel {
    padding: 28px;
}

.loading-panel p {
    margin: 0;
    line-height: 1.7;
}

.load-control {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #edf0f5;
}

.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border-radius: 10px;
    background: #20242d;
    color: #ffffff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/*
 * 실험 카드 전체가 시각 자극의 영역이다.
 *
 * visual-effects는 카드 전체를 차지하지만
 * pointer-events: none으로 입력과 클릭에는 영향을 주지 않는다.
 */
.experiment-panel {
    position: relative;
    overflow: hidden;
    isolation: isolate;
}

.experiment-content {
    position: relative;
    z-index: 2;
    padding: 28px;
}

.visual-effects {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.trial-topline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.trial-topline h2 {
    margin: 0;
    font-size: 23px;
    letter-spacing: -0.03em;
}

.condition-badge {
    flex-shrink: 0;
    padding: 8px 12px;
    border: 1px solid #dfe4ec;
    border-radius: 999px;
    background: rgba(247, 248, 251, 0.88);
    color: #697286;
    font-size: 12px;
    font-weight: 700;
    transition: 0.2s ease;
}

.condition-badge.is-on {
    border-color: rgba(101, 88, 190, 0.28);
    background: rgba(244, 241, 255, 0.9);
    color: #6659a8;
}

.typing-area {
    margin-top: 28px;
}

.sentence-area {
    min-height: 92px;
    padding: 20px;
    border: 1px solid rgba(226, 230, 238, 0.9);
    border-radius: 14px;
    background: rgba(250, 251, 253, 0.76);
    backdrop-filter: blur(2px);
}

.section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 9px;
    color: #6a7487;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.sentence-text {
    margin: 0;
    color: #252a35;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.7;
    letter-spacing: -0.02em;
    word-break: keep-all;
}

.hint {
    color: #9aa2b1;
    font-size: 11px;
    font-weight: 500;
}

#typing-input {
    display: block;
    width: 100%;
    min-height: 72px;
    margin: 0;
    padding: 15px 16px;
    resize: none;
    border: 1px solid #dce1ea;
    border-radius: 12px;
    outline: none;
    background: rgba(255, 255, 255, 0.94);
    color: #20242d;
    font-size: 17px;
    line-height: 1.6;
    transition:
        border-color 0.18s ease,
        box-shadow 0.18s ease;
}

#typing-input:focus {
    border-color: #9aa6bb;
    box-shadow: 0 0 0 4px rgba(95, 109, 138, 0.08);
}

#typing-input:disabled {
    cursor: not-allowed;
    background: rgba(246, 248, 251, 0.92);
}

.input-help {
    margin: 8px 0 0;
    color: #929aaa;
    font-size: 11px;
    line-height: 1.6;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 20px;
}

.metric {
    min-height: 92px;
    padding: 16px;
    border: 1px solid rgba(228, 232, 239, 0.92);
    border-radius: 13px;
    background: rgba(249, 250, 252, 0.78);
    backdrop-filter: blur(2px);
}

.metric-label {
    display: block;
    margin-bottom: 7px;
    color: #737d90;
    font-size: 12px;
    font-weight: 600;
}

.metric strong {
    font-size: 25px;
    line-height: 1;
    letter-spacing: -0.04em;
}

.metric small {
    margin-left: 3px;
    color: #727b8c;
    font-size: 12px;
    font-weight: 600;
}

.trial-status {
    min-height: 22px;
    margin: 14px 0 0;
    color: #6d7687;
    font-size: 12px;
    line-height: 1.6;
}

.measurement-details {
    margin-top: 18px;
    border-top: 1px solid rgba(235, 237, 242, 0.9);
    padding-top: 14px;
}

.measurement-details summary {
    color: #727c8f;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.measurement-note {
    margin: 10px 0 0;
    color: #8a93a2;
    font-size: 11px;
    line-height: 1.7;
}

/*
 * ==========================
 * 랜덤 시각 자극
 * ==========================
 */

.firework {
    position: absolute;
    width: 0;
    height: 0;
    transform: translate(-50%, -50%);
    opacity: 0;
    animation: firework-life var(--life) ease-out forwards;
}

.firework-core {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--core-size);
    height: var(--core-size);
    border-radius: 50%;
    background: rgba(91, 88, 185, 0.72);
    box-shadow:
        0 0 8px rgba(91, 88, 185, 0.36),
        0 0 18px rgba(118, 109, 211, 0.18);
    transform: translate(-50%, -50%);
}

.firework-ring {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--ring-size);
    height: var(--ring-size);
    border: 2px solid rgba(105, 99, 194, 0.36);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0.1);
    animation: ring-expand var(--life) ease-out forwards;
}

.firework-particle {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--particle-size);
    height: var(--particle-size);
    border-radius: 50%;
    background: rgba(94, 106, 191, 0.62);
    box-shadow: 0 0 8px rgba(98, 106, 190, 0.24);
    transform:
        translate(-50%, -50%)
        rotate(var(--angle))
        translateY(0)
        scale(0.7);
    animation: particle-spread var(--life) ease-out forwards;
}

.spark {
    position: absolute;
    width: var(--spark-size);
    height: var(--spark-size);
    border-radius: 50%;
    background: rgba(126, 116, 203, 0.58);
    transform:
        translate(-50%, -50%)
        rotate(var(--angle))
        translateY(0);
    animation: spark-move var(--life) ease-out forwards;
}

@keyframes firework-life {
    0% {
        opacity: 0;
    }

    12% {
        opacity: 0.9;
    }

    55% {
        opacity: 0.68;
    }

    100% {
        opacity: 0;
    }
}

@keyframes ring-expand {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.1);
    }

    20% {
        opacity: 0.7;
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes particle-spread {
    0% {
        opacity: 0;
        transform:
            translate(-50%, -50%)
            rotate(var(--angle))
            translateY(0)
            scale(0.7);
    }

    18% {
        opacity: 0.9;
    }

    100% {
        opacity: 0;
        transform:
            translate(-50%, -50%)
            rotate(var(--angle))
            translateY(calc(var(--distance) * -1))
            scale(0.25);
    }
}

@keyframes spark-move {
    0% {
        opacity: 0;
        transform:
            translate(-50%, -50%)
            rotate(var(--angle))
            translateY(0);
    }

    15% {
        opacity: 0.8;
    }

    100% {
        opacity: 0;
        transform:
            translate(-50%, -50%)
            rotate(var(--angle))
            translateY(calc(var(--distance) * -1));
    }
}

/*
 * 결과 영역
 */

.results-panel {
    margin-top: 24px;
    padding: 28px;
}

.results-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}

.results-header h2 {
    margin: 0;
    font-size: 23px;
    letter-spacing: -0.03em;
}

.download-button {
    min-height: 42px;
    padding: 0 15px;
    border: 0;
    border-radius: 10px;
    background: #20242d;
    color: #ffffff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

.download-button:hover {
    background: #303641;
}

.results-note {
    margin: 12px 0 18px;
    color: #7c8595;
    font-size: 12px;
    line-height: 1.6;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid #e7eaf0;
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 520px;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid #edf0f4;
    text-align: center;
    font-size: 12px;
}

th {
    background: #f8f9fb;
    color: #687286;
    font-weight: 700;
}

td {
    color: #353b48;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.download-status {
    min-height: 20px;
    margin: 12px 0 0;
    color: #66708a;
    font-size: 12px;
}

.error-message {
    margin-top: 24px;
    padding: 20px;
    color: #9b3e3e;
}

.page-footer {
    padding: 22px 0 0;
    color: #9aa2b1;
    font-size: 11px;
    text-align: center;
}

code {
    padding: 2px 5px;
    border-radius: 5px;
    background: #f0f2f6;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9em;
}

@media (max-width: 640px) {
    .page-shell {
        width: min(100% - 20px, 860px);
        padding-top: 28px;
    }

    .experiment-content,
    .results-panel,
    .loading-panel {
        padding: 20px;
    }

    .trial-topline,
    .results-header {
        flex-direction: column;
    }

    .condition-badge {
        align-self: flex-start;
    }

    .sentence-area {
        padding: 16px;
    }

    .sentence-text {
        font-size: 16px;
    }

    .metrics {
        grid-template-columns: 1fr;
    }

    .metric {
        min-height: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .firework,
    .firework-ring,
    .firework-particle,
    .spark {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}