/* erahs - mobile first, light and dark following the device */

:root {
  color-scheme: light dark;
  --bg: #f5f6ef;
  --surface: #ffffff;
  --surface-2: #eceedf;
  --ink: #1d2113;
  --muted: #63684f;
  --line: #dde1cb;
  --accent: #3c4a12;
  --accent-ink: #ffffff;
  --accent-soft: #e5ebcc;
  --gold: #ffc21a;
  --danger: #b3261e;
  --ok: #1f7a4a;
  --shadow: 0 1px 2px rgba(29, 33, 19, 0.06), 0 6px 18px rgba(29, 33, 19, 0.08);
  --radius: 14px;
  --tap: 46px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10120a;
    --surface: #1a1d12;
    --surface-2: #24281a;
    --ink: #eef0e2;
    --muted: #a5ab8d;
    --line: #353b26;
    --accent: #bccb72;
    --accent-ink: #171b07;
    --accent-soft: #2d3418;
    --danger: #ff8a80;
    --ok: #6fd39c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
img { max-width: 100%; }
.hidden, [hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand img { width: 34px; height: 34px; flex: none; }
.brand h1 { margin: 0; font-size: 1.2rem; letter-spacing: 0.02em; }
.topbar .spacer { flex: 1; }
.topbar .actions { display: flex; gap: 6px; align-items: center; }

/* ------------------------------------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, .card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}
.btn[disabled] { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn.block { width: 100%; }
.btn.icon { width: var(--tap); padding: 0; }
.btn svg { width: 20px; height: 20px; flex: none; }

/* the main action, within reach of the thumb on a phone */
.fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 60;
  min-height: 56px;
  padding: 0 22px;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------------------------------------- layout */

main {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px max(12px, env(safe-area-inset-right)) 96px max(12px, env(safe-area-inset-left));
}

main.narrow { max-width: 760px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 14px;
}

.section-head h2 { margin: 0; font-size: 1.25rem; }

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ------------------------------------------------------------------------------------------- forms */

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; }
label .hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }

input[type="text"], input[type="email"], input:not([type]), textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  /* 16px at least, or iOS zooms on focus */
  font: 16px/1.4 var(--font);
}

textarea { resize: vertical; }

.notice {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
}

.notice.warning { background: color-mix(in srgb, var(--gold) 22%, var(--surface)); }
.notice.error { background: color-mix(in srgb, var(--danger) 16%, var(--surface)); }

/* ------------------------------------------------------------------------------------------- dialogs */

dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(10, 12, 4, 0.55); }
dialog .dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 1.25rem; }

/* a sheet rising from the bottom on phones, easy to reach */
@media (max-width: 600px) {
  dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ------------------------------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 88px));
  z-index: 500;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #23281a;
  color: #fff;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.toast.error { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------------------------------- cards */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 14px;
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}

.card:hover { transform: translateY(-2px); }
.card.new { animation: arrive 0.5s ease; }

@keyframes arrive {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: none; }
}

.card .caption { padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card .caption .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .caption .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; color: var(--muted); font-size: 0.85rem; }
.card .caption .summary { color: var(--muted); font-size: 0.9rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge svg { width: 14px; height: 14px; }
.badge.draft { background: color-mix(in srgb, var(--gold) 30%, var(--surface)); }
.badge.banned { background: color-mix(in srgb, var(--danger) 25%, var(--surface)); }

/* miniatures */
.mini {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--surface-2);
}

.mini img.cover { width: 100%; height: 100%; object-fit: cover; display: block; }

.mini.mosaic { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.mini.mosaic.n1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.mini.mosaic.n2 { grid-template-rows: 1fr; }
.mini.mosaic.n3 img:first-child { grid-row: span 2; }
.mini.mosaic img { width: 100%; height: 100%; object-fit: cover; display: block; }

.mini .count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(15, 10, 20, 0.72);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}

/* the top of a document, drawn at a reading width then scaled down */
.mini.doc { background: var(--surface); border-bottom: 1px solid var(--line); }
.mini.doc .page {
  position: absolute;
  top: 0;
  left: 0;
  width: 720px;
  transform-origin: 0 0;
  pointer-events: none;
}
.mini.doc::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 30%;
  background: linear-gradient(transparent, var(--surface));
}

/* the first slides: the first one large, the next ones as a strip */
.mini.slides { display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; gap: 3px; background: #2a2233; }
.mini.slides.single { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.mini.slides .static-slide { aspect-ratio: auto; height: 100%; }
.mini.slides .static-slide:first-child { grid-row: span 2; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}

.empty-state img { width: 72px; opacity: 0.9; }

.missing-picture {
  display: inline-block;
  padding: 2px 8px;
  border: 1px dashed var(--muted);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9em;
}

/* ------------------------------------------------------------------------------------------- footer */

footer.page {
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

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

/* a user as the public knows them */
.author { display: inline-flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; color: var(--ink); text-decoration: none; }
.author .avatar { flex: none; border-radius: 6px; }
a.author:hover { text-decoration: underline; }
.identity-chip { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 600; }
.identity-chip .avatar { border-radius: 8px; }
