/* ===========================================================
   Deaf Movies Directory
   Palette checked against WCAG 2.1 AA (4.5:1 body, 3:1 large).
   The old site used red (#f00) and orange (#FFAA33) on black,
   plus white on #333 - several of those combinations failed.
   =========================================================== */

:root {
  --ink:        #14161a;
  --ink-soft:   #4a5058;
  --paper:      #ffffff;
  --paper-alt:  #f4f6f8;
  --line:       #d6dbe1;
  --brand:      #10457e;   /* 8.6:1 on white */
  --brand-deep: #0b3159;
  --accent:     #a8410a;   /* 5.4:1 on white - replaces the old #f00 */
  --ok:         #10604a;
  --focus:      #b4530a;
  --radius:     8px;
  /* Explicit tints rather than color-mix(), which Safari below 16.2
     and Firefox below 113 do not support - there they would render
     with no background at all. */
  --ok-tint:     #e7f2ee;
  --accent-tint: #fbeee7;
  --field-bg:    #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:       #eef1f5;
    --ink-soft:  #b3bcc8;
    --paper:     #14171c;
    --paper-alt: #1d2229;
    --line:      #333b46;
    --brand:     #7fb2ee;   /* 7.1:1 on #14171c */
    --brand-deep:#a8ccf5;
    --accent:    #ff9e6b;
    --ok:        #6fd3b2;
    --focus:     #ffb066;
    --ok-tint:     #15302a;
    --accent-tint: #38241a;
    --field-bg:    #1a1f26;
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

.wrap { width: min(1180px, 92vw); margin-inline: auto; }

/* ---- focus: never remove it, this site must be keyboard usable ---- */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--brand); color: #fff; padding: .75rem 1.25rem; z-index: 100;
}
.skip-link:focus { left: 0; }

/* Visible to screen readers, not on screen. Used for table captions
   that would be redundant next to a visible heading. */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

/* ---- header ---- */
.site-header { border-bottom: 1px solid var(--line); background: var(--paper-alt); }
.header-inner {
  display: flex; flex-wrap: wrap; gap: 1rem;
  align-items: center; justify-content: space-between; padding: .9rem 0;
}
.brand img { display: block; height: 48px; width: auto; }
.nav-list { display: flex; flex-wrap: wrap; gap: .35rem; list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: block; padding: .55rem .85rem; border-radius: var(--radius);
  color: var(--brand); font-weight: 600; text-decoration: none;
}
.nav-list a:hover { background: var(--paper); text-decoration: underline; }

/* ---- typography ---- */
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); line-height: 1.2; margin: 1.5rem 0 .5rem; }
h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); margin: 2rem 0 .5rem; }
h3 { font-size: 1.1rem; margin: 1.25rem 0 .35rem; }
a  { color: var(--brand); }
.lede { font-size: 1.1rem; color: var(--ink-soft); max-width: 68ch; }

/* ---- filters ---- */
.filters {
  background: var(--paper-alt); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin: 1.5rem 0;
}
.filter-grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.field label { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .92rem; }

/* Every control gets the same treatment. textarea was missing here, which
   is why the message box rendered as a narrow white browser default while
   everything around it was dark. */
.field input,
.field select,
.field textarea,
input[type="text"], input[type="email"], input[type="url"],
input[type="search"], input[type="number"], input[type="password"],
input[type="date"], select, textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: .6rem .7rem;
  /* 16px minimum: iOS Safari zooms the page in when a focused field is
     smaller than this, which feels like a bug to the user. */
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  /* Stop iOS and older Android painting their own control styling. */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* The select still needs its arrow back after appearance:none. */
.field select, select {
  padding-right: 2.1rem;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
  background-size: 12px 8px;
}

/* Placeholder colour, with the old prefixed forms for reach. */
::-webkit-input-placeholder { color: var(--ink-soft); opacity: 1; }
::-moz-placeholder          { color: var(--ink-soft); opacity: 1; }
:-ms-input-placeholder      { color: var(--ink-soft); opacity: 1; }
::placeholder               { color: var(--ink-soft); opacity: 1; }

/* Checkboxes keep their native look - appearance:none above would make
   them invisible, and the browser's own control is the accessible one. */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: auto;
  -moz-appearance: auto;
  appearance: auto;
  width: auto; display: inline-block;
}
input[type="file"] {
  -webkit-appearance: auto; appearance: auto;
  padding: .5rem; background-color: var(--paper-alt);
}

.hint { font-size: .85rem; color: var(--ink-soft); margin: .25rem 0 0; }

.btn {
  display: inline-block; padding: .6rem 1.1rem; font-size: 1rem; font-weight: 600;
  border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
  text-decoration: none;
}
.btn-primary  { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); }
.btn-secondary { background: var(--paper); color: var(--brand); border-color: var(--line); }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .9rem; }

