/* Glance -- white glass (T4). Tokens from glance-design-system.md. */
:root {
  color-scheme: light;
  --bg: #F4F1EE;
  --bg-lift: #FBFAF8;
  --bg-recede: #E7E2DC;
  --hairline: rgba(20, 18, 16, 0.10);
  --glass: rgba(255, 255, 255, 0.55);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --ink: #14120F;
  --ink-2: #4A453F;
  --ink-3: #8A837A;
  --focus: #2E6FB0;
  --shadow-panel: 0 8px 40px rgba(20, 18, 16, 0.14);
  --font-ui: "Anonymous Pro", "JetBrains Mono", ui-monospace, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background:
    radial-gradient(120% 120% at 50% 42%, var(--bg-lift) 0%, var(--bg) 46%, var(--bg-recede) 100%);
  font-family: var(--font-ui);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#field {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;    /* fallback */
  height: 100dvh;   /* iOS: track the VISIBLE viewport (excludes the Safari toolbars),
                       so the canvas never extends behind them and the field fits */
  display: block;
  touch-action: none; /* we handle pan/zoom */
  cursor: grab;
}
#field:active { cursor: grabbing; }

/* frosted-glass chrome bar */
.chrome {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(7px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           7px max(14px, env(safe-area-inset-left));
  background: var(--glass);
  backdrop-filter: saturate(1.3) blur(20px);
  -webkit-backdrop-filter: saturate(1.3) blur(20px);
  border-bottom: 1px solid var(--hairline);
  box-shadow: var(--shadow-panel);
  z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.wordmark { font-size: 17px; font-weight: 700; letter-spacing: 0.12em; }
.edition { font-size: 11px; color: var(--ink-3); letter-spacing: 0.08em; }

.search-shell { flex: 1 1 auto; min-width: 0; max-width: 420px; display: flex; align-items: center; gap: 8px; }
/* mobile-only affordances: hidden on desktop where the input is always shown */
.search-toggle { display: none; }
.search-cancel { display: none; }
.search-shell input {
  width: 100%;
  font-family: inherit;
  font-size: 16px; /* prevent iOS auto-zoom */
  color: var(--ink);
  background: var(--glass-strong);
  border: 1px solid var(--hairline);
  border-radius: 9999px;
  padding: 6px 15px;
  outline: none;
}
.search-shell input:disabled { color: var(--ink-3); opacity: 0.8; cursor: not-allowed; }

.rule { display: flex; gap: 4px; background: var(--glass-strong);
  border: 1px solid var(--hairline); border-radius: 9999px; padding: 2px; }
.rule button {
  font-family: inherit; font-size: 13px; color: var(--ink-2);
  background: transparent; border: 0; border-radius: 9999px;
  padding: 6px 12px; min-height: 30px; cursor: pointer;
  letter-spacing: 0.02em;
}
.rule button.on { color: #fff; background: var(--focus); }
.rule button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums;
  white-space: nowrap; }

@media (max-width: 640px) {
  .search-shell { display: none; }          /* input hidden until the magnifier expands it */
  .edition { display: none; }
  .rule-by { display: none; }               /* "by event"/"by date" -> "event"/"date" */
  .wordmark { font-size: 15px; letter-spacing: 0.09em; }
  /* single line, never wrap: brand + magnifier + rule toggles + count all on one row */
  .chrome {
    gap: 6px; justify-content: flex-start; flex-wrap: nowrap;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: 6px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .brand { flex: 0 0 auto; }
  .rule { flex: 0 0 auto; }
  .rule button { padding: 6px 10px; font-size: 13px; white-space: nowrap; min-height: 34px; }
  /* count is pushed to the right edge; it shrinks + ellipsizes LAST if the row is
     tight, so everything stays on one line (never wraps to a second). */
  .count { font-size: 11px; flex: 0 1 auto; min-width: 0; margin-left: auto;
    overflow: hidden; text-overflow: ellipsis; }

  /* magnifier button that expands search (44px tap target) */
  .search-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex: 0 0 auto;
    color: var(--ink-2); background: var(--glass-strong);
    border: 1px solid var(--hairline); border-radius: 9999px; cursor: pointer;
  }
  .search-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

  /* searching state: the search row takes over the top line; the result count
     (query feedback) sits on its own full-width line beneath it, so it is never
     hidden behind the input. The resting bar is nowrap (single line); searching
     re-enables wrap so the feedback line can drop below the input. */
  .chrome.searching { flex-wrap: wrap; }
  .chrome.searching .brand,
  .chrome.searching .rule,
  .chrome.searching .search-toggle { display: none; }
  .chrome.searching .search-shell {
    display: flex; flex: 1 1 auto; max-width: none; min-width: 0;
    margin: 0;
  }
  .chrome.searching .search-shell input { flex: 1 1 auto; min-width: 0; }
  .chrome.searching .count {
    flex: 1 0 100%; overflow: visible; text-overflow: clip;
    margin-left: 0;                 /* override the resting margin-left:auto */
    padding: 6px 2px 0; color: var(--ink-2);
  }
  .chrome.searching .search-cancel {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; flex: 0 0 auto;
    font-size: 22px; line-height: 1; color: var(--ink-2);
    background: transparent; border: 0; border-radius: 9999px; cursor: pointer;
  }
}

/* ---- metadata card (T7): right glass drawer on desktop ---- */
:root {
  --glass-card: rgba(255, 255, 255, 0.80);
  --shadow-card: 0 10px 60px rgba(20, 18, 16, 0.20);
  --manifest: #2E6FB0;
}

.scrim {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(20, 18, 16, 0.14);
  -webkit-backdrop-filter: saturate(1.05) blur(1px);
  backdrop-filter: saturate(1.05) blur(1px);
}
.scrim[hidden] { display: none; }

.card {
  position: fixed; z-index: 21;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  display: flex; flex-direction: column;
  background: var(--glass-card);
  -webkit-backdrop-filter: saturate(1.3) blur(24px);
  backdrop-filter: saturate(1.3) blur(24px);
  border-left: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
  /* enters from the right edge; time-based ease (design §8 expressive) */
  transform: translateX(100%);
  transition: transform 500ms cubic-bezier(0.2, 0, 0, 1);
  padding-top: env(safe-area-inset-top);
}
.card.open { transform: translateX(0); }
.card[hidden] { display: none; }

.card-grip { display: none; }

.card-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 40px; height: 40px; min-width: 40px;
  display: grid; place-items: center;
  font-family: var(--font-ui); font-size: 20px; line-height: 1;
  color: var(--ink-2);
  background: var(--glass-strong);
  border: 1px solid var(--hairline); border-radius: 9999px;
  cursor: pointer;
}
.card-close:hover { color: var(--ink); }
.card-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.card-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  overflow-x: hidden;   /* nothing ever spills the sheet sideways (belt for v2 editors) */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 max(24px, env(safe-area-inset-bottom));
}

