:root {
    color-scheme: dark;
    --ink: #fff7fb;
    --muted: rgba(255, 247, 251, 0.68);
    --soft: rgba(255, 247, 251, 0.12);
    --panel: rgba(35, 14, 31, 0.78);
    --panel-strong: rgba(20, 8, 20, 0.9);
    --line: rgba(255, 247, 251, 0.18);
    --theme-a: #ff4f87;
    --theme-b: #ff9ab8;
    --theme-c: #ffd166;
    --theme-dark: #1a0715;
    --theme-glow: rgba(255, 79, 135, 0.35);
    --watermark: "FLAMES";
    --shadow: 0 28px 90px rgba(16, 3, 16, 0.44);
    --radius: 8px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="idle"] {
    --theme-a: #ff4f87;
    --theme-b: #b83280;
    --theme-c: #ffd166;
    --theme-dark: #180615;
    --theme-glow: rgba(255, 79, 135, 0.36);
    --watermark: "FLAMES";
}

body[data-theme="F"] {
    --theme-a: #26c6da;
    --theme-b: #4fc3f7;
    --theme-c: #b2ebf2;
    --theme-dark: #061b24;
    --theme-glow: rgba(38, 198, 218, 0.36);
    --watermark: "FRIENDS";
}

body[data-theme="L"] {
    --theme-a: #ff2d75;
    --theme-b: #ff5b9b;
    --theme-c: #ffd1dc;
    --theme-dark: #220512;
    --theme-glow: rgba(255, 45, 117, 0.44);
    --watermark: "LOVE";
}

body[data-theme="A"] {
    --theme-a: #ff7ab6;
    --theme-b: #b388ff;
    --theme-c: #ffe0f0;
    --theme-dark: #1c0a25;
    --theme-glow: rgba(255, 122, 182, 0.38);
    --watermark: "AFFECTION";
}

body[data-theme="M"] {
    --theme-a: #c7a45d;
    --theme-b: #f7d774;
    --theme-c: #fff1b8;
    --theme-dark: #1d1608;
    --theme-glow: rgba(247, 215, 116, 0.35);
    --watermark: "MARRIAGE";
}

body[data-theme="E"] {
    --theme-a: #ff7a1a;
    --theme-b: #d7263d;
    --theme-c: #ffd166;
    --theme-dark: #220904;
    --theme-glow: rgba(255, 122, 26, 0.38);
    --watermark: "ENEMIES";
}

body[data-theme="S"] {
    --theme-a: #8e7dff;
    --theme-b: #33d6a6;
    --theme-c: #d9fff3;
    --theme-dark: #080d24;
    --theme-glow: rgba(142, 125, 255, 0.42);
    --watermark: "SOULMATE";
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--theme-dark);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(120deg, var(--theme-dark), #16091b 42%, rgba(37, 11, 31, 0.96)),
        conic-gradient(from 215deg at 52% 46%, rgba(255, 255, 255, 0.02), var(--theme-glow), rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0));
    transition: background 420ms ease, color 420ms ease;
    overflow-x: hidden;
}

body::before,
body::after {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

body::before {
    z-index: -2;
    background:
        repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 28px),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 46px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.035), transparent 32%, rgba(255, 255, 255, 0.03) 68%, transparent);
    content: "";
    opacity: 0.75;
}

body::after {
    z-index: -1;
    display: grid;
    place-items: center;
    color: rgba(255, 255, 255, 0.055);
    content: var(--watermark);
    font-size: clamp(4.2rem, 15vw, 14rem);
    font-weight: 950;
    letter-spacing: 0;
    text-align: center;
    text-transform: uppercase;
    transform: rotate(-8deg);
    transition: content 420ms ease, color 420ms ease;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
}

[hidden] {
    display: none !important;
}

.app-shell {
    display: grid;
    width: min(1180px, calc(100vw - 32px));
    min-height: 100vh;
    margin: 0 auto;
    padding: 28px 0;
    grid-template-columns: minmax(0, 1.08fr) minmax(340px, 0.92fr);
    gap: 18px;
    align-items: stretch;
}

.visual-panel,
.control-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.035)),
        var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(22px);
}

