:root {
    --bg-color: #020617;
    --text-color: #f8fafc;
    --muted-text: #94a3b8;
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --accent: #38bdf8;
    --accent-2: #22d3ee;
    --accent-3: #a3e635;
    --accent-4: #f472b6;
    --surface: rgba(15, 23, 42, 0.74);
    --surface-strong: rgba(15, 23, 42, 0.92);
    --surface-soft: rgba(30, 41, 59, 0.6);
    --surface-border: rgba(148, 163, 184, 0.25);
    --glass-shadow: 0 24px 56px rgba(2, 6, 23, 0.55);
    --input-bg: rgba(2, 6, 23, 0.52);
    --focus-ring: 0 0 0 3px rgba(139, 92, 246, 0.28);
    --radius-xl: 28px;
    --radius-lg: 18px;
    --radius-md: 14px;
    --radius-sm: 10px;
    --transition-fast: 140ms ease;
    --transition-normal: 220ms ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    min-height: 100%;
}

body {
    font-family: 'Inter', sans-serif;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: clamp(0.95rem, 2.8vw, 2.5rem);
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 12% 8%, rgba(139, 92, 246, 0.25), transparent 32%),
        radial-gradient(circle at 85% 15%, rgba(56, 189, 248, 0.24), transparent 28%),
        radial-gradient(circle at 70% 85%, rgba(139, 92, 246, 0.18), transparent 35%),
        linear-gradient(180deg, #020617 0%, #0f172a 100%);
    background-attachment: fixed;
}

.app-container {
    width: min(100%, 980px);
    min-height: calc(100vh - clamp(1.9rem, 5.6vw, 5rem));
    margin: 0 auto;
    padding: clamp(1.2rem, 2.7vw, 2.4rem);
    border-radius: var(--radius-xl);
    border: 1px solid var(--surface-border);
    background:
        linear-gradient(145deg, rgba(30, 41, 59, 0.55), rgba(15, 23, 42, 0.84)),
        var(--surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--glass-shadow);
    display: flex;
    flex-direction: column;
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

.app-container::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(130deg, rgba(255, 255, 255, 0.06), transparent 36%, rgba(56, 189, 248, 0.1));
    pointer-events: none;
    z-index: -1;
}

header {
    text-align: center;
    margin-bottom: clamp(1.2rem, 2.8vw, 2.2rem);
    position: relative;
    z-index: 0;
}

header::after {
    content: none;
}

h1 {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: -0.03em;
    margin-bottom: 0.7rem;
    text-wrap: balance;
    position: relative;
    z-index: 1;
    color: #ffffff;
    text-shadow:
        0 0 2px rgba(255, 255, 255, 0.35),
        0 0 8px rgba(255, 255, 255, 0.2);
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.62));
    animation: h1GlowOrbit 11s linear infinite, h1GlowPulse 3.2s ease-in-out infinite;
}

