/* «Случайный стих» */
.random-poem-page { display: grid; gap: 18px; min-width: 0; }

/* Фильтры */
.random-filters {
    display: grid;
    gap: 16px;
    padding: clamp(16px, 2.4vw, 24px);
    border-radius: 18px;
}
.random-filters fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.random-filters fieldset[hidden] { display: none; }

.random-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: fit-content;
    max-width: 100%;
    padding: 4px;
    border: 1px solid var(--line-new);
    border-radius: 14px;
    background: var(--panel-soft);
}
.random-source { position: relative; cursor: pointer; }
.random-source input { position: absolute; opacity: 0; pointer-events: none; }
.random-source span {
    display: block;
    padding: 8px 15px;
    border-radius: 10px;
    color: var(--text);
    font-size: max(var(--mobile-text-min), 13px);
    font-weight: 750;
    line-height: 1.2;
    white-space: nowrap;
    transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}
.random-source:hover span { color: var(--violet); }
.random-source input:checked + span {
    background: var(--panel);
    color: var(--violet-dark);
    box-shadow: 0 2px 10px rgba(31, 24, 58, .1);
}
body.theme-dark .random-source input:checked + span { color: var(--ink); }
.random-source input:focus-visible + span { outline: 2px solid var(--violet); outline-offset: 2px; }

.random-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}
.random-panel { display: contents; }
.random-panel[hidden] { display: none; }

.random-field { display: grid; gap: 6px; min-width: 0; }
.random-field-label {
    color: var(--muted-new);
    font-size: max(var(--mobile-text-min), 10px);
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.random-field select {
    width: 100%;
    min-height: 42px;
    padding: 0 34px 0 12px;
    border: 1px solid var(--line-new);
    border-radius: 11px;
    background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5' fill='none' stroke='%23777282' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 10px center / 16px;
    color: var(--ink);
    font: inherit;
    font-size: max(var(--mobile-text-min), 14px);
    appearance: none;
    cursor: pointer;
}
.random-field select:hover { border-color: color-mix(in srgb, var(--violet) 40%, var(--line-new)); }
.random-field select:focus-visible { border-color: var(--violet); outline: 2px solid color-mix(in srgb, var(--violet) 30%, transparent); outline-offset: 1px; }

.random-toggles { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 42px; }
.random-toggle { position: relative; cursor: pointer; }
.random-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.random-toggle span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 13px;
    border: 1px solid var(--line-new);
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    font-size: max(var(--mobile-text-min), 13px);
    font-weight: 700;
    white-space: nowrap;
}
.random-toggle span::before {
    width: 14px;
    height: 14px;
    border: 1.5px solid color-mix(in srgb, var(--violet) 45%, var(--line-new));
    border-radius: 4px;
    content: "";
}
.random-toggle input:checked + span { border-color: var(--violet); background: var(--violet-soft); color: var(--violet-dark); }
body.theme-dark .random-toggle input:checked + span { color: var(--ink); }
.random-toggle input:checked + span::before {
    border-color: var(--violet);
    background: var(--violet) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 12.5 4 4 8-9' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}
.random-toggle input:focus-visible + span { outline: 2px solid var(--violet); outline-offset: 2px; }

.random-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 6px 0 13px;
    border: 1px solid var(--violet);
    border-radius: 11px;
    background: var(--violet-soft);
    color: var(--ink);
    font-size: max(var(--mobile-text-min), 14px);
    font-weight: 700;
}
.random-chip button {
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--violet-dark);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}
.random-chip button:hover { background: var(--panel); }

.random-filters-actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; }
.random-filters-actions:not(:has(> :not(.is-js-hidden))) { display: none; }
.random-submit.is-js-hidden { display: none; }
.random-reset { color: var(--violet); font-size: max(var(--mobile-text-min), 13px); font-weight: 750; }

/* Карточка */
.random-card-slot { min-width: 0; transition: opacity .16s ease; }
.random-card-slot.is-loading { opacity: .55; pointer-events: none; }

.random-card.poem { padding-top: clamp(14px, 2.4vw, 22px); overflow: visible; }

