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

:root {
  color-scheme: light dark;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-sunken: #eceef1;
  --text: #202122;
  --text-subtle: #54595d;
  --border: #c8ccd1;
  --border-strong: #a2a9b1;
  --accent: #3366cc;
  --accent-strong: #2a4b8d;
  --accent-soft: #e8effc;
  --on-accent: #ffffff;
  /* WikiPortraits red: primary buttons, destructive outlines */
  --primary: #c8102e;
  --primary-strong: #a50d26;
  --on-primary: #ffffff;
  --danger: #c8102e;
  --danger-soft: #fdecea;
  --success: #0f6b57;
  --success-soft: #dff6ef;
  --warning-soft: #fdf3dc;
  --warning-border: #e0a824;
  --radius: 6px;
  --shadow-color: rgb(0 0 0 / 0.12);
  --shadow: 0 4px 16px var(--shadow-color);
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Control heights: buttons and inputs, small ones, the photo header strip */
  --control-height: 36px;
  --control-height-sm: 30px;
  --control-height-xs: 26px;
  /* Page side padding */
  --gutter: 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131518;
    --surface: #1d2025;
    --surface-sunken: #0d0f11;
    --text: #eaecf0;
    --text-subtle: #a7adb5;
    --border: #383d45;
    --border-strong: #5a616b;
    --accent: #7ba6f7;
    --accent-strong: #a6c3fa;
    --accent-soft: #1d2a45;
    --on-accent: #0b1730;
    --danger: #f28b80;
    --danger-soft: #3b1e1b;
    --success: #62d1b2;
    --success-soft: #11332b;
    --warning-soft: #372b10;
    --warning-border: #8a6a1c;
    --shadow-color: rgb(0 0 0 / 0.5);
  }
}

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

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

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

h2 {
  font-size: 1.0625rem;
  line-height: 1.3;
  font-weight: 650;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9375em;
}

/* One underline: dotted at rest, solid on hover */
a,
.link-button,
.field-state button {
  color: var(--accent);
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover,
.link-button:hover,
.field-state button:hover {
  color: var(--accent-strong);
  text-decoration-style: solid;
}

.link-button,
.field-state button,
.nav-link,
.chip button {
  padding: 0;
  font: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  /* Forced-colors mode drops box-shadow but keeps the outline */
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
  border-radius: 4px;
}

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

.subtle {
  color: var(--text-subtle);
}

main {
  flex: 1 0 auto;
  width: 100%;
}

/* ---------- Top bar: matches photos.wikiportraits.org ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  min-height: 60px;
  padding: 0 1rem;
  color: #fff;
  background: #1d1d1d;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.4);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
  color: #fff;
  text-decoration: none;
}

.brand:hover {
  color: #fff;
}

.brand-mark {
  display: inline-flex;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 3px;
  background: #fff;
  border-radius: 50%;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-name {
  overflow: hidden;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-nav {
  display: flex;
  flex: none;
  align-items: center;
  gap: 1rem;
}

.user-name {
  overflow: hidden;
  max-width: 14rem;
  font-size: 0.9rem;
  color: rgb(255 255 255 / 0.6);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Also the log-out button */
.nav-link {
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: rgb(255 255 255 / 0.8);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.12s;
}

.nav-link:hover {
  color: #fff;
}

/* Log in; .topbar so it beats .button, which comes later */
.topbar .nav-button {
  min-height: var(--control-height-sm);
  padding: 0 1.125rem;
  font-size: 0.82rem;
}

.topbar :focus-visible {
  box-shadow: 0 0 0 2px #1d1d1d, 0 0 0 4px #fff;
}

@media (max-width: 480px) {
  .topbar {
    padding: 0.625rem 1rem;
  }

  .brand-name {
    font-size: 0.85rem;
    letter-spacing: 0;
  }

  .user-nav {
    gap: 0.75rem;
  }

  .topbar .nav-button {
    padding: 0 0.75rem;
  }
}

/* ---------- Page header ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-head > :first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex: none;
}

/* Label and value columns */
.meta {
  display: grid;
  gap: 0.375rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.875rem;
}

.meta-row {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: inherit;
}

.meta dt {
  color: var(--text-subtle);
}

.meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Section title, count, and what sits beside */
.section-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 1.75rem 0 0.75rem;
}

