/* ══════════════════════════════════════════════════════════════════════
   seempol-upp — 16-bit JRPG menu system, revision 2.
   Real pixel font (Press Start 2P, embedded, OFL), real stepped pixel
   window frames (inline-SVG border-image), dithered window fills,
   starfield, Mode-7 title floor. No external requests.
   ══════════════════════════════════════════════════════════════════════ */

@font-face {
  font-family: "Press Start 2P";
  src: url("/PressStart2P.ttf") format("truetype");
  font-display: swap;
}

:root {
  --void:      #05051c;
  --win-hi:    #5060b4;
  --win-mid:   #2a3382;
  --win-lo:    #0e1034;
  --ink:       #0a0a30;
  --gold:      #f8d878;
  --gold-deep: #d8a830;
  --text:      #f0f0f8;
  --dim:       #9aa4e8;
  --red:       #e85848;
  --btn-a:     #e03c28;
  --btn-b:     #f0b800;
  --btn-x:     #38b048;
  --btn-y:     #3858f0;

  --font-display: "Press Start 2P", monospace;
  --font-body: "JetBrainsMono Nerd Font", "JetBrains Mono", ui-monospace, monospace;

  /* The window frame: 2px black rim, 4px white, navy inner band, with
     hand-stepped pixel corners. Drawn once, worn by every panel. */
  --frame: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30" shape-rendering="crispEdges"><path fill="%23000000" d="M6,0 H24 V2 H26 V4 H28 V6 H30 V24 H28 V26 H26 V28 H24 V30 H6 V28 H4 V26 H2 V24 H0 V6 H2 V4 H4 V2 H6 Z"/><path fill="%23f8f8f8" d="M8,2 H22 V4 H24 V6 H26 V8 H28 V22 H26 V24 H24 V26 H22 V28 H8 V26 H6 V24 H4 V22 H2 V8 H4 V6 H6 V4 H8 Z"/><path fill="%23161c78" d="M8,6 H22 V8 H24 V22 H22 V24 H8 V22 H6 V8 H8 Z"/></svg>');
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--text);
  font: 13.5px/1.55 var(--font-body);
  background-color: var(--void);
  background-image:
    radial-gradient(1px 1px at 23% 17%, rgba(240,240,255,.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 67% 63%, rgba(240,240,255,.35) 50%, transparent 51%),
    radial-gradient(2px 2px at 84% 29%, rgba(154,164,232,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 41% 83%, rgba(240,240,255,.3) 50%, transparent 51%),
    radial-gradient(ellipse at 50% -20%, #16165a 0%, transparent 55%);
  background-size: 310px 290px, 270px 250px, 390px 350px, 230px 210px, 100% 100%;
}

/* CRT: scanlines + soft vignette, always beneath the pointer */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 999;
  background: repeating-linear-gradient(
    0deg, rgba(0,0,0,.14) 0 1px, transparent 1px 3px);
}
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 998;
  background: radial-gradient(ellipse at center,
    transparent 58%, rgba(2,2,16,.5) 100%);
}

::selection { background: var(--gold); color: var(--ink); }

/* ── The dialog window ────────────────────────────────────────────────── */
.card, .drawer, section.catsection, .dblist button.open {
  border: 10px solid transparent;
  border-image: var(--frame) 10;
  background:
    repeating-conic-gradient(rgba(255,255,255,.035) 0% 25%, transparent 0% 50%)
      0 0 / 4px 4px,
    linear-gradient(180deg, var(--win-hi) 0%, var(--win-mid) 16%, var(--win-lo) 92%);
  background-clip: padding-box;
  filter: drop-shadow(0 5px 0 rgba(0,0,0,.5));
}
.card { padding: 12px 14px; margin-bottom: 22px; }