/* ---- results ---- */
.result-count { font-weight: 600; margin: 1.25rem 0 .5rem; }

.film-grid {
  display: grid; gap: 1.1rem; padding: 0; list-style: none;
  /* Poster-shaped cards want to be narrow, the way a film directory
     shelf reads - five or six across, not three enormous ones. */
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
}
.film-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--paper-alt); padding: 1rem; display: flex; flex-direction: column;
  /* Grid and flex children default to min-width:auto, which refuses to
     shrink below the content's minimum size. A long film title then forces
     the track wider than its container and the page scrolls sideways on
     small phones. This lets the card shrink and the title wrap instead. */
  min-width: 0;
}
.film-card > *, .cover-gen, .cover-gen-title { min-width: 0; }

/* ---- covers -------------------------------------------------------
   A film either has a real poster or gets a generated one. The
   generated cover is a designed object in its own right, so a film
   with no poster still looks deliberate instead of broken.
   ------------------------------------------------------------------ */
.cover-link { display: block; margin: -1rem -1rem .85rem; }
.cover-link:focus-visible { outline-offset: -3px; }

.cover-img, .cover-gen {
  display: block; width: 100%;
  -o-object-fit: cover;
     object-fit: cover;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--paper);
  /* Fallback for Safari below 15 and Chrome below 88, which have no
     aspect-ratio: keep a sensible poster height rather than collapsing. */
  min-height: 250px;
}
@supports (aspect-ratio: 2 / 3) {
  .cover-img, .cover-gen { aspect-ratio: 2 / 3; min-height: 0; }
}

.cover-gen {
  /* Hue comes from the film's slug, so each cover is stable and distinct.
     Lightness is fixed low enough that white text clears AA at any hue. */
  background:
    linear-gradient(160deg,
      hsl(var(--cover-hue, 220) 26% 27%) 0%,
      hsl(var(--cover-hue, 220) 32% 17%) 100%);
  color: #fff;
  display: flex; flex-direction: column; justify-content: center;
  padding: 1.1rem 1rem; gap: .3rem;
  text-align: left; overflow: hidden; position: relative;
}

/* a quiet film-strip edge, so it reads as a cover rather than a colour swatch */
.cover-gen::before {
  /* Longhand rather than the inset shorthand, which Safari below 14.1 ignores. */
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 9px;
  background-image: repeating-linear-gradient(
    to bottom, rgba(255,255,255,.22) 0 7px, transparent 7px 15px);
  opacity: .55;
}

.cover-gen-title {
  font-weight: 700; line-height: 1.18; letter-spacing: -.015em;
  padding-left: .55rem;
  overflow-wrap: anywhere; hyphens: auto;
}
.cover-gen-lg .cover-gen-title { font-size: 1.08rem; }
.cover-gen-md .cover-gen-title { font-size: .98rem; }
.cover-gen-sm .cover-gen-title { font-size: .88rem; }
.cover-gen-xs .cover-gen-title { font-size: .79rem; }

.cover-gen-year {
  font-variant-numeric: tabular-nums; font-weight: 600;
  font-size: .82rem; opacity: .78; padding-left: .55rem;
}

/* Only the big detail-page cover explains itself. Repeating the same
   note down a grid of forty cards just reads as forty apologies. */
.cover-gen-note { display: none; }
.cover-gen-large .cover-gen-note {
  display: block;
  position: absolute; left: 1.1rem; right: 1.1rem; bottom: .9rem;
  padding-left: .55rem;
  font-size: .66rem; letter-spacing: .09em; text-transform: uppercase;
  opacity: .5;
}

.cover-gen-large { border-radius: var(--radius); padding: 1.4rem 1.25rem; }
.cover-gen-large .cover-gen-title { font-size: 1.5rem; }
.cover-gen-large .cover-gen-year { font-size: 1rem; }

.poster-frame { max-width: 320px; }
.poster-frame .cover-img { border-radius: var(--radius); border: 1px solid var(--line); }
.film-card h3 { margin: 0 0 .2rem; font-size: 1.08rem; }
.film-card h3 a { text-decoration: none; }
.film-card h3 a:hover { text-decoration: underline; }
.film-meta { color: var(--ink-soft); font-size: .9rem; margin: 0 0 .5rem; }
.film-synopsis { margin: 0 0 .75rem; font-size: .95rem; }

/* ---- badges: never rely on colour alone, each carries text ---- */
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: auto; }
.badge {
  font-size: .78rem; font-weight: 600; padding: .22rem .5rem;
  border-radius: 999px; border: 1px solid var(--line); background: var(--paper);
}
.badge-lang { border-color: var(--brand); color: var(--brand); }
.badge-deaf-led  { border-color: var(--ok); color: var(--ok); }
.badge-deaf-cast { border-color: var(--brand); color: var(--brand); }
.badge-portrayal { border-color: var(--accent); color: var(--accent); }

