/* Base */
.page {
    --page-padding-top: 0.5rem;
    --page-padding-bottom: 0;
}

.page main.container {
    padding-top: var(--page-padding-top);
    padding-bottom: var(--page-padding-bottom);
}

.page nav {
    margin: 0 0 0.5rem 0;
}

.page nav ul {
    margin: 0;
    gap: 0.75rem;
}

.page nav a {
    padding: 0.2rem 0.4rem;
}

.page hgroup {
    margin: 0.25rem 0 0.5rem 0;
}

.page hgroup h1 {
    margin-bottom: 0.1rem;
}

.page hgroup h2 {
    margin-top: 0;
}

.page-start {
    --page-padding-top: 0.25rem;
    --page-padding-bottom: 90px;
}

.page-context {
    --page-padding-top: 0.5rem;
}

.page-auth {
    --page-padding-top: 0;
}

.page-auth main.container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.authCard {
    width: min(420px, 100%);
    border: 1px solid var(--muted-border-color);
}

.authCard hgroup {
    text-align: center;
    margin-top: 0;
}

.authForm {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.authForm button[type="submit"] {
    align-self: center;
    min-width: 140px;
    padding: 0 18px;
}

.authError {
    margin-top: 0;
}

/* Utilities */
.u-flex {
    display: flex;
}

.u-row {
    flex-direction: row;
}

.u-col {
    flex-direction: column;
}

.u-gap-xs {
    gap: 6px;
}

.u-gap-sm {
    gap: 8px;
}

.u-gap-md {
    gap: 12px;
}

.u-align-center {
    align-items: center;
}

.u-justify-between {
    justify-content: space-between;
}

.u-wrap {
    flex-wrap: wrap;
}

.u-text-right {
    text-align: right;
}

/* Cards */
.card {
    background: var(--card-background-color);
    border-radius: 1rem;
    box-shadow: var(--card-box-shadow);
    padding: 1rem;
}

.card--compact {
    padding: 0.75rem;
}

.card--link {
    text-decoration: none;
    color: inherit;
    border: 1px solid var(--muted-border-color);
}

.card--link:hover {
    border-color: var(--primary);
}

/* Start screen */
.start-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

@media (max-width: 768px) {
    .start-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.photo-tile {
    padding: 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--muted-border-color);
    background: var(--card-background-color);
    position: relative;
}

.photo-tile button {
    padding: 0;
    width: 100%;
    border: 0;
    background: transparent;
}

.photo-tile img {
    display: block;
    width: 100%;
    height: auto;
}

.photo-tile.selected {
    outline: 4px solid var(--primary);
}

.photo-tile.menu-open {
    z-index: 2;
}

.photo-action-menu {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    gap: 6px;
    justify-content: flex-start;
    padding: 8px;
    border-radius: inherit;
    background: rgba(8, 12, 16, 0.88);
    backdrop-filter: blur(6px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
    overflow-y: auto;
}

.photo-action-menu.is-open {
    display: flex;
}

.photo-action-menu button {
    width: 100%;
    min-height: 36px;
    font-size: clamp(0.75rem, 2.4vw, 0.9rem);
    line-height: 1.2;
    padding: 6px 10px;
    text-align: center;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--primary);
    color: var(--primary-inverse);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.photo-action-menu button.secondary {
    background: var(--secondary);
    color: var(--secondary-inverse);
}

.photo-action-menu button.contrast {
    background: var(--contrast);
    color: var(--contrast-inverse);
}

.album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 1rem;
}

.album-meta {
    color: var(--muted-color);
    font-size: 0.9rem;
}

.bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px;
    background: rgba(20, 20, 20, 0.92);
    color: #fff;
    display: none;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    z-index: 50;
}

.bottom-bar > div:first-child {
    flex: 0 0 auto;
    white-space: nowrap;
}

.bottom-bar .actions {
    display: flex;
    gap: 10px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.bottom-bar button {
    min-height: 44px;
}

.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    z-index: 60;
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card-background-color);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    padding: 12px;
    display: none;
    z-index: 61;
}

.sheet button {
    width: 100%;
    margin-bottom: 10px;
    min-height: 52px;
    font-size: 1.05rem;
}

.viewer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    z-index: 70;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.viewer img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
}

.viewerHint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.viewerHint.is-visible {
    opacity: 1;
}

/* Album picker */
.albumPicker {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 80;
}

.albumPicker.is-open {
    display: flex;
}

.albumPicker__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
}

.albumPicker__dialog {
    position: relative;
    width: min(520px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 1;
}

.albumPicker__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.albumPicker__title {
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.albumPicker__close {
    width: auto;
    min-width: auto;
    min-height: 36px;
    padding: 0 10px;
    flex: 0 0 auto;
    white-space: nowrap;
}

.albumPicker__search {
    width: 100%;
}

.albumPicker__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 320px;
    overflow: auto;
    padding-right: 4px;
}

.albumPicker__item {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--muted-border-color);
    background: transparent;
    text-align: left;
}

.albumPicker__left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.albumPicker__thumb {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid var(--muted-border-color);
    object-fit: cover;
    flex: 0 0 auto;
    display: block;
    background: #0f161d;
}

.albumPicker__thumb--empty {
    background: rgba(255, 255, 255, 0.05);
}

.albumPicker__item:hover {
    border-color: var(--primary);
}

.albumPicker__name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.albumPicker__meta {
    color: var(--muted-color);
    font-size: 0.85rem;
    white-space: nowrap;
}

.albumPicker__empty {
    text-align: center;
}

/* Toast */
.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 999px;
    background: rgba(10, 16, 22, 0.92);
    border: 1px solid var(--muted-border-color);
    color: var(--contrast-inverse);
    z-index: 90;
    backdrop-filter: blur(8px);
}

.toast.is-visible {
    display: flex;
}

.toast__link {
    color: var(--primary);
    font-weight: 600;
    white-space: nowrap;
}

.toast__close {
    width: auto;
    min-width: 32px;
    min-height: 32px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--contrast-inverse);
}

.viewer .close {
    position: fixed;
    top: 12px;
    left: 12px;
    width: 56px;
    height: 56px;
    border-radius: 999px;
    font-size: 1.5rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    backdrop-filter: blur(8px);
}

.viewerAction {
    position: fixed;
    top: 12px;
    right: 12px;
    min-height: 44px;
    padding: 0 14px;
    border-radius: 999px;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: auto;
    white-space: nowrap;
    background: #e53935;
    border: 1px solid #c62828;
    color: #fff;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.heroPanel {
    margin-bottom: 1rem;
}

.heroPanel__text h1 {
    margin-bottom: 0.2rem;
}

.heroPanel__text h2 {
    margin-top: 0;
    margin-bottom: 0.35rem;
}

.heroPanel__meta {
    color: var(--muted-color);
    font-size: 0.95rem;
}

.loadMoreSentinel {
    height: 1px;
}

@media (max-width: 768px) {
    .heroPanel {
        flex-direction: column;
        align-items: stretch;
    }

    .heroPanel__actions {
        text-align: right;
    }
}

/* Context (S01) */
.topControls {
    display: grid;
    grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
    gap: 12px;
    align-items: stretch;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 0;
}

@media (max-width: 768px) {
    .topControls {
        grid-template-columns: 1fr;
    }
}

#recorder-root,
#story-summary-root {
    height: 100%;
    align-self: stretch;
}

.contextSection {
    margin-top: 0.75rem;
}

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

@media (max-width: 768px) {
    .contextGrid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.contextGrid img {
    width: 100%;
    height: auto;
    border-radius: 10px;
    border: 1px solid var(--muted-border-color);
    background: var(--card-background-color);
    display: block;
}

.contextThumb {
    padding: 0;
    border: 0;
    background: transparent;
    display: block;
}

.contextHero {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--muted-border-color);
    background: var(--card-background-color);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.contextHero img {
    width: 100%;
    height: auto;
    display: block;
}

#context-title {
    cursor: pointer;
}

#context-title.is-editing {
    cursor: default;
}

.contextTitleEditor {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    width: 100%;
}

.contextTitleInput {
    margin: 0;
    font-size: 1.25rem;
    height: 44px;
    min-width: 0;
    width: auto;
    flex: 1 1 0;
}

