/* ===== base (replaces the old pink theme; only what is still used) ===== */
        * { margin: 0; padding: 0; box-sizing: border-box; }
        button, input { font-family: inherit; }
        a { text-decoration: none; }

        @keyframes cardIn {
            from { transform: scale(.85) translateY(20px); opacity: 0; }
            to { transform: scale(1) translateY(0); opacity: 1; }
        }
        @keyframes heartbeat {
            0%, 100% { transform: scale(1); }
            14% { transform: scale(1.15); }
            28% { transform: scale(1); }
            42% { transform: scale(1.1); }
            56% { transform: scale(1); }
        }
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            20% { transform: translateX(-8px); }
            40% { transform: translateX(8px); }
            60% { transform: translateX(-6px); }
            80% { transform: translateX(6px); }
        }
        @keyframes float {
            0% { transform: translateY(0) scale(1); opacity: 1; }
            50% { transform: translateY(-400px) scale(1.2); opacity: .8; }
            100% { transform: translateY(-800px) scale(1); opacity: 0; }
        }
        @keyframes spin { to { transform: rotate(360deg); } }
        @keyframes shimmerBar { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

        .heart { position: fixed; bottom: -20px; color: red; animation: float 4s linear forwards; pointer-events: none; }

        .site-header { display: flex; justify-content: space-between; align-items: center; width: 100%; }
        .header-logo { display: flex; align-items: center; gap: 8px; font-weight: 700; }
        .header-socials { display: flex; }
        .header-socials a { font-size: 20px; transition: transform .3s, color .3s, background .3s; }
        #darkModeToggle .fa-sun { display: none; }
        body.dark-mode #darkModeToggle .fa-moon { display: none; }
        body.dark-mode #darkModeToggle .fa-sun { display: inline-block; }

        /* =====================================================================
           COSMIC THEME — Phase 1 (space background, story gate, memories world)
           Everything below overrides/extends the original styles above.
           ===================================================================== */
        :root {
            --ink: #f8efff;
            --ink-soft: #dccbf2;
            --pink: #ff7aa8;
            --pink-soft: #ffb3d1;
            --panel: rgba(24, 10, 50, .68);
            --panel-strong: rgba(34, 14, 68, .94);
            --line: rgba(255, 160, 205, .32);
        }

        html { background: #0b0620; }

        body {
            display: block;
            min-height: 100vh;
            min-height: 100dvh;
            overflow: hidden;
            color: var(--ink);
            font-family: 'Cairo', 'Inter', Arial, sans-serif;
        }
        /* the sky layers live behind the body, so the body itself must stay transparent (also in dark mode) */
        body, body.dark-mode { background: transparent !important; }

        body::before {
            content: "";
            position: fixed;
            inset: 0;
            z-index: -3;
            background:
                radial-gradient(70% 55% at 18% 12%, rgba(150, 80, 220, .55), transparent 70%),
                radial-gradient(60% 50% at 88% 78%, rgba(255, 80, 160, .32), transparent 72%),
                radial-gradient(90% 80% at 50% 45%, #2c1257 0%, #190b3b 55%, #0b0620 100%);
        }

        body::after {
            content: "";
            position: fixed;
            inset: -20%;
            z-index: -2;
            pointer-events: none;
            opacity: .55;
            background:
                radial-gradient(40% 30% at 30% 30%, rgba(190, 110, 255, .35), transparent 70%),
                radial-gradient(35% 28% at 70% 65%, rgba(255, 110, 190, .28), transparent 70%);
            filter: blur(30px);
            animation: nebula 70s ease-in-out infinite alternate;
        }

        @keyframes nebula {
            to { transform: translate3d(4%, 3%, 0) rotate(8deg) scale(1.08); }
        }

        body.dark-mode::before { filter: brightness(.72); }

        #sky {
            position: fixed;
            inset: 0;
            width: 100%;
            height: 100%;
            z-index: -1;
            pointer-events: none;
        }

        /* ---------- shared bits ---------- */
        .ubtn { all: unset; box-sizing: border-box; cursor: pointer; -webkit-tap-highlight-color: transparent; }

        #gate button:focus-visible, #app button:focus-visible, #modal button:focus-visible,
        #app a:focus-visible, #gate input:focus-visible {
            outline: 3px solid #ffd1e6;
            outline-offset: 3px;
        }

        .btn-main {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-height: 48px;
            padding: 12px 28px;
            border-radius: 16px;
            background: linear-gradient(135deg, #ff5c98, #b44bd6);
            color: #fff;
            font-size: 18px;
            font-weight: 700;
            box-shadow: 0 8px 26px rgba(255, 70, 150, .38);
            transition: transform .2s, box-shadow .2s, opacity .2s;
        }
        .btn-main:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 12px 32px rgba(255, 70, 150, .5); }
        .btn-main[disabled] { opacity: .6; cursor: progress; transform: none; }

        .heart { z-index: 40; }
        .nav-card.wide { grid-column: 1 / -1; min-height: 70px; flex-direction: row; gap: 12px; }
        .nav-card.wide i { font-size: 22px; }

        .burst {
            position: fixed;
            z-index: 10000;
            pointer-events: none;
            transform: translate(-50%, -50%);
            animation: burstOut 1s ease-out forwards;
        }
        @keyframes burstOut {
            to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.6); opacity: 0; }
        }

        /* ---------- glowing heart ---------- */
        .heart-stage {
            position: relative;
            display: grid;
            place-items: center;
            width: min(46vw, 200px);
            aspect-ratio: 1;
            transform: translate(calc(var(--px, 0) * 16px), calc(var(--py, 0) * 12px)) rotate(calc(var(--px, 0) * 5deg));
            -webkit-tap-highlight-color: transparent;
        }
        button.heart-stage { all: unset; box-sizing: border-box; cursor: pointer; position: relative; display: grid; place-items: center; width: min(46vw, 200px); aspect-ratio: 1; transform: translate(calc(var(--px, 0) * 16px), calc(var(--py, 0) * 12px)) rotate(calc(var(--px, 0) * 5deg)); }
        .heart-glow {
            position: absolute;
            inset: -48%;
            border-radius: 50%;
            background: radial-gradient(circle, rgba(255, 80, 150, .6), rgba(190, 70, 255, .28) 45%, transparent 70%);
            filter: blur(14px);
            opacity: calc(.5 + var(--glow, .35) * .5);
            transform: scale(calc(.85 + var(--glow, .35) * .4));
            animation: glowPulse 3.6s ease-in-out infinite;
            pointer-events: none;
        }
        @keyframes glowPulse { 50% { scale: 1.12; } }
        .heart-beat { position: relative; width: 100%; height: 100%; animation: heartbeat 2.4s ease-in-out infinite; }
        .heart-svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 0 18px rgba(255, 80, 150, .85)); }
        .heart-stage.pulse .heart-beat { animation: heartbeat .6s ease-out 2; }

        /* ---------- entry gate ---------- */
        #gate {
            position: fixed;
            inset: 0;
            z-index: 9999;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 18px;
            overflow-y: auto;
            direction: rtl;
            transition: opacity .8s ease, transform .8s ease, filter .8s ease;
        }
        #gate.leaving { opacity: 0; transform: scale(1.05); filter: blur(8px); pointer-events: none; }

        .gate-card {
            width: min(410px, 100%);
            margin: auto;
            padding: 30px 26px 26px;
            display: flex;
            flex-direction: column;
            align-items: stretch;
            gap: 14px;
            text-align: center;
            background: var(--panel);
            backdrop-filter: blur(18px);
            -webkit-backdrop-filter: blur(18px);
            border: 1.5px solid var(--line);
            border-radius: 28px;
            box-shadow: 0 24px 70px rgba(0, 0, 0, .5), 0 0 60px rgba(255, 90, 160, .16);
            animation: cardIn .7s cubic-bezier(.34, 1.56, .64, 1) both;
        }
        .gate-heart { width: 96px; margin: 4px auto 2px; }
        .gate-heart .heart-svg { filter: drop-shadow(0 0 12px rgba(255, 80, 150, .85)); }
        .gate-card.ok .gate-heart { animation: gateOk 1.3s ease forwards; }
        @keyframes gateOk { 40% { transform: scale(1.35); } 100% { transform: scale(1.15); } }
        .gate-card.ok { box-shadow: 0 24px 70px rgba(0, 0, 0, .5), 0 0 110px rgba(255, 90, 160, .55); transition: box-shadow .8s; }
        .gate-title { font-size: 28px; font-weight: 800; color: #fff; line-height: 1.3; }
        .gate-sub { font-size: 17px; line-height: 1.7; color: var(--ink-soft); }
        .gate-sub.jp { font-size: 14px; opacity: .85; }
        .gate-foot { font-size: 14px; color: var(--ink-soft); opacity: .8; direction: ltr; }
        .gfield { display: flex; flex-direction: column; gap: 6px; text-align: start; }
        .gfield label { font-size: 14px; font-weight: 600; color: var(--pink-soft); direction: ltr; text-align: center; }
        .gwrap { position: relative; }
        .gate-input {
            width: 100%;
            min-height: 50px;
            padding: 12px 48px;
            border: 2px solid rgba(255, 160, 205, .45);
            border-radius: 14px;
            background: rgba(10, 4, 28, .6);
            color: #fff;
            font: 600 18px 'Cairo', 'Inter', sans-serif;
            letter-spacing: 2px;
            text-align: center;
            transition: border-color .25s, box-shadow .25s;
        }
        .gate-input::placeholder { letter-spacing: 0; font-size: 15px; color: rgba(255, 200, 225, .55); }
        .gate-input:focus { outline: none; border-color: #ff7aa8; box-shadow: 0 0 0 4px rgba(255, 122, 168, .2); }
        .gate-input.shake { animation: shake .4s ease; border-color: #ff5c7c; }
        .eye { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); width: 38px; height: 38px; display: grid; place-items: center; color: var(--pink-soft); font-size: 17px; border-radius: 10px; }
        .gate-msg { min-height: 26px; font-size: 15px; font-weight: 600; line-height: 1.6; color: var(--ink-soft); }
        .gate-msg.err { color: #ffc2d1; }
        .gate-msg.ok { color: #ffe08a; font-size: 18px; }

        /* ---------- app shell ---------- */
        #app { position: fixed; inset: 0; opacity: 0; transition: opacity .9s ease; }
        #app[hidden] { display: none; }
        #app.show { opacity: 1; }

        #app .site-header {
            position: fixed;
            top: 0; left: 0;
            padding: 12px 18px;
            z-index: 30;
            background: linear-gradient(to bottom, rgba(11, 6, 32, .85), rgba(11, 6, 32, 0));
        }
        #app .header-logo { color: var(--pink-soft); font-size: 22px; }
        #app .header-socials { gap: 4px; }
        #app .header-socials a {
            width: 46px; height: 46px;
            display: inline-flex; align-items: center; justify-content: center;
            color: var(--pink-soft);
            border-radius: 50%;
        }
        #app .header-socials a:hover { color: #fff; background: rgba(255, 255, 255, .1); }

        .scene {
            position: absolute;
            inset: 0;
            padding: 84px 18px 36px;
            overflow-y: auto;
            direction: rtl;
            opacity: 0;
            visibility: hidden;
            transform: translateY(14px) scale(.99);
            filter: blur(6px);
            transition: opacity .55s ease, transform .55s ease, filter .55s ease, visibility 0s linear .55s;
            -webkit-overflow-scrolling: touch;
        }
        .scene.active { opacity: 1; visibility: visible; transform: none; filter: none; transition-delay: 0s; }
        .scene-inner { width: min(720px, 100%); margin: 0 auto; }
        .scene-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
        .scene-title { font-size: 28px; font-weight: 800; color: #fff; line-height: 1.3; }
        .scene-title:focus { outline: none; }
        .scene-sub { font-size: 16px; color: var(--ink-soft); margin-top: 2px; }
        .back-btn {
            flex-shrink: 0;
            width: 46px; height: 46px;
            display: grid; place-items: center;
            border-radius: 50%;
            background: var(--panel);
            border: 1.5px solid var(--line);
            color: #fff;
            font-size: 18px;
            transition: transform .2s, background .2s;
        }
        .back-btn:hover { transform: scale(1.08); background: rgba(255, 255, 255, .12); }

        /* home */
        .home { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding-bottom: 8px; }
        .home-heart { margin-bottom: 8px; }
        .name-title {
            font-size: clamp(48px, 13vw, 78px);
            font-weight: 800;
            line-height: 1.15;
            background: linear-gradient(90deg, #ffd6e8, #ff8fc0, #d8a6ff, #ffd6e8);
            background-size: 200% 100%;
            -webkit-background-clip: text; background-clip: text;
            color: transparent;
            filter: drop-shadow(0 0 16px rgba(255, 110, 180, .45));
            animation: nameIn 1.8s ease both, shimmer 9s linear 1.8s infinite;
        }
        .name-title:focus { outline: none; }
        @keyframes nameIn { from { opacity: 0; letter-spacing: .35em; filter: blur(10px); } }
        @keyframes shimmer { to { background-position: -200% 0; } }
        .name-sub { font-size: 18px; color: var(--ink-soft); letter-spacing: .08em; }
        .home-tag { font-size: 17px; color: var(--ink-soft); margin-top: 6px; }
        .nav-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: min(460px, 100%); margin-top: 8px; }
        .nav-card {
            display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
            min-height: 104px; padding: 14px 10px;
            border-radius: 22px;
            background: var(--panel);
            border: 1.5px solid var(--line);
            color: var(--ink);
            font-size: 18px; font-weight: 700;
            backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
            transition: transform .2s, border-color .2s, box-shadow .2s, background .2s;
        }
        .nav-card i { font-size: 26px; color: var(--pink-soft); }
        .nav-card:hover { transform: translateY(-4px); border-color: #ff8fc0; box-shadow: 0 10px 30px rgba(255, 90, 160, .25); background: rgba(50, 20, 95, .75); }

        /* story timeline */
        .timeline { list-style: none; position: relative; display: flex; flex-direction: column; gap: 14px; padding-right: 30px; }
        .timeline::before { content: ""; position: absolute; top: 6px; bottom: 6px; right: 9px; width: 3px; border-radius: 3px; background: linear-gradient(to bottom, #ff7aa8, #b46bff); opacity: .7; }
        .tl-item { position: relative; }
        .tl-item::before { content: ""; position: absolute; top: 22px; right: -29px; width: 15px; height: 15px; border-radius: 50%; background: #ff7aa8; box-shadow: 0 0 14px 3px rgba(255, 122, 168, .7); }
        .scene.active .tl-item { animation: rise .6s ease both; animation-delay: calc(var(--i, 0) * 80ms); }
        @keyframes rise { from { opacity: 0; transform: translateY(18px); } }
        .tl-card {
            display: block; width: 100%;
            padding: 14px 16px;
            border-radius: 20px;
            background: var(--panel);
            border: 1.5px solid var(--line);
            backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
            color: var(--ink);
            text-align: right;
            transition: border-color .2s, background .2s;
        }
        .tl-card:hover, .tl-item.open .tl-card { border-color: #ff8fc0; background: rgba(46, 18, 88, .78); }
        .tl-top { display: flex; align-items: center; gap: 10px; }
        .tl-emoji { font-size: 26px; }
        .tl-titles { flex: 1; min-width: 0; }
        .tl-date { display: block; font-size: 14px; color: var(--pink-soft); font-weight: 600; }
        .tl-title { display: block; font-size: 19px; font-weight: 700; color: #fff; }
        .tl-chev { color: var(--pink-soft); transition: transform .3s; }
        .tl-item.open .tl-chev { transform: rotate(180deg); }
        .tl-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .4s ease; }
        .tl-item.open .tl-body { grid-template-rows: 1fr; }
        .tl-body > div { overflow: hidden; }
        .tl-text { padding-top: 12px; font-size: 18px; line-height: 1.9; color: var(--ink); white-space: pre-line; }

        /* love letter envelope */
        .env { position: relative; width: min(430px, 90%); aspect-ratio: 4 / 3; margin: 26px auto 22px; perspective: 900px; filter: drop-shadow(0 18px 30px rgba(0, 0, 0, .5)); }
        .env-body { position: absolute; inset: 0; border-radius: 12px; overflow: hidden; background: linear-gradient(160deg, #ffa9c6, #ff7aa8); }
        .env-flap { position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: linear-gradient(180deg, #ff93b5, #ff7aa8); clip-path: polygon(0 0, 100% 0, 50% 60%); transform-origin: top; transition: transform 1s ease; z-index: 3; }
        .env.open .env-flap { transform: rotateX(180deg); z-index: 0; }
        .env-front { position: absolute; inset: 0; background: linear-gradient(160deg, #ff8fb4, #ee6a9a); clip-path: polygon(0 100%, 0 38%, 50% 66%, 100% 38%, 100% 100%); z-index: 2; }
        .env-letter {
            position: absolute; left: 7.5%; bottom: -100%;
            width: 85%; height: 85%;
            padding: 12px 14px;
            overflow-y: auto;
            border-radius: 8px;
            background: #fff8fb;
            color: #4a1735;
            direction: rtl; text-align: center;
            font-size: clamp(15px, 4.1vw, 20px); font-weight: 700; line-height: 1.7;
            opacity: 0;
            transition: bottom 1s ease, opacity 1s ease;
            z-index: 1;
            display: flex; align-items: flex-start; justify-content: center;
        }
        .env-letter p { margin: auto 0; }
        .env.open .env-letter { bottom: 6%; opacity: 1; z-index: 4; }
        .env-actions { display: flex; justify-content: center; }
        .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

        /* "open me when..." */
        .ow-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
        .ow-card {
            position: relative;
            display: flex; flex-direction: column; align-items: center; gap: 8px;
            min-height: 140px; padding: 16px 12px;
            border-radius: 22px;
            background: var(--panel);
            border: 1.5px solid var(--line);
            backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
            text-align: center; color: var(--ink);
            transition: transform .2s, border-color .2s, box-shadow .2s;
        }
        .ow-card:hover { transform: translateY(-4px) rotate(-1deg); border-color: #ff8fc0; box-shadow: 0 10px 28px rgba(255, 90, 160, .25); }
        .ow-card .ow-ic { font-size: 28px; color: var(--pink-soft); }
        .ow-card .ow-emoji { font-size: 30px; }
        .ow-card .ow-label { font-size: 17px; font-weight: 700; line-height: 1.5; }
        .ow-card .ow-badge { position: absolute; top: 10px; left: 10px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: rgba(255, 224, 138, .18); color: #ffe08a; display: none; }
        .ow-card.seen .ow-badge { display: inline-block; }
        .ow-card.seen { border-color: rgba(255, 224, 138, .5); }

        /* tappable stars */
        .sky-zone { position: relative; width: 100%; height: clamp(340px, calc(100dvh - 230px), 560px); margin-top: 6px; }
        .wish {
            position: absolute;
            width: 52px; height: 52px;
            margin: -26px 0 0 -26px;
            display: grid; place-items: center;
            border-radius: 50%;
            color: #ffe9a8;
            font-size: 28px;
            text-shadow: 0 0 14px rgba(255, 220, 130, .95), 0 0 30px rgba(255, 190, 90, .6);
            animation: twinkle 3.4s ease-in-out infinite;
            animation-delay: var(--d, 0s);
            transition: color .3s;
        }
        @keyframes twinkle { 0%, 100% { scale: 1; opacity: .85; } 50% { scale: 1.25; opacity: 1; } }
        .wish:hover { scale: 1.35; }
        .wish.seen { color: #ff9ec6; text-shadow: 0 0 14px rgba(255, 120, 180, .85); }
        .sky-count { font-size: 16px; font-weight: 700; color: #ffe08a; }

        /* memory / message modal */
        .modal {
            position: fixed; inset: 0; z-index: 10001;
            display: grid; place-items: center;
            padding: 18px;
            background: rgba(8, 3, 22, .74);
            backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
            opacity: 0; visibility: hidden;
            transition: opacity .35s ease, visibility 0s linear .35s;
        }
        .modal.open { opacity: 1; visibility: visible; transition-delay: 0s; }
        .modal-card {
            position: relative;
            width: min(430px, 100%);
            max-height: 86dvh; overflow-y: auto;
            padding: 34px 24px 26px;
            text-align: center; direction: rtl;
            border-radius: 28px;
            background: linear-gradient(160deg, rgba(66, 26, 108, .97), rgba(30, 12, 62, .97));
            border: 1.5px solid var(--line);
            box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 70px rgba(255, 90, 160, .2);
            transform: translateY(26px) scale(.93);
            transition: transform .45s cubic-bezier(.34, 1.4, .64, 1);
        }
        .modal.open .modal-card { transform: none; }
        .modal-close { position: absolute; top: 12px; left: 12px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: #fff; font-size: 18px; background: rgba(255, 255, 255, .08); }
        .modal-close:hover { background: rgba(255, 255, 255, .18); }
        #m-emoji { font-size: 48px; line-height: 1.2; }
        #m-meta { font-size: 14px; color: var(--pink-soft); font-weight: 600; margin-top: 4px; }
        #m-title { font-size: 24px; font-weight: 800; color: #fff; margin: 6px 0 12px; line-height: 1.4; }
        #m-title:empty { display: none; }
        .m-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }
        .m-actions:empty { display: none; }
        .btn-soft { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 20px; border-radius: 14px; background: rgba(255,255,255,.1); border: 1.5px solid var(--line); color: #fff; font-size: 16px; font-weight: 700; transition: background .2s, transform .2s; }
        .btn-soft:hover { background: rgba(255,255,255,.18); transform: translateY(-2px); }
        #m-text { font-size: 19px; line-height: 2; color: var(--ink); white-space: pre-line; }

        @media only screen and (max-width: 480px) {
            #app .site-header { padding: 8px 10px; }
            #app .header-logo { font-size: 19px; }
            .scene { padding: 76px 14px 30px; }
            .scene-title { font-size: 24px; }
            .gate-card { padding: 26px 20px 22px; }
        }

        @media (prefers-reduced-motion: reduce) {
            *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
            .scene { filter: none; transform: none; }
        }

        /* =====================================================================
           WORLD (planets + achievements), GIFT of the visit, TOAST, MEMORY GAME
           ===================================================================== */
        .visit-line { font-size: 15px; color: var(--ink-soft); opacity: .85; margin-top: -4px; }

        .gift-btn {
            display: flex; align-items: center; gap: 14px;
            width: min(460px, 100%); min-height: 72px; padding: 12px 18px; margin-top: 6px;
            border-radius: 22px; text-align: right; color: #fff; cursor: pointer;
            background: linear-gradient(135deg, rgba(255, 92, 152, .92), rgba(140, 70, 220, .92));
            border: 1.5px solid rgba(255, 255, 255, .35);
            box-shadow: 0 10px 32px rgba(255, 70, 150, .4);
            transition: transform .2s, box-shadow .2s;
            animation: giftPulse 2.6s ease-in-out infinite;
            -webkit-tap-highlight-color: transparent;
        }
        .gift-btn[hidden] { display: none; }
        .gift-btn:hover { transform: translateY(-3px); }
        .gift-btn.opened { animation: none; background: var(--panel); border-color: var(--line); box-shadow: none; }
        .gift-ic { font-size: 34px; line-height: 1; }
        .gift-txt { display: flex; flex-direction: column; gap: 2px; }
        #gift-label { font-size: 19px; font-weight: 800; }
        #gift-sub { font-size: 14px; opacity: .92; }
        @keyframes giftPulse { 50% { box-shadow: 0 10px 46px rgba(255, 90, 170, .75); transform: scale(1.015); } }

        .nav-card { position: relative; }
        .badge-new { position: absolute; top: 8px; left: 10px; padding: 2px 10px; border-radius: 999px; background: #ffe08a; color: #3b1d00; font-size: 12px; font-weight: 800; }
        .badge-new[hidden] { display: none; }
        .nav-card { min-height: 92px; }

        /* ---------- toast ---------- */
        .toast {
            position: fixed; top: 12px; left: 50%; z-index: 10005;
            width: min(430px, calc(100vw - 24px));
            display: flex; align-items: center; gap: 12px;
            padding: 12px 14px; border-radius: 20px; direction: rtl; color: var(--ink);
            background: var(--panel-strong); border: 1.5px solid rgba(255, 224, 138, .7);
            box-shadow: 0 18px 50px rgba(0, 0, 0, .55), 0 0 40px rgba(255, 200, 100, .2);
            transform: translate(-50%, -170%); opacity: 0; pointer-events: none;
            transition: transform .45s cubic-bezier(.34, 1.4, .64, 1), opacity .3s;
        }
        .toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
        .toast-emoji { font-size: 30px; line-height: 1; }
        .toast-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
        .toast-title { font-size: 13px; color: #ffe08a; font-weight: 800; }
        .toast-text { font-size: 17px; font-weight: 700; color: #fff; }
        .toast-go { min-height: 40px; padding: 6px 14px; border-radius: 12px; background: linear-gradient(135deg, #ff5c98, #b44bd6); color: #fff; font-weight: 800; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; }
        .toast-go[hidden] { display: none; }
        .toast-x { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-soft); font-size: 16px; cursor: pointer; }
        .toast button:focus-visible { outline: 3px solid #ffd1e6; outline-offset: 2px; }

        /* ---------- world map ---------- */
        .world-map { position: relative; width: 100%; height: clamp(640px, 86dvh, 780px); margin: 4px 0 40px; }
        .world-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
        .world-lines line { stroke: rgba(255, 255, 255, .2); stroke-width: 1.5; stroke-dasharray: 3 6; vector-effect: non-scaling-stroke; }
        .world-lines line.on { stroke: rgba(255, 150, 200, .8); }

        .planet {
            position: absolute; transform: translate(-50%, -42%);
            display: flex; flex-direction: column; align-items: center; gap: 6px;
            min-width: 76px; padding: 4px; border-radius: 18px; color: var(--ink);
            cursor: pointer; -webkit-tap-highlight-color: transparent;
        }
        .pl-orb {
            position: relative; width: var(--sz, 62px); height: var(--sz, 62px); border-radius: 50%;
            display: grid; place-items: center; font-size: calc(var(--sz, 62px) * .46); line-height: 1;
            background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .65), rgba(255, 255, 255, 0) 38%), linear-gradient(145deg, var(--c1, #ffc2dd), var(--c2, #7d4bd8));
            box-shadow: 0 0 26px rgba(255, 150, 210, .45), inset -6px -8px 14px rgba(0, 0, 0, .28);
            animation: orbFloat 6s ease-in-out infinite; animation-delay: var(--fd, 0s);
            transition: transform .25s;
        }
        @keyframes orbFloat { 50% { transform: translateY(-7px); } }
        .planet:hover .pl-orb { scale: 1.08; }
        .pl-orb.ring::after { content: ""; position: absolute; left: -22%; right: -22%; top: 40%; height: 24%; border: 3px solid rgba(255, 255, 255, .55); border-radius: 50%; transform: rotate(-18deg); pointer-events: none; }
        .pl-name { font-size: 14px; font-weight: 700; text-align: center; line-height: 1.3; max-width: 112px; text-shadow: 0 1px 8px rgba(0, 0, 0, .8); }
        .pl-new { position: absolute; top: -8px; right: -14px; padding: 1px 8px; border-radius: 999px; background: #ffe08a; color: #3b1d00; font-size: 11px; font-weight: 800; font-family: inherit; }
        .planet:not(.fresh) .pl-new { display: none; }
        .planet.fresh .pl-orb { animation: orbFloat 6s ease-in-out infinite, freshGlow 1.8s ease-in-out infinite; animation-delay: var(--fd, 0s), 0s; }
        @keyframes freshGlow { 50% { box-shadow: 0 0 0 9px rgba(255, 224, 138, .25), 0 0 44px rgba(255, 224, 138, .85), inset -6px -8px 14px rgba(0, 0, 0, .28); } }
        .planet.locked .pl-orb {
            background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0) 40%), linear-gradient(145deg, #4b4366, #231b3d);
            box-shadow: inset -6px -8px 14px rgba(0, 0, 0, .45); filter: saturate(.6);
        }
        .planet.locked .pl-name { opacity: .78; }

        .world-actions { display: flex; justify-content: center; margin-top: 4px; }
        .sec-title { display: flex; align-items: baseline; gap: 8px; margin: 26px 0 12px; font-size: 22px; font-weight: 800; color: #fff; }
        .sec-title small { font-size: 15px; color: #ffe08a; font-weight: 700; }

        /* ---------- achievements ---------- */
        .ach-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
        .ach { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 18px; background: var(--panel); border: 1.5px solid var(--line); opacity: .8; }
        .ach.done { opacity: 1; border-color: rgba(255, 224, 138, .6); background: linear-gradient(135deg, rgba(70, 40, 110, .8), rgba(40, 18, 80, .8)); }
        .ach-ic { font-size: 28px; width: 40px; text-align: center; line-height: 1; }
        .ach-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
        .ach-title { font-weight: 800; font-size: 17px; color: #fff; }
        .ach-desc { font-size: 14px; color: var(--ink-soft); line-height: 1.5; }
        .ach-bar { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .12); overflow: hidden; margin-top: 4px; }
        .ach-bar span { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #ff7aa8, #ffe08a); transition: width .6s ease; }
        .ach-num { min-width: 40px; text-align: center; font-size: 15px; font-weight: 800; color: var(--ink-soft); }
        .ach.done .ach-num { color: #ffe08a; font-size: 20px; }

        /* ---------- memory game ---------- */
        .game-card h3 { font-size: 24px; font-weight: 800; color: #fff; }
        .g-sub { font-size: 16px; color: var(--ink-soft); margin: 4px 0 14px; }
        .g-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; direction: ltr; }
        .g-card {
            position: relative; display: block; aspect-ratio: 1; border-radius: 14px; cursor: pointer;
            background: linear-gradient(145deg, #5a2fa6, #2a1360); border: 1.5px solid var(--line); color: #fff;
            font-size: clamp(24px, 8vw, 34px); transform-style: preserve-3d; transition: transform .45s;
            -webkit-tap-highlight-color: transparent;
        }
        .g-back, .g-face { position: absolute; inset: 0; display: grid; place-items: center; border-radius: inherit; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
        .g-back { color: rgba(255, 200, 230, .7); font-size: 22px; }
        .g-face { transform: rotateY(180deg); background: linear-gradient(145deg, #fff3fa, #ffd1e6); }
        .g-card.up, .g-card.matched { transform: rotateY(180deg); }
        .g-card.matched .g-face { background: linear-gradient(145deg, #ffe9a8, #ffb3d1); box-shadow: 0 0 18px rgba(255, 224, 138, .7); }
        .g-card.matched { cursor: default; }
        .g-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; font-weight: 700; color: var(--ink); }
        #g-result { min-height: 28px; margin-top: 10px; font-size: 18px; font-weight: 800; color: #ffe08a; }
        #g-result-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
        #g-result-actions:empty { display: none; }
        @media (prefers-reduced-motion: reduce) {
            .g-card, .g-card.up, .g-card.matched { transform: none; transition: none; }
            .g-back, .g-face { backface-visibility: visible; -webkit-backface-visibility: visible; }
            .g-face { transform: none; }
            .g-card:not(.up):not(.matched) .g-face { opacity: 0; }
            .g-card.up .g-back, .g-card.matched .g-back { opacity: 0; }
            .pl-orb, .planet.fresh .pl-orb, .gift-btn { animation: none !important; }
        }

        /* ---------- images inside dialogs / timeline ---------- */
        #m-img { display: block; max-width: 100%; max-height: 46dvh; margin: 12px auto 4px; border-radius: 16px; }
        #m-img[hidden] { display: none; }
        .tl-img { display: block; max-width: 100%; border-radius: 14px; margin-top: 12px; }
        .tl-item.seen .tl-date::after { content: ' ✓'; color: #ffe08a; }

        @media (max-height: 760px) {
            .home .heart-stage { width: min(34vw, 130px); }
        }

        /* =====================================================================
           LIVE SCENE (sky follows the time of day + mood) and SECRET ADVENTURE
           Night is the base look. html[data-tod] = dawn | morning | afternoon | evening | night
           html[data-mood] = calm | playful | warm | cheer (only changes the two glows).
           ===================================================================== */
        @property --sk1 { syntax: '<color>'; inherits: true; initial-value: rgba(150, 80, 220, .55); }
        @property --sk2 { syntax: '<color>'; inherits: true; initial-value: rgba(255, 80, 160, .32); }
        @property --sk3 { syntax: '<color>'; inherits: true; initial-value: #2c1257; }
        @property --sk4 { syntax: '<color>'; inherits: true; initial-value: #190b3b; }
        @property --sk5 { syntax: '<color>'; inherits: true; initial-value: #0b0620; }

        html {
            --sk1: rgba(150, 80, 220, .55); --sk2: rgba(255, 80, 160, .32);
            --sk3: #2c1257; --sk4: #190b3b; --sk5: #0b0620;
            --cx: 78%; --cy: 14%; --cs: 74px; --cc1: #fffdf2; --cc2: #cfc8ff; --cg: rgba(205, 195, 255, .45); --co: .95;
            transition: --sk1 2.5s ease, --sk2 2.5s ease, --sk3 2.5s ease, --sk4 2.5s ease, --sk5 2.5s ease;
        }
        html[data-tod="dawn"] {
            --sk1: rgba(255, 150, 120, .5); --sk2: rgba(255, 120, 190, .36);
            --sk3: #5a2d7a; --sk4: #34194f; --sk5: #170a30;
            --cx: 80%; --cy: 68%; --cs: 84px; --cc1: #fff1d6; --cc2: #ffb48a; --cg: rgba(255, 170, 120, .55); --co: .9;
        }
        html[data-tod="morning"] {
            --sk1: rgba(255, 190, 140, .45); --sk2: rgba(120, 190, 255, .38);
            --sk3: #4a4aa0; --sk4: #2e2a78; --sk5: #1b1650;
            --cx: 72%; --cy: 22%; --cs: 82px; --cc1: #fffbe0; --cc2: #ffd36a; --cg: rgba(255, 215, 120, .6); --co: .95;
        }
        html[data-tod="afternoon"] {
            --sk1: rgba(255, 210, 150, .4); --sk2: rgba(110, 170, 255, .42);
            --sk3: #3f56a8; --sk4: #2b3a86; --sk5: #1a2260;
            --cx: 42%; --cy: 9%; --cs: 78px; --cc1: #ffffff; --cc2: #ffe28a; --cg: rgba(255, 235, 150, .6); --co: .95;
        }
        html[data-tod="evening"] {
            --sk1: rgba(255, 130, 90, .55); --sk2: rgba(220, 70, 160, .42);
            --sk3: #6a2a6e; --sk4: #3a1655; --sk5: #1a0838;
            --cx: 22%; --cy: 62%; --cs: 108px; --cc1: #ffe0b0; --cc2: #ff7a4a; --cg: rgba(255, 110, 70, .6); --co: .92;
        }
        html[data-mood="calm"]    { --sk1: rgba(80, 150, 220, .5);  --sk2: rgba(60, 200, 190, .28); }
        html[data-mood="playful"] { --sk1: rgba(255, 200, 80, .5);  --sk2: rgba(255, 90, 170, .45); }
        html[data-mood="warm"]    { --sk1: rgba(255, 100, 130, .55); --sk2: rgba(255, 150, 100, .4); }
        html[data-mood="cheer"]   { --sk1: rgba(255, 215, 100, .5); --sk2: rgba(140, 220, 160, .3); }

        body::before {
            background:
                radial-gradient(70% 55% at 18% 12%, var(--sk1), transparent 70%),
                radial-gradient(60% 50% at 88% 78%, var(--sk2), transparent 72%),
                radial-gradient(90% 80% at 50% 45%, var(--sk3) 0%, var(--sk4) 55%, var(--sk5) 100%);
        }

        /* the sun / moon */
        #celestial {
            position: fixed; z-index: -2; pointer-events: none;
            left: var(--cx); top: var(--cy);
            width: var(--cs); height: var(--cs);
            margin: calc(var(--cs) / -2) 0 0 calc(var(--cs) / -2);
            transition: left 3s ease, top 3s ease, width 3s ease, height 3s ease, margin 3s ease, opacity 1.5s ease;
            opacity: var(--co);
        }
        .cel-body {
            display: block; width: 100%; height: 100%; border-radius: 50%;
            background:
                radial-gradient(circle at 34% 30%, rgba(255, 255, 255, .55), transparent 38%),
                radial-gradient(circle at 70% 70%, rgba(0, 0, 0, .12), transparent 45%),
                radial-gradient(circle at 50% 50%, var(--cc1), var(--cc2) 72%);
            box-shadow: 0 0 calc(var(--cs) * .5) var(--cg), 0 0 calc(var(--cs) * 1.4) var(--cg);
            animation: celGlow 7s ease-in-out infinite alternate;
        }
        html[data-tod="night"] .cel-body {
            background:
                radial-gradient(circle at 30% 34%, rgba(150, 140, 200, .35) 0 9%, transparent 10%),
                radial-gradient(circle at 62% 58%, rgba(150, 140, 200, .3) 0 13%, transparent 14%),
                radial-gradient(circle at 46% 78%, rgba(150, 140, 200, .28) 0 6%, transparent 7%),
                radial-gradient(circle at 36% 30%, var(--cc1), var(--cc2) 85%);
        }
        @keyframes celGlow { to { filter: brightness(1.12); transform: scale(1.04); } }

        /* ---------- home: greeting + mood ---------- */
        .live-greet { max-width: 440px; font-size: 18px; line-height: 1.9; font-weight: 600; color: var(--ink); margin-top: -2px; }
        .live-greet[hidden], .mood-box[hidden], .mood-card[hidden] { display: none; }
        .mood-box { width: min(460px, 100%); display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 4px; }
        .mood-q { font-size: 16px; color: var(--ink-soft); }
        .mood-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
        .mood-chip {
            display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 14px;
            border-radius: 999px; font-size: 15px; font-weight: 700; color: #fff;
            background: rgba(255, 255, 255, .1); border: 1.5px solid var(--line);
            transition: background .2s, transform .2s, border-color .2s;
        }
        .mood-chip:hover { background: rgba(255, 255, 255, .18); transform: translateY(-2px); }
        .mood-chip[aria-pressed="true"] { background: linear-gradient(135deg, rgba(255, 92, 152, .85), rgba(140, 70, 220, .85)); border-color: rgba(255, 255, 255, .5); }
        .mood-card { width: 100%; padding: 16px 16px 14px; border-radius: 20px; background: var(--panel); border: 1.5px solid var(--line); animation: moodIn .45s ease both; }
        .mood-text { font-size: 18px; line-height: 2; color: var(--ink); white-space: pre-line; }
        .mood-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }
        .mood-actions .btn-soft { min-height: 44px; padding: 8px 14px; font-size: 15px; }
        @keyframes moodIn { from { opacity: 0; transform: translateY(8px); } }

        /* ---------- secret adventure ---------- */
        .adv-card { width: min(470px, 100%); }
        #adv-emoji { font-size: 44px; line-height: 1.2; }
        #adv-title { font-size: 24px; font-weight: 800; color: #fff; margin: 4px 0 10px; }
        .adv-steps { list-style: none; margin: 0 0 14px; padding: 0; display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; }
        .adv-dot {
            width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
            font-size: 18px; font-weight: 800; color: #fff;
            background: rgba(255, 255, 255, .08); border: 1.5px solid var(--line);
        }
        .adv-dot.done { background: rgba(255, 150, 200, .3); border-color: rgba(255, 190, 220, .7); }
        .adv-dot.now { background: linear-gradient(135deg, rgba(255, 92, 152, .9), rgba(140, 70, 220, .9)); border-color: #fff; box-shadow: 0 0 18px rgba(255, 110, 180, .6); }
        .adv-dot.locked { opacity: .45; cursor: default; }
        .adv-dot.view { outline: 2.5px solid #ffe08a; outline-offset: 2px; }
        .adv-intro, .adv-story { font-size: 17px; line-height: 2; color: var(--ink-soft); white-space: pre-line; }
        .adv-intro:empty, .adv-story:empty { display: none; }
        .adv-riddle { font-size: 21px; line-height: 1.9; font-weight: 800; color: #fff; margin: 10px 0 14px; white-space: pre-line; }
        #adv-form { display: flex; gap: 8px; align-items: stretch; }
        #adv-form[hidden], #adv-hint[hidden], #live-greet[hidden] { display: none; }
        .adv-input {
            flex: 1; min-width: 0; min-height: 50px; padding: 8px 14px; border-radius: 14px;
            font: inherit; font-size: 18px; color: #fff; text-align: center;
            background: rgba(255, 255, 255, .1); border: 1.5px solid var(--line); outline: none;
        }
        .adv-input:focus { border-color: #ffb3d1; box-shadow: 0 0 0 3px rgba(255, 150, 200, .3); }
        .adv-input::placeholder { color: rgba(255, 255, 255, .5); }
        .adv-input.shake { animation: advShake .4s; }
        @keyframes advShake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
        #adv-form .btn-main { min-height: 50px; padding: 0 20px; }
        #adv-msg { min-height: 30px; margin-top: 8px; font-size: 16px; font-weight: 700; color: #ffd3a8; }
        #adv-msg.good { color: #b8ffcf; }
        .adv-hints { list-style: none; margin: 4px 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: right; }
        .adv-hints:empty { display: none; }
        .adv-hints li { padding: 8px 12px; border-radius: 12px; background: rgba(255, 224, 138, .12); border: 1px solid rgba(255, 224, 138, .35); font-size: 16px; line-height: 1.7; }
        #adv-hint.nudge { animation: giftPulse 1.8s ease-in-out infinite; border-color: #ffe08a; }
        #adv-hint[disabled] { opacity: .55; cursor: default; }
        #adv-reward { margin-top: 6px; padding: 16px; border-radius: 20px; background: rgba(255, 255, 255, .07); border: 1.5px solid var(--line); animation: moodIn .5s ease both; }
        #adv-reward[hidden], #adv-puzzle[hidden] { display: none; }
        #adv-r-title { font-size: 20px; font-weight: 800; color: #ffe08a; margin: 0 0 8px; }
        #adv-r-img { display: block; max-width: 100%; max-height: 44dvh; margin: 6px auto 10px; border-radius: 16px; }
        #adv-r-img[hidden] { display: none; }
        #adv-r-text { font-size: 18px; line-height: 2; color: var(--ink); white-space: pre-line; }
        #adv-actions:empty { display: none; }

        .world-actions { flex-wrap: wrap; gap: 10px; }

        @media (prefers-reduced-motion: reduce) {
            html { transition: none; }
            #celestial { transition: none; }
            .cel-body, .mood-card, #adv-reward, #adv-hint.nudge { animation: none !important; }
        }

        /* ---------- app mode: install / alerts / offline ---------- */
        .app-row { display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(460px, 100%); margin-top: 6px; }
        .app-row[hidden], .app-row [hidden] { display: none; }
        .app-row .btn-soft { min-height: 46px; width: 100%; font-size: 15px; }
        .app-row .btn-soft[disabled] { opacity: .55; cursor: default; }
        .app-note { font-size: 13px; color: var(--ink-soft); opacity: .85; line-height: 1.7; }
        .net-pill {
            position: fixed; z-index: 10002; left: 50%; bottom: 14px; transform: translateX(-50%);
            max-width: calc(100% - 24px); padding: 9px 16px; border-radius: 999px; text-align: center;
            font-size: 14px; font-weight: 700; color: #fff; background: rgba(60, 20, 90, .95);
            border: 1.5px solid rgba(255, 190, 220, .6); box-shadow: 0 8px 26px rgba(0, 0, 0, .45);
        }
        .net-pill[hidden] { display: none; }

        /* =====================================================================
           CHAT — own vs Hager bubbles, status, banners, images, archive
           ===================================================================== */
        #chat-overlay {
            position: fixed; inset: 0; z-index: 9998;
            display: none; align-items: center; justify-content: center;
            padding: 12px;
            background: rgba(8, 3, 22, .62);
            backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
        }
        #chat-overlay.visible { display: flex; }

        .chat-card {
            display: none;
            direction: rtl;
            background: var(--panel-strong);
            border: 1.5px solid var(--line);
            border-radius: 26px;
            box-shadow: 0 30px 80px rgba(0, 0, 0, .6), 0 0 60px rgba(255, 90, 160, .14);
            color: var(--ink);
            animation: cardIn .4s cubic-bezier(.34, 1.56, .64, 1) both;
        }
        .chat-card.visible { display: flex; }

        #chat-window, #archive-window, #archive-detail-window {
            flex-direction: column;
            width: min(440px, 100%);
            height: min(660px, calc(100dvh - 24px));
            overflow: hidden;
            position: relative;
        }

        #chat-blocked-screen, #identity-card {
            flex-direction: column; align-items: center; gap: 16px;
            padding: 36px 30px; width: min(340px, 92vw); text-align: center;
        }
        .id-icon { font-size: 50px; animation: heartbeat 1.6s ease-in-out infinite; }
        .id-hint { font-size: 19px; font-weight: 700; line-height: 1.7; color: var(--ink); }
        .chat-name-options { display: flex; flex-direction: column; gap: 12px; width: 100%; }
        .name-btn {
            min-height: 50px; padding: 12px; border: none; border-radius: 14px; cursor: pointer;
            background: linear-gradient(135deg, #ff5c98, #b44bd6); color: #fff;
            font-size: 17px; font-weight: 700; box-shadow: 0 6px 18px rgba(255, 77, 140, .35);
            transition: transform .2s;
        }
        .name-btn:hover { transform: scale(1.03); }
        #identity-overlay {
            position: fixed; inset: 0; z-index: 9997;
            display: none; align-items: center; justify-content: center;
            background: rgba(8, 3, 22, .7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
        }
        #identity-overlay.visible { display: flex; }

        /* header */
        .chat-header {
            display: flex; align-items: center; justify-content: space-between; gap: 8px;
            padding: 10px 12px 10px 10px;
            background: linear-gradient(135deg, #6f35c9, #d6478f);
            color: #fff;
        }
        .chat-title-wrap { display: flex; flex-direction: column; min-width: 0; padding-inline-start: 6px; }
        .chat-title { font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .chat-status { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .92; }
        .chat-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #5df2a0; box-shadow: 0 0 8px #5df2a0; }
        .chat-status.connecting::before { background: #ffd166; box-shadow: 0 0 8px #ffd166; animation: pulseDot 1.2s infinite; }
        .chat-status.offline::before { background: #ff6b81; box-shadow: 0 0 8px #ff6b81; }
        @keyframes pulseDot { 50% { opacity: .35; } }
        .chat-header-actions { display: flex; align-items: center; gap: 2px; }
        .hbtn {
            width: 42px; height: 42px; display: grid; place-items: center;
            border: none; border-radius: 50%; background: none; color: #fff;
            font-size: 16px; cursor: pointer; transition: background .2s;
        }
        .hbtn:hover { background: rgba(255, 255, 255, .18); }
        .hbtn[disabled] { opacity: .5; cursor: progress; }

        #chat-window button:focus-visible, #archive-window button:focus-visible, #archive-detail-window button:focus-visible,
        #lightbox button:focus-visible, #identity-card button:focus-visible, #chat-input:focus-visible {
            outline: 3px solid #ffd1e6; outline-offset: 2px;
        }

        /* connection / error banner */
        .conn-banner {
            display: none; align-items: center; gap: 10px;
            padding: 8px 14px; font-size: 14px; font-weight: 600; line-height: 1.5;
        }
        .conn-banner.show { display: flex; }
        .conn-banner.offline { background: #5a3b00; color: #ffe2a0; }
        .conn-banner.error { background: #5d1530; color: #ffc2d1; }
        .conn-banner.ok { background: #0f4a36; color: #b6f5d6; }
        .conn-banner span { flex: 1; }
        .conn-banner button { border: 1.5px solid currentColor; background: none; color: inherit; border-radius: 10px; padding: 4px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }

        /* message area */
        #chat-scroll {
            position: relative; flex: 1; overflow-y: auto; overscroll-behavior: contain;
            padding: 12px 12px 6px;
            background: rgba(10, 4, 28, .55);
            scrollbar-width: thin; scrollbar-color: #7a4a8c transparent;
        }
        #chat-scroll::-webkit-scrollbar { width: 7px; }
        #chat-scroll::-webkit-scrollbar-thumb { background: #7a4a8c; border-radius: 10px; }
        #chat-messages { display: flex; flex-direction: column; gap: 2px; }

        #chat-older { text-align: center; font-size: 13px; color: var(--ink-soft); padding: 4px 0 10px; min-height: 8px; }
        #chat-older button { background: rgba(255, 255, 255, .1); border: 1.5px solid var(--line); color: #fff; border-radius: 999px; padding: 6px 16px; font-size: 13px; font-weight: 700; cursor: pointer; }
        .spinner { display: inline-block; width: 16px; height: 16px; border: 2.5px solid rgba(255, 255, 255, .3); border-top-color: #ff9bc0; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-inline-end: 8px; }

        #chat-skeleton { display: none; flex-direction: column; gap: 14px; padding-top: 8px; }
        #chat-skeleton.show { display: flex; }
        .sk { height: 42px; width: 62%; border-radius: 18px; background: linear-gradient(90deg, rgba(255,255,255,.06) 25%, rgba(255,255,255,.16) 50%, rgba(255,255,255,.06) 75%); background-size: 200% 100%; animation: shimmerBar 1.6s linear infinite; }
        .sk.me { align-self: flex-start; }
        .sk.them { align-self: flex-end; width: 50%; }
        .sk.tall { height: 64px; }

        #chat-empty { display: none; text-align: center; color: var(--ink-soft); padding: 60px 20px; font-size: 17px; line-height: 1.9; }
        #chat-empty .big { font-size: 46px; display: block; margin-bottom: 8px; }

        .day-sep { align-self: center; margin: 12px 0 8px; padding: 3px 14px; border-radius: 999px; background: rgba(255, 255, 255, .1); color: var(--ink-soft); font-size: 12px; font-weight: 700; }

        .msg-row { display: flex; flex-direction: column; max-width: 84%; margin-top: 8px; }
        .msg-row.grp-cont { margin-top: 0; }
        .msg-row.mine { align-self: flex-start; }
        .msg-row.theirs { align-self: flex-end; }
        .msg-sender { font-size: 12px; font-weight: 800; margin: 0 6px 3px; color: #cdb8ff; }
        .msg-row.mine .msg-sender { display: none; }
        .msg-row.grp-cont .msg-sender { display: none; }

        .msg-bubble {
            position: relative; padding: 8px 12px 6px; border-radius: 18px;
            font-size: 16px; line-height: 1.55; overflow-wrap: anywhere; cursor: pointer;
            box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
        }
        .msg-row.mine .msg-bubble { background: linear-gradient(135deg, #ff5c98, #b44bd6); color: #fff; border-top-right-radius: 6px; }
        .msg-row.mine.grp-cont .msg-bubble { border-top-right-radius: 18px; }
        .msg-row.mine.grp-cont:not(.grp-last) .msg-bubble { border-bottom-right-radius: 6px; }
        .msg-row.theirs .msg-bubble { background: rgba(255, 255, 255, .11); color: #f4ecff; border: 1.5px solid rgba(190, 160, 255, .45); border-top-left-radius: 6px; backdrop-filter: blur(6px); }
        .msg-row.theirs.grp-cont .msg-bubble { border-top-left-radius: 18px; }
        .msg-row.theirs.grp-cont:not(.grp-last) .msg-bubble { border-bottom-left-radius: 6px; }

        .msg-meta { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 3px; font-size: 11px; opacity: .78; direction: rtl; }
        .msg-state.sending { color: #ffe08a; }
        .msg-state.failed { color: #ffd0da; font-weight: 800; }
        .msg-row.mine .msg-state.sent { color: #fff; }

        .msg-reply-quote { display: block; margin-bottom: 6px; padding: 5px 9px; border-radius: 10px; border-right: 3px solid currentColor; background: rgba(0, 0, 0, .22); font-size: 13px; opacity: .92; cursor: pointer; }
        .msg-reply-quote b { display: block; font-size: 11px; opacity: .85; }

        .msg-img { display: block; width: min(250px, 62vw); max-width: 100%; height: auto; border-radius: 12px; margin-bottom: 4px; background: rgba(255, 255, 255, .12); cursor: zoom-in; }
        .msg-caption { display: block; }

        .msg-failed-actions { display: none; gap: 8px; margin-top: 6px; }
        .msg-row.failed .msg-failed-actions { display: flex; }
        .msg-row.failed .msg-bubble { outline: 2px solid #ff6b81; outline-offset: 1px; }
        .msg-failed-actions button { border: 1.5px solid #ffd0da; background: rgba(255, 107, 129, .2); color: #ffd0da; border-radius: 10px; padding: 4px 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
        .msg-row.flash .msg-bubble { animation: flashMsg 1.2s ease; }
        @keyframes flashMsg { 0%, 60% { box-shadow: 0 0 0 4px rgba(255, 209, 230, .8); } 100% { box-shadow: 0 2px 8px rgba(0, 0, 0, .25); } }

        #jump-latest {
            position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
            display: none; align-items: center; gap: 6px;
            padding: 7px 16px; border: none; border-radius: 999px; cursor: pointer;
            background: linear-gradient(135deg, #ff5c98, #b44bd6); color: #fff; font-size: 14px; font-weight: 700;
            box-shadow: 0 6px 20px rgba(0, 0, 0, .45);
        }
        #jump-latest.show { display: inline-flex; }
        .chat-body { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }

        #typing-indicator { min-height: 22px; padding: 0 16px 4px; font-size: 13px; color: #ffb3d1; font-style: italic; opacity: 0; transition: opacity .2s; }
        #typing-indicator.visible { opacity: 1; }

        #reply-preview { display: none; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 14px; background: rgba(255, 255, 255, .08); border-top: 1px solid var(--line); font-size: 13px; color: #ffb3d1; }
        #reply-preview.visible { display: flex; }
        #reply-preview .reply-preview-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
        #reply-preview button, #img-preview button.rm { background: none; border: none; color: inherit; cursor: pointer; font-size: 16px; padding: 4px 8px; }

        #img-preview { display: none; align-items: center; gap: 10px; padding: 8px 14px; background: rgba(255, 255, 255, .08); border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-soft); }
        #img-preview.show { display: flex; }
        #img-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }
        #img-preview .info { flex: 1; }
        #img-preview .err { color: #ffc2d1; }

        .chat-input-row { display: flex; align-items: center; gap: 6px; padding: 10px; background: rgba(20, 8, 44, .95); border-top: 1px solid var(--line); }
        #chat-input {
            flex: 1; min-width: 0; min-height: 44px; padding: 10px 16px;
            border: 2px solid rgba(255, 160, 205, .4); border-radius: 22px;
            background: rgba(10, 4, 28, .7); color: #fff; font-size: 16px; direction: rtl;
        }
        #chat-input::placeholder { color: rgba(255, 200, 225, .5); }
        #chat-input:focus { outline: none; border-color: #ff7aa8; }
        #chat-input:disabled { opacity: .55; }
        .round-btn { width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center; border: none; border-radius: 50%; cursor: pointer; font-size: 18px; transition: transform .2s, background .2s; }
        #chat-send { background: linear-gradient(135deg, #ff5c98, #b44bd6); color: #fff; box-shadow: 0 4px 14px rgba(255, 77, 140, .4); }
        #chat-send:hover { transform: scale(1.06); }
        #chat-send[disabled] { opacity: .45; transform: none; cursor: not-allowed; }
        #emojiToggleBtn, #attachBtn { background: rgba(255, 255, 255, .1); color: #ffb3d1; }
        #emojiToggleBtn:hover, #attachBtn:hover, #emojiToggleBtn.active { background: rgba(255, 255, 255, .2); }
        #attachBtn[disabled] { opacity: .45; cursor: not-allowed; }
        #emoji-picker { display: none; flex-wrap: wrap; gap: 4px; padding: 8px 10px; background: rgba(20, 8, 44, .98); border-top: 1px solid var(--line); max-height: 130px; overflow-y: auto; }
        #emoji-picker.visible { display: flex; }
        #emoji-picker button { width: 38px; height: 38px; font-size: 21px; border: none; background: none; cursor: pointer; border-radius: 10px; }
        #emoji-picker button:hover { background: rgba(255, 255, 255, .14); }

        /* lightbox */
        #lightbox { position: fixed; inset: 0; z-index: 10002; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 14px; padding: 16px; background: rgba(5, 2, 15, .92); }
        #lightbox.show { display: flex; }
        #lightbox img { max-width: 100%; max-height: calc(100dvh - 130px); border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
        #lightbox .lb-msg { color: var(--ink); font-size: 16px; text-align: center; }
        #lightbox .lb-bar { display: flex; gap: 10px; }
        #lightbox .lb-bar a, #lightbox .lb-bar button { min-height: 44px; padding: 10px 20px; border-radius: 12px; border: 1.5px solid var(--line); background: rgba(255, 255, 255, .1); color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; }

        /* archive */
        #archive-list, #archive-detail-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: rgba(10, 4, 28, .55); scrollbar-width: thin; scrollbar-color: #7a4a8c transparent; }
        .archive-item { background: rgba(255, 255, 255, .08); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 16px; cursor: pointer; text-align: right; transition: background .15s; }
        .archive-item:hover { background: rgba(255, 255, 255, .15); }
        .archive-item-title { font-weight: 800; font-size: 15px; color: #ffb3d1; }
        .archive-item-meta { font-size: 12px; color: var(--ink-soft); margin-top: 4px; overflow-wrap: anywhere; direction: ltr; text-align: right; }
        .archive-item-remove { float: left; color: #ff9bb0; font-size: 13px; cursor: pointer; padding: 2px 6px; }
        .archive-empty { text-align: center; color: var(--ink-soft); font-size: 15px; padding: 40px 20px; }
        .archive-add-row { display: flex; gap: 8px; padding: 12px; background: rgba(20, 8, 44, .95); border-bottom: 1px solid var(--line); }
        .archive-add-row input { flex: 1; min-width: 0; padding: 10px 14px; border: 2px solid rgba(255, 160, 205, .4); border-radius: 16px; font-size: 14px; background: rgba(10, 4, 28, .7); color: #fff; direction: ltr; text-align: right; }
        .archive-add-row input:focus { outline: none; border-color: #ff7aa8; }
        .archive-add-row button { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #ff4d6d; color: #fff; border: none; cursor: pointer; flex-shrink: 0; }

        @media only screen and (max-width: 480px) {
            #chat-overlay { padding: 0; }
            #chat-window, #archive-window, #archive-detail-window { width: 100%; height: 100dvh; border-radius: 0; }
        }