/* Palette carried over from v1. Defined once as variables so Stage 5 polish
   only has to change values here. */
:root {
  --bg: #14110F;
  --surface: #1E1A17;
  --surface-2: #2A2420;
  --text: #EDE6DC;
  --muted: #A89F94;
  --accent: #E8A33D;
  --danger: #E06C5A;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Keep content clear of the notch and home bar on iPhone. */
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

main { max-width: 640px; margin: 0 auto; padding-block: 16px 32px; }

h1 { font-size: 1.25rem; margin: 0; }

/* iOS zooms into any input with text smaller than 16px, so inputs stay at 16px. */
input, button { font: inherit; }

input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 48px minimum height: big enough to hit with a thumb. */
button {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #1A1206;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.quiet { background: transparent; color: var(--muted); padding: 0 8px; }

.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }

/* ---- Login screen ---- */
.login { display: flex; flex-direction: column; justify-content: center; min-height: 80vh; }
.login h1 { font-size: 1.6rem; margin-bottom: 24px; color: var(--accent); }
.login form { display: grid; gap: 12px; }
.login label { color: var(--muted); }

/* ---- Main screen ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

/* Title takes the remaining width; year and Add size to their content. */
.add-form { display: grid; grid-template-columns: 1fr 5.5rem auto; gap: 8px; }

.status { color: var(--muted); min-height: 1.4em; margin: 12px 0; }
.status.is-error { color: var(--danger); }

/* The 2-column poster grid. */
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.card { position: relative; }

/* Placeholder "poster" until Stage 5 adds real images. 2:3 is the standard
   movie poster shape, so real posters will drop in without a layout change. */
.poster {
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--surface-2);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  overflow: hidden;
}
/* With a real poster: the image fills the tile, and the text sits on a dark
   fade at the bottom so it stays readable over any artwork. */
.poster { position: relative; }
.poster-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* cover = fill the 2:3 box, cropping slightly if a poster is a bit off. */
  object-fit: cover;
}
.poster.has-image::after {
  content: "";
  position: absolute;
  inset: 45% 0 0;
  background: linear-gradient(transparent, rgba(20, 17, 15, 0.92));
}
/* Text above the image and the fade. */
.poster > span { position: relative; z-index: 1; }

.poster .title { font-weight: 600; overflow-wrap: anywhere; }
.poster .year { color: var(--muted); font-size: 0.9rem; }

.remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  background: rgba(20, 17, 15, 0.75);
  color: var(--text);
  font-size: 1.2rem;
  line-height: 1;
}

.poster .where { color: var(--accent); font-size: 0.85rem; font-weight: 600; margin-top: 4px; }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.muted { color: var(--muted); font-weight: 400; }

/* ---- Services panel ---- */
.services {
  margin-top: 12px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
}
.services summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}
.services[open] summary { border-bottom: 1px solid var(--surface-2); }

.chips { list-style: none; margin: 0; padding: 12px 14px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-left: 12px;
  border-radius: 999px;
  background: var(--surface-2);
}
.chip button {
  min-height: 40px;
  width: 40px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
}

.service-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 12px 14px 14px; }

/* ---- Check + sort ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); }
select {
  font: inherit;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

button.secondary { background: var(--surface-2); color: var(--text); }

/* ---- Suggestions under the add form ---- */
/* position: relative here lets the list below float over the page
   (position: absolute) instead of pushing everything down as it appears. */
.add-area { position: relative; }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.suggestion {
  width: 100%;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  background: transparent;
  color: var(--text);
  font-weight: 400;
  text-align: left;
}
.suggestion:hover, .suggestion:focus-visible { background: var(--surface-2); }
.suggestion-text, .match-body { display: flex; flex-direction: column; min-width: 0; gap: 4px; }
.suggestion .title, .match-body .title { font-weight: 600; }
.suggestion .year { color: var(--muted); font-size: 0.9rem; }

.thumb {
  flex: none;
  width: 40px;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  background: var(--surface-2);
  object-fit: cover;
}

/* ---- Match years ---- */
.match { margin-top: 16px; }
.match h2 { font-size: 1.1rem; margin: 0 0 4px; }
.match > p { margin: 0 0 12px; }
.match-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.match-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
}
.match-body select { width: 100%; }
.match-body .year { color: var(--muted); font-size: 0.9rem; }
/* Keep Save reachable at the bottom of a long list. */
.match-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}

/* ---- Groups after a check ---- */
.group + .group { margin-top: 24px; }
.group h2 { font-size: 1rem; color: var(--muted); margin: 0 0 10px; }
