:root {
  /* Warmer paper tones — closer to "old cream paper" than tech-cool gray. */
  --bg: #f7f4ee;
  --surface: #fbf9f4;
  --fg: #1c1b18;
  --muted: #6b6863;
  --subtle: #a8a49b;
  --border: #e5e0d4;
  --hover: #efeae0;
  --accent: #762e1f;   /* deep editorial wine — used sparingly */
  --danger: #a23a2a;
  --danger-soft: #fdf1ee;

  --font-display: "Fraunces", "Georgia", serif;
  --font-body: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", "SF Mono", ui-monospace, monospace;

  --radius: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
*[hidden] { display: none !important; }

html { font-size: 15px; }

body {
  font-family: var(--font-body);
  font-feature-settings: "ss01", "cv01", "cv11";
  background: var(--bg);
  color: var(--fg);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}
/* Very subtle paper grain. SVG fractal noise, ~3% opacity, fixed to viewport. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
body > * { position: relative; z-index: 1; }

button { font-family: inherit; }

/* ───── brand wordmark ─────────────────────────────────────────────── */
.brand {
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  font-size: 1.4rem;
  letter-spacing: 0;
  color: var(--fg);
}
.brand-xl {
  font-size: 4.5rem;
  line-height: 1.1;
  letter-spacing: 0.005em;
  /* Disable any contextual kerning quirks that pull glyphs too tight */
  font-kerning: normal;
}
.brand-sub {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
}

/* ───── sign-in ──────────────────────────────────────────────────── */
.signin-section:not([hidden]) {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 2rem;
  animation: fade-in 0.5s ease-out both;
}
.signin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  text-align: center;
}
.signin-card .btn-google { margin-top: 1.75rem; }
.signin-card > * {
  opacity: 0;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
.signin-card > *:nth-child(1) { animation-delay: 0.05s; }
.signin-card > *:nth-child(2) { animation-delay: 0.15s; }
.signin-card > *:nth-child(3) { animation-delay: 0.32s; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.6rem 1.1rem 0.6rem 0.9rem;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: box-shadow 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}
.btn-google:hover {
  border-color: var(--fg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
  transform: translateY(-1px);
}
.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  max-width: 28rem;
}

/* ───── header ───────────────────────────────────────────────────── */
header#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  /* vignette-like horizontal accent fading from the wine accent to nothing */
  background-image: linear-gradient(to right, rgba(118, 46, 31, 0.04), transparent 40%);
  animation: fade-in 0.45s ease-out both;
}
header#app-header .brand { font-size: 1.25rem; }
.header-right {
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
.email {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease;
}
.link-btn:hover { color: var(--fg); }

/* ───── main layout ──────────────────────────────────────────────── */
main {
  max-width: 56rem;
  margin: 0 auto;
  padding: 3.5rem 2rem 6rem;
  display: flex;
  flex-direction: column;
  gap: 4rem;
  animation: fade-in 0.55s ease-out both;
  animation-delay: 0.05s;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  min-height: 32px;
}
.count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--subtle);
}
.list-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}
/* Search and sort describe the shelf being viewed, so they come and go with
   its contents. The shelf switch beside them must not: it is the only way off
   an empty shelf. */
.list-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.search-input {
  width: 13rem;
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}
.select-input {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 1.6rem 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--fg);
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 12px;
  transition: border-color 0.15s ease;
}
.select-input:hover { border-color: var(--muted); }
.select-input:focus { border-color: var(--fg); }

/* Shelf switch: same chip as the select, but it reads as a state rather than a
   menu, so the pressed form inverts instead of just darkening its border. */
.shelf-toggle {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--muted);
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.shelf-toggle:not(.on):hover { border-color: var(--muted); color: var(--fg); }
.shelf-toggle.on {
  background-color: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}
/* An outline, not a border colour: when pressed the border is already --fg, so
   a border-only focus ring would be invisible exactly where it is needed. */
.shelf-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Label filter row. It sits between the header and the list rather than in
   .list-controls: eight chips would push search and sort off a narrow screen,
   and the chips describe the rows below them. */