.random-controls {
    position: sticky;
    top: calc(var(--header-height) + 8px);
    z-index: 5;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    margin: 0 calc(-1 * clamp(6px, 2vw, 30px)) clamp(22px, 3vw, 34px);
    padding: 10px;
    border: 1px solid color-mix(in srgb, var(--violet) 14%, var(--line-new));
    border-radius: 16px;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    box-shadow: 0 10px 30px rgba(31, 24, 58, .07);
    backdrop-filter: blur(10px);
}
.random-counter {
    color: var(--muted-new);
    font-size: max(var(--mobile-text-min), 13px);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    text-align: center;
}
.random-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 12px;
    font-size: max(var(--mobile-text-min), 14px);
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}
.random-nav svg { width: 20px; height: 20px; flex: none; }
.random-prev { border: 1px solid var(--line-new); background: var(--panel); color: var(--text); }
.random-prev:hover { border-color: var(--violet); color: var(--violet); }
.random-prev.is-disabled { opacity: .4; cursor: default; }
.random-prev.is-disabled:hover { border-color: var(--line-new); color: var(--text); }
.random-next { background: var(--violet); color: #fff; box-shadow: 0 8px 20px color-mix(in srgb, var(--violet) 30%, transparent); }
.random-next:hover { background: var(--violet-dark); color: #fff; }
.random-next:hover .random-dice { transform: rotate(90deg); }
.random-dice { transition: transform .25s ease; }
.random-card-slot.is-loading .random-dice { animation: random-roll .6s linear infinite; }
@keyframes random-roll { to { transform: rotate(360deg); } }

.random-card-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.random-card-meta .section-kicker { color: var(--violet); }
.random-labels.poem-taxonomy { margin: 0; gap: 6px; }
.random-labels.poem-taxonomy > a,
.random-labels.poem-taxonomy > span { padding: 4px 10px; font-size: max(var(--mobile-text-min), 11px); }

.random-title {
    margin: 14px 0 0;
    color: var(--ink);
    font-family: Georgia, serif;
    font-size: clamp(30px, 4vw, 46px);
    font-weight: 500;
    letter-spacing: -.035em;
    line-height: 1.08;
}
.random-title a { color: inherit; text-decoration: none; }
.random-title a:hover { color: var(--violet); }

.random-byline-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 22px;
}
.random-byline { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; min-width: 0; margin: 0; font-size: max(var(--mobile-text-min), 15px); }
.random-byline a { color: var(--violet); font-weight: 800; text-decoration: none; }
.random-byline a:hover { text-decoration: underline; }
.random-byline > span:first-child { color: var(--ink); font-weight: 800; }
.random-byline-note { color: var(--muted-new); font-size: .9em; }

.random-body p { margin: 0 0 1.1em; }
.random-more { margin: -4px 0 0; font-weight: 750; }
.random-more a { color: var(--violet); }

.random-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-top: 26px;
    padding-top: 18px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--violet) 22%, transparent), var(--line-new) 55%, transparent) top / 100% 1px no-repeat;
}
.random-open { color: var(--violet); font-size: max(var(--mobile-text-min), 14px); font-weight: 800; text-decoration: none; }
.random-open::after { content: " →"; }
.random-open:hover { text-decoration: underline; }
.random-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.random-empty { padding: 10px 0 6px; text-align: center; }
.random-empty h2 { margin: 0 0 8px; color: var(--ink); font-family: Georgia, serif; font-size: clamp(22px, 3vw, 30px); font-weight: 500; }
.random-empty p { margin: 0 0 18px; color: var(--muted-new); }

/* Пояснение */
.random-about { padding: clamp(18px, 3vw, 28px); border-radius: 18px; }
.random-about h2 { margin: 0 0 10px; color: var(--ink); font-family: Georgia, serif; font-size: clamp(20px, 2.4vw, 26px); font-weight: 500; }
.random-about p { margin: 0 0 10px; color: var(--text); font-size: max(var(--mobile-text-min), 14px); line-height: 1.7; }
.random-about p:last-child { margin-bottom: 0; }

/* Точки входа на других страницах */
.random-entry {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 14px;
    border: 1px solid color-mix(in srgb, var(--violet) 25%, var(--line-new));
    border-radius: 999px;
    background: var(--panel);
    color: var(--violet);
    font-size: max(var(--mobile-text-min), 13px);
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}
.random-entry svg { width: 18px; height: 18px; flex: none; }
.random-entry:hover { border-color: var(--violet); background: var(--violet-soft); }

.random-filters-toggle {
    display: none;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--line-new);
    border-radius: 11px;
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    font-size: max(var(--mobile-text-min), 14px);
    font-weight: 750;
    cursor: pointer;
}
.random-filters-toggle::after {
    width: 16px;
    height: 16px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5' fill='none' stroke='%23777282' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
    content: "";
    transition: transform .15s ease;
}
.random-filters-toggle[aria-expanded="true"]::after { transform: rotate(180deg); }
.random-filters-toggle small { margin-left: auto; margin-right: 8px; color: var(--violet); font-size: .9em; }

@media (max-width: 780px) {
    .random-filters-toggle:not([hidden]) { display: flex; }
    .random-filters.is-collapsed .random-fields,
    .random-filters.is-collapsed .random-filters-actions { display: none; }
    .random-sources { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .random-source span { padding: 9px 8px; text-align: center; }
    .random-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .random-toggles { grid-column: 1 / -1; }
    .random-poet { grid-column: 1 / -1; }
    .random-controls { margin-left: -6px; margin-right: -6px; padding: 8px; gap: 8px; }
    .random-nav { min-height: 42px; padding: 0 12px; }
    .random-prev span { display: none; }
    .random-byline-row { align-items: flex-start; }
}

@media (max-width: 420px) {
    .random-fields { grid-template-columns: minmax(0, 1fr); }
}

@media print {
    .random-filters,
    .random-controls,
    .random-actions,
    .random-about,
    .random-hero { display: none !important; }
}

.portal-section-hero-copy > .random-entry { margin-top: 12px; }
