/* ============================================================
   VARIABLES
   ============================================================ */
:root {
  /* Backgrounds */
  --bg:                #0e1318;
  --surface:           #161d26;
  --surface-raised:    #1c2635;
  --surface-hero:      #111820;

  /* Borders */
  --border:            #22303f;
  --border-subtle:     #1a2736;
  --border-accent:     rgba(61, 186, 74, 0.20);

  /* Text */
  --text:              #ccd8e8;
  --text-dim:          #8aa0b8;
  --text-muted:        #627a90;
  --text-bright:       #eef4fc;

  /* Accent */
  --accent:            #3dba4a;
  --accent-hover:      #4dd95a;
  --accent-dim:        rgba(61, 186, 74, 0.10);
  --accent-border:     rgba(61, 186, 74, 0.22);
  --accent-glow:       rgba(61, 186, 74, 0.18);

  /* Stars */
  --star-filled:       #3dba4a;
  --star-glow:         rgba(61, 186, 74, 0.35);
  --star-empty:        #283848;

  /* Danger */
  --danger:            #de4d57;
  --danger-dim:        rgba(222, 77, 87, 0.08);

  /* Warn */
  --warn:              #c9a23a;
  --warn-dim:          rgba(201, 162, 58, 0.12);

  /* Shape */
  --radius:            12px;
  --radius-sm:         8px;
  --radius-xs:         4px;

  /* Shadows */
  --shadow-sm:         0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:         0 4px 20px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg:         0 12px 48px rgba(0,0,0,0.6), 0 4px 16px rgba(0,0,0,0.3);
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: radial-gradient(ellipse 120% 60% at 0% 0%, rgba(61,186,74,0.04) 0%, transparent 50%), var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* ============================================================
   PAGE NOISE OVERLAY
   ============================================================ */
#page-noise {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.022;
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: overlay;
}

/* ============================================================
   LAYOUT — single column, centred
   Workspace on top · Stage (results) below, seamlessly integrated
   ============================================================ */
#app-layout {
  display: flex;
  flex-direction: column;
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
}

/* Stage — results section below workspace */
#stage {
  order: 2;
  background: transparent;
  box-shadow: inset 0 3px 0 var(--accent);
  border-top: 1px solid var(--border);
}

/* Workspace — rating workflow */
#workspace {
  order: 1;
  padding: 0 56px 80px;
  min-width: 0;
}

#site-header,
#workflow {
  max-width: none;
}

/* ============================================================
   HEADER
   ============================================================ */
#site-header {
  padding-top: 80px;
  padding-bottom: 56px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0;
}

.header-kicker {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-kicker::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 1px;
  background: var(--accent);
  opacity: 0.6;
}

#site-header h1 {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 52px;
  font-weight: 400;
  color: var(--text-bright);
  letter-spacing: -0.025em;
  line-height: 1.08;
  margin-bottom: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.site-logo {
  height: 36px;
  width: auto;
  flex-shrink: 0;
}

.intro {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.72;
  max-width: 540px;
}

/* ============================================================
   TOOLTIP SYSTEM
   ============================================================ */
.info-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.info-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 9.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: help;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
  transition: border-color 0.15s, color 0.15s;
}

.info-btn:hover,
.info-btn:focus-visible {
  border-color: var(--text-dim);
  color: var(--text-dim);
  outline: none;
}

.info-btn-light {
  border-color: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.28);
}

.info-btn-light:hover,
.info-btn-light:focus-visible {
  border-color: rgba(255,255,255,0.28);
  color: rgba(255,255,255,0.5);
}

.tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.6;
  width: 230px;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  z-index: 100;
  text-align: left;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  white-space: normal;
}

.tooltip.tooltip-end {
  left: auto;
  right: 0;
  transform: none;
}

.info-wrap:hover .tooltip,
.info-wrap:focus-within .tooltip {
  opacity: 1;
  visibility: visible;
}

/* ============================================================
   FILM ROW
   ============================================================ */
#film-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   FILM SEARCH — wrap, dropdown, results
   ============================================================ */
#film-search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.movie-clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.12s ease;
}

.movie-clear-btn:hover {
  color: var(--danger);
}

#search-results {
  position: absolute;
  top: calc(100% + 10px);
  left: -14px;
  right: -14px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s ease;
  outline: none;
}

.search-result-item:hover,
.search-result-item:focus-visible {
  background: var(--bg);
}

.search-result-item + .search-result-item {
  border-top: 1px solid var(--border-subtle);
}

.result-poster {
  width: 32px;
  height: 48px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--surface);
  display: block;
}

.result-poster-empty {
  width: 32px;
  height: 48px;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
}

