:root {
  --paper: #efe7d4;
  --paper-deep: #e7dcc2;
  --ink: #2b2317;
  --ink-soft: #6d5f45;
  --hairline: #3a3122;
  --oxide: #973b26;
  --caption-h: 108px;
  --serif: "EB Garamond", "Iowan Old Style", Georgia, serif;
  --mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

/* ---------- the plate ---------- */

#frame {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #0a0b12;
}

#plate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  animation: unveil 1.6s cubic-bezier(.6, 0, .2, 1) both;
}

@keyframes unveil {
  from { clip-path: inset(0 0 100% 0); opacity: .4; }
  to   { clip-path: inset(0 0 0 0);    opacity: 1; }
}

.corner {
  position: absolute;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .22em;
  color: var(--ink-soft);
  background: var(--paper);
  padding: 6px 10px;
  animation: fade-in 1s .9s both;
}
.corner-tl { top: 14px; left: 18px; }
.corner-tr { top: 14px; right: 18px; text-align: right; color: var(--oxide); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

#drop-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  color: var(--ink-soft);
  background: var(--paper);
  padding: 5px 12px;
  border: 1px solid var(--hairline);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
body.dragging #drop-hint { opacity: 1; }

/* ---------- the label ---------- */

#caption {
  flex: none;
  height: var(--caption-h);
  border-top: 1px solid var(--hairline);
  background: var(--paper);
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  align-items: center;
  gap: 36px;
  padding: 0 36px;
  animation: fade-in .9s .5s both;
}

.cap-left h1 {
  font-size: 30px;
  font-weight: 500;
  letter-spacing: .04em;
  line-height: 1.05;
}
.cap-left .role {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.cap-mid {
  font-style: italic;
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  max-width: 62ch;
  border-left: 1px solid var(--hairline);
  padding-left: 36px;
}

.cap-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  text-align: right;
}
.cap-right a {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color .15s, border-color .15s;
}
.cap-right a:hover { color: var(--oxide); border-color: var(--oxide); }

/* ---------- notes overlay ---------- */

#notes-scrim {
  position: fixed;
  inset: 0;
  background: rgba(43, 35, 23, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
  z-index: 8;
}
body.notes-open #notes-scrim { opacity: 1; pointer-events: auto; }

#notes {
  position: fixed;
  inset: 0;
  width: 100%;
  /* everything (head, body, foot) aligns to one centred reading column */
  --gutter: max(32px, calc((100% - 760px) / 2));
  background: var(--paper-deep);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
  z-index: 9;
  display: flex;
  flex-direction: column;
}
body.notes-open #notes {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.notes-head {
  flex: none;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 22px var(--gutter) 14px;
  border-bottom: 1px solid var(--hairline);
}
.notes-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .28em;
  text-transform: uppercase;
}
.notes-close {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
  text-decoration: none;
}
.notes-close:hover { color: var(--oxide); }

#notes-body {
  flex: 1;
  overflow-y: auto;
  padding: 34px var(--gutter);
}

.notes-foot {
  flex: none;
  padding: 12px var(--gutter);
  border-top: 1px solid var(--hairline);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

#notes-list { list-style: none; }
#notes-list li + li { margin-top: 4px; }
#notes-list a {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  padding: 12px 2px;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px dotted var(--ink-soft);
}
#notes-list .t {
  font-size: 19px;
  font-weight: 500;
}
#notes-list .d {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
  color: var(--ink-soft);
  white-space: nowrap;
}
#notes-list a:hover .t { color: var(--oxide); font-style: italic; }

/* hierarchical sections (vault folders → collapsible groups).
   A folder row mirrors a note row exactly — same serif title, same dotted
   rule, same right-aligned mono meta — but the meta reads "n notes" and a
   disclosure triangle marks it as an openable folder. */
#notes-list .note-group > details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  padding: 12px 2px;
  border-bottom: 1px dotted var(--ink-soft);
  color: var(--ink);
}
#notes-list .note-group summary::-webkit-details-marker { display: none; }
/* folder triangle, sized to sit beside the serif title */
#notes-list .note-group .t::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  margin-left: -2px;
  font-size: 11px;
  color: var(--ink-soft);
  transition: transform .15s;
}
#notes-list .note-group details[open] > summary .t::before { transform: rotate(90deg); }
#notes-list .note-group summary:hover .t { color: var(--oxide); font-style: italic; }
#notes-list .note-group summary:hover .t::before { color: var(--oxide); }
/* nested notes indent under their folder with a hairline spine */
#notes-list .note-group ul {
  list-style: none;
  margin: 0 0 0 12px;
  padding-left: 14px;
  border-left: 1px solid var(--hairline);
}