.highlight {
    background: linear-gradient(130deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

header p {
    max-width: 68ch;
    margin: 0.2rem auto 0;
    color: var(--muted-text);
    font-size: clamp(0.96rem, 1.65vw, 1.04rem);
    line-height: 1.72;
}

main {
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
    flex: 1;
}

.content-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: var(--radius-lg);
    padding: clamp(0.95rem, 2.1vw, 1.3rem);
    background: linear-gradient(160deg, rgba(2, 6, 23, 0.42), rgba(15, 23, 42, 0.28));
}

.instruction-card {
    border: 1px solid rgba(56, 189, 248, 0.38);
    border-radius: var(--radius-lg);
    padding: clamp(0.95rem, 1.7vw, 1.3rem);
    background:
        radial-gradient(circle at top right, rgba(56, 189, 248, 0.16), transparent 38%),
        linear-gradient(140deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.84));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.instruction-card h2 {
    margin-bottom: 0.45rem;
    color: #e0f2fe;
    font-size: 0.86rem;
    font-weight: 700;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.instruction-card p {
    color: #dbeafe;
    font-size: 0.96rem;
    line-height: 1.6;
}

.instruction-card strong {
    color: #ffffff;
    font-weight: 700;
}

.instruction-steps {
    margin-top: 0.75rem;
    padding-top: 0.72rem;
    border-top: 1px dashed rgba(148, 163, 184, 0.42);
    display: flex;
    flex-wrap: wrap;
    gap: 0.48rem;
}

.instruction-steps span {
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(30, 41, 59, 0.74);
    color: #e2e8f0;
    border-radius: 999px;
    padding: 0.34rem 0.6rem;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}

.input-section {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 0.85rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.input-group label {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #cbd5e1;
    margin-bottom: 0.06rem;
}

input[type="text"] {
    width: 100%;
    min-height: 48px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: var(--input-bg);
    color: #f8fafc;
    font-family: inherit;
    font-size: 0.98rem;
    padding: 0.78rem 0.94rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

input[type="text"]::placeholder {
    color: #64748b;
}

input[type="text"]:hover {
    border-color: rgba(139, 92, 246, 0.58);
}

input[type="text"]:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
    background: rgba(2, 6, 23, 0.64);
}

.plus-icon {
    margin-bottom: 0.6rem;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-size: 1.3rem;
    font-weight: 800;
    color: #e2e8f0;
    background: linear-gradient(140deg, rgba(139, 92, 246, 0.3), rgba(56, 189, 248, 0.26));
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.style-section {
    margin-top: 0.12rem;
}

.style-section label {
    display: block;
    margin-bottom: 0.72rem;
    color: #cbd5e1;
    font-size: 0.87rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chip-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.54rem;
}

#styleSelector {
    display: grid;
    grid-template-rows: repeat(2, minmax(0, auto));
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 0.58rem;
}

#styleSelector .chip {
    min-height: 40px;
    width: 100%;
}

.tone-section {
    margin-top: 0.45rem;
    padding: 0.78rem 0.86rem;
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: linear-gradient(150deg, rgba(15, 23, 42, 0.45), rgba(2, 6, 23, 0.35));
}

.tone-section label {
    display: block;
    margin-bottom: 0.75rem;
    color: #cbd5e1;
    font-size: 0.87rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.tone-chip-container {
    margin-bottom: 0.72rem;
    gap: 0.58rem;
}

#toneSelector {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, auto));
    gap: 0.58rem;
}

.tone-chip {
    background: rgba(15, 23, 42, 0.22);
    padding: 0.52rem 0.98rem;
    font-size: 0.89rem;
    min-height: 40px;
    border-color: rgba(148, 163, 184, 0.3);
}

.tone-helper {
    font-size: 0.86rem;
    line-height: 1.55;
    color: #94a3b8;
    margin-top: 0.08rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.36);
    background: rgba(15, 23, 42, 0.56);
    color: #dbeafe;
    padding: 0.47rem 0.95rem;
    font-family: inherit;
    font-size: 0.87rem;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
    transition: transform var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.chip:hover {
    border-color: rgba(56, 189, 248, 0.7);
    background: rgba(30, 41, 59, 0.92);
    transform: translateY(-1px);
}

.chip:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-color: var(--primary);
}

.chip.active {
    border-color: transparent;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    box-shadow: 0 8px 22px rgba(139, 92, 246, 0.34);
    font-weight: 700;
}

.primary-btn {
    width: 100%;
    min-height: 52px;
    border: 0;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: #ffffff;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(59, 130, 246, 0.24), 0 6px 16px rgba(139, 92, 246, 0.36);
    transition: transform var(--transition-fast), filter var(--transition-fast), box-shadow var(--transition-fast);
}

.primary-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
    box-shadow: 0 14px 30px rgba(59, 130, 246, 0.28), 0 8px 18px rgba(139, 92, 246, 0.45);
}

.primary-btn:active {
    transform: translateY(0);
}

.primary-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring), 0 12px 28px rgba(59, 130, 246, 0.24), 0 6px 16px rgba(139, 92, 246, 0.36);
}

.primary-btn:disabled {
    cursor: not-allowed;
    transform: none;
    filter: saturate(0.72);
    opacity: 0.65;
    box-shadow: none;
}

.small-btn {
    min-height: 42px;
    font-size: 0.9rem;
    margin-top: 1rem;
}