/* ── Chrome ───────────────────────────────────────────────────────────── */
header {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 20px;
  background: linear-gradient(180deg, #23237a, #10104a 80%, #060630);
  border-bottom: 3px solid #000;
  box-shadow: 0 3px 0 rgba(255,255,255,.08);
  position: relative; z-index: 2;
}
header h1 {
  margin: 0;
  cursor: pointer;
  font: 13px var(--font-display);
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
}
header h1::after {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-left: 18px;
  vertical-align: 1px;
  background: var(--btn-x);
  box-shadow:
    15px 0 0 var(--btn-a),
    30px 0 0 var(--btn-b),
    45px 0 0 var(--btn-y),
    0 0 0 2px #000, 15px 0 0 2px #000, 30px 0 0 2px #000, 45px 0 0 2px #000;
}
header .spacer { flex: 1; }
#who { display: flex; align-items: center; gap: 6px; }

main {
  padding: 26px 16px 72px;
  max-width: 1400px;
  margin: 0 auto;
  position: relative; z-index: 1;
}

/* ── Type ─────────────────────────────────────────────────────────────── */
h2 {
  font: 10px/1.6 var(--font-display);
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
  margin: 28px 0 12px;
}
section.catsection h2 {
  margin: 0;
  padding: 11px 14px 9px;
  background: rgba(6,6,40,.4);
  border-bottom: 2px solid rgba(255,255,255,.25);
}
.dim { color: var(--dim); }
.err { color: var(--red); font-weight: 700; margin: 8px 0; min-height: 1em;
       text-shadow: 1px 1px 0 #000; }

/* ── Controls ─────────────────────────────────────────────────────────── */
button {
  font: 700 12px var(--font-body);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink);
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  border: 2px solid #000;
  padding: 7px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 #000, inset 0 2px 0 rgba(255,255,255,.55);
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(3px); box-shadow: 0 0 0 #000; }
button.ghost {
  background: rgba(6,6,40,.6);
  color: var(--text);
  border-color: #d8d8e8;
  box-shadow: 0 3px 0 #000;
}
button.link {
  background: none; border: 0; box-shadow: none;
  color: var(--gold); padding: 0;
  text-transform: none; letter-spacing: 0;
  text-decoration: underline 1px dotted;
}
button.link:active { transform: none; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--ink);
  border: 2px solid #6870c8;
  padding: 7px 9px;
  width: 100%;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,.6);
}
input::placeholder, textarea::placeholder { color: #6f77c0; }
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus, select:focus, button:focus-visible,
summary:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(248,216,120,.45), inset 2px 2px 0 rgba(0,0,0,.6);
}
button:focus-visible { box-shadow: 0 3px 0 #000, 0 0 0 3px rgba(248,216,120,.6); }

.row { display: flex; gap: 10px; align-items: center; }
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font: 8px/1.6 var(--font-display);
  color: var(--gold);
  margin-bottom: 5px;
  text-shadow: 1px 1px 0 #000;
}

/* ── Menu tables ──────────────────────────────────────────────────────── */
section.catsection { margin-bottom: 26px; overflow: hidden; }
section.catsection > div { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 12px; text-align: left; vertical-align: top; }
th {
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--gold);
  text-shadow: 1px 1px 0 #000;
  border-bottom: 2px solid rgba(255,255,255,.25);
  background: rgba(6,6,40,.35);
  position: sticky; top: 0;
}
th + th, td + td { border-left: 1px solid rgba(255,255,255,.11); }
tbody tr { cursor: pointer; }
tbody tr + tr td { border-top: 1px solid rgba(255,255,255,.09); }
tbody td:first-child { padding-left: 30px; position: relative; }
tbody td:first-child::before {
  content: "▶";
  position: absolute; left: 10px;
  color: transparent;
}
tbody tr:hover { background: rgba(248,216,120,.13); }
tbody tr:hover td { color: var(--gold); }
tbody tr:hover td:first-child::before {
  color: var(--gold);
  animation: cursor-blink .8s steps(2, jump-none) infinite;
}
@keyframes cursor-blink { 50% { opacity: 0; } }

/* ── Badges: cartridge labels ─────────────────────────────────────────── */
.badge {
  display: inline-block;
  background: var(--ink);
  border: 2px solid #6870c8;
  padding: 1px 8px;
  font-size: 11px;
  color: var(--dim);
  box-shadow: 1px 1px 0 #000;
}

/* ── Filter console ───────────────────────────────────────────────────── */
.filterbar {
  align-items: center;
  background: rgba(10,10,48,.7);
  border: 2px solid #3a3f8c;
  padding: 10px 12px;
  margin-bottom: 20px;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,.5);
}
.filterbar input, .filterbar select { width: auto; }
.filtergroup {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  border-left: 2px solid #3a3f8c;
  padding-left: 10px;
}
.fglabel {
  font: 7px/1.6 var(--font-display);
  color: var(--dim);
}
.chip {
  font: 700 12px var(--font-body);
  background: var(--ink);
  color: var(--text);
  border: 2px solid #6870c8;
  padding: 2px 7px;
  box-shadow: 0 2px 0 #000;
  text-transform: none; letter-spacing: 0;
}
.chip:active { transform: translateY(2px); box-shadow: 0 0 0 #000; }
.chip.on {
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  color: var(--ink);
  border-color: #000;
}
#filterCount {
  font: 10px var(--font-display);
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
}

