/* ---------- Base & "official paper" vibe ---------- */
:root {
  --paper: #f5ecd7;
  --paper-dark: #e9dcb8;
  --ink: #1d1a14;
  --ink-soft: #4a3f2a;
  --red-stamp: #a01919;
  --gold: #b58a2a;
  --green-stamp: #1f6b3a;
  --line: #b89b5e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}

body { position: relative; min-height: 100vh; padding-bottom: 4rem; }

/* Subtle paper texture + faint ruled lines */
.paper-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  background:
    repeating-linear-gradient(transparent 0 31px, rgba(120, 90, 30, 0.08) 31px 32px),
    radial-gradient(circle at 20% 20%, rgba(180, 140, 60, 0.07), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(180, 140, 60, 0.07), transparent 40%),
    var(--paper);
}

/* ---------- Masthead ---------- */
.masthead {
  max-width: 1100px;
  margin: 2rem auto 1rem;
  padding: 1.2rem 1.5rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.2rem;
  align-items: center;
  border: 3px double var(--ink);
  background: var(--paper-dark);
  position: relative;
}
.masthead::before, .masthead::after {
  content: "★";
  position: absolute;
  top: -14px;
  background: var(--paper-dark);
  padding: 0 6px;
  font-size: 1.1rem;
  color: var(--red-stamp);
}
.masthead::before { left: 24px; }
.masthead::after  { right: 24px; }

.seal svg {
  width: 96px;
  height: 96px;
  transform: rotate(-6deg);
  filter: drop-shadow(1px 1px 0 rgba(0,0,0,0.1));
}
.masthead-text { text-align: center; }
.kicker { margin: 0; font-style: italic; color: var(--ink-soft); letter-spacing: 0.05em; }
.masthead-text h1 {
  margin: 0.1rem 0;
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.tagline { margin: 0; font-style: italic; color: var(--ink-soft); }

.live-indicator {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 2px solid var(--red-stamp);
  border-radius: 4px;
  background: #fff8e6;
  font-weight: bold;
  font-size: 0.85rem;
  color: var(--red-stamp);
}
.live-indicator .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--red-stamp);
  animation: pulse 1.6s infinite;
}
.live-indicator.off .dot { background: #888; animation: none; }
.live-indicator.off { border-color: #888; color: #888; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.4; transform: scale(0.7); }
}

/* ---------- Counters ---------- */
.counters {
  max-width: 1100px;
  margin: 0 auto 1.5rem;
  padding: 0 1rem;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.counter {
  flex: 1 1 240px;
  background: var(--paper-dark);
  border: 1px solid var(--line);
  padding: 0.8rem 1rem;
  text-align: center;
  border-radius: 4px;
}
.counter-num {
  display: block;
  font-size: 2rem;
  font-weight: bold;
  color: var(--red-stamp);
  font-variant-numeric: tabular-nums;
}
.counter-label {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---------- Main grid ---------- */
.grid {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.2rem;
}
@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
  .masthead { grid-template-columns: 1fr; text-align: center; }
  .seal { margin: 0 auto; }
}

.card {
  background: #fffaeb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1.2rem 1.4rem;
  position: relative;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.08);
}
.card-corner {
  position: absolute;
  top: -10px;
  right: 14px;
  background: var(--red-stamp);
  color: #fff;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  font-weight: bold;
  padding: 3px 10px;
  transform: rotate(3deg);
  border: 2px solid #fff;
  box-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}
.card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.muted { color: var(--ink-soft); font-style: italic; margin: 0 0 0.8rem; }

/* ---------- Stamps ---------- */
.stamp {
  display: inline-block;
  padding: 2px 10px;
  margin-right: 8px;
  border: 3px double currentColor;
  border-radius: 6px;
  font-weight: 900;
  font-family: "Impact", "Arial Black", sans-serif;
  letter-spacing: 0.1em;
  transform: rotate(-4deg);
  text-transform: uppercase;
}
.stamp-ok   { color: var(--green-stamp); background: rgba(31,107,58,0.06); }
.stamp-bad  { color: var(--red-stamp); background: rgba(160,25,25,0.06); }

/* ---------- Form ---------- */
form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.95rem;
}
form label > span {
  display: block;
  font-weight: bold;
  margin-bottom: 4px;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
form label > span em { color: var(--red-stamp); font-style: normal; }
form input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fffdf3;
  font: inherit;
  color: var(--ink);
}
form input[type="text"]:focus {
  outline: none;
  border-color: var(--red-stamp);
  box-shadow: 0 0 0 3px rgba(160,25,25,0.15);
}
.hint { display: block; text-align: right; font-size: 0.8rem; color: var(--ink-soft); margin-top: 2px; }