.result-section {
    min-height: 138px;
    margin-top: 0.22rem;
    padding: clamp(1rem, 2.2vw, 1.4rem);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(148, 163, 184, 0.3);
    background:
        linear-gradient(165deg, rgba(15, 23, 42, 0.82), rgba(2, 6, 23, 0.92));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-placeholder {
    color: #64748b;
    font-style: italic;
    text-align: center;
}

.result-content {
    width: 100%;
    font-size: 1.02rem;
    line-height: 1.72;
    color: #f1f5f9;
    white-space: pre-wrap;
    word-break: break-word;
}

.result-glow-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.12rem 0.52rem;
    margin: 0 0.14rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--primary) 77%, transparent);
    background: transparent;
    color: #ffffff;
    font-weight: 700;
    line-height: 1.35;
    box-shadow:
        0 0 0.144rem color-mix(in srgb, var(--primary) 41%, transparent),
        0 0 0.336rem color-mix(in srgb, var(--accent) 40%, transparent);
    animation: chipGlowOrbit 7.5s linear infinite, chipGlowPulse 2.8s ease-in-out infinite;
}

.result-tone-badge {
    margin-top: 1rem;
    font-size: 0.78rem;
    color: #94a3b8;
}

.experiment-note {
    margin: 0;
    max-width: none;
    text-align: center;
    color: #64748b;
    font-size: 0.87rem;
    line-height: 1.62;
    padding-top: 0.42rem;
    padding-inline: clamp(1rem, 6.4vw, 4rem);
}

.icon-btn {
    position: absolute;
    top: 5px;
    right: 0;
    border: none;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: color var(--transition-fast), transform var(--transition-fast);
}

.icon-btn:hover {
    color: var(--text-color);
    transform: rotate(22deg);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    background-color: rgba(2, 6, 23, 0.66);
    backdrop-filter: blur(6px);
}

.glass-panel {
    width: min(90%, 420px);
    border-radius: 20px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: var(--surface-strong);
    box-shadow: var(--glass-shadow);
    padding: 2rem;
    position: relative;
}

.close-modal {
    position: absolute;
    top: 12px;
    right: 16px;
    color: #cbd5e1;
    font-size: 28px;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover {
    color: #ffffff;
}

.glass-panel h2 {
    margin-bottom: 0.92rem;
}

.glass-panel p {
    color: #94a3b8;
    margin-bottom: 1.42rem;
    font-size: 0.92rem;
    line-height: 1.6;
}

/* Loader */
.loader {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.36);
    border-top-color: #ffffff;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes h1GlowOrbit {
    0% {
        text-shadow:
            0 0 2px rgba(255, 255, 255, 0.4),
            0 -6px 14px color-mix(in srgb, var(--primary) 92%, transparent),
            6px 0 14px color-mix(in srgb, var(--accent) 90%, transparent),
            0 6px 14px color-mix(in srgb, var(--accent-2) 90%, transparent),
            -6px 0 14px color-mix(in srgb, var(--accent-3) 90%, transparent),
            0 0 18px color-mix(in srgb, var(--accent-4) 80%, transparent);
    }
    25% {
        text-shadow:
            0 0 2px rgba(255, 255, 255, 0.42),
            6px -4px 14px color-mix(in srgb, var(--primary) 92%, transparent),
            4px 6px 14px color-mix(in srgb, var(--accent) 90%, transparent),
            -4px 6px 14px color-mix(in srgb, var(--accent-2) 90%, transparent),
            -6px -4px 14px color-mix(in srgb, var(--accent-3) 90%, transparent),
            0 0 18px color-mix(in srgb, var(--accent-4) 80%, transparent);
    }
    50% {
        text-shadow:
            0 0 2px rgba(255, 255, 255, 0.44),
            0 6px 14px color-mix(in srgb, var(--primary) 92%, transparent),
            -6px 0 14px color-mix(in srgb, var(--accent) 90%, transparent),
            0 -6px 14px color-mix(in srgb, var(--accent-2) 90%, transparent),
            6px 0 14px color-mix(in srgb, var(--accent-3) 90%, transparent),
            0 0 18px color-mix(in srgb, var(--accent-4) 80%, transparent);
    }
    75% {
        text-shadow:
            0 0 2px rgba(255, 255, 255, 0.42),
            -6px 4px 14px color-mix(in srgb, var(--primary) 92%, transparent),
            -4px -6px 14px color-mix(in srgb, var(--accent) 90%, transparent),
            4px -6px 14px color-mix(in srgb, var(--accent-2) 90%, transparent),
            6px 4px 14px color-mix(in srgb, var(--accent-3) 90%, transparent),
            0 0 18px color-mix(in srgb, var(--accent-4) 80%, transparent);
    }
    100% {
        text-shadow:
            0 0 2px rgba(255, 255, 255, 0.4),
            0 -6px 14px color-mix(in srgb, var(--primary) 92%, transparent),
            6px 0 14px color-mix(in srgb, var(--accent) 90%, transparent),
            0 6px 14px color-mix(in srgb, var(--accent-2) 90%, transparent),
            -6px 0 14px color-mix(in srgb, var(--accent-3) 90%, transparent),
            0 0 18px color-mix(in srgb, var(--accent-4) 80%, transparent);
    }
}