.section-head h2 {
  font-size: 1rem;
}

.section-count {
  font-size: 0.875rem;
  color: var(--text-subtle);
}

/* The link above a page title */
.back {
  display: inline-block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  text-decoration: none;
}

.back:hover {
  text-decoration: underline dotted;
}

@media (max-width: 760px) {
  :root {
    --gutter: 1rem;
  }

  .page-head {
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions {
    justify-content: flex-start;
  }

  .meta-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.125rem;
  }
}

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: var(--control-height);
  padding: 0 0.875rem;
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}

.button:hover {
  color: var(--text);
  background: var(--surface-sunken);
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:disabled {
  color: var(--text-subtle);
  background: var(--surface-sunken);
  border-color: var(--border);
  cursor: not-allowed;
}

.button-primary {
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}

.button-primary:hover:not(:disabled) {
  color: var(--on-primary);
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.button-danger {
  color: var(--danger);
  border-color: currentColor;
}

.button-danger:hover:not(:disabled) {
  color: var(--danger);
  background: var(--danger-soft);
}

.button-quiet {
  padding: 0 0.5rem;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border-color: transparent;
}

.button-quiet:hover:not(:disabled) {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.button-quiet:disabled {
  background: none;
  border-color: transparent;
}

.button-small {
  min-height: var(--control-height-sm);
  padding: 0 0.625rem;
  font-size: 0.875rem;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Notices ---------- */

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}

.notice > :first-child {
  flex: 1 1 280px;
}

.notice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.notice-warning {
  background: var(--warning-soft);
  border-left-color: var(--warning-border);
}

.notice-error {
  background: var(--danger-soft);
  border-left-color: var(--danger);
}

.notice-success {
  background: var(--success-soft);
  border-left-color: var(--success);
}

/* ---------- Empty lists ---------- */

.empty-state {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--text-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.empty-state strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--text);
}

/* ---------- Forms ---------- */

.field {
  display: grid;
  align-content: start;
  gap: 0.25rem;
}

.field + .field,
.field-row + .field-error {
  margin-top: 1rem;
}

.field-row .field {
  margin-top: 0;
}

/* Short and long field on one line; stacked on a phone */
.field-row {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 1rem;
}

/* The long field takes the row when the short one is hidden */
.field-row > .field[hidden] + .field {
  grid-column: 1 / -1;
}

@media (max-width: 480px) {
  .field-row:not(.field-row-action) {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
  }

  .field-row:not(.field-row-action) > .field:first-child input {
    max-width: 8rem;
  }
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

label,
.label {
  font-weight: 600;
}

.optional,
.field-state,
.hint {
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.optional,
.field-state {
  font-weight: 400;
}

.field-error {
  font-size: 0.8125rem;
  color: var(--danger);
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: var(--control-height);
  padding: 0.25rem 0.625rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

textarea {
  min-height: 4.5rem;
  resize: vertical;
}

:is(input, select, textarea):focus-visible {
  border-color: var(--accent);
  border-radius: var(--radius);
  outline: 2px solid transparent;
  outline-offset: 0;
  box-shadow: 0 0 0 1px var(--accent);
}

:is(input, select, textarea):disabled {
  color: var(--text-subtle);
  background: var(--surface-sunken);
  border-color: var(--border);
}

:is(input, textarea)::placeholder {
  color: var(--text-subtle);
  opacity: 0.85;
}

/* After :focus-visible and :disabled: wins on order */
:is(input, select, textarea)[aria-invalid="true"] {
  border-color: var(--danger);
}

.color-field {
  display: flex;
  gap: 0.5rem;
}

.color-field input[type="color"] {
  flex: none;
  width: 44px;
  height: var(--control-height);
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.25rem 1rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.checks legend {
  margin-bottom: 0.25rem;
  padding: 0;
  font-weight: 600;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--control-height-sm);
  font-weight: 400;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

/* ---------- Combobox and chips ---------- */

.combo {
  position: relative;
}

.combo-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 300px;
  margin: 0;
  padding: 0.25rem;
  overflow-y: auto;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.combo-group {
  padding: 0.375rem 0.5rem 0.125rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-subtle);
}

.combo-option {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 0.75rem;
  padding: 0.375rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
}

.combo-option[aria-selected="true"] {
  background: var(--accent-soft);
}

/* An action row */
.combo-action .combo-label {
  font-weight: 500;
  color: var(--accent);
}

.combo-label {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.combo-meta {
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.combo-description {
  grid-column: 1 / -1;
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.combo-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.combo-status .spinner {
  width: 12px;
  height: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chips:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.chip-text {
  padding: 0.125rem 0.125rem 0.125rem 0.625rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip button {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--control-height-xs);
  height: var(--control-height-xs);
  font-size: 1.0625rem;
  line-height: 1;
  color: var(--text-subtle);
  border-radius: 50%;
}

.chip button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.chip-locked .chip-text {
  padding-right: 0.625rem;
}

/* ---------- Wikitext and JSON previews ---------- */

.preview {
  margin-top: 0.75rem;
}

.preview summary {
  font-size: 0.875rem;
  color: var(--accent);
  cursor: pointer;
}

.preview[open] summary {
  margin-bottom: 0.5rem;
}

.code {
  margin: 0;
  padding: 0.625rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.code-title {
  margin: 0.75rem 0 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

/* Key and value pairs */
.data-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.375rem 1rem;
  margin: 0;
  font-size: 0.875rem;
}

.data-list dt {
  font-weight: 600;
}

.data-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

/* ---------- Dialogs and toasts ---------- */

dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.dialog-wide {
  width: min(760px, calc(100vw - 2rem));
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

/* The body scrolls; title and buttons stay */
dialog > form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
}

.dialog-head,
.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
}

.dialog-head {
  border-bottom: 1px solid var(--border);
}

.dialog-foot {
  flex-wrap: wrap;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
}

.dialog-foot .push-left {
  margin-right: auto;
}

.dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 1rem 1.25rem 1.25rem;
  overflow-y: auto;
}

.dialog-body > * + * {
  margin-top: 0.75rem;
}

/* A step below section headings */
.dialog-body label,
.dialog-body .label {
  font-size: 0.875rem;
}

/* Field groups under small headings */
.form-section + .form-section {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-section h3 {
  margin: 0 0 0.625rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

.form-section > .field + .field,
.form-section > .field + details,
.form-section > .hint + div {
  margin-top: 0.75rem;
}

.version {
  margin: 0.75rem 0 0;
  padding: 0.5rem 0.875rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.version legend {
  padding: 0 0.375rem;
  font-weight: 600;
}

.version .button {
  margin-top: 0.5rem;
}

.dialog-body ul:not([class]) {
  margin: 0.375rem 0 0;
  padding-left: 1.2rem;
}

.choices {
  display: grid;
  gap: 0.25rem;
  padding: 0;
  border: 0;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 60;
  display: grid;
  gap: 0.5rem;
  width: min(460px, calc(100vw - 2rem));
  transform: translateX(-50%);
}

.toast {
  padding: 0.625rem 0.875rem;
  color: var(--surface);
  background: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toast-error {
  color: var(--on-primary);
  background: var(--primary);
}

/* ---------- Filters ---------- */

/* Pill buttons that pick what a list shows */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.filter {
  min-height: var(--control-height-sm);
  padding: 0 0.75rem;
  font: inherit;
  font-size: 0.875rem;
  color: var(--text-subtle);
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}

.filter:hover {
  color: var(--text);
  background: var(--surface-sunken);
}

.filter .count {
  font-weight: 400;
  color: var(--text-subtle);
}

.filter[aria-pressed="true"] {
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  margin-top: auto;
  padding: 1.25rem var(--gutter);
  font-size: 0.8125rem;
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
}

.site-footer a {
  color: inherit;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