.result-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.result-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-bright);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-year {
  font-size: 12px;
  color: var(--text-muted);
}

.tmdb-attr {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

/* ============================================================
   MOVIE TITLE INPUT
   ============================================================ */
#movie-title-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-bright);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 6px 0;
  outline: none;
  transition: border-color 0.18s ease;
}

#movie-title-input::placeholder {
  color: var(--text-muted);
}

#movie-title-input:focus {
  border-bottom-color: var(--accent);
}

/* ============================================================
   UTILITY ROW — mode controls
   ============================================================ */
#utility-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.utility-label {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  white-space: nowrap;
  flex-shrink: 0;
}

#mode-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

#mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.mode-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
  letter-spacing: 0.01em;
}

.mode-btn.active {
  background: var(--surface-raised);
  color: var(--text-bright);
}

.mode-btn:hover:not(.active) {
  color: var(--text);
}

.utility-secondary-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}

.utility-secondary-btn:hover,
.utility-secondary-btn[aria-expanded="true"] {
  color: var(--text);
  border-color: rgba(255,255,255,0.16);
}

.utility-secondary-btn[aria-expanded="true"] {
  background: var(--surface);
}

.utility-secondary-btn.has-custom {
  color: var(--accent);
  border-color: var(--accent-border);
}

.custom-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: 3px;
  padding: 1px 5px;
  line-height: 1.4;
}

/* ============================================================
   MODE DESCRIPTION ROW
   ============================================================ */
#mode-description-row {
  padding: 12px 0 4px;
  min-height: 28px;
}

.mode-description {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.groups-hint {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 16px 0 4px;
}

/* ============================================================
   WEIGHTS PANEL
   ============================================================ */
#weights-panel {
  border: 1px solid var(--border-subtle);
  border-top: 2px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: rgba(255,255,255,0.015);
  margin-top: 0;
  margin-bottom: 32px;
}

.weights-panel-inner {
  padding: 20px 24px;
}

.weights-panel-header {
  margin-bottom: 16px;
}

.weights-panel-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.weights-panel-note {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 480px;
}

#weights-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.weight-editor-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.weight-editor-label {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--text-dim);
}

.weight-input {
  width: 52px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  padding: 4px 7px;
  border-radius: var(--radius-xs);
  text-align: right;
  outline: none;
  transition: border-color 0.15s ease;
  -moz-appearance: textfield;
}

.weight-input::-webkit-outer-spin-button,
.weight-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.weight-input:focus {
  border-color: var(--accent);
}

.weight-pct-suffix {
  font-size: 12px;
  color: var(--text-dim);
  width: 12px;
}

.weights-panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.weights-total {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease;
}

.weights-total.warn {
  color: var(--warn);
}

.weights-reset-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.weights-reset-btn:hover {
  color: var(--text);
  border-color: rgba(255,255,255,0.16);
}

/* ============================================================
   GROUP SECTIONS — workspace workflow
   ============================================================ */
#groups-container {
  display: flex;
  flex-direction: column;
  margin-bottom: 80px;
}

.group-card {
  padding: 44px 0;
}

.group-card:first-child {
  padding-top: 32px;
}

.group-card + .group-card {
  border-top: 1px solid var(--border);
}

/* Header: title + weight badge left, stars right (Simple mode) */
.group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.group-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.group-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 28px;
  font-weight: 400;
  color: var(--text-bright);
  letter-spacing: -0.015em;
  white-space: nowrap;
  line-height: 1.1;
}

.group-weight {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  border-radius: 4px;
  padding: 2px 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Right cluster: Simple mode stars + clear */
.group-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.group-header-right .star-control .star {
  font-size: 20px;
  padding: 0 2px;
}

.group-description {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.65;
  margin-top: 6px;
  margin-bottom: 14px;
  max-width: 480px;
}

/* ============================================================
   INPUT ROWS
   ============================================================ */
.group-inputs {
  display: flex;
  flex-direction: column;
}

.input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 0;
  border-top: 1px solid var(--border-subtle);
  transition: background 0.1s ease;
}

.input-label-area {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.input-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-bright);
  line-height: 1.4;
}

.input-helper {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 2px;
}

.input-control-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ============================================================
   STAR CONTROL
   ============================================================ */
.star-control {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 2px 0;
}

.star-control .star {
  font-size: 22px;
  display: inline-block;
  user-select: none;
  cursor: pointer;
  line-height: 1;
  padding: 0 3px;
  transition:
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1),
    color 0.12s ease,
    filter 0.12s ease;
}

.star-control .star:hover {
  transform: scale(1.22);
}