@keyframes h1GlowPulse {
    0%,
    100% {
        filter: brightness(1);
    }
    50% {
        filter: brightness(1.08);
    }
}

@keyframes chipGlowOrbit {
    0% {
        border-color: color-mix(in srgb, var(--primary) 78%, transparent);
        box-shadow:
            0 0 0.144rem color-mix(in srgb, var(--primary) 69%, transparent),
            0 0 0.336rem color-mix(in srgb, var(--accent) 67%, transparent);
    }
    25% {
        border-color: color-mix(in srgb, var(--accent) 78%, transparent);
        box-shadow:
            0 0 0.144rem color-mix(in srgb, var(--accent) 69%, transparent),
            0 0 0.336rem color-mix(in srgb, var(--accent-2) 67%, transparent);
    }
    50% {
        border-color: color-mix(in srgb, var(--accent-2) 78%, transparent);
        box-shadow:
            0 0 0.144rem color-mix(in srgb, var(--accent-2) 69%, transparent),
            0 0 0.336rem color-mix(in srgb, var(--accent-3) 67%, transparent);
    }
    75% {
        border-color: color-mix(in srgb, var(--accent-3) 78%, transparent);
        box-shadow:
            0 0 0.144rem color-mix(in srgb, var(--accent-3) 69%, transparent),
            0 0 0.336rem color-mix(in srgb, var(--accent-4) 67%, transparent);
    }
    100% {
        border-color: color-mix(in srgb, var(--primary) 78%, transparent);
        box-shadow:
            0 0 0.144rem color-mix(in srgb, var(--primary) 69%, transparent),
            0 0 0.336rem color-mix(in srgb, var(--accent) 67%, transparent);
    }
}

@keyframes chipGlowPulse {
    0%,
    100% {
        transform: translateY(0);
        filter: brightness(1);
    }
    50% {
        transform: translateY(-0.5px);
        filter: brightness(1.08);
    }
}

@media (max-width: 900px) {
    .app-container {
        min-height: calc(100vh - 2rem);
    }

    .content-stack {
        padding: 0.9rem;
    }

    .tone-section {
        padding: 0.66rem 0.72rem;
    }

    #styleSelector {
        display: flex;
        flex-wrap: wrap;
        gap: 0.54rem;
    }

    #toneSelector {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: auto;
    }
}

@media (min-width: 901px) {
    .experiment-note {
        padding-inline: clamp(1.2rem, 8vw, 6rem);
    }
}

@media (max-width: 680px) {
    .input-section {
        grid-template-columns: 1fr;
        align-items: stretch;
        gap: 0.65rem;
    }

    .plus-icon {
        margin: 0;
        justify-self: center;
    }

    .instruction-steps span {
        width: 100%;
        text-align: center;
    }
}

@media (max-width: 480px) {
    body {
        padding: 0.72rem;
    }

    .app-container {
        border-radius: 18px;
        padding: 0.96rem;
        min-height: calc(100vh - 1.4rem);
    }

    h1 {
        font-size: 1.62rem;
    }

    .result-section {
        min-height: 124px;
    }

    .chip {
        flex: 1 1 calc(50% - 0.3rem);
        text-align: center;
    }

    #styleSelector,
    #toneSelector {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