.visual-panel {
    display: grid;
    min-height: 640px;
    padding: 24px;
    grid-template-rows: auto minmax(320px, 1fr) auto;
    gap: 18px;
    overflow: hidden;
}

.brand-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 13px;
    align-items: center;
}

.brand-mark {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border: 1px solid color-mix(in srgb, var(--theme-a), white 28%);
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--theme-a), var(--theme-b));
    color: #fff;
    font-size: 1.35rem;
    font-weight: 950;
    box-shadow: 0 16px 34px var(--theme-glow);
}

.eyebrow,
.live-label,
.result-kicker,
.result-theme {
    margin: 0 0 4px;
    color: var(--theme-c);
    font-size: 0.76rem;
    font-weight: 850;
    letter-spacing: 0;
    text-transform: uppercase;
}

.brand-row h1,
.panel-heading h2,
.live-card h2,
.result-title {
    margin: 0;
    letter-spacing: 0;
}

.brand-row h1 {
    font-size: 1.35rem;
    line-height: 1.08;
}

.status-chip {
    min-width: 118px;
    padding: 8px 10px;
    border: 1px solid color-mix(in srgb, var(--theme-a), white 15%);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-align: center;
}

.status-chip.ready,
.status-chip.revealed {
    color: var(--theme-c);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 10px 26px var(--theme-glow);
}

.orbit-scene {
    --ring-color: color-mix(in srgb, var(--theme-a), white 18%);
    position: relative;
    display: grid;
    min-height: 430px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background:
        linear-gradient(160deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.025)),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 16px);
    overflow: hidden;
}

.orbit-scene::before,
.orbit-scene::after {
    position: absolute;
    inset: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    content: "";
}

.orbit-scene::after {
    inset: 64px;
    border-style: dashed;
    opacity: 0.65;
    animation: orbit 22s linear infinite reverse;
}

.connection-line {
    position: absolute;
    width: min(62%, 410px);
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--theme-a), var(--theme-c), var(--theme-b));
    box-shadow: 0 0 28px var(--theme-glow);
    opacity: 0.72;
    transform: rotate(-10deg);
    transform-origin: center;
}

.avatar {
    position: absolute;
    z-index: 2;
    display: grid;
    width: 112px;
    height: 112px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.11);
    color: var(--ink);
    font-size: 2.4rem;
    font-weight: 950;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.22);
    transition: transform 220ms ease, background 220ms ease, color 220ms ease, box-shadow 220ms ease;
}

.avatar-one {
    left: 13%;
    top: 23%;
}

.avatar-two {
    right: 13%;
    bottom: 22%;
}

.orbit-scene.active .avatar-one {
    transform: translate(10px, 8px) rotate(-4deg);
    background: color-mix(in srgb, var(--theme-a), transparent 68%);
    color: #fff;
    box-shadow: 0 20px 55px var(--theme-glow);
}

.orbit-scene.active .avatar-two {
    transform: translate(-10px, -8px) rotate(4deg);
    background: color-mix(in srgb, var(--theme-b), transparent 68%);
    color: #fff;
    box-shadow: 0 20px 55px var(--theme-glow);
}

.center-symbol {
    position: relative;
    z-index: 3;
    display: grid;
    width: 96px;
    height: 96px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.26);
    border-radius: 50%;
    background:
        linear-gradient(145deg, var(--theme-a), var(--theme-b));
    color: #ffffff;
    font-size: 2.6rem;
    box-shadow: 0 22px 60px var(--theme-glow);
    transition: transform 240ms ease, background 240ms ease;
}

.orbit-scene.active .center-symbol {
    transform: scale(1.08);
    animation: heartbeat 1.1s ease-in-out infinite;
}

.flames-ring {
    position: absolute;
    width: min(74%, 420px);
    aspect-ratio: 1;
    border: 1px dashed var(--ring-color);
    border-radius: 50%;
    animation: orbit 18s linear infinite;
}

.flames-ring span {
    position: absolute;
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: var(--muted);
    font-weight: 950;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.16);
    animation: counter-orbit 18s linear infinite;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

