/* MemoToMIDI — shared site styles.
   Palette follows the app's "Paper Instrument" redesign (AppVisualStyle.swift):
   warm cream/ink grounds, structure drawn in ink/paper alpha, and the default
   Violet accent (light 0x4E4763, dark 0xA49CB6) — the brand default of the
   jewel-tone palette — used sparingly as the one chromatic element. Light/dark
   follow the system. No trackers. */

:root {
  color-scheme: light dark;
  --bg: #efe7d6;            /* screenBackground — cream paper */
  --text: #221c15;          /* ink */
  --muted: rgba(34, 28, 21, 0.62);
  --link: #4E4763;          /* violet accent (light) — jewel-tone default */
  --accent: #4E4763;
  --accent-deep: #3b3550;
  --cta-bg: #4E4763;
  --cta-bg-hover: #3b3550;
  --cta-text: #ffffff;
  --border: rgba(34, 28, 21, 0.12);        /* outline = ink alpha */
  --surface: #f6f0e2;       /* groupedSurface (sidebar hover, zebra) */
  --callout-bg: #faf5e9;    /* raisedSurface — paper card */
  --table-head: #faf5e9;
  --code-bg: rgba(34, 28, 21, 0.07);
  --eyebrow: #6e6250;       /* accentMuted — mono micro-labels */
  --header-bg: rgba(239, 231, 214, 0.85);
  --shadow: rgba(0, 0, 0, 0.09);
  --measure: 720px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1712;          /* screenBackground — warm ink */
    --text: #ebe3d2;        /* paper */
    --muted: rgba(235, 227, 210, 0.60);
    --link: #A49CB6;        /* violet accent (dark) — jewel-tone default */
    --accent: #A49CB6;
    --accent-deep: #b8b0c8;
    --cta-bg: #A49CB6;
    --cta-bg-hover: #b8b0c8;
    --cta-text: #1a1712;
    --border: rgba(235, 227, 210, 0.10);
    --surface: #241f17;     /* groupedSurface */
    --callout-bg: #2a241b;  /* raisedSurface */
    --table-head: #2a241b;
    --code-bg: rgba(235, 227, 210, 0.08);
    --eyebrow: #a89a82;
    --header-bg: rgba(26, 23, 18, 0.75);
    --shadow: rgba(0, 0, 0, 0.30);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* In body copy the violet accent stays close to ink, so content links keep a
   quiet underline for affordance. */
.content a {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 2px;
}
.content a:hover { text-decoration-color: var(--accent); }

/* ---- Header ---------------------------------------------------------------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  color: var(--text);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}
.wordmark:hover { text-decoration: none; }
.wordmark-mark { display: block; border-radius: 6px; }

/* ---- Layout ---------------------------------------------------------------- */
.layout {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem 1.25rem 3.5rem;
}
@media (min-width: 980px) {
  .has-toc .layout {
    max-width: 1040px;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 2.75rem;
    align-items: start;
  }
}
.content { max-width: var(--measure); }

/* ---- Sidebar TOC (desktop only) ------------------------------------------- */
.toc-sidebar { display: none; }
@media (min-width: 980px) {
  .toc-sidebar {
    display: block;
    position: sticky;
    top: 4.25rem;
    align-self: start;
    max-height: calc(100vh - 5.5rem);
    overflow-y: auto;
    font-size: 0.92rem;
  }
}
.toc-title {
  margin: 0 0 0.6rem;
  color: var(--eyebrow);
  font: 600 0.68rem/1.4 var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.11em;
}
.toc-sidebar ul { margin: 0; padding: 0; list-style: none; }
.toc-sidebar a {
  display: block;
  padding: 0.28rem 0.55rem;
  margin: 0.05rem 0;
  color: var(--text);
  border-left: 2px solid transparent;
  border-radius: 0 7px 7px 0;
}
.toc-sidebar a:hover {
  background: var(--surface);
  border-left-color: var(--accent);
  color: var(--accent-deep);
  text-decoration: none;
}

/* ---- Inline TOC (mobile only) --------------------------------------------- */
.toc-inline {
  margin: 1.5rem 0 2.5rem;
  padding: 1rem 1.25rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.toc-inline ul { margin: 0; padding: 0; list-style: none; }
.toc-inline li { margin: 0.4rem 0; }
.toc-inline a { color: var(--text); }
.toc-inline a:hover { color: var(--accent-deep); }
@media (min-width: 980px) { .toc-inline { display: none; } }

/* ---- Content typography ---------------------------------------------------- */
.content h1 {
  margin: 0.4rem 0 1rem;
  font-size: 2rem;
  line-height: 1.15;
  letter-spacing: -0.015em;
}
.content h2 {
  margin: 2.75rem 0 0.85rem;
  font-size: 1.5rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
  scroll-margin-top: 4.75rem;
}
.content h3 {
  margin: 1.9rem 0 0.55rem;
  font-size: 1.18rem;
  line-height: 1.25;
  scroll-margin-top: 4.75rem;
}
.content p { margin: 0.95rem 0; }
.content ul, .content ol { margin: 0.7rem 0; padding-left: 1.4rem; }
.content li { margin: 0.35rem 0; }
.content li > ul, .content li > ol { margin: 0.3rem 0; }
.content strong { font-weight: 600; }
.content em { font-style: italic; }
.content hr { margin: 2.5rem 0; border: none; border-top: 1px solid var(--border); }
.content img { max-width: 100%; height: auto; }
.content > p:first-of-type em { color: var(--muted); }

/* ---- Figures (app screenshots) -------------------------------------------- */
.content figure.shot {
  margin: 1.9rem 0;
  text-align: center;
}
.content figure.shot img {
  width: 100%;
  max-width: 340px;
  border-radius: 24px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px var(--shadow);
}
.content figure.shot--wide img {
  max-width: 580px;
  border-radius: 12px;
}
.content figure.shot figcaption {
  margin: 0.65rem auto 0;
  max-width: 32rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.45;
}

/* Hover-reveal heading anchors */
.header-anchor {
  margin-left: 0.4em;
  color: var(--muted);
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.content h2:hover .header-anchor,
.content h3:hover .header-anchor { opacity: 0.5; }
.header-anchor:hover { opacity: 1; color: var(--accent-deep); text-decoration: none; }
@media (hover: none) { .header-anchor { display: none; } }

/* ---- Callouts (blockquotes) ------------------------------------------------ */
.content blockquote {
  margin: 1.4rem 0;
  padding: 0.85rem 1.1rem;
  background: var(--callout-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 0 10px 10px 0;
}
.content blockquote :first-child { margin-top: 0; }
.content blockquote :last-child { margin-bottom: 0; }

/* ---- Tables ---------------------------------------------------------------- */
.table-wrap {
  margin: 1.4rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}
.content table {
  width: 100%;
  min-width: 30rem;
  border-collapse: collapse;
  font-size: 0.96rem;
}
.content th, .content td {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.content thead th { background: var(--table-head); font-weight: 600; }
.content tbody tr:nth-child(even) { background: var(--surface); }

/* ---- Inline code ----------------------------------------------------------- */
.content code {
  padding: 0.12em 0.38em;
  background: var(--code-bg);
  border-radius: 5px;
  font: 0.88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---- Report page: CTA + note ---------------------------------------------- */
.cta {
  display: inline-block;
  margin: 1.75rem 0 0.5rem;
  padding: 0.85rem 1.5rem;
  background: var(--cta-bg);
  color: var(--cta-text);
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 10px;
  box-shadow: 0 3px 10px var(--shadow);
}
.cta:hover { background: var(--cta-bg-hover); text-decoration: none; }
.note { margin-top: 2rem; color: var(--muted); font-size: 0.95rem; }
.updated { margin: -0.3rem 0 1.8rem; color: var(--muted); font-size: 0.95rem; }

/* ---- Footer ---------------------------------------------------------------- */
.site-footer { margin-top: 3rem; border-top: 1px solid var(--border); }
.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.75rem;
  font-size: 0.92rem;
}
.footer-nav a { color: var(--muted); }
.footer-nav a:hover { color: var(--link); }

/* ---- Back to top ----------------------------------------------------------- */
.back-to-top {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--header-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.back-to-top[hidden] { display: none; }
.back-to-top:hover { color: var(--accent-deep); border-color: var(--accent); }