.contextTitleActions {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    flex: 0 0 auto;
    white-space: nowrap;
}

.contextTitleActions button {
    height: 44px;
    padding: 0 12px;
}

.contextCaption {
    color: var(--muted-color);
}

.contextCaption--spaced {
    margin: 0.5rem 0;
}

.contextCaption--tight {
    margin: 0;
}

.storyDetails {
    margin-top: 0.75rem;
}

/* Stories screen */
.storiesToolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filters a[role="button"] {
    min-height: 44px;
}

.storiesGrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

@media (max-width: 960px) {
    .storiesGrid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .storiesGrid {
        grid-template-columns: 1fr;
    }
}

.storyCard {
    display: grid;
    grid-template-columns: 96px 1fr;
    gap: 12px;
    align-items: start;
}

.storyPreview {
    width: 96px;
    height: 96px;
    border-radius: 12px;
    border: 1px solid var(--muted-border-color);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.04);
}

.storyPreviewLink {
    text-decoration: none;
    color: inherit;
}

.storyPreview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.storyMeta {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.storySummaryShort {
    font-size: 0.95rem;
    color: var(--color);
}

.storyTitleRow {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.storyTitleLink {
    font-weight: 600;
    color: inherit;
    text-decoration: none;
}

.storyTitleLink:hover {
    text-decoration: underline;
}

.chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--muted-border-color);
    color: var(--muted-color);
    font-size: 0.85rem;
}

.muted {
    color: var(--muted-color);
}

.storiesSearch {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.storiesSearch input[type="search"] {
    min-width: 220px;
    flex: 1 1 auto;
    width: auto;
    margin: 0;
}

.iconButton {
    max-width: 60px;
    margin: 0;
    display: inline-flex;
    flex: 0 0 auto;
}

/* View (S07) */
.viewPlayer {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.viewPlayer__row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.viewSegmentsHeader {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-top: 0.25rem;
}

.viewSegmentsToggle {
    font-size: 0.9rem;
    padding: 0.35rem 0.75rem;
}

.viewPlayer__hint {
    color: var(--muted-color);
    font-size: 0.9rem;
}

.viewPlayer audio {
    width: 100%;
}

.viewSegments {
    margin: 0;
    padding-left: 1.2rem;
}

.viewSegments li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--muted-border-color);
}

.viewSegments__main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.viewSegments__summary {
    color: var(--muted-color);
    font-size: 0.9rem;
}

.viewSegments__play {
    padding: 0.25rem 0.6rem;
    font-size: 0.85rem;
    min-height: 32px;
    align-self: center;
    max-width: 100px;
}

.viewSegments li:last-child {
    border-bottom: 0;
}

.viewSegments li.is-active {
    outline: 3px solid var(--primary);
    outline-offset: 6px;
    border-radius: 8px;
    padding-left: 8px;
    padding-right: 8px;
}

.viewSegments__main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.viewSegments__meta {
    color: var(--muted-color);
    font-size: 0.85rem;
}

.viewTranscript {
    margin-top: 1rem;
}

/* Share screen */
.shareMeta {
    margin: 0;
}

