:root {
  --bg: #0b0d12;
  --surface: #121726;
  --surface-2: #171e31;
  --border: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.62);
  --muted-2: rgba(255, 255, 255, 0.45);
  --accent: #4f8cff;
  --accent-2: #73a6ff;
  --danger: #ff5d5d;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: radial-gradient(1200px 500px at 40% -10%, rgba(79, 140, 255, 0.22), transparent 60%),
    var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
  line-height: 1.45;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.75);
  backdrop-filter: blur(10px);
}

#headerTitle {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.2px;
  min-height: 18px;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 18px 28px;
}

/* Hero */
.hero {
  text-align: center;
  padding: 18px 10px 8px;
}
.hero__title {
  margin: 6px 0 4px;
  font-size: clamp(26px, 3vw, 36px);
  letter-spacing: 0.2px;
}
.hero__subtitle {
  margin: 0 auto;
  max-width: 720px;
  color: var(--muted);
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
}

.btn:active { transform: translateY(1px); }

.btn--ghost { background: transparent; }

.btn--primary {
  border-color: rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.18);
}
.btn--primary:hover { background: rgba(79, 140, 255, 0.26); }

/* Lang Toggle */
.lang-toggle {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  gap: 4px;
}

.lang-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.lang-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.lang-btn.is-active {
  color: var(--bg);
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

/* Search */
.search-section { margin: 12px 0 16px; }

#searchForm { display: flex; gap: 10px; align-items: center; }

#searchInput {
  flex: 1;
  min-width: 0;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  outline: none;
}

#searchInput:focus {
  border-color: rgba(79, 140, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.15);
}

#searchBtn {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(79, 140, 255, 0.5);
  background: rgba(79, 140, 255, 0.16);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}
#searchBtn:hover { background: rgba(79, 140, 255, 0.24); }

/* Loading/Error */
.error {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid rgba(255, 93, 93, 0.35);
  background: rgba(255, 93, 93, 0.08);
  border-radius: 12px;
  color: var(--text);
}
.loading-steps ul { margin: 10px 0; padding-left: 18px; color: var(--muted); }

/* Grid Cards */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.movie-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.movie-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.16);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
}
.movie-card__poster { aspect-ratio: 2 / 3; width: 100%; background: rgba(255, 255, 255, 0.05); overflow: hidden; }
.movie-card__poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.movie-card__poster--placeholder { width: 100%; height: 100%; background: radial-gradient(circle at 30% 20%, rgba(255,255,255,.08), transparent 45%), rgba(255, 255, 255, 0.05); }
.movie-card__meta { padding: 10px 10px 12px; }
.movie-card__title { font-weight: 900; font-size: 13px; line-height: 1.2; }

/* Movie Detail */
.movie-detail {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
  box-shadow: var(--shadow);
}
.movie-detail__backdrop { height: 220px; background: rgba(255, 255, 255, 0.04); overflow: hidden; }
.movie-detail__backdrop img { width: 100%; height: 100%; object-fit: cover; filter: saturate(1.05) contrast(1.02); }
.movie-detail__body { display: grid; grid-template-columns: 170px 1fr; gap: 14px; padding: 14px; }
.movie-detail__poster { width: 170px; aspect-ratio: 2 / 3; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); background: rgba(255, 255, 255, 0.05); }
.movie-detail__poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.movie-detail__poster--placeholder { width: 100%; height: 100%; background: rgba(255, 255, 255, 0.05); }
.movie-detail__title { margin: 0; font-size: 22px; line-height: 1.15; }
.movie-detail__tagline { margin-top: 6px; color: var(--muted); font-style: italic; }
.movie-detail__sub { margin-top: 8px; color: var(--muted); font-weight: 600; }
.movie-detail__genres { margin-top: 8px; color: var(--muted-2); }
.movie-detail__overview { margin-top: 10px; color: var(--text); }
.movie-detail__actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 10px; }

@media (max-width: 720px) {
  .movie-detail__body { grid-template-columns: 1fr; }
  .movie-detail__poster { width: 100%; max-width: 240px; }
  .movie-detail__backdrop { height: 180px; }
}

