:root {
  --bg: #0e0b0d;
  --surface: #1b1418;
  --surface2: #241a1f;
  --gold: #c9a227;
  --gold-bright: #e6c14a;
  --wine: #7d1f38;
  --ivory: #f1e9dc;
  --muted: #9c8b83;
  --border: #3a2e30;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #201519 0%, var(--bg) 55%);
  color: var(--ivory);
  font-family: 'Libre Baskerville', Georgia, serif;
}
body {
  display: flex;
  flex-direction: column;
}

.mc-display {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.05em;
}

.mc-mono { font-family: 'JetBrains Mono', monospace; }

.hidden { display: none !important; }

a { color: var(--gold); }

/* Header */
.header {
  padding: 28px 32px 16px;
  border-bottom: 1px solid var(--border);
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.1rem;
  color: var(--gold-bright);
  letter-spacing: 0.06em;
  margin: 0;
}
.tagline {
  margin: 8px 0 0;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--muted);
}

.reel {
  height: 4px;
  background-image: repeating-linear-gradient(to right, var(--gold) 0px, var(--gold) 8px, transparent 8px, transparent 20px);
  opacity: 0.55;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 16px 32px 0;
}
.tab {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 16px;
  cursor: pointer;
}
.tab.active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold-bright);
}
.tab:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.main {
  padding: 24px 48px 60px;
  width: 100%;
  flex: 1;
}

/* Buttons */
.btn-ghost {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  background: var(--wine);
  color: var(--ivory);
  border: none;
  padding: 12px 22px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-primary.full { width: 100%; margin-top: 8px; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-back {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  margin-bottom: 16px;
  padding: 0;
}
.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
}

/* Search */
.search-form {
  display: flex;
  gap: 8px;
  max-width: 720px;
  width: 100%;
}
.search-input-wrap {
  position: relative;
  flex: 1;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 14px;
  color: var(--muted);
}
#search-input {
  width: 100%;
  padding: 13px 12px 13px 36px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ivory);
  font-family: inherit;
  font-size: 1rem;
}

.hint { color: var(--muted); font-size: 0.9rem; margin: 14px 0; }
.error { color: #e07a7a; font-size: 0.9rem; margin: 14px 0; }

.results-list {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  width: 100%;
}
.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: inherit;
  font-family: inherit;
}
.result-item img { width: 46px; height: 68px; object-fit: cover; border-radius: 3px; }
.result-item .r-title { display: block; color: var(--ivory); }
.result-item .r-year { display: block; font-size: 0.85rem; color: var(--muted); }

/* Movie / rating panel */
.movie-header {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.movie-header img {
  width: 140px;
  height: 207px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}
.movie-title { font-size: 2rem; color: var(--gold-bright); margin: 0; }
.movie-meta { font-size: 0.9rem; color: var(--muted); margin: 4px 0; }
.movie-plot { font-size: 0.95rem; color: var(--ivory); opacity: 0.85; margin-top: 10px; max-width: 90ch; }

.perf {
  height: 14px;
  background-image: radial-gradient(circle at 7px 7px, var(--bg) 6px, transparent 7px);
  background-size: 18px 14px;
  background-repeat: repeat-x;
  margin: 24px 0;
}

.section-title { font-size: 1.3rem; color: var(--gold); margin-bottom: 2px; }

.criteria-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px 40px;
  margin-top: 16px;
}
@media (min-width: 800px) {
  .criteria-list { grid-template-columns: 1fr 1fr; }
}
.criterion-row .crit-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.crit-name-wrap { display: flex; align-items: center; gap: 6px; }
.criterion-row .crit-name { color: var(--ivory); }
.criterion-row .crit-note { color: var(--gold-bright); font-size: 0.9rem; }

.tooltip-wrap {
  position: relative;
  display: inline-flex;
}
.tooltip-icon {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  background: none;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  padding: 0;
  font-family: 'JetBrains Mono', monospace;
}
.tooltip-icon:hover,
.tooltip-icon:focus-visible {
  color: var(--gold-bright);
  border-color: var(--gold-bright);
}
.tooltip-bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: 220px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--ivory);
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 0.8rem;
  line-height: 1.35;
  padding: 10px 12px;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}