.card-media {
  margin: 0;
  width: 100%;
  background: var(--bg-recede);
  border-bottom: 1px solid var(--hairline);
}
.card-img, .card-video {
  display: block; width: 100%; height: auto;
  max-height: 46vh; object-fit: contain;
  background: var(--bg-recede);
}

.card-pill {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 14px 16px 0;
  font-family: var(--font-ui); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px; border-radius: 9999px;
  border: 1px solid var(--hairline);
}
.card-pill::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
}
.card-pill.is-manifest { color: var(--manifest); background: rgba(46,111,176,0.10); }
.card-pill.is-manifest::before { background: var(--manifest); }
.card-pill.is-latent { color: var(--ink-3); background: rgba(20,18,16,0.04); }
.card-pill.is-latent::before {
  background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-3);
}

.card-body { padding: 8px 16px 0; }

.card-sec { padding: 8px 0; }
.card-sec + .card-sec { border-top: 1px solid var(--hairline); }
.card-sec-h {
  margin: 6px 0 8px; font-family: var(--font-ui); font-size: 11px;
  letter-spacing: 0.10em; text-transform: uppercase; color: var(--ink-3);
}

/* the edit-ready row: fixed label column, value fills. v2 swaps .fld-v for an
   input/select at the SAME geometry -> zero layout shift. */
.fld {
  display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px;
  align-items: baseline;
  padding: 7px 0; min-height: 34px;
}
.fld-l {
  font-family: var(--font-ui); font-size: 13px; color: var(--ink-2);
  letter-spacing: 0.02em;
}
.fld-v {
  font-family: var(--font-ui); font-size: 15px; color: var(--ink);
  word-break: break-word; font-variant-numeric: tabular-nums;
  min-width: 0;   /* let the value column shrink below content (v2 select/inputs) */
}
.fld-empty { color: var(--ink-3); font-style: italic; }