/* Analysis entry on movie page */
.analysis-entry {
  margin-top: 14px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.analysis-entry__title { font-weight: 900; font-size: 16px; }
.analysis-entry__sub { margin-top: 6px; color: var(--muted); }
.analysis-entry__modes { margin-top: 12px; display: grid; gap: 10px; }
.analysis-entry__hint { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
  font-size: 12px;
}
.chip--warn {
  border-color: rgba(255, 93, 93, 0.35);
  background: rgba(255, 93, 93, 0.10);
}

/* Cast */
.cast-block {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
  padding: 12px;
}
.cast-block__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cast-block__title { margin: 0; font-size: 16px; font-weight: 900; }
.cast-row {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
}
.cast-row::-webkit-scrollbar { height: 10px; }
.cast-row::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 999px; }
.cast-card {
  flex: 0 0 auto;
  width: 140px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  color: inherit;
  scroll-snap-align: start;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}
.cast-card:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, 0.16); background: rgba(255, 255, 255, 0.06); }
.cast-card__img { width: 100%; aspect-ratio: 1 / 1; background: rgba(255, 255, 255, 0.05); overflow: hidden; }
.cast-card__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cast-card__img--placeholder { width: 100%; height: 100%; background: radial-gradient(circle at 30% 20%, rgba(255,255,255,.1), transparent 45%), rgba(255,255,255,.05); }
.cast-card__meta { padding: 10px 10px 12px; }
.cast-card__name { font-weight: 900; font-size: 13px; line-height: 1.15; }
.cast-card__role { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.2; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-weight: 800;
}

/* Modal */
.modal-open { overflow: hidden; }
#castModalRoot { display: none; }
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: min(980px, 96vw);
  max-height: 90vh;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(18, 23, 38, 0.98), rgba(18, 23, 38, 0.92));
  box-shadow: var(--shadow);
}
.modal__header {
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal__title { margin: 0; font-size: 16px; font-weight: 900; }
.modal__content { padding: 12px 14px 16px; overflow: auto; max-height: calc(90vh - 60px); }
.cast-modal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }

/* Analysis topbar */
.analysis-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.analysis-nav { display: flex; gap: 10px; flex-wrap: wrap; }
.analysis-controls { display: flex; gap: 10px; align-items: center; }

/* Pills */
.pill-group {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  gap: 4px;
}
.pill {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
}
.pill.is-active {
  color: var(--bg);
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

/* Analysis title card */
.analysis-title-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.03);
  box-shadow: 0 10px 24px rgba(0,0,0,.22);
  padding: 14px;
  margin-bottom: 12px;
}
.analysis-title-card__title {
  font-size: 22px;
  font-weight: 950;
  margin-bottom: 6px;
}
.analysis-title-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.dot { opacity: 0.6; }

/* Cards / Report */
.report-layout { display: grid; gap: 12px; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.03);
  box-shadow: 0 10px 24px rgba(0,0,0,.20);
  padding: 14px;
}
.card__title {
  font-weight: 950;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0.2px;
}
.card__body { margin-top: 10px; }

.card--error {
  border-color: rgba(255, 93, 93, 0.35);
  background: rgba(255, 93, 93, 0.08);
}

.card-grid-2 {
  display: grid;
  gap: 12px;
}
@media (min-width: 860px) {
  .card-grid-2 { grid-template-columns: 1fr 1fr; }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bullets { margin: 0; padding-left: 18px; }
.bullets li { margin: 6px 0; color: var(--text); }

.quotes { display: grid; gap: 10px; }
.quote {
  margin: 0;
  padding: 12px 12px;
  border-left: 3px solid rgba(79, 140, 255, 0.6);
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
}
.quote p { margin: 0; color: var(--text); }
.quote footer { margin-top: 8px; color: var(--muted); font-weight: 700; }

.kv { display: flex; gap: 10px; align-items: baseline; }
.kv__k { color: var(--muted); font-weight: 900; }
.kv__v { color: var(--text); font-weight: 800; }

/* Footer */
.app-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
}

/* ---- Analysis footer: author links (append-only) ---- */
.app-footer--analysis {
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.app-footer--analysis .footer-line {
  text-align: center;
}

.footer-author {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  text-align: center;
}

.footer-author__label {
  color: var(--muted-2);
  font-weight: 600;
}

.footer-icons {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
  min-width: 40px;   /* tap target */
  min-height: 40px;  /* tap target */
}

.icon-link:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.10);
  color: var(--text);
}

.icon-link:active {
  transform: translateY(1px);
}

.icon-link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(79, 140, 255, 0.18);
  border-color: rgba(79, 140, 255, 0.35);
}

.icon {
  display: block;
}

/* Screen-reader-only text utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}