:root {
  --paper: #fdfcf8;
  --card: #ffffff;
  --ink: #1e2430;
  --red: #d6453d;
  --blue: #2b4c9b;
  --muted: #8a8578;
  --line: rgba(30, 36, 48, 0.16);
  --display: "American Typewriter", "Courier New", Courier, serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141a28;
    --card: #1c2334;
    --ink: #e8e6df;
    --red: #e05c54;
    --blue: #7d97d8;
    --muted: #7a8296;
    --line: rgba(232, 230, 223, 0.16);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 -apple-system, system-ui, sans-serif;
  min-height: 100vh;
}

.airmail {
  height: 8px;
  background: repeating-linear-gradient(-45deg,
    var(--red) 0 14px, var(--paper) 14px 26px,
    var(--blue) 26px 40px, var(--paper) 40px 52px);
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.wordmark {
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}
nav { display: flex; gap: 1rem; }
nav a { color: var(--muted); text-decoration: none; font-size: 0.9rem; }
nav a:hover { color: var(--red); }

main { max-width: 44rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

h1 { font-family: var(--display); font-weight: 400; font-size: 1.6rem; line-height: 1.25; margin: 0.4rem 0 1rem; }

.toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.toolbar .eyebrow { margin: 0.25rem 0 0; }
.toolbar + .grid, .toolbar + .empty { margin-top: 1rem; }

.eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0.25rem 0 1rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1rem;
}
.chip {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  text-decoration: none;
}
.chip:hover { color: var(--red); border-color: var(--red); }
.chip-active { color: var(--paper); background: var(--blue); border-color: var(--blue); }

.grid {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  gap: 0.9rem;
}
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1rem 3.4rem 0.9rem 1rem;
}
.stamp {
  position: absolute;
  top: 0.7rem; right: 0.7rem;
  width: 2rem; height: 2.4rem;
  display: grid; place-items: center;
  font-family: var(--display);
  font-size: 1.05rem;
  color: var(--muted);
  border: 1px dashed var(--muted);
  transform: rotate(3deg);
  background: var(--paper);
}
.stamp-public { color: var(--red); border-color: var(--red); }
.card-title {
  font-family: var(--display);
  font-size: 1.02rem;
  color: var(--ink);
  text-decoration: none;
  display: block;
  overflow-wrap: anywhere;
}
.card-title:hover { color: var(--red); }
.card-meta { font-family: var(--mono); font-size: 0.7rem; color: var(--muted); margin-top: 0.35rem; }
.card-actions { display: flex; gap: 0.5rem; margin-top: 0.7rem; }

button, .btn {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  background: none;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  text-decoration: none;
}
button:hover { border-color: var(--ink); }
button.danger:hover { color: var(--red); border-color: var(--red); }
.btn {
  display: inline-block;
  color: var(--paper);
  background: var(--red);
  border: none;
  padding: 0.7rem 1.2rem;
  font-size: 0.8rem;
}
.btn:hover { filter: brightness(1.08); }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.empty, .letter { text-align: center; padding: 3rem 0.5rem; }
.empty p, .letter p { color: var(--muted); }
.letter { max-width: 26rem; margin: 0 auto; }
.login-form { display: flex; flex-direction: column; gap: 0.7rem; margin: 1.4rem 0 0.8rem; }
.login-form input {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.7rem 0.9rem;
  text-align: center;
}
.hint { font-size: 0.85rem; }

.viewer-bar {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.8rem;
  font-family: var(--mono);
  font-size: 0.8rem;
}
.viewer-bar a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.viewer-bar a:hover { color: var(--red); }
.viewer-title { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer {
  width: 100%;
  height: calc(100vh - 12rem);
  min-height: 20rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 2rem;
  font-size: 0.85rem;
}
.admin-table th {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  font-weight: 400;
}
.admin-table th, .admin-table td {
  padding: 0.45rem 0.6rem 0.45rem 0;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.admin-table a { color: var(--ink); }
.admin-table a:hover { color: var(--red); }
.admin-table form { margin: 0; }

body.full {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.fullbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(env(safe-area-inset-top) + 0.45rem) 0.9rem 0.45rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.78rem;
}
.fullbar a { color: var(--red); text-decoration: none; white-space: nowrap; }
.fullbar-title {
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--display);
  font-size: 0.85rem;
}
.fullbar-spacer { width: 4ch; }
.fullframe { flex: 1; width: 100%; border: 0; background: #fff; }

footer {
  max-width: 44rem;
  margin: 0 auto;
  padding: 0 1.25rem 2.5rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}
footer a { color: var(--blue); }

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