/* ---- detail page ---- */
.film-detail { display: grid; gap: 2rem; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 720px) { .film-detail { grid-template-columns: 1fr; } }

.facts { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.facts th, .facts td {
  text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.facts th { width: 12rem; font-weight: 600; }

.poster { width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); }

/* ---- pagination ---- */
.pagination { display: flex; gap: .4rem; flex-wrap: wrap; list-style: none; padding: 0; margin: 2rem 0; }
.pagination a, .pagination span {
  display: block; padding: .5rem .8rem; border: 1px solid var(--line);
  border-radius: 6px; text-decoration: none;
}
.pagination [aria-current="page"] { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- messages ---- */
.notice { padding: .9rem 1.1rem; border-radius: var(--radius); border: 1px solid; margin: 1.25rem 0; }
.notice-ok    { border-color: var(--ok);     background: var(--ok-tint); }
.notice-error { border-color: var(--accent); background: var(--accent-tint); }

/* ---- footer ---- */
.site-footer {
  margin-top: 3.5rem; padding: 2rem 0; border-top: 1px solid var(--line);
  background: var(--paper-alt); color: var(--ink-soft); font-size: .92rem;
}
.footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.footer-note { max-width: 60ch; }

/* ---- forms ---- */
.form-stack { display: grid; gap: 1rem; max-width: 52rem; }
textarea {
  /* Wider and taller: the old rule set no width, so browsers fell back to
     the default ~20 columns and it rendered as a small white box. */
  width: 100%;
  min-height: 11rem;
  resize: vertical;
  font-family: inherit;
}
.form-stack textarea { min-height: 13rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }
.required { color: var(--accent); font-weight: 700; }

/* ---- admin ---- */
.admin-table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.admin-table th, .admin-table td {
  padding: .55rem .5rem; border-bottom: 1px solid var(--line); text-align: left;
}
.admin-table thead th { background: var(--paper-alt); }
.table-scroll { overflow-x: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    -webkit-animation-duration: .01ms !important;
            animation-duration: .01ms !important;
    -webkit-transition-duration: .01ms !important;
            transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===================================================================
   Cross-browser and small-screen hardening
   =================================================================== */

html {
  /* Stop iOS inflating text when the phone is turned sideways. */
  -webkit-text-size-adjust: 100%;
     -moz-text-size-adjust: 100%;
          text-size-adjust: 100%;
}

body {
  /* Nothing should ever cause a sideways scroll on a phone. */
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Long titles, URLs and film slugs must wrap rather than push the
   layout wide. `anywhere` is newer, so break-word comes first. */
h1, h2, h3, p, td, th, li, .film-card, .facts td {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

img, svg, video { max-width: 100%; height: auto; }

/* Flexbox `gap` is Safari 14.1 and later. Where the spacing actually
   matters, fall back to margins on older builds. */
@supports not (gap: 1rem) {
  .btn-row > *, .badges > *, .nav-list > * { margin: 0 .5rem .5rem 0; }
  .footer-links > * { margin-right: 1rem; }
}

/* Tap targets: 44px is the size a finger reliably hits. */
@media (pointer: coarse) {
  .btn, .nav-list a, .pagination a, .pagination span { min-height: 44px; }
  .btn { padding-top: .75rem; padding-bottom: .75rem; }
  .nav-list a { display: flex; align-items: center; }
  input[type="checkbox"], input[type="radio"] { width: 1.25rem; height: 1.25rem; }
}

@media (max-width: 700px) {
  .wrap { width: 94vw; }
  .header-inner { flex-direction: column; align-items: flex-start; }
  .filter-grid { grid-template-columns: 1fr; }
  .btn-row { flex-direction: column; align-items: stretch; }
  .btn { text-align: center; }
  .facts th { width: auto; }
  /* Fact tables read better stacked than squeezed into two columns. */
  .facts, .facts tbody, .facts tr, .facts th, .facts td { display: block; width: 100%; }
  .facts th { border-bottom: 0; padding-bottom: 0; color: var(--ink-soft); }
  .facts td { padding-top: .15rem; }
}

@media (max-width: 420px) {
  .film-grid { grid-template-columns: 1fr 1fr; }
  .cover-gen { padding: .75rem .7rem; }
  .cover-gen-lg .cover-gen-title,
  .cover-gen-md .cover-gen-title { font-size: .85rem; }
}

/* High contrast mode (Windows): keep borders visible. */
@media (forced-colors: active) {
  .btn, .film-card, .badge, .notice, .field input,
  .field select, .field textarea { border: 1px solid currentColor; }
}

@media print {
  body { background: #fff; color: #000; }
  .site-header, .filters, .pagination, .btn, .cover-link { display: none; }
  .film-card { break-inside: avoid; page-break-inside: avoid; border: 1px solid #999; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .85em; }
}