.label-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0 0 0.85rem;
}
.label-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: var(--surface);
  color: var(--muted);
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.label-chip:not(.on):hover { border-color: var(--muted); color: var(--fg); }
.label-chip.on {
  background-color: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}
.label-chip-count {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  opacity: 0.65;
}
/* The starred chip is a glyph where the others are words, so it needs its own
   size to sit level with them. */
.label-chip.star {
  font-size: 0.92rem;
  line-height: 1;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}
/* An outline, not a border colour: when selected the border is already --fg. */
.label-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ───── dropzone ─────────────────────────────────────────────────── */
.dropzone {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 2.25rem 2rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.dropzone.drag {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(118, 46, 31, 0.06);
}
.dropzone-text {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--muted);
}
.dropzone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.picker-row {
  display: flex;
  gap: 0.5rem;
}

/* ───── buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}
.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--fg);
}
.btn-outline:hover {
  border-color: var(--fg);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover {
  color: var(--fg);
  background: var(--hover);
}
.btn-primary {
  background: var(--fg);
  color: var(--bg);
}
.btn-primary:hover { background: #000; }
.btn-primary:disabled {
  background: var(--subtle);
  cursor: not-allowed;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #991b1b; }

.text-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s ease;
}
.text-input::placeholder { color: var(--subtle); }
.text-input:hover { border-color: var(--muted); }
.text-input:focus { border-color: var(--fg); }
.text-input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ───── staged + recipients ──────────────────────────────────────── */
.recipients-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.6rem;
  margin-top: 1.5rem;
}
.recipients-label:first-child { margin-top: 0; }
.recipients-label .hint {
  text-transform: none;
  letter-spacing: 0;
  color: var(--subtle);
  font-size: 0.7rem;
}

.staged {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  max-height: 9rem;
  overflow-y: auto;
}
.staged-file {
  display: block;
  padding: 0.1rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.checks label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.825rem;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}
.checks label:hover { border-color: var(--muted); }
.checks input { position: absolute; opacity: 0; pointer-events: none; }
.checks label:has(input:checked) {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.upload-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.progress {
  margin-top: 1rem;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
  display: none;
}
.progress.active { display: block; }
.progress > div {
  height: 100%;
  width: 0;
  background: var(--fg);
  transition: width 0.2s ease;
}

/* ───── shares list (state at rest, actions on hover) ────────────── */
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--border);
}
.row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.95rem 0.25rem;
  border-bottom: 1px solid var(--border);
  position: relative;
  transition: padding-left 0.18s ease;
}
.row:hover { padding-left: 0.75rem; }
.row.drag {
  padding-left: 0.75rem;
  background: rgba(118, 46, 31, 0.04);
}
.row.replacing {
  opacity: 0.55;
  pointer-events: none;
}
.row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 2px;
  height: 0;
  background: var(--accent);
  transition: height 0.18s ease, top 0.18s ease;
}
.row:hover::before { height: calc(100% - 1rem); top: 0.5rem; }
.row-title {
  /* Do not grow: the public badge sits immediately after the title, and a
     growing title would push it to the far right. Shrinking still works, so
     long titles keep their ellipsis. */
  flex: 0 1 auto;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.005em;
}
.row-right {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-left: auto;
  min-height: 30px;
  min-width: 5rem;
}
.row-date {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--muted);
  white-space: nowrap;
  letter-spacing: -0.005em;
  transition: opacity 0.15s ease;
}
.row-hover {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.row-recipients {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-recipients.muted { color: var(--subtle); font-style: italic; }
.row-pill {
  flex-shrink: 0;
  font-size: 0.7rem;
  letter-spacing: 0.01em;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}
/* A label on a row is quieter than the public badge: it groups, it does not
   warn. Lowercase and borderless keeps a row with three of them calm. */
.row-label {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  color: var(--subtle);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}
/* The hover overlay slides in from the right; labels are the first thing it
   would collide with on a narrow row, so they fade rather than overlap. */
.row:hover .row-label,
.row:focus-within .row-label { opacity: 0; }

/* The star is the viewer's own state, like the labels, not one of the hover
   actions — so it stays put ahead of the title rather than living in
   .row-hover. Unstarred it is faint but never hidden: hover-only would put it
   out of reach on a phone, which is where these lists get read. */
.row-star {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-right: -0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--subtle);
  opacity: 0.4;
  cursor: pointer;
  border-radius: 6px;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.row-star svg { width: 15px; height: 15px; stroke-width: 1.6; }
.row:hover .row-star { opacity: 0.8; }
.row-star:hover { opacity: 1; color: var(--fg); }
/* Filled, not coloured: the accent stays reserved for deletion. */
.row-star.on,
.row:hover .row-star.on { opacity: 1; color: var(--fg); }
.row-star.on svg { fill: currentColor; }
.row-star:focus-visible {
  opacity: 1;
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}
.row:hover .row-date,
.row:focus-within .row-date { opacity: 0; }
.row:hover .row-hover,
.row:focus-within .row-hover { opacity: 1; pointer-events: auto; }

.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--surface);
  color: var(--fg);
}
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn svg { width: 15px; height: 15px; stroke-width: 1.6; }

