/* CoH Character Database v2 — dark theme, responsive */
:root {
  --bg: #0b0d12;
  --panel: rgba(20, 23, 31, 0.94);
  --panel-2: #1b1f2a;
  --line: #2b3140;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --accent: #ffd23f;        /* the old site's yellow, a touch warmer */
  --accent-ink: #1a1400;
  --link: #ffd23f;
  --blue: #5aa9ff;
  --danger: #ff5d5d;
  --ok: #4fd18b;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Verdana, sans-serif;
  --display: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg) url("bg.jpg") repeat;
  color: var(--text);
  font: 15px/1.55 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
h1, h2, h3 { font-family: var(--display); line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.75rem; letter-spacing: .01em; }
h2 { font-size: 1.1rem; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  background: rgba(8, 9, 13, .96);
  border-bottom: 2px solid var(--accent);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.brand { color: var(--text); font: 700 1.1rem var(--display); white-space: nowrap; }
.brand:hover { text-decoration: none; color: var(--accent); }
.brand-mark { color: var(--accent); }
.mainnav { display: flex; align-items: center; gap: .25rem; flex: 1; flex-wrap: wrap; }
.mainnav a, .linklike {
  color: var(--text); padding: .4rem .7rem; border-radius: 6px; font-size: .95rem;
}
.mainnav a:hover, .linklike:hover { background: var(--panel-2); text-decoration: none; }
.mainnav a.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.mainnav a.active .role-badge { background: rgba(0,0,0,.2); color: inherit; }
.nav-spacer { flex: 1; }
.role-badge {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  background: var(--panel-2); color: var(--muted); padding: .1rem .4rem; border-radius: 4px; margin-left: .2rem;
}
.linklike { background: none; border: 0; cursor: pointer; font: inherit; }
form.inline { display: inline; margin: 0; }
.nav-toggle { display: none; }

/* ---------- layout ---------- */
.container { max-width: 1400px; width: 100%; margin: 0 auto; padding: 1.5rem 1rem 3rem; flex: 1; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.4rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 620px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin-bottom: .1em; }
.page-head p { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2 + *, .grid-3 + * { margin-top: 1.25rem; }
.crumbs { margin-bottom: .75rem; font-size: .9rem; }
.footer {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
  max-width: 1180px; width: 100%; margin: 0 auto; padding: 1rem; color: var(--muted); font-size: .8rem;
}

/* ---------- alerts ---------- */
.alert { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: rgba(79, 209, 139, .12); border-color: rgba(79, 209, 139, .5); }
.alert-error { background: rgba(255, 93, 93, .12); border-color: rgba(255, 93, 93, .55); }
.alert-info { background: rgba(90, 169, 255, .12); border-color: rgba(90, 169, 255, .5); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: 600 .92rem var(--font);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #ffe16f; border-color: #ffe16f; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #1b0000; }
.btn-danger-ghost { background: transparent; border-color: rgba(255, 93, 93, .5); color: var(--danger); }
.btn-danger-ghost:hover { background: rgba(255, 93, 93, .1); border-color: var(--danger); }
.btn-small { padding: .3rem .6rem; font-size: .82rem; }
.btn-block { width: 100%; }
.button-row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

/* ---------- forms ---------- */
label { font-weight: 600; font-size: .88rem; color: var(--muted); }
input[type="text"], input[type="search"], input[type="password"], select, textarea {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--line); background: #0f1219; color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(255, 210, 63, .18); }
[aria-invalid="true"] { border-color: var(--danger) !important; }
textarea { resize: vertical; min-height: 8rem; line-height: 1.5; }
select { appearance: auto; }
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.hint { color: var(--muted); font-size: .82rem; margin: 0; }
.field-error { color: var(--danger); font-size: .85rem; margin: 0; }
.req { color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; color: var(--text); cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
fieldset.checks { border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; margin: 1.25rem 0 0; display: flex; flex-wrap: wrap; gap: .6rem 1.5rem; }
fieldset.checks legend { padding: 0 .4rem; font-weight: 600; font-size: .88rem; color: var(--muted); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .45rem 1rem; }
.columns-picker { margin-top: 1.25rem; }
.columns-picker summary { cursor: pointer; font-weight: 600; color: var(--accent); margin-bottom: .75rem; }
.form-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: 1.25rem; }
.form-actions .spacer { flex: 1; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; margin: 0 -1rem; padding: .8rem 1rem;
  background: rgba(8, 9, 13, .95); border-top: 1px solid var(--line);
}
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form select, .inline-form input[type="password"] { width: auto; min-width: 8rem; padding: .35rem .5rem; }

/* ---------- list page ---------- */
.toolbar { display: flex; flex-direction: column; gap: .9rem; }
.quicksearch { display: flex; gap: .5rem; }
.quicksearch input { flex: 1; }
.letters { display: flex; flex-wrap: wrap; gap: .25rem; }
.letters a {
  min-width: 2.1rem; text-align: center; padding: .3rem .45rem; border-radius: 6px;
  background: var(--panel-2); color: var(--text); font-weight: 600; font-size: .88rem;
}
.letters a:hover { background: #262c3a; text-decoration: none; }
.letters a.active { background: var(--accent); color: var(--accent-ink); }
.result-count { color: var(--muted); font-size: .9rem; margin: .25rem 0 .6rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
/* Character list and search results slide sideways instead of being clipped or squeezed */
.table-wrap.card.slide { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.slide table.data th, .slide table.data td { white-space: nowrap; }
.slide table.data td.bio-cell { white-space: normal; min-width: 30rem; }
.slide .tags { flex-wrap: nowrap; }
table.data { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.data th, table.data td { padding: .6rem .85rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data thead th { background: #10131b; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; position: sticky; top: 0; }
table.data thead th a { color: var(--muted); }
table.data thead th a:hover { color: var(--accent); }
table.data tbody tr:nth-child(even) { background: rgba(255, 255, 255, .025); }
table.data tbody tr:hover { background: rgba(255, 210, 63, .06); }
table.data tbody tr:last-child td { border-bottom: 0; }
.name-cell a { font-weight: 600; }
.pic-dot { color: var(--blue); font-size: .6rem; vertical-align: middle; }
table.data .pic-col, table.data .pic-cell { width: 1%; padding-right: 0; text-align: center; }
.actions { white-space: nowrap; text-align: right; }
.actions a + a { margin-left: .8rem; }
.actions-col { width: 1%; }
.bio-cell { min-width: 18rem; max-width: 40rem; color: var(--muted); }
.tags { display: flex; gap: .3rem; flex-wrap: wrap; }
.tag { font-size: .72rem; padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag-incarnate { border-color: rgba(255, 210, 63, .6); color: var(--accent); }
.tag-rptoon { border-color: rgba(90, 169, 255, .6); color: var(--blue); }
.tag-storytoon { border-color: rgba(79, 209, 139, .6); color: var(--ok); }
.tag-pines { border-color: rgba(200, 140, 255, .6); color: #c88cff; }

/* ---------- character page ---------- */
.char-hero { display: grid; grid-template-columns: 260px 1fr; gap: 1.5rem; align-items: start; }
.char-pic { display: block; border-radius: 8px; overflow: hidden; background: #0f1219; border: 1px solid var(--line); }
.char-pic img { display: block; width: 100%; }
.char-pic.placeholder {
  aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center;
  font: 700 5rem var(--display); color: #2f3646;
}
.char-intro h1 { font-size: 2.1rem; margin-bottom: .2rem; }
.char-sub { color: var(--muted); font-size: 1.05rem; margin-bottom: .3rem; }
.char-sg { font-weight: 600; }
.battlecry {
  margin: 1rem 0; padding: .6rem 1rem; border-left: 3px solid var(--accent);
  font: italic 1.15rem var(--display); color: #fff3c4; background: rgba(255, 210, 63, .05);
}
dl.details { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .9rem 1.5rem; margin: 0; }
dl.details dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
dl.details dd { margin: .1rem 0 0; font-weight: 500; }
.bio { white-space: normal; line-height: 1.7; max-width: 75ch; }

/* ---------- edit page ---------- */
.pic-edit { display: grid; grid-template-columns: 220px 1fr; gap: 1.5rem; align-items: start; }
.pic-preview {
  border: 1px dashed var(--line); border-radius: 8px; padding: .5rem; text-align: center; min-height: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.pic-preview img { max-height: 280px; border-radius: 6px; }
.pic-preview p { margin: .4rem 0 0; }
input[type="file"] { color: var(--muted); font-size: .9rem; }
input[type="file"]::file-selector-button {
  margin-right: .75rem; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-weight: 600; cursor: pointer;
}

/* ---------- misc ---------- */
.login-card { max-width: 400px; margin: 3rem auto; }
.confirm h1 { font-size: 1.4rem; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { display: flex; justify-content: space-between; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.link-list li:last-child { border-bottom: 0; }
.count { color: var(--muted); font-size: .82rem; background: var(--panel-2); border-radius: 999px; padding: 0 .55rem; }
pre.debug { white-space: pre-wrap; background: #0f1219; padding: 1rem; border-radius: 8px; font-size: .8rem; overflow: auto; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .char-hero { grid-template-columns: 1fr; }
  .char-pic { max-width: 320px; }
  .pic-edit { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  body { font-size: 15px; }
  .container { padding: 1rem .75rem 2.5rem; }
  .card { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .nav-toggle {
    display: inline-block; margin-left: auto; background: var(--panel-2); color: var(--text);
    border: 1px solid var(--line); border-radius: 6px; padding: .35rem .75rem; font: 600 .9rem var(--font); cursor: pointer;
  }
  .mainnav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; }
  .mainnav.open { display: flex; }
  .nav-spacer { display: none; }
  .mainnav form.inline { display: block; }
  .linklike { width: 100%; text-align: left; }
  .letters a { min-width: 1.9rem; padding: .35rem .3rem; }

  /* Other tables become stacked cards; .slide tables stay as tables */
  .table-wrap:not(.slide) table.data thead { display: none; }
  .table-wrap:not(.slide) table.data, .table-wrap:not(.slide) table.data tbody,
  .table-wrap:not(.slide) table.data tr, .table-wrap:not(.slide) table.data td { display: block; width: 100%; }
  .table-wrap:not(.slide) table.data tr { padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
  .table-wrap:not(.slide) table.data td { border: 0; padding: .15rem 0; }
  .table-wrap:not(.slide) table.data td:empty { display: none; }
  .table-wrap:not(.slide) .actions { text-align: left; padding-top: .4rem !important; }
  .inline-form select, .inline-form input[type="password"] { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
@media print {
  body { background: #fff; color: #000; }
  .topbar, .footer, .button-row, .crumbs, .sticky-actions { display: none; }
  .card { box-shadow: none; border-color: #ccc; background: #fff; }
  h2 { color: #000; }
}
