* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #e50914;
  --accent-hover: #ff1a25;
  --star: #f5c518;
  --green: #46d369;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* --- Login --- */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

#login-screen {
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  padding: 2rem;
  gap: 1.5rem;
}

#login-screen h1 {
  font-size: 1.8rem;
  font-weight: 700;
}

#login-screen input {
  width: 100%;
  max-width: 300px;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

#login-screen button {
  width: 100%;
  max-width: 300px;
  padding: 0.75rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#login-screen button:hover { background: var(--accent-hover); }

#login-error {
  color: var(--accent);
  font-size: 0.875rem;
  min-height: 1.25rem;
}

/* --- Public history on login screen --- */
#public-history {
  width: 100%;
  max-width: 500px;
  margin-top: 1rem;
}

#public-history h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
  text-align: center;
}

.public-history-item {
  cursor: default;
}

/* --- App shell --- */
#app-screen {
  min-height: 100dvh;
  padding-bottom: 64px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1rem 0.5rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.app-header h1 { font-size: 1.25rem; }

.app-header button {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
}

/* --- Tabs --- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.tab-bar button {
  flex: 1;
  padding: 0.6rem 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.tab-bar button.active { color: var(--accent); }
.tab-bar button .tab-icon { font-size: 1.25rem; }

/* --- Tab content --- */
.tab-content { display: none; padding: 0 1rem 1rem; }
.tab-content.active { display: block; }

/* --- Add movie --- */
.add-movie {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.add-movie input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}

.add-movie button {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* --- Movie cards --- */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.movie-card {
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s;
}

.movie-card:hover { transform: scale(1.03); }

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

.movie-card .card-info {
  padding: 0.5rem;
}

.movie-card .card-title {
  font-size: 0.8rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.movie-card .card-year {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.movie-card .card-rating {
  font-size: 0.7rem;
  color: var(--star);
  margin-top: 0.15rem;
}

/* --- History list --- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.history-item {
  display: flex;
  gap: 0.75rem;
  background: var(--surface);
  border-radius: 10px;
  padding: 0.6rem;
  cursor: pointer;
}

.history-item img {
  width: 50px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface2);
}

.history-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
}

.history-info .h-title {
  font-size: 0.85rem;
  font-weight: 600;
}

.history-info .h-date {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.history-info .h-stars {
  font-size: 0.8rem;
  color: var(--star);
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 30;
  justify-content: center;
  align-items: flex-end;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  float: right;
  line-height: 1;
}

.modal-poster {
  width: 120px;
  aspect-ratio: 2/3;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  background: var(--surface2);
}

.modal h2 {
  font-size: 1.2rem;
  margin-bottom: 0.25rem;
}

.modal .meta {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.modal .plot {
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
  color: var(--text-dim);
}

.modal .imdb-rating {
  font-size: 0.85rem;
  color: var(--star);
  margin-bottom: 1rem;
}

/* --- Star rating input --- */
.star-input {
  display: flex;
  gap: 0.25rem;
  margin: 0.5rem 0;
}

.star-input span {
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--border);
  user-select: none;
}

.star-input span.filled { color: var(--star); }

/* --- Action buttons --- */
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

/* --- Viewing history in modal --- */
.viewing-history {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.viewing-history h3 {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  color: var(--text-dim);
}

.viewing-entry {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 0.3rem 0;
  color: var(--text-dim);
}

/* --- Watch form --- */
.watch-form {
  background: var(--surface2);
  border-radius: 10px;
  padding: 0.75rem;
  margin-top: 0.75rem;
}

.watch-form label {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.25rem;
}

.watch-form input[type="date"] {
  width: 100%;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem 1rem;
  font-size: 0.9rem;
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

/* --- Loading --- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  justify-content: center;
  padding: 2rem;
}