.flames-ring span:nth-child(1) { top: -21px; left: calc(50% - 21px); }
.flames-ring span:nth-child(2) { top: 20%; right: 2%; }
.flames-ring span:nth-child(3) { right: 2%; bottom: 20%; }
.flames-ring span:nth-child(4) { bottom: -21px; left: calc(50% - 21px); }
.flames-ring span:nth-child(5) { left: 2%; bottom: 20%; }
.flames-ring span:nth-child(6) { top: 20%; left: 2%; }

.flames-ring span[data-letter="F"] { color: #84e8f2; }
.flames-ring span[data-letter="L"] { color: #ff9cbd; }
.flames-ring span[data-letter="A"] { color: #ffc2ea; }
.flames-ring span[data-letter="M"] { color: #ffe28a; }
.flames-ring span[data-letter="E"] { color: #ff9a4d; }
.flames-ring span[data-letter="S"] { color: #a99dff; }

.flames-ring span.active {
    background: linear-gradient(145deg, var(--theme-a), var(--theme-b));
    color: #ffffff;
    transform: scale(1.18);
    box-shadow: 0 12px 32px var(--theme-glow);
}

.live-card {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
}

.live-card h2 {
    font-size: 1.35rem;
    line-height: 1.2;
}

.theme-signal {
    display: inline-flex;
    width: fit-content;
    margin-top: 8px;
    padding: 6px 9px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--theme-c);
    font-size: 0.78rem;
    font-weight: 850;
}

.meter,
.result-meter {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
}

.meter span,
.result-meter span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--theme-a), var(--theme-c), var(--theme-b));
    box-shadow: 0 0 18px var(--theme-glow);
    transition: width 360ms ease, background 260ms ease;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.stat-grid div {
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
}

.stat-grid strong,
.stat-grid span {
    display: block;
}

.stat-grid strong {
    font-size: 1.28rem;
}

.stat-grid span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 750;
}

.control-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 22px;
    padding: 24px;
}

.panel-heading h2 {
    font-size: 2.15rem;
    line-height: 1.02;
}

.panel-heading p:last-child {
    max-width: 34rem;
    margin: 12px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.form {
    display: grid;
    gap: 18px;
}

.input-grid {
    display: grid;
    gap: 14px;
}

.input-group {
    display: grid;
    gap: 8px;
}

.input-group span {
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 820;
}

.input-group input {
    width: 100%;
    min-height: 54px;
    padding: 0 15px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.09);
    color: var(--ink);
    font-size: 1rem;
    outline: 0;
    transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease, background 180ms ease;
}

.input-group input::placeholder {
    color: rgba(255, 247, 251, 0.48);
}

.input-group input:focus {
    border-color: color-mix(in srgb, var(--theme-a), white 20%);
    background: rgba(255, 255, 255, 0.13);
    box-shadow: 0 0 0 4px var(--theme-glow);
    transform: translateY(-1px);
}

.name-tiles {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: center;
}

.name-tile {
    display: grid;
    min-width: 0;
    min-height: 92px;
    padding: 12px;
    place-items: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
    text-align: center;
}

.name-tile span {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--theme-a), var(--theme-b));
    color: #fff;
    font-weight: 950;
}

.name-tile strong {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.88rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.plus-mark {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    background: var(--theme-c);
    color: var(--theme-dark);
    font-weight: 950;
}

.btn-primary,
.btn-secondary {
    display: inline-flex;
    min-height: 54px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border-radius: var(--radius);
    font-weight: 850;
    letter-spacing: 0;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, opacity 180ms ease;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--theme-a), var(--theme-b));
    color: #ffffff;
    box-shadow: 0 18px 40px var(--theme-glow);
}

.btn-primary:hover:not(:disabled),
.btn-primary:focus-visible:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 24px 50px var(--theme-glow);
}

.btn-primary:disabled {
    cursor: not-allowed;
    opacity: 0.48;
    box-shadow: none;
}

.btn-icon {
    display: grid;
    width: 24px;
    height: 24px;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
}

.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-primary.loading .spinner {
    display: block;
}

.btn-primary.loading .btn-icon {
    display: none;
}

.meaning-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.meaning-strip span {
    min-width: 0;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 750;
}