.star-control .star.empty {
  color: var(--star-empty);
  filter: none;
}

.star-control .star.full {
  color: var(--star-filled);
  filter: drop-shadow(0 0 6px var(--star-glow));
}

.star-control .star.half {
  color: var(--star-filled);
  background: linear-gradient(
    to right,
    var(--star-filled) 50%,
    var(--star-empty) 50%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: none;
}

.star-control:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 5px;
  border-radius: 4px;
}

/* ============================================================
   CLEAR BUTTON
   ============================================================ */
.clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 15px;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.clear-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-dim);
}

/* ============================================================
   STAGE — RAIL MOVIE (portrait poster + metadata)
   ============================================================ */
#rail-movie {
  border-bottom: 1px solid var(--border);
}

/* Empty state */
.rail-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 24px;
  text-align: center;
}

.rail-empty-icon {
  font-size: 20px;
  color: var(--text-muted);
  line-height: 1;
  opacity: 0.45;
}

.rail-empty-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 200px;
}

/* Movie card — portrait poster left, metadata right */
.rail-movie-card {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 18px;
  padding: 20px 24px;
  animation: stageFadeIn 0.28s ease;
}

@keyframes stageFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Portrait poster container — natural 2:3 ratio */
.rail-poster-wrap {
  width: 88px;
  height: 132px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
}

.rail-poster {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.rail-poster-empty {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--surface-raised);
}

/* Metadata sits beside the poster */
.rail-movie-meta {
  flex: 1;
  min-width: 0;
  padding: 2px 0;
}

.rail-movie-title {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-bright);
  line-height: 1.2;
  margin-bottom: 6px;
}

.rail-movie-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.rail-movie-year {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.rail-sub-sep {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1;
}

.rail-tmdb-rating {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.01em;
}

.rail-movie-overview {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   RESULTS — Outer
   ============================================================ */
#results {
  border-top: none;
}

.results-pad {
  padding: 22px 24px;
}

#letterboxd-hero,
#actions {
  border-top: 1px solid var(--border);
}

/* ============================================================
   RESULTS — Section heading
   ============================================================ */
#results > .results-pad > h2 {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#results > .results-pad > h2::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* ============================================================
   RESULTS — Group averages
   ============================================================ */
#group-averages {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.group-avg-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  column-gap: 8px;
}

.group-avg-name {
  font-size: 12.5px;
  color: var(--text-dim);
  padding-right: 4px;
  white-space: nowrap;
}

.group-avg-row::after {
  content: '';
  grid-column: 2;
  align-self: end;
  border-bottom: 1px dotted var(--border);
  margin-bottom: 4px;
}

.group-avg-value {
  grid-column: 3;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.25s ease, font-weight 0.25s ease;
  padding-left: 4px;
}

.group-avg-value.active {
  font-weight: 700;
  color: var(--text-bright);
}

/* ============================================================
   RESULTS — Stats
   ============================================================ */
#result-stats {
  display: flex;
  gap: 36px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.stat-value {
  font-size: 28px;
  font-weight: 400;
  color: var(--text-bright);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-family: 'DM Serif Display', Georgia, serif;
  letter-spacing: -0.01em;
}

/* ============================================================
   RESULTS — Weighted score
   ============================================================ */
#weighted-score-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 14px 0 8px;
  border-top: 1px solid var(--border);
}

.wscore-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.wscore-value {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  color: var(--text-bright);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ============================================================
   RESULTS — Score insight
   ============================================================ */
.score-insight {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.01em;
  margin-top: 2px;
  margin-bottom: 4px;
}

/* ============================================================
   RESULTS — Letterboxd hero
   ============================================================ */
#letterboxd-hero {
  padding: 52px 24px 48px;
  border-top: 1px solid var(--border-accent);
  background: radial-gradient(ellipse 70% 60% at 50% 100%, rgba(61,186,74,0.07) 0%, transparent 70%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
}

.hero-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.result-stars {
  display: flex;
  align-items: center;
  gap: 2px;
}

.result-stars .star {
  font-size: 32px;
  display: inline-block;
  line-height: 1;
}

.result-stars .star.empty {
  color: var(--star-empty);
}

.result-stars .star.full {
  color: var(--star-filled);
  filter: drop-shadow(0 0 8px var(--star-glow));
}

.result-stars .star.half {
  color: var(--star-filled);
  background: linear-gradient(
    to right,
    var(--star-filled) 50%,
    var(--star-empty) 50%
  );
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-score {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 96px;
  font-weight: 400;
  color: var(--accent);
  letter-spacing: -0.025em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 60px rgba(61,186,74,0.25), 0 0 120px rgba(61,186,74,0.12);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */
#results.is-empty #group-averages,
#results.is-empty #result-stats,
#results.is-empty #weighted-score-row {
  display: none;
}

#results.is-empty > .results-pad:first-child {
  padding-bottom: 4px;
}

#results.is-empty > .results-pad:first-child > h2 {
  margin-bottom: 0;
}

#results.is-empty .hero-score {
  font-family: 'DM Serif Display', Georgia, serif;
  font-size: 36px;
  font-weight: 400;
  color: var(--text-muted);
  text-shadow: none;
}

#empty-hint {
  display: none;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  margin-top: -4px;
  font-style: italic;
}

#results.is-empty #empty-hint {
  display: block;
}

#results.is-empty #result-letterboxd-stars {
  display: none;
}

/* ============================================================
   SUMMARY BOX
   ============================================================ */
#summary-section {
  border-top: 1px solid var(--border);
}

.summary-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 18px;
}

#summary-section h3 {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

.summary-note {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* The generated text — reads like a piece of writing, not a code block */
#summary-text {
  background: transparent;
  border: none;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 20px 0;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: hidden;
}

.summary-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 20px;
}

#copy-btn {
  background: var(--accent);
  color: #071209;
  border: 1px solid transparent;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

#copy-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px rgba(61,186,74,0.3);
}

#copy-btn:disabled {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
  cursor: default;
}

/* ============================================================
   ACTIONS
   ============================================================ */
#actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding-top: 16px;
  padding-bottom: 20px;
}

#view-card-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 0.12s ease, border-color 0.12s ease;
}

#view-card-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent-border);
}

#view-card-btn:disabled {
  color: var(--text-muted);
  border-color: var(--border);
  cursor: default;
  opacity: 0.5;
}

#share-link-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 0.12s ease, border-color 0.12s ease;
}

#share-link-btn:hover {
  color: var(--accent);
  border-color: var(--accent-border);
}

#reset-all-btn {
  background: none;
  border: 1px solid rgba(222, 77, 87, 0.38);
  color: var(--danger);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

#reset-all-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-dim);
}

/* ============================================================
   SCORE PILL — floating live companion, glassmorphism
   ============================================================ */
#score-pill {
  position: fixed;
  bottom: 32px;
  right: 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(22, 29, 38, 0.85);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 10px 22px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.06);
  z-index: 50;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#score-pill.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  cursor: pointer;
}

#score-pill.is-visible:hover {
  border-color: rgba(61,186,74,0.25);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 1px rgba(61,186,74,0.15);
}

.pill-score {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.pill-sep {
  width: 1px;
  height: 14px;
  background: rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.pill-lb {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* ============================================================
   FOCUS STATES
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ============================================================
   DESKTOP FINE-TUNING (≥ 600px)
   Align results content to the same horizontal rhythm as workspace
   ============================================================ */
@media (min-width: 600px) {
  #site-header h1 {
    font-size: 56px;
  }

  .rail-movie-card {
    padding: 24px 56px;
    gap: 22px;
  }

  .rail-poster-wrap {
    width: 100px;
    height: 150px;
  }

  .group-title {
    font-size: 28px;
  }

  .hero-score {
    font-size: 96px;
  }

  /* Match results padding to workspace horizontal padding */
  .results-pad {
    padding: 24px 56px;
  }

  #letterboxd-hero {
    padding: 52px 56px 48px;
  }

  #summary-section.results-pad {
    padding: 40px 56px;
  }

  #actions.results-pad {
    padding: 20px 56px 56px;
  }

  .rail-empty-state {
    padding: 40px 56px;
    text-align: left;
    align-items: flex-start;
  }
}

/* ============================================================
   MOBILE — single-column stack (≤ 767px)
   ============================================================ */