.tooltip-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border);
}
.tooltip-wrap:hover .tooltip-bubble,
.tooltip-icon:focus-visible + .tooltip-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}
@media (max-width: 640px) {
  .tooltip-bubble { left: 0; transform: translateX(0) translateY(4px); width: 200px; }
  .tooltip-wrap:hover .tooltip-bubble,
  .tooltip-icon:focus-visible + .tooltip-bubble { transform: translateX(0) translateY(0); }
}

input[type="range"].mc-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--gold) 0%, var(--gold) var(--fill, 50%), #3a2e30 var(--fill, 50%), #3a2e30 100%);
}
input[type="range"].mc-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid var(--bg);
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--gold);
}
input[type="range"].mc-slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--gold-bright);
  border: 2px solid var(--bg);
  cursor: pointer;
}

.weight-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}
.weight-row .weight-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-right: 4px;
}
.star-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  color: #3a2e30;
}
.star-btn.filled { color: var(--gold-bright); }

.tags-section {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.quick-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}
.quick-tag-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ivory);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.quick-tag-btn:hover { border-color: var(--gold); color: var(--gold-bright); }
.quick-tag-btn.filled { background: var(--wine); border-color: var(--wine); color: var(--ivory); }
.tag-input-row {
  display: flex;
  gap: 8px;
  max-width: 420px;
}
.tag-input-row input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ivory);
  font-family: inherit;
}
.tag-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--wine);
  color: var(--ivory);
  font-size: 0.82rem;
  padding: 5px 10px 5px 12px;
  border-radius: 999px;
}
.tag-chip button {
  background: none;
  border: none;
  color: var(--ivory);
  opacity: 0.8;
  cursor: pointer;
  display: flex;
  padding: 0;
}
.tag-chip button:hover { opacity: 1; }

.collection-toolbar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.collection-search { max-width: 380px; flex: 1; }
.collection-search input {
  width: 100%;
  padding: 11px 12px 11px 36px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ivory);
  font-family: inherit;
}
.export-buttons { display: flex; gap: 8px; }

.ticket-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0 12px 10px;
}
.ticket-tag {
  font-size: 0.7rem;
  background: var(--surface2);
  color: var(--gold-bright);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

.save-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 32px;
  flex-wrap: wrap;
}
.stamp {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid var(--gold-bright);
  transform: rotate(-8deg);
  color: var(--gold-bright);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: stamp-in 0.35s ease-out;
}
.stamp #score-value { font-size: 1.5rem; font-weight: 700; }
.stamp-sub { font-size: 0.62rem; }

@keyframes stamp-in {
  0% { transform: scale(1.4) rotate(-8deg); opacity: 0; }
  100% { transform: scale(1) rotate(-8deg); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .stamp { animation: none; }
}

/* Collection */
.empty { text-align: center; padding: 60px 0; color: var(--muted); }
.empty-title { font-size: 1.4rem; color: var(--gold); margin: 10px 0 4px; }

.collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 12px;
  width: 100%;
}
.ticket-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.ticket-top {
  display: flex;
  gap: 12px;
  padding: 12px;
}
.ticket-top img { width: 64px; height: 94px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
.ticket-info { min-width: 0; }
.ticket-title {
  font-size: 1.1rem;
  line-height: 1.1;
  color: var(--ivory);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.ticket-year { font-size: 0.78rem; color: var(--muted); margin: 4px 0 8px; }
.mini-stamp {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--gold-bright);
  transform: rotate(-8deg);
  color: var(--gold-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}
.ticket-perf {
  height: 14px;
  background-image: radial-gradient(circle at 7px 7px, var(--bg) 6px, transparent 7px);
  background-size: 18px 14px;
  background-repeat: repeat-x;
}
.ticket-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--gold);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  font-family: inherit;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
}

/* Save flash */
.save-flash {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--wine);
  color: var(--ivory);
  padding: 12px 16px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.modal-head h2 { color: var(--gold-bright); font-size: 1.5rem; margin: 0; }
#api-key-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--ivory);
  font-family: inherit;
  margin-top: 6px;
}

@media (max-width: 640px) {
  .header, .tabs, .main { padding-left: 18px; padding-right: 18px; }
}