/* ── Drawer: the big dialog ───────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(2,2,16,.72);
  display: flex; justify-content: flex-end;
  z-index: 10;
}
.drawer {
  width: min(620px, 100%);
  height: calc(100% - 24px);
  margin: 12px 14px 12px 0;
  overflow-y: auto;
  padding: 14px 16px;
  animation: drawer-in .22s steps(5, jump-end);
}
@keyframes drawer-in {
  from { transform: translateX(48px); opacity: .3; }
  to   { transform: none; opacity: 1; }
}

details summary { color: var(--text); }
details summary h2, .drawer h2 { display: inline-block; margin: 10px 0 6px; }

/* ── History + comments: nested message boxes ─────────────────────────── */
.editlog, .comment {
  background: rgba(6,6,40,.55);
  border: 2px solid #3a3f8c;
  border-left: 4px solid var(--gold);
  padding: 8px 12px;
  margin: 10px 0;
}
.editlog .meta, .comment .meta {
  font-size: 11px; color: var(--dim);
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
}
.editlog .change { font-size: 12.5px; }
.editlog .change b { color: var(--gold); font-weight: 700; }
.editlog s { color: var(--red); }

/* ── Portraits ────────────────────────────────────────────────────────── */
.avatar {
  width: 24px; height: 24px;
  object-fit: cover;
  image-rendering: pixelated;
  border: 2px solid #f8f8f8;
  box-shadow: 1px 1px 0 #000;
  vertical-align: -7px;
  margin-right: 5px;
}
span.avatar.initial {
  display: inline-block;
  text-align: center; line-height: 20px;
  font-weight: 900; font-size: 12px;
  background: var(--win-mid);
  color: var(--gold);
}

/* ── Database select screen ───────────────────────────────────────────── */
.dblist button.open {
  display: block;
  width: 100%; text-align: left;
  padding: 10px 12px 10px 34px;
  margin-bottom: 14px;
  color: var(--text);
  font: 700 13px var(--font-body);
  text-transform: none; letter-spacing: 0;
  position: relative;
  box-shadow: none;
  cursor: pointer;
}
.dblist button.open::before {
  content: "▶";
  position: absolute; left: 12px;
  color: transparent;
}
.dblist button.open:hover { filter: drop-shadow(0 5px 0 rgba(0,0,0,.5)) brightness(1.15); }
.dblist button.open:hover::before {
  color: var(--gold);
  animation: cursor-blink .8s steps(2, jump-none) infinite;
}
.dblist button.open:active { transform: translateY(2px); }
.dblist button.open b { color: var(--gold); }
.dblist button.open .badge { margin-left: 8px; }

/* ── Title screen ─────────────────────────────────────────────────────── */
.mode7 {
  position: fixed;
  left: -40%; right: -40%; bottom: 0;
  height: 54vh;
  z-index: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(248,216,120,.28) 0 2px, transparent 2px 64px),
    repeating-linear-gradient(0deg, rgba(248,216,120,.24) 0 2px, transparent 2px 44px),
    linear-gradient(180deg, #181868, #0a0a34);
  transform: perspective(340px) rotateX(58deg);
  transform-origin: 50% 0%;
  mask-image: linear-gradient(180deg, transparent 0%, #000 34%);
  animation: mode7-scroll 2.2s linear infinite;
}
@keyframes mode7-scroll {
  to { background-position: 0 44px, 0 44px, 0 0; }
}
.titlecard {
  max-width: 560px;
  margin: 11vh auto 0;
  padding: 34px 34px 30px;
  text-align: center;
}
.titlecard .logo {
  font: 26px/1.4 var(--font-display);
  background: linear-gradient(180deg, #fff0b8 18%, var(--gold) 46%, #e88820 78%, #b05810 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(3px 3px 0 #000) drop-shadow(0 3px 0 rgba(0,0,0,.5));
  margin-bottom: 10px;
}
.titlecard .tagline {
  font: 8px/1.6 var(--font-display);
  letter-spacing: .18em;
  color: var(--dim);
  margin-bottom: 26px;
}
.titlecard p { text-align: left; }
.titlecard button.start {
  font: 12px var(--font-display);
  padding: 14px 26px;
  margin-top: 20px;
  animation: start-pulse 1.2s steps(2, jump-none) infinite;
}
@keyframes start-pulse { 50% { opacity: .45; } }
.titlecard button.start:hover, .titlecard button.start:focus-visible {
  animation: none;
}

/* ── Scrollbars ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--ink); }
::-webkit-scrollbar-thumb { background: #6870c8; border: 2px solid var(--ink); }
* { scrollbar-color: #6870c8 var(--ink); }

/* ── Quality floor ────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  header { padding: 10px 12px; }
  header h1::after { display: none; }
  main { padding: 14px 8px 48px; }
  .filterbar { flex-direction: column; align-items: stretch; }
  .filtergroup { border-left: 0; padding-left: 0; }
  .drawer { margin: 0; height: 100%; }
  .titlecard { margin-top: 5vh; }
  .titlecard .logo { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  tbody tr:hover td:first-child::before,
  .dblist button.open:hover::before,
  .titlecard button.start,
  .mode7 { animation: none; }
  .drawer { animation: none; }
}