.shareCard {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.shareRow {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}

.shareRow input[type="text"] {
    flex: 1 1 0;
    min-width: 220px;
    width: 100%;
}

.shareRow button {
    flex: 0 0 auto;
    min-width: 120px;
    width: auto;
}

.sharePrompt ul {
    margin: 0.5rem 0 0 1rem;
}

/* Story summary widget */
.storySummary {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
}

.storySummary__row {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.storySummary__count {
    color: var(--muted-color);
}

.storySummary__actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.storySummary__actions button {
    min-width: 56px;
    min-height: 50px;
    padding: 0;
    font-size: 1.1rem;
}

.storySummary__share {
    width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 1.1rem;
}

.storySummary__hint {
    color: var(--muted-color);
    font-size: 0.85rem;
}

/* Story player */
.storyPlayer {
    background: var(--card-background-color);
    border-radius: 1rem;
    box-shadow: var(--card-box-shadow);
    padding: 1rem;
}

.storyPlayer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.storyPlayer__headerActions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.storyPlayer__field {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fieldAiBadge {
    position: absolute;
    top: 0;
    right: 0;
    transform: translateY(2px);
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 0.7rem;
    color: var(--contrast-inverse);
    background: rgba(24, 119, 242, 0.85);
}

.storyPlayer input.is-ai {
    border-color: rgba(24, 119, 242, 0.6);
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.15);
}

#context-title.is-ai::after {
    content: "ИИ";
    margin-left: 10px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    color: var(--contrast-inverse);
    background: rgba(24, 119, 242, 0.85);
    vertical-align: middle;
}

.storyPlayer__playerRow {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.storyPlayer__hint {
    color: var(--muted-color);
    font-size: 0.9rem;
}

.storyPlayer audio {
    width: 100%;
    margin-top: 0.5rem;
}

.storyPlayer__segmentsHeader {
    margin-top: 0.75rem;
}

.storyPlayer__segments {
    margin: 0.5rem 0 0 0;
    padding-left: 1.2rem;
}

.storyPlayer__segments li {
    display: grid;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--muted-border-color);
}

.storyPlayer__segments li:last-child {
    border-bottom: 0;
}

.storyPlayer__segments li.is-active {
    outline: 3px solid var(--primary);
    outline-offset: 6px;
    border-radius: 8px;
    padding-left: 8px;
    padding-right: 8px;
}

.storyPlayer__segments li.is-overwrite {
    border-left: 4px solid var(--primary);
    padding-left: 12px;
}

.storyPlayer__segments button {
    min-height: 44px;
}

.storyPlayer__segments .segmentMain {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.storyPlayer__segments .segmentMeta {
    color: var(--muted-color);
    font-size: 0.85rem;
}

.storyPlayer__segments .segmentActions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
}

.storyPlayer__segments .segmentActions button {
    width: auto;
    flex: 0 0 auto;
}

.segmentAi {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.segmentStatus {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--muted-color);
}

.segmentStatus::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--muted-color);
}

.segmentStatus--processing::before,
.segmentStatus--queued::before {
    background: #2da8ff;
    animation: pulse 1.2s infinite;
}

.segmentStatus--ready::before {
    background: #4ade80;
}

.segmentStatus--failed::before {
    background: #f87171;
}

.segmentStatus--stale::before,
.segmentStatus--blocked::before {
    background: #fbbf24;
}

.segmentSummary {
    font-size: 0.9rem;
    color: var(--muted-color);
}

.segmentSummary--skeleton {
    flex: 1 1 140px;
    min-height: 12px;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
}

.segmentRetry {
    padding: 0 10px;
    min-height: 30px;
}

.storyPlayer__summary {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid var(--muted-border-color);
    border-radius: 12px;
    display: grid;
    gap: 6px;
}

.storyPlayer__summaryBody {
    font-size: 0.95rem;
    line-height: 1.5;
}

.storyPlayer__summaryBody--skeleton {
    min-height: 46px;
    border-radius: 10px;
    background: linear-gradient(90deg, rgba(255,255,255,0.05) 25%, rgba(255,255,255,0.12) 50%, rgba(255,255,255,0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
}

.storyPlayer__summaryStatus {
    font-size: 0.85rem;
    color: var(--muted-color);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

/* Recorder controls */
.recorderControls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 0;
}

.recorderControls__status {
    text-align: center;
}

.recorderControls__timer {
    font-size: 2rem;
    font-family: monospace;
    display: block;
    font-variant-numeric: tabular-nums;
}

.recorderControls__state {
    font-size: 0.8rem;
    color: var(--muted-color);
}

.recorderControls__upload {
    font-size: 0.75rem;
    color: var(--muted-color);
    display: block;
    margin-top: 0.25rem;
}

.recorderControls__actions {
    width: 100%;
    display: flex;
    justify-content: center;
}

.recorderControls__btn {
    min-width: 60px;
    min-height: 50px; /* Touch target */
}

.recorderControls__btn--start {
    --background-color: #e53935;
    --border-color: #e53935;
    width: 100%;
    max-width: 200px;
}

.recorderControls__group {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    justify-content: center;
}