.btn {
  display: inline-block;
  padding: 0.65rem 1.2rem;
  border: 2px solid var(--ink);
  background: var(--paper-dark);
  color: var(--ink);
  font: bold 0.95rem Georgia, serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
  transition: transform 0.08s, background 0.2s;
}
.btn:hover  { background: #f0e2b6; }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--red-stamp);
  color: #fff;
  border-color: #6e0e0e;
  width: 100%;
  margin-top: 0.4rem;
  font-size: 1rem;
}
.btn-primary:hover { background: #8a1414; }

.form-msg {
  margin: 0.6rem 0 0;
  min-height: 1.2em;
  font-style: italic;
}
.form-msg.ok  { color: var(--green-stamp); font-weight: bold; }
.form-msg.err { color: var(--red-stamp); font-weight: bold; }

/* ---------- CRUD ops (visible, mostly broken) ---------- */
.crud-card .crud-row { margin-bottom: 0.6rem; }
.op {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 2px solid var(--ink);
  background: #fffdf3;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  transition: transform 0.08s;
}
.op:hover  { background: #fff5d4; }
.op:active { transform: translateY(1px); }
.op[disabled] { cursor: not-allowed; opacity: 0.85; background: #efe6c8; }
.op-letter {
  display: inline-block;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  text-align: center;
  line-height: 36px;
  font-weight: bold;
  font-size: 1.1rem;
}
.op-name { font-weight: bold; text-transform: uppercase; letter-spacing: 0.05em; }
.op-status {
  font-size: 0.7rem;
  font-weight: bold;
  padding: 3px 8px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  letter-spacing: 0.1em;
  transform: rotate(-2deg);
  white-space: nowrap;
}
.op-create .op-status { color: var(--green-stamp); }
.op-read   .op-status { color: var(--ink-soft); }
.op-update .op-status { color: #b07000; }
.op-delete .op-status { color: var(--red-stamp); }

.op.shake { animation: shake 0.5s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px) rotate(-1deg); }
  40%, 80% { transform: translateX(6px)  rotate(1deg); }
}

.footnote {
  margin: 0.8rem 0 0;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- Registry (live entries) ---------- */
.registry {
  max-width: 1100px;
  margin: 2rem auto 0;
  padding: 0 1rem;
}
.registry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 6px;
  margin-bottom: 1rem;
}
.registry-header h2 { margin: 0; }
.live-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--red-stamp); color: #fff;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
}
.live-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #fff;
  animation: pulse 1.6s infinite;
}

.entries {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.entry {
  background: #fffaeb;
  border: 1px solid var(--line);
  border-left: 6px solid var(--red-stamp);
  padding: 0.9rem 1rem 0.8rem;
  position: relative;
  border-radius: 4px;
  box-shadow: 1px 2px 0 rgba(0,0,0,0.06);
  animation: pop-in 0.4s ease-out;
}
.entry::before {
  content: "#" attr(data-num);
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.75rem;
  color: var(--ink-soft);
  font-style: italic;
}
@keyframes pop-in {
  0%   { transform: scale(0.85) rotate(-2deg); opacity: 0; }
  60%  { transform: scale(1.05) rotate(1deg); opacity: 1; }
  100% { transform: scale(1)    rotate(0); }
}
.entry h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  color: var(--red-stamp);
}
.entry .holder {
  font-weight: bold;
  font-size: 0.9rem;
  margin: 0.2rem 0;
}
.entry .holder::before { content: "Holder: "; font-weight: normal; font-style: italic; color: var(--ink-soft); }
.entry .effect {
  margin: 0.2rem 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.entry .effect::before { content: "Side effect: "; font-style: italic; }
.entry .stamp-row {
  margin-top: 0.7rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.entry .stamp-row time {
  font-size: 0.75rem;
  color: var(--ink-soft);
  font-style: italic;
}
.entry .stamp-row .stamp-mini {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 6px;
  border: 2px solid var(--green-stamp);
  color: var(--green-stamp);
  font-weight: bold;
  transform: rotate(-3deg);
  letter-spacing: 0.1em;
}

/* Tiny per-entry R/U/D buttons (also broken) */
.entry-actions {
  display: flex;
  gap: 4px;
  margin-top: 0.5rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.5rem;
}
.entry-actions button {
  flex: 1;
  font-size: 0.7rem;
  padding: 4px 6px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.05em;
}
.entry-actions button:hover { background: #fff5d4; }

.empty {
  text-align: center;
  font-style: italic;
  color: var(--ink-soft);
  padding: 2rem 0;
}
.hidden { display: none !important; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(20, 15, 5, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fade-in 0.2s;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-inner {
  background: #fffaeb;
  border: 4px double var(--red-stamp);
  border-radius: 8px;
  padding: 2rem 2.2rem 1.6rem;
  max-width: 460px;
  width: 90%;
  text-align: center;
  position: relative;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.modal-stamp {
  display: inline-block;
  font-family: "Impact", "Arial Black", sans-serif;
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--red-stamp);
  border: 6px double var(--red-stamp);
  padding: 6px 22px;
  transform: rotate(-8deg);
  letter-spacing: 0.15em;
  margin-bottom: 1rem;
  background: rgba(160,25,25,0.04);
}
.modal-inner h3 {
  margin: 0.6rem 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.modal-inner p {
  margin: 0 0 1rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  margin-top: 3rem;
  padding: 1rem;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}
.footer .tiny { font-size: 0.75rem; opacity: 0.7; }

/* ---------- Confetti ---------- */
.confetti {
  position: fixed;
  width: 10px; height: 14px;
  top: -20px;
  pointer-events: none;
  z-index: 200;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.3; }
}

/* ---------- Toast (live arrivals) ---------- */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 4px;
  font-size: 0.9rem;
  z-index: 90;
  opacity: 0;
  transition: transform 0.35s, opacity 0.35s;
  max-width: 90%;
  border-left: 4px solid var(--red-stamp);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }