:root {
    --bg: #070707;
    --panel: #111;
    --muted: #9b9b9b;
    --accent: #f5c518;
    --card: #151515;
    --maxWidth: 1280px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Segoe UI, Roboto, Arial;
    background: var(--bg);
    color: #eee;
}

a {
    color: inherit;
    text-decoration: none;
}

/* HEADER */
.site-header {
    border-bottom: 1px solid #d12626;
    padding-bottom: 8px;
    background-color: #141414;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    max-width: var(--maxWidth);
    margin: 0 auto;
    padding: 15px 24px 0px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 54px;
    height: auto;
}

.sitename {
    color: var(--accent);
    font-weight: 700;
    font-size: 24px;
}

/* HEADER BODY */
.header-body {
    max-width: var(--maxWidth);
    margin: 0 auto;
    padding: 16px;
}

.header-body h1 {
    color: var(--accent);
    margin: 0 0 14px;
    font-size: 24px;
}

/* SEARCH WRAPPER */
.search-wrap {
    margin-bottom: 14px;
}

#searchForm {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
}

#searchForm button[type="submit"] {
    padding: 12px 18px;
    border-radius: 28px;
    border: none;
    background: var(--accent);
    color: #000;
    font-weight: 700;
    cursor: pointer;
}

.search-wrapper {
    max-width: 680px;
    position: relative;
    display: flex;
    gap: 8px;
}

#searchInput {
    flex: 1;
    padding: 12px 40px 12px 14px;
    border-radius: 28px;
    border: 1px solid #222;
    background: #0f0f0f;
    color: #fff;
    font-size: 15px;
    outline: none;
    position: relative;
}

#searchInput:focus {
    background: #1a1a1a;
}

#searchClear {
    position: absolute;
    right: 110px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: #2a6cff;
    color: #fff;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    cursor: pointer;
    display: none;
    padding: 0;
}

/* MENU */
.menu {
    max-width: var(--maxWidth);
    margin: 6px auto;
    padding: 6px 0;
}

.menu-left {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

@media (max-width: 768px) {
    .menu-left select {
        flex: 1 1 100%;
        margin-bottom: 10px;
    }

    .menu-left .menu-btn {
        flex: 0 0 auto;
    }
}

.menu-left select {
    background: #111;
    border: 1px solid #222;
    color: #fff;
    padding: 8px;
    border-radius: 6px;
}

.menu-btn {
    background: transparent;
    border: none;
    color: #bbb;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: 700;
}

.menu-btn.active {
    color: #fff;
    border-bottom: 3px solid #2a6cff;
    padding-bottom: 6px;
}

#sortSelect {
    weight: 190px;
}

/* CONTAINER */
.container {
    max-width: var(--maxWidth);
    margin: 18px auto;
    padding: 0 18px;
}

/* GRID */
.grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: 430px;
    gap: 10px;
    transition: none;
}

@media (max-width: 1200px) {
    .grid { grid-template-columns: repeat(4, 1fr); grid-auto-rows: 400px; }
}

@media (max-width: 900px) {
    .grid { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 360px; }
}

@media (max-width: 600px) {
    .grid { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 370px; }
}

/* CARD */
.card {
    background: var(--card);
    border-radius: 19px;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease, filter 0.3s ease;
}

.card:hover {
    transform: translateY(-6px) scale(1.03);
    box-shadow: 0 12px 20px rgba(0, 0, 0, 0.5);
    filter: brightness(1.05);
}

/* POSTER */
.card-poster {
    flex-shrink: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #111;
}

.card-poster img {
    width: 100%;
    height: auto;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    display: block;
}

@media (max-width: 600px) {
    .card-poster img {
        width: 100%;
        height: auto;
        aspect-ratio: 2 / 3;
        object-fit: cover;
    }
}

/* CARD BODY */
.card-body {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 8px 6px;
    background-color: #bb0e0e59;
    gap: 2px;

    height: 130px; /* фиксированная высота для 2-х линий жанров + даты */
    box-sizing: border-box;
}


/* TITLE */
.card-title {
    font-size: 15px;
    color: #fff;
    font-weight: 600;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    padding: 0 5px;
    min-height: calc(1.25em * 2);
}

/* RATING */
.rating-line {
    display: flex;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
    color: var(--accent);
    padding-left: 5px;
    padding-top: 5px;
}

.rating-line svg {
    width: 15px;
    height: 15px;
    fill: var(--accent);
    margin-right: 6px;
}

/* ЖАНРЫ */
.card-genres {
    font-size: 12px;
    color: #ccc;
    line-height: 1.2;
    padding-left: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 2;        /* максимум 2 строки */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: calc(1.2em * 2);  /* резерв на 2 строки */
    word-break: break-word;
}


/* ДАТА */
.card-date {
    font-size: 13px;
    font-style: italic;
    font-weight: 600;
    color: #dbdbdb8f;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 5px;
}

@media (max-width: 600px) {
    .card-title { font-size: 13.5px; min-height: calc(1.2em * 2); line-height: 1.2; }
    .rating-line { font-size: 12.5px; margin-bottom: 3px; }
    .rating-line svg { width: 14px; height: 14px; margin-right: 5px; }
    .card-genres { font-size: 11.5px; }
    .card-date { font-size: 12px; }
}

/* LOAD MORE */
.loadmore-wrap {
    display: flex;
    justify-content: center;
    padding: 26px;
}

.loadmore {
    background: var(--accent);
    color: #000;
    padding: 12px 24px;
    border-radius: 6px;
    border: none;
    font-weight: 700;
    cursor: pointer;
}

/* MODAL */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* теперь окно начинается сверху, а не строго по центру */
    background: rgba(0,0,0,0.7);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.05s ease;

    /* добавляем внутренний скролл для длинных описаний */
    overflow-y: auto;
    overflow-x: hidden;
    padding: 40px 0; /* небольшой отступ сверху и снизу */
    box-sizing: border-box;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-inner {
    background: #333;
    border-top: 26px solid #f5c518;
    border-bottom: 15px solid #f5c518;
    border-radius: 45px;
    max-width: 480px;
    width: 90%;
    color: #fff;
    padding: 20px;
    box-shadow: 0 0 20px rgba(0,0,0,0.4);
    position: relative;
    animation: modalFadeIn 1.05s ease;

    /* убираем внутренний скролл и ограничения по высоте */
    max-height: none;
    overflow: visible;
}

@keyframes modalFadeIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Кнопка закрытия — фиксирована относительно экрана */
.modal-close {
    position: fixed;
    top: 30px;
    right: calc(50% - 240px); /* выравнивание по правому краю модалки (центр экрана минус половина ширины модалки) */
    width: 36px;
    height: 36px;
    background: #FFD700;
    border: 3px solid #333;
    border-radius: 50%;
    font-size: 20px;
    color: #000;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s ease;
    z-index: 10000;
}

.modal-close:hover {
    transform: rotate(90deg);
}

.modal-header {
    text-align: center;
    margin-bottom: 10px;
}

.modal-header h2 {
    font-size: 28px;
    margin-bottom: 5px;
}

.modal-header p {
    font-size: 14px;
    color: #ccc;
}

.modal-video {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #222;
    border: 1px solid #888;
    margin-bottom: 15px;
}

.modal-video iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 2px;
}

.modal-overview h3 {
    font-size: 1.2rem;
    color: #FFD700;
    border-bottom: 2px solid #FFD700;
    display: inline-block;
    margin-bottom: 8px;
}

.modal-overview p {
    font-size: 14px;
    line-height: 1.5;
    color: #eee;
}

/* Мобильная адаптация */
@media (max-width: 480px) {
    .modal-inner {
        max-width: 90%;
        padding: 15px;
    }
    .modal-header h2 {
        font-size: 26px;
    }
    .modal-close {
        right: 10px; /* прижимаем к краю экрана */
        top: 30px;
    }
}

.modal-discussion {
  margin-top: 25px;
}

.modal-discussion h3 {
  color: #FFD700;
  border-bottom: 2px solid #FFD700;
  padding-bottom: 5px;
  margin-bottom: 10px;
  font-size: 1.2rem;
}

#comment-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 15px;
}

#comment-text {
  width: 100%;
  background: #111;
  color: #f5f5f5;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px;
  resize: vertical;
  font-size: 0.95rem;
}

.comment-button {
  align-self: flex-start;
  background: #FFD700;
  border: none;
  color: #000;
  font-weight: bold;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.2s ease;
}

.comment-button:hover {
  background: #e0c000;
}

.comment {
  background: #151515;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.comment strong {
  color: #FFD700;
  display: block;
  margin-bottom: 3px;
}

.comment p {
  color: #ddd;
  margin: 0 0 5px 0;
}

.comment small {
  color: #888;
  font-size: 0.8rem;
  display: block;
}

.comment hr {
  border: 0;
  border-top: 1px solid #333;
  margin-top: 10px;
}


/* FOOTER */
.site-footer {
    border-top: 1px solid #d12626;
    padding: 18px;
    margin-top: 30px;
    background: #0f0f0f;
}

.footer-inner {
    max-width: var(--maxWidth);
    margin: 0 auto;
    justify-content: space-between;
    align-items: center;
    padding: 0 18px;
}

.footer-links {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    display: flex;
    gap: 12px;
}

.footer-links a {
    color: #9b9b9b;
    font-size: 13px;
}

.tmdb-attr {
    display: flex;
    align-items: center;
    gap: 8px;
}

.attr-text {
    color: #9b9b9b;
    font-size: 12px;
}

/* FADE ANIMATION */
#grid {
    transition: opacity 0.9s ease-in-out;
}

#grid.loading {
    opacity: 0;
}

.card.fade-in {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.45s ease, transform 0.45s ease;
}

.card.fade-in.visible {
    opacity: 1;
    transform: translateY(0);
}
