:root {
  --ground: #0d1a33;
  --rail: #0a1428;
  --surface: #17264a;
  --surface-raised: #1f3159;
  --line: #2c4170;
  --text: #edf2fc;
  --text-soft: #b4c3df;
  --accent: #7fb2ff;
  --done: #143d33;
  --done-text: #a8e6cf;
  --late: #ffcf70;
  --error-ground: #40202b;
  --error-text: #ffc2cd;
  --primary: #3f7fe8;
  --radius: 12px;
  --gap: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 0.9375rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  scrollbar-color: var(--line) transparent;
}

::selection { background: var(--primary); color: #fff; }

a { color: var(--accent); text-underline-offset: 2px; }

h1, h2, h3, p { margin: 0; }

h1 { font-size: 1.375rem; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }

code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-raised);
  font: 0.875em ui-monospace, SFMono-Regular, Menlo, monospace;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.2em; }

.sr, .skip:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip { position: fixed; top: 8px; left: 8px; z-index: 10; padding: 8px 12px; border-radius: 8px; background: var(--surface-raised); }

/* Shell */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 16px 12px;
  overflow-y: auto;
  background: var(--rail);
}

.brand {
  padding: 2px 8px 14px;
  color: var(--text);
  font-size: 1.0625rem;
  font-weight: 700;
  text-decoration: none;
}

.rail-all, .rail-festival {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 150ms ease-out, filter 150ms ease-out;
}

.rail-all { margin-bottom: 8px; color: var(--text); background: var(--surface); }
.rail-all.is-active { background: var(--surface-raised); box-shadow: inset 0 0 0 2px var(--text); }

.rail-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }

/* The festival's own colour is the block: recognisable before any text is read. */
.rail-festival { background: var(--festival); color: var(--on-festival); }
.rail-festival:hover { filter: brightness(1.08); }
.rail-festival.is-active { box-shadow: 0 0 0 2px var(--rail), 0 0 0 4px var(--text); }
.rail-festival.is-off { background: transparent; color: var(--text-soft); box-shadow: inset 0 0 0 1px var(--line); font-weight: 500; }
.rail-festival.is-off.is-active { box-shadow: inset 0 0 0 2px var(--text); }

.rail-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-note { flex: none; font-size: 0.75rem; font-weight: 500; }

.count { flex: none; font-weight: 700; }
.rail-festival .count, .rail-all .count { min-width: 1.6em; text-align: right; }

.rail-foot { margin-top: auto; padding-top: 16px; }

.main { min-width: 0; padding: 20px 24px 48px; }

/* Controls */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}

.button:hover { background: #29406f; border-color: #48639a; }
.button:active { background: #223660; }
.button:disabled { opacity: 0.55; cursor: progress; }
.button.small { min-height: 32px; padding: 4px 10px; font-size: 0.875rem; }
.button.quiet { width: 100%; justify-content: flex-start; border-color: transparent; background: transparent; color: var(--text-soft); }
.button.quiet:hover { background: var(--surface); color: var(--text); }
.button.primary { border-color: transparent; background: var(--primary); color: #fff; }
.button.primary:hover { background: #5590ee; }

input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ground);
  color: var(--text);
  caret-color: var(--accent);
  font: inherit;
}

input::placeholder { color: #9fb0ce; opacity: 1; }

/* Top of the page */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 14px; }
.search { position: relative; flex: 1 1 240px; max-width: 380px; margin-left: auto; color: var(--text-soft); }
.search .icon { position: absolute; top: 50%; left: 10px; transform: translateY(-50%); pointer-events: none; }
.search input { min-height: 36px; padding-left: 32px; background: var(--surface); }
.sync { display: flex; align-items: center; gap: 10px; }
.sync-note { color: var(--text-soft); font-size: 0.875rem; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }

.tab {
  flex: none;
  margin-bottom: -1px;
  padding: 8px 12px 10px;
  border-bottom: 3px solid transparent;
  color: var(--text-soft);
  font-weight: 600;
  text-decoration: none;
  transition: color 150ms ease-out;
}

.tab:hover { color: var(--text); }
.tab.is-active { border-bottom-color: var(--accent); color: var(--text); }
.tab .count { margin-left: 3px; font-weight: 500; }

/* Cards */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: var(--gap); }

.card { position: relative; display: flex; flex-direction: column; overflow: hidden; border-radius: var(--radius); background: var(--surface); }
.card:hover .card-person a { text-decoration: underline; }

.card-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 14px;
  background: var(--festival);
  color: var(--on-festival);
  font-size: 0.8125rem;
  font-weight: 700;
}

