/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0d0d0f;
  --surface:     #18181c;
  --surface2:    #222228;
  --border:      #2e2e36;
  --accent:      #e8b400;
  --accent-dk:   #c49a00;
  --text:        #f0f0f0;
  --text-secondary: #c8c8d8;
  --muted:       #888899;
  --danger:      #e05252;
  --header-bg:   rgba(13,13,15,.92);
  --radius:      10px;
  --card-w:      180px;
}

[data-theme="light"] {
  --bg:          #f4f4f8;
  --surface:     #ffffff;
  --surface2:    #eaeaf0;
  --border:      #d0d0dc;
  --accent:      #b58900;
  --accent-dk:   #9a7500;
  --text:        #111118;
  --text-secondary: #44445a;
  --muted:       #6b6b80;
  --danger:      #d44040;
  --header-bg:   rgba(244,244,248,.92);
}

html { font-size: 16px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

#logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--accent);
  white-space: nowrap;
  text-decoration: none;
  flex-shrink: 0;
}

/* ── Search Bar ── */
.search-bar {
  flex: 1;
  display: flex;
  max-width: 520px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  transition: border-color .2s;
}

.search-bar:focus-within { border-color: var(--accent); }

#search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  padding: .55rem 1rem;
  color: var(--text);
  font-size: .95rem;
}

#search-input::placeholder { color: var(--muted); }

#search-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 0 .9rem;
  display: flex;
  align-items: center;
  transition: color .2s;
}

#search-btn:hover { color: var(--accent); }

#change-key-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: .4rem .85rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: .8rem;
  white-space: nowrap;
  transition: border-color .2s, color .2s;
}

#change-key-btn:hover { border-color: var(--accent); color: var(--accent); }

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, color .2s;
  padding: 0;
}

#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
#theme-toggle svg { pointer-events: none; }

/* ── Main ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

/* ── Movie Grid ── */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-w), 1fr));
  gap: 1.25rem;
}

/* ── Movie Card ── */
.movie-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  display: flex;
  flex-direction: column;
}

.movie-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 32px rgba(232,180,0,.15);
}

.movie-card img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
  background: var(--surface2);
}

.movie-card .no-poster {
  width: 100%;
  aspect-ratio: 2/3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  color: var(--muted);
  font-size: .8rem;
  text-align: center;
  padding: 1rem;
}

.card-body {
  padding: .65rem .75rem .75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.card-title {
  font-size: .88rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: .35rem;
}

.card-year { font-size: .78rem; color: var(--muted); }

.card-rating {
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: .25rem;
}

.card-rating::before { content: '★'; }

/* ── Skeleton Loader ── */
.skeleton {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  pointer-events: none;
}

.skeleton-poster {
  width: 100%;
  aspect-ratio: 2/3;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

.skeleton-body { padding: .65rem .75rem .75rem; }

.skeleton-line {
  height: .75rem;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  margin-bottom: .5rem;
}

.skeleton-line.short { width: 55%; }

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

/* ── Pagination ── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  margin-top: 2rem;
  flex-wrap: wrap;
}

.pagination button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .45rem .9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
  transition: border-color .2s, background .2s;
}

.pagination button:hover:not(:disabled) { border-color: var(--accent); }
.pagination button.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.pagination button:disabled { opacity: .35; cursor: default; }

/* ── Modal Overlay ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fade-in .18s ease;
}

.modal-overlay[hidden] { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── API Key Modal ── */
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: slide-up .22s ease;
}

@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal h2 { font-size: 1.3rem; }
.modal p  { color: var(--muted); font-size: .92rem; line-height: 1.5; }
.hint { font-size: .78rem !important; color: var(--border) !important; }

.modal input[type="text"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem .9rem;
  color: var(--text);
  font-size: .95rem;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}

.modal input[type="text"]:focus { border-color: var(--accent); }

.modal button[id="api-key-save"] {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  padding: .7rem 1.2rem;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s;
}

.modal button[id="api-key-save"]:hover { background: var(--accent-dk); }

/* ── Detail Modal ── */
.detail-modal {
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 0;
  position: relative;
}

.close-btn {
  position: sticky;
  top: 0;
  float: right;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.4rem;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: .75rem .75rem 0 0;
  transition: border-color .2s;
  z-index: 1;
}

.close-btn:hover { border-color: var(--accent); }

/* Detail content layout */
.detail-hero {
  display: flex;
  gap: 1.5rem;
  padding: 1.5rem;
  padding-top: 0;
}

.detail-poster {
  flex-shrink: 0;
  width: 160px;
  border-radius: var(--radius);
  overflow: hidden;
  align-self: flex-start;
}

.detail-poster img {
  width: 100%;
  display: block;
}

.detail-info { flex: 1; min-width: 0; }

.detail-title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: .35rem;
}

.detail-tagline {
  color: var(--muted);
  font-style: italic;
  font-size: .9rem;
  margin-bottom: .75rem;
}

.detail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .9rem;
}

.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .2rem .7rem;
  font-size: .78rem;
  color: var(--muted);
}

.chip.rating {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.detail-overview {
  font-size: .9rem;
  line-height: 1.65;
  color: var(--text-secondary);
}

.detail-backdrop {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  display: block;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: .65rem 1.25rem;
  border-radius: 999px;
  font-size: .88rem;
  font-weight: 600;
  z-index: 300;
  animation: fade-in .2s ease;
  white-space: nowrap;
}

.toast[hidden] { display: none; }

/* ── Empty / Error state ── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--muted);
  grid-column: 1 / -1;
}

.empty-state .icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-state p { font-size: 1rem; }

/* ── Responsive ── */
@media (max-width: 600px) {
  :root { --card-w: 140px; }
  .header-inner { flex-wrap: wrap; }
  .search-bar { order: 3; max-width: 100%; flex: 1 0 100%; }
  #change-key-btn { margin-left: auto; }
  .detail-hero { flex-direction: column; }
  .detail-poster { width: 120px; }
}