.notes-error {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-soft);
}

/* article view */
#notes-article .back {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-decoration: none;
  margin-bottom: 22px;
}
#notes-article .back:hover { color: var(--oxide); }

#notes-article h1 {
  font-size: 27px;
  font-weight: 500;
  line-height: 1.15;
  margin-bottom: 4px;
}
#notes-article .meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .16em;
  color: var(--ink-soft);
  margin-bottom: 24px;
}
#notes-article h2 { font-size: 20px; font-weight: 500; margin: 26px 0 8px; }
#notes-article h3 { font-size: 17px; font-weight: 500; margin: 20px 0 6px; }
#notes-article p  { font-size: 16.5px; line-height: 1.62; margin: 0 0 14px; }
#notes-article ul, #notes-article ol { margin: 0 0 14px 22px; font-size: 16.5px; line-height: 1.62; }
#notes-article blockquote {
  border-left: 2px solid var(--oxide);
  padding-left: 16px;
  font-style: italic;
  color: var(--ink-soft);
  margin: 0 0 14px;
}
#notes-article code {
  font-family: var(--mono);
  font-size: .82em;
  background: rgba(43, 35, 23, .08);
  padding: 1px 5px;
}
#notes-article pre {
  background: rgba(43, 35, 23, .08);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.55;
}
#notes-article pre code { background: none; padding: 0; }
#notes-article a { color: var(--oxide); }
#notes-article hr {
  border: none;
  border-top: 1px dotted var(--ink-soft);
  margin: 22px 0;
}

/* headings below h3 */
#notes-article h4 { font-size: 15.5px; font-weight: 500; margin: 18px 0 6px; }
#notes-article h5,
#notes-article h6 { font-size: 14px; font-weight: 500; color: var(--ink-soft); margin: 14px 0 4px; }

/* nested lists sit tighter than top-level ones */
#notes-article li { margin-bottom: 2px; }
#notes-article li > ul,
#notes-article li > ol { margin: 3px 0 5px 20px; }

/* embedded images */
#notes-article img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 0 14px;
  border: 1px solid var(--hairline);
}

/* tables */
#notes-article .table-wrap { overflow-x: auto; margin: 0 0 16px; }
#notes-article table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
  line-height: 1.5;
}
#notes-article th,
#notes-article td {
  border: 1px solid var(--hairline);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
#notes-article th { font-weight: 500; background: rgba(43, 35, 23, .07); }
#notes-article tbody tr:nth-child(even) td { background: rgba(43, 35, 23, .03); }
#notes-article td code { white-space: nowrap; }

/* Obsidian callouts */
#notes-article .callout {
  border-left: 3px solid var(--ink-soft);
  background: rgba(43, 35, 23, .05);
  padding: 12px 16px;
  margin: 0 0 16px;
}
#notes-article .callout-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 7px;
}
#notes-article .callout-body > :last-child { margin-bottom: 0; }
#notes-article .callout-body blockquote { margin-bottom: 8px; }
/* attention-grade callouts pick up the oxide accent */
#notes-article .callout-warning,
#notes-article .callout-caution,
#notes-article .callout-danger,
#notes-article .callout-error,
#notes-article .callout-important,
#notes-article .callout-bug { border-left-color: var(--oxide); }
#notes-article .callout-warning .callout-title,
#notes-article .callout-caution .callout-title,
#notes-article .callout-danger .callout-title,
#notes-article .callout-error .callout-title,
#notes-article .callout-important .callout-title,
#notes-article .callout-bug .callout-title { color: var(--oxide); }

/* KaTeX math — keep inline math from bloating the line height, let
   display math scroll instead of overflowing the panel */
#notes-article .katex { font-size: 1.04em; }
#notes-article .katex-display {
  margin: 12px 0;
  padding: 2px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ---------- grain ---------- */

#grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: .55;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- small screens ---------- */

@media (max-width: 860px) {
  /* stack the ribbon: name/role on top, links below — no fixed height,
     so there's no dead space and the name never gets squeezed into a wrap */
  #caption {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: auto;
    gap: 14px;
    padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
    align-items: start;
  }
  .cap-left h1 { font-size: 26px; }
  .cap-left .role { max-width: 34ch; }
  .cap-mid {
    grid-column: 1 / -1;
    border-left: none;
    padding-left: 0;
    font-size: 14.5px;
  }
  .cap-right {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 12px 22px;
    text-align: left;
  }
  .corner-tr { display: none; }
}