/* bottom sheet on mobile */
@media (max-width: 640px) {
  .card {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    max-height: 88vh;    /* fallback for browsers without dvh */
    max-height: 86dvh;   /* dvh EXCLUDES the browser chrome, so the sheet top
                            (grip + close) never hides behind the iOS URL bar */
    border-left: 0; border-top: 1px solid var(--hairline);
    border-radius: 18px 18px 0 0;
    /* --sheet-y drives the snap position: 100% = closed, 0% = full open.
       Dragging the grip sets it live; .open animates it to 0%. */
    transform: translateY(var(--sheet-y, 100%));
    padding-top: 0;
    overflow: hidden;    /* clip media corners to the rounded top */
  }
  /* transform here too (not just the var) so it beats the desktop .card.open
     translateX rule by equal specificity + later source order */
  .card.open { --sheet-y: 0%; transform: translateY(var(--sheet-y, 0%)); }
  .card.sheet-dragging { transition: none; }   /* 1:1 follow the finger while dragging */
  /* grip = drag handle: a thin pill with a taller transparent hit area
     (content-box padding) so it is easy to grab; close = a glass circle. */
  .card-grip {
    display: block; box-sizing: content-box;
    width: 44px; height: 5px; padding: 11px 0; margin: 0 auto;
    background: var(--ink-3); opacity: 0.45;
    border-radius: 9999px; background-clip: content-box;
    touch-action: none; cursor: grab;
  }
  .card-grip:active { cursor: grabbing; }
  .card-close {
    top: max(8px, env(safe-area-inset-top));
    right: 12px;
    width: 44px; height: 44px;               /* full 44px tap target */
    background: var(--glass-strong);
    box-shadow: 0 2px 10px rgba(20, 18, 16, 0.20);
  }
  .card-img, .card-video {
    max-height: 40vh;
    max-height: 40dvh;
  }
  /* a touch more breathing room from the notch/status area at the sheet top */
  .card-scroll { padding-top: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
}

/* ---- T7.2 card body: chips, copyable, badges, caption, media shimmer ---- */
.mono {
  font-family: "JetBrains Mono", var(--font-ui);
  font-size: 13px; color: var(--ink);
  word-break: break-all; font-variant-numeric: tabular-nums;
}

.card-caption {
  font-family: "Glacial Indifference", Inter, system-ui, sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--ink);
}

/* chip + chip list (artists, scene, artworks, persons, event) */
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-ui); font-size: 13px; color: var(--ink);
  background: rgba(20, 18, 16, 0.05);
  border: 1px solid var(--hairline); border-radius: 9999px;
  padding: 4px 10px; line-height: 1.2;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.chip-dot.is-confirmed { background: var(--focus); }
.chip-dot.is-pending { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-3); }

/* small basis badge next to the date */
.date-val { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge {
  font-family: var(--font-ui); font-size: 10px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-3);
  background: rgba(20, 18, 16, 0.05);
  border: 1px solid var(--hairline); border-radius: 4px;
  padding: 2px 6px;
}

/* tap-to-copy value (provenance ids, public link) */
.copyable { cursor: pointer; position: relative; border-bottom: 1px dashed var(--hairline); }
.copyable:hover { color: var(--focus); border-bottom-color: var(--focus); }
.copyable:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.copyable.copied::after {
  content: "copied"; position: absolute; left: 0; top: -20px;
  font-family: var(--font-ui); font-size: 10px; letter-spacing: 0.06em;
  color: #fff; background: var(--focus); border-radius: 4px; padding: 2px 6px;
  white-space: nowrap; pointer-events: none;
}

/* media shimmer: reserve space + shimmer until the poster/image decodes,
   so the card does not jump when the image lands (no layout shift). */
.card-media.is-loading {
  min-height: 200px;
  background:
    linear-gradient(100deg, var(--bg-recede) 30%, var(--bg-lift) 50%, var(--bg-recede) 70%)
    var(--bg-recede);
  background-size: 200% 100%;
  animation: glance-shimmer 1.2s ease-in-out infinite;
}
@keyframes glance-shimmer {
  from { background-position: 180% 0; }
  to { background-position: -80% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .card-media.is-loading { animation: none; }
}

.card-media-error {
  margin: 0; padding: 12px 16px;
  font-family: var(--font-ui); font-size: 13px; color: var(--glance-error, #B0492E);
  background: rgba(176, 73, 46, 0.06);
}