.meaning-strip span[data-letter="F"] b { color: #84e8f2; }
.meaning-strip span[data-letter="L"] b { color: #ff9cbd; }
.meaning-strip span[data-letter="A"] b { color: #ffc2ea; }
.meaning-strip span[data-letter="M"] b { color: #ffe28a; }
.meaning-strip span[data-letter="E"] b { color: #ff9a4d; }
.meaning-strip span[data-letter="S"] b { color: #a99dff; }

.meaning-strip span.active {
    border-color: color-mix(in srgb, var(--theme-a), white 24%);
    background: linear-gradient(135deg, color-mix(in srgb, var(--theme-a), transparent 76%), rgba(255, 255, 255, 0.08));
    color: #fff;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        linear-gradient(135deg, rgba(0, 0, 0, 0.7), color-mix(in srgb, var(--theme-a), black 74%)),
        repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 30px);
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(13px);
    transition: opacity 180ms ease;
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    position: relative;
    width: min(440px, 100%);
    padding: 26px;
    border: 1px solid rgba(255, 255, 255, 0.26);
    border-radius: var(--radius);
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06)),
        color-mix(in srgb, var(--theme-dark), black 8%);
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.44), 0 0 70px var(--theme-glow);
    transform: translateY(14px) scale(0.98);
    transition: transform 200ms ease;
}

.modal.show .modal-content {
    transform: translateY(0) scale(1);
}

.close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.1);
    color: var(--muted);
    font-size: 1.35rem;
    cursor: pointer;
}

.close:hover,
.close:focus-visible {
    color: var(--ink);
}

.result-container {
    display: grid;
    gap: 14px;
    padding-top: 10px;
    text-align: center;
}

.result-emoji {
    font-size: 4.8rem;
    line-height: 1;
    filter: drop-shadow(0 14px 26px var(--theme-glow));
    animation: pop 480ms ease;
}

.result-theme {
    color: var(--theme-c);
}

.result-title {
    color: var(--theme-a);
    font-size: 2.1rem;
}

.result-title.friends,
.result-title.love,
.result-title.affection,
.result-title.marriage,
.result-title.enemies,
.result-title.soulmate {
    color: var(--theme-a);
}

.result-names {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--ink);
    font-weight: 850;
}

.result-names span:not(.plus) {
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-names .plus {
    color: var(--theme-c);
}

.result-description {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.btn-secondary {
    padding: 0 22px;
    border: 1px solid color-mix(in srgb, var(--theme-a), white 20%);
    background: linear-gradient(135deg, var(--theme-a), var(--theme-b));
    color: #ffffff;
}

.spark {
    position: fixed;
    z-index: 30;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--spark-color, var(--theme-a));
    pointer-events: none;
    animation: spark 760ms ease-out forwards;
}

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

@keyframes counter-orbit {
    to { transform: rotate(-360deg); }
}

@keyframes heartbeat {
    50% { transform: scale(1.14); }
}

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

@keyframes pop {
    0% { transform: scale(0.72); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes spark {
    to {
        opacity: 0;
        transform: translate(var(--spark-x), var(--spark-y)) scale(0.4);
    }
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 18px 0;
    }

    .visual-panel {
        min-height: auto;
    }

    .orbit-scene {
        min-height: 360px;
    }

    .control-panel {
        justify-content: flex-start;
    }
}

@media (max-width: 560px) {
    .app-shell {
        width: min(100vw - 20px, 1180px);
    }

    .visual-panel,
    .control-panel {
        padding: 16px;
    }

    .brand-row {
        grid-template-columns: auto 1fr;
    }

    .status-chip {
        grid-column: 1 / -1;
        width: 100%;
    }

    .orbit-scene {
        min-height: 300px;
    }

    .avatar {
        width: 82px;
        height: 82px;
        font-size: 1.8rem;
    }

    .center-symbol {
        width: 72px;
        height: 72px;
        font-size: 2rem;
    }

    .flames-ring span {
        width: 36px;
        height: 36px;
    }

    .panel-heading h2 {
        font-size: 1.72rem;
    }

    .stat-grid,
    .meaning-strip {
        grid-template-columns: 1fr 1fr;
    }

    .name-tiles {
        grid-template-columns: 1fr;
    }

    .plus-mark {
        justify-self: center;
    }
}
