/*
 * La Magica — сайт-чат с Оракулом (lamagica.ru).
 * Та же ночная тема, что у мини-приложения (static/miniapp/app.css): золото —
 * только акцент, всё остальное — полупрозрачные поверхности на звёздном небе.
 */
:root {
    --bg: #0b0a1a;
    --surface: rgba(255, 255, 255, 0.05);
    --surface-2: rgba(255, 255, 255, 0.08);
    --surface-solid: #16142e;
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.14);
    --text: #f3effb;
    --muted: #a7a1c2;
    --faint: #75708f;
    --gold: #e3c07e;
    --gold-soft: rgba(227, 192, 126, 0.12);
    --gold-line: rgba(227, 192, 126, 0.34);
    --gold-grad: linear-gradient(135deg, #f5dfae 0%, #e3c07e 48%, #c49a52 100%);
    --violet: #8c74ea;
    --violet-soft: rgba(140, 116, 234, 0.18);
    --r-lg: 20px;
    --r-md: 16px;
    --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
    --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
/* Фон — только у html: непрозрачный body лёг бы поверх неба (.sky, z-index -1). */
body { background: transparent; overflow: hidden; }

button, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

svg {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sky {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    transform: translateZ(0);
    background:
        radial-gradient(1px 1px at 14% 12%, rgba(255,255,255,.55) 50%, transparent 51%),
        radial-gradient(1px 1px at 78% 7%, rgba(255,255,255,.45) 50%, transparent 51%),
        radial-gradient(1.4px 1.4px at 88% 28%, rgba(245,223,174,.6) 50%, transparent 51%),
        radial-gradient(1px 1px at 32% 36%, rgba(255,255,255,.35) 50%, transparent 51%),
        radial-gradient(1.2px 1.2px at 62% 52%, rgba(255,255,255,.4) 50%, transparent 51%),
        radial-gradient(1px 1px at 8% 68%, rgba(255,255,255,.35) 50%, transparent 51%),
        radial-gradient(1.4px 1.4px at 44% 84%, rgba(245,223,174,.5) 50%, transparent 51%),
        radial-gradient(1px 1px at 92% 78%, rgba(255,255,255,.4) 50%, transparent 51%),
        radial-gradient(60% 45% at 50% -8%, rgba(140,116,234,.28), transparent 70%),
        radial-gradient(50% 40% at 100% 100%, rgba(227,192,126,.08), transparent 70%),
        var(--bg);
}

/* ---------- Каркас: шапка, лента, поле ввода ---------- */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 760px;
    margin: 0 auto;
}

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gold-soft);
    border: 1px solid var(--gold-line);
    color: var(--gold);
    font-size: 18px;
}
.brand-name {
    font-family: var(--serif);
    font-size: 24px;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: .02em;
}
.brand-sub { color: var(--muted); font-size: 12.5px; }

.tg-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 9px 14px;
    border-radius: 999px;
    border: 1px solid var(--gold-line);
    color: var(--gold);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: background .2s var(--ease);
}
.tg-link:hover { background: var(--gold-soft); }

.chat {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 16px 8px;
}
.log { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Сообщения ---------- */
.msg {
    max-width: 86%;
    padding: 11px 15px;
    border-radius: var(--r-lg);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    animation: rise .35s var(--ease) both;
}
.msg.oracle {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--line);
    border-bottom-left-radius: 6px;
}
.msg.user {
    align-self: flex-end;
    background: var(--violet-soft);
    border: 1px solid rgba(140, 116, 234, 0.3);
    border-bottom-right-radius: 6px;
}
.msg.system {
    align-self: center;
    max-width: 100%;
    color: var(--muted);
    font-size: 13px;
    background: none;
    padding: 4px 8px;
}

.card {
    align-self: flex-start;
    width: min(220px, 62vw);
    margin: 4px 0;
    padding: 10px;
    border-radius: var(--r-lg);
    background: var(--surface);
    border: 1px solid var(--gold-line);
    animation: reveal .6s var(--ease) both;
}
.card img {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 5;
    object-fit: cover;
    border-radius: 12px;
    background: var(--surface-solid);
}
.card figcaption {
    margin-top: 8px;
    text-align: center;
    font-family: var(--serif);
    font-size: 19px;
    font-weight: 600;
    color: var(--gold);
}

.typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 5px;
    padding: 14px 16px;
    border-radius: var(--r-lg);
    border-bottom-left-radius: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
}
.typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }

/* ---------- Лимит ---------- */
.limit {
    margin: 0 16px 8px;
    padding: 14px 16px;
    border-radius: var(--r-md);
    background: var(--gold-soft);
    border: 1px solid var(--gold-line);
    text-align: center;
}
.limit p { margin: 0 0 10px; color: var(--text); }
.limit-btn {
    display: inline-block;
    padding: 11px 22px;
    border-radius: 999px;
    background: var(--gold-grad);
    color: #1d1630;
    font-weight: 700;
    text-decoration: none;
}

/* ---------- Поле ввода ---------- */
.composer {
    padding: 8px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    background: rgba(11, 10, 26, 0.72);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: none;
    padding: 7px 13px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--muted);
    font-size: 13.5px;
    white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--gold-line); }

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 14px;
    border-radius: 24px;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
}
.input-row:focus-within { border-color: var(--gold-line); }

textarea {
    flex: 1;
    min-width: 0;
    max-height: 140px;
    padding: 8px 0;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    font-size: 16px; /* меньше 16px — iOS зумит страницу при фокусе */
    line-height: 1.4;
}
textarea::placeholder { color: var(--faint); }

.send {
    display: grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: var(--gold-grad);
    color: #1d1630;
    transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.send:disabled { opacity: .4; cursor: default; }
.send:not(:disabled):active { transform: scale(.94); }

.meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    color: var(--faint);
    font-size: 12px;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}
@keyframes reveal {
    from { opacity: 0; transform: rotateY(80deg) scale(.96); }
    to { opacity: 1; transform: none; }
}
@keyframes blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
    .msg, .card, .typing span { animation: none; }
}

@media (max-width: 420px) {
    .tg-link span { display: none; }
    .tg-link { padding: 9px; }
    .brand-name { font-size: 22px; }
    .msg { max-width: 92%; }
}