.card-festival { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-age { flex: none; font-weight: 600; }
.card-age.is-late { padding: 0 7px; border-radius: 999px; background: #0b1426; color: var(--late); }

.card-body { display: grid; gap: 3px; padding: 12px 14px 10px; }

.card-person { font-size: 1rem; font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.card-person a { color: var(--text); text-decoration: none; }
/* The whole card opens the conversation. */
.card-person a::after { content: ""; position: absolute; inset: 0; }

.card-subject { font-weight: 550; overflow-wrap: anywhere; }

.card-snippet {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-soft);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; margin-top: auto; padding: 0 14px 12px; }
.card-foot form { position: relative; z-index: 1; }
.card-facts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--text-soft); font-size: 0.8125rem; }
.tag { padding: 1px 7px; border-radius: 6px; background: var(--surface-raised); color: var(--text); font-weight: 550; }

/* Finished cards change colour; they are never struck through. */
.card.is-done { background: var(--done); }
.card.is-done .card-snippet, .card.is-done .card-facts { color: var(--done-text); }
.card.is-done .tag { background: #1d5346; }

/* Reader */
.reader { max-width: 860px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 12px; color: var(--text-soft); font-weight: 600; text-decoration: none; }
.back:hover { color: var(--text); }

.reader-head { margin-bottom: 16px; overflow: hidden; border-radius: var(--radius); background: var(--surface); }
.reader-band { display: flex; justify-content: space-between; gap: 12px; padding: 8px 18px; background: var(--festival); color: var(--on-festival); font-size: 0.875rem; font-weight: 700; }
.reader-state { flex: none; }
.reader-title { display: grid; gap: 3px; padding: 16px 18px 12px; }
.reader-title h1 { overflow-wrap: anywhere; text-wrap: balance; }
.reader-title p { color: var(--text-soft); overflow-wrap: anywhere; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 16px; }

.thread { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }

.message { padding: 14px 18px; border-radius: var(--radius); background: var(--surface); }
.message.is-out { margin-left: 32px; background: #15305a; }
.message-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; margin-bottom: 8px; }
.message-head time { color: var(--text-soft); font-size: 0.8125rem; }
.message-text { max-width: 72ch; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-missing { color: var(--text-soft); }
.message-quoted { margin-top: 10px; color: var(--text-soft); }
.message-quoted summary { width: fit-content; font-size: 0.875rem; font-weight: 600; cursor: pointer; }
.message-quoted .message-text { margin-top: 8px; font-size: 0.875rem; }

.attachments { display: grid; gap: 4px; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line); color: var(--text-soft); font-size: 0.875rem; list-style: none; }
.attachments li { overflow-wrap: anywhere; }

/* Certificates */
.cert-form { display: grid; gap: 14px; max-width: 620px; }
.field { display: grid; flex: 1 1 200px; gap: 5px; min-width: 0; }
.field label { font-weight: 600; }
.field-row { display: flex; flex-wrap: wrap; gap: 14px; }
.cert-form .button { justify-self: start; }
.cert-note { color: var(--text-soft); font-size: 0.875rem; }
.button.quiet.is-active { background: var(--surface); color: var(--text); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 18px; }
.filters .field { flex: 0 1 200px; }
.filters .field-grow { flex: 1 1 260px; }
textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ground);
  color: var(--text);
  caret-color: var(--accent);
  font: inherit;
  resize: vertical;
}
input[type="number"] {
  width: 100%;
  min-height: 42px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ground);
  color: var(--text);
  font: inherit;
}
.table-scroll { overflow-x: auto; }
.winners { width: 100%; border-collapse: collapse; }
.winners th { padding: 8px 10px; border-bottom: 1px solid var(--line); color: var(--text-soft); font-size: 0.8125rem; font-weight: 600; text-align: left; }
.winners td { padding: 9px 10px; border-bottom: 1px solid var(--surface); vertical-align: top; overflow-wrap: anywhere; }
.winners tbody tr:hover { background: var(--surface); }
.winner-film a { color: var(--text); font-weight: 600; text-decoration: none; }
.winner-film a:hover { text-decoration: underline; }
.winner-film .tag { margin-left: 6px; font-size: 0.75rem; }
.tag.is-check { background: var(--late); color: #0b1426; }
.winners td.winner-files { width: 1%; overflow-wrap: normal; text-align: right; white-space: nowrap; }
.winner-files .button + .button { margin-left: 4px; }
.nowrap { white-space: nowrap; }
.add-winners { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); }
.add-winners h2 { margin-bottom: 12px; font-size: 1.0625rem; font-weight: 650; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.button.danger { border-color: #7a3442; background: transparent; color: var(--error-text); }
.button.danger:hover { background: var(--error-ground); }
.winner-layout { display: grid; grid-template-columns: minmax(0, 480px) minmax(0, 1fr); gap: 28px; align-items: start; }
.winner-preview { position: sticky; top: 16px; display: grid; gap: 12px; }
.winner-preview img { display: block; width: 100%; border-radius: 8px; }
.winner-preview .laurel-preview { max-width: 340px; }
.corrections { padding: 12px 14px; border-radius: 8px; background: var(--surface); }
.corrections summary { font-weight: 600; cursor: pointer; }
.corrections[open] summary { margin-bottom: 10px; }
.corrections .field { margin-top: 10px; }
.correction-row { flex-wrap: nowrap; align-items: flex-start; }
.field-grow { flex: 1 1 auto; }
.field-small { flex: 0 0 84px; }

/* Messages to Michele */
.notice { margin-bottom: 14px; padding: 10px 14px; border-radius: 8px; background: var(--surface); overflow-wrap: anywhere; }
.notice.is-error { background: var(--error-ground); color: var(--error-text); }
.notice.is-error strong { color: #fff; }

.empty { max-width: 56ch; padding: 40px 4px; }
.empty h2 { margin-bottom: 6px; font-size: 1.125rem; font-weight: 650; }
.empty p { color: var(--text-soft); }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--ground); }
.login { width: min(100%, 380px); padding: 24px; border-radius: var(--radius); background: var(--surface); }
.login h1 { margin-bottom: 16px; }
.login form { display: grid; gap: 6px; }
.login label { margin-top: 8px; font-weight: 600; }
.login .button { margin-top: 14px; }
.login .notice { background: var(--surface-raised); }
.login .notice.is-error { background: var(--error-ground); }

/* Small screens: the festival blocks become a scrolling row above the work. */
@media (max-width: 760px) {
  .shell { display: block; }
  .rail { position: static; height: auto; padding: 12px 16px; overflow: visible; }
  .rail nav { display: flex; gap: 6px; margin: 0 -16px; padding: 0 16px 4px; overflow-x: auto; scrollbar-width: none; }
  .rail-all { flex: none; margin: 0; }
  .rail-list { display: flex; }
  .rail-list li { flex: none; }
  .rail-festival { max-width: 180px; }
  .rail-foot { margin-top: 8px; padding-top: 0; }
  .button.quiet { width: auto; padding-left: 0; }
  .main { padding: 16px 16px 40px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .sync { margin-left: auto; }
  .board { grid-template-columns: minmax(0, 1fr); }
  .message.is-out { margin-left: 12px; }
  .winner-layout { grid-template-columns: minmax(0, 1fr); }
  .winner-preview { position: static; order: -1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