@media (max-width: 767px) {
  .rail-movie-card {
    padding: 16px 18px;
    gap: 14px;
  }

  .rail-poster-wrap {
    width: 72px;
    height: 108px;
  }

  .rail-empty-state {
    padding: 20px 18px;
  }

  #workspace {
    padding: 0 18px 60px;
  }

  #site-header {
    padding-top: 44px;
    padding-bottom: 40px;
  }

  #site-header h1 {
    font-size: 36px;
  }

  #groups-container {
    margin-bottom: 48px;
  }

  .group-card {
    padding: 36px 0;
  }

  .group-card:first-child {
    padding-top: 24px;
  }

  .group-title {
    font-size: 22px;
  }

  /* Full mode: stack label above stars on mobile */
  .input-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .input-control-area {
    width: 100%;
    justify-content: space-between;
  }

  /* Simple mode header stays horizontal */
  .group-header {
    flex-wrap: nowrap;
    align-items: center;
  }

  /* Larger tap targets */
  .star-control .star {
    font-size: 26px;
    padding: 0 4px;
  }

  .group-header-right .star-control .star {
    font-size: 20px;
    padding: 0 2px;
  }

  .clear-btn {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }

  .results-pad {
    padding: 20px 18px;
  }

  #result-stats {
    gap: 24px;
  }

  .stat-value {
    font-size: 22px;
  }

  #letterboxd-hero {
    padding: 36px 18px 32px;
  }

  .hero-score {
    font-size: 64px;
  }

  #results.is-empty .hero-score {
    font-size: 30px;
  }

  .result-stars .star {
    font-size: 24px;
  }

  #film-row {
    padding: 16px 0;
  }

  #utility-row {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 0;
  }

  #actions {
    flex-wrap: wrap;
    justify-content: center;
    padding-top: 14px;
    padding-bottom: 18px;
  }

  #copy-btn {
    width: 100%;
    text-align: center;
    padding: 10px 16px;
  }

  .summary-actions {
    justify-content: stretch;
  }

  #summary-text {
    font-size: 13px;
  }

  .weights-panel-inner {
    padding: 20px 18px;
  }

  .weight-editor-row {
    gap: 8px;
  }

  .tooltip {
    width: 200px;
  }

  .tooltip.tooltip-end {
    right: -8px;
  }

  .summary-header {
    flex-direction: column;
    gap: 4px;
  }

  /* Pill: centered at bottom on mobile */
  #score-pill {
    right: auto;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    bottom: 20px;
  }

  #score-pill.is-visible {
    transform: translateX(-50%) translateY(0);
  }
}

/* ============================================================
   MOBILE — tighter horizontal padding (≤ 600px)
   ============================================================ */
@media (max-width: 600px) {
  #workspace {
    padding-left: 20px;
    padding-right: 20px;
  }
}

/* ============================================================
   MOBILE — very small screens (≤ 400px)
   ============================================================ */
@media (max-width: 400px) {
  #workspace {
    padding-left: 14px;
    padding-right: 14px;
  }

  #site-header h1 {
    font-size: 30px;
  }

  .star-control .star {
    font-size: 24px;
    padding: 0 3px;
  }

  .group-header-right .star-control .star {
    font-size: 18px;
    padding: 0 2px;
  }

  .result-stars .star {
    font-size: 20px;
  }

  .hero-score {
    font-size: 52px;
  }

  #results.is-empty .hero-score {
    font-size: 26px;
  }

  .stat-value {
    font-size: 20px;
  }

  .group-title {
    font-size: 20px;
  }
}

/* ============================================================
   CARD LIGHTBOX
   ============================================================ */
#card-lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#card-lightbox[hidden] {
  display: none;
}

#card-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  cursor: pointer;
}

#card-lightbox-inner {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  max-width: 900px;
  width: 100%;
  overflow: hidden;
}

#card-lightbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
}

#card-lightbox-title {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.11em;
}

#card-lightbox-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  font-family: inherit;
  transition: color 0.12s ease, background 0.12s ease;
}

#card-lightbox-close:hover {
  color: var(--danger);
  background: var(--danger-dim);
}

#card-lightbox-body {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

#card-preview-loading {
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
}

#card-preview-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

#card-lightbox-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

/* Share — primary green action */
#lightbox-share-btn {
  background: var(--accent);
  color: #061108;
  border: 1px solid transparent;
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.15s ease;
}

#lightbox-share-btn:hover {
  background: var(--accent-hover);
}

/* Copy + Download — icon-only ghost buttons */
#lightbox-copy-btn,
#lightbox-download-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.12s ease, border-color 0.12s ease;
}

#lightbox-copy-btn:hover,
#lightbox-download-btn:hover:not(:disabled) {
  color: var(--text-bright);
  border-color: rgba(255,255,255,0.2);
}

#lightbox-download-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

@media (min-width: 768px) {
  #card-lightbox-inner {
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
  }

  #card-lightbox-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  #card-preview-img {
    width: auto;
    max-width: 100%;
    max-height: calc(100vh - 200px);
  }
}

@media (max-width: 767px) {
  #card-lightbox {
    padding: 12px;
    align-items: flex-end;
  }

  #card-lightbox-inner {
    max-height: 90vh;
    overflow-y: auto;
  }

  #card-lightbox-body {
    padding: 12px;
  }

  #card-lightbox-footer {
    flex-wrap: wrap;
  }

  #lightbox-share-btn {
    flex: 1;
    text-align: center;
    padding: 10px 12px;
  }
}