.empty {
  padding: 3.5rem 0 3rem;
  text-align: center;
  color: var(--subtle);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.05rem;
  letter-spacing: -0.005em;
  border-bottom: 1px solid var(--border);
}

/* ───── toast ────────────────────────────────────────────────────── */
.toast-wrap {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}
.toast {
  background: var(--fg);
  color: var(--bg);
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  font-size: 0.82rem;
  letter-spacing: 0.005em;
  animation: slide-up 0.25s ease-out;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}
.toast.err { background: var(--danger); }
@keyframes slide-up {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

/* ───── dialogs ──────────────────────────────────────────────────── */
dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  border: none;
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.5rem 1.25rem;
  max-width: 90vw;
  max-height: min(80vh, 42rem);
  width: 26rem;
  background: var(--surface);
  font-family: inherit;
  color: var(--fg);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.16);
  overflow: auto;
}
dialog::backdrop {
  background: rgba(24, 24, 27, 0.4);
  backdrop-filter: blur(2px);
}
.dialog-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.2rem;
  margin-bottom: 0.75rem;
  letter-spacing: -0.005em;
}
.dialog-body {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  line-height: 1.55;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
#edit-dialog .checks { margin: 0.5rem 0 0.5rem; }
.dialog-spacer { flex: 1; }
#publink-dialog .checks { margin: 0.5rem 0 0.5rem; }
#publink-url {
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
.version-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.86rem;
  text-align: left;
}
.version-row:hover:not(:disabled) {
  border-color: var(--fg);
}
.version-row:disabled {
  cursor: default;
  color: var(--muted);
  background: var(--bg);
}
.version-row small {
  color: var(--subtle);
  font-size: 0.75rem;
}

.token-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.86rem;
}
.token-row span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.token-row small {
  flex: none;
  color: var(--subtle);
  font-size: 0.72rem;
  white-space: nowrap;
}

/* One-time reveal of a minted token: the value fills the row and the copy
   control sits at its right edge. */
.secret-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.secret-row .text-input {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
}

/* ───── responsive ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  html { font-size: 14px; }
  header#app-header { padding: 1rem 1.25rem; }
  main { padding: 2.5rem 1.25rem 4rem; gap: 3rem; }
  .brand-xl { font-size: 3.5rem; }
  .dropzone { padding: 1.75rem 1.25rem; }

  .list-controls {
    margin-left: 0;
    width: 100%;
    margin-top: 0.5rem;
  }
  .search-input { flex: 1; width: auto; }
}

/* ───── touch / no hover devices ─────────────────────────────────── */
/* On touch devices, hover doesn't exist; show actions + recipients
 * stacked below the title so taps still work. */
@media (hover: none) {
  .row {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.35rem 1rem;
  }
  .row-title { flex-basis: 100%; }
  .row-right { width: 100%; justify-content: space-between; min-height: 0; }
  .row-hover {
    position: static;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    gap: 0.75rem;
    flex-wrap: wrap;
  }
  .row-date { display: none; }
}
