/* =========================================================================
   As You Like It — Canadian School Shakespeare (Stevenson, annotated)
   Clean reading edition. Pure-CSS margin sidenotes (Tufte-style floats).
   No JavaScript, no external resources — opens straight from the filesystem.
   ========================================================================= */

:root {
  --paper:  #f7f3e9;   /* warm off-white, evoking the original page   */
  --ink:    #2b2620;   /* near-black warm text                        */
  --muted:  #9a9078;   /* line numbers, quiet UI                      */
  --rule:   #ddd3bf;   /* hairlines                                   */
  --note:   #5a5142;   /* sidenote text                               */
  --accent: #86622f;   /* headings / links                            */
  --callout:#efe8d5;   /* critical-comment background                 */
  --measure: 55rem;    /* overall reading container width             */
  --textcol: 70%;      /* share of container used by the text column  */
  /* A sidenote's %-widths resolve against ITS containing block — the .lines
     CONTENT box, i.e. the text column — not the whole container. So to span
     the reserved margin the ratio must be (100 - textcol) / textcol, not
     (100 - textcol). Keep this in step with --textcol.                     */
  --noteratio: 42%; /* = 43 / 57                                   */
  --notegap: 3rem;   /* breathing room between text and note        */
  --gutter: 1.5rem;    /* left line-number gutter                     */
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:  #1b1915;
    --ink:    #e7ddca;
    --muted:  #7f765f;
    --rule:   #38322a;
    --note:   #c2b8a0;
    --accent: #cda86a;
    --callout:#262119;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
               Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

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

/* ---- Top navigation bar ------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .35rem 1.1rem;
  padding: .55rem 1.15rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.topbar .brand {
  font-variant: small-caps;
  letter-spacing: .04em;
  font-size: 1.02rem;
  color: var(--ink);
  margin-right: .5rem;
}
.topbar nav { display: flex; flex-wrap: wrap; gap: .15rem .9rem; }
.topbar nav a {
  color: var(--note);
  font-size: .82rem;
  letter-spacing: .03em;
  text-transform: uppercase;
  padding: .1rem 0;
  border-bottom: 2px solid transparent;
}
.topbar nav a:hover { text-decoration: none; color: var(--ink); }
.topbar nav a.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

/* ---- Page shell -------------------------------------------------------- */
.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.4rem 1.4rem 5rem;
}
.chapter-title {
  font-variant: small-caps;
  letter-spacing: .06em;
  font-weight: 600;
  text-align: center;
  font-size: 1.9rem;
  margin: .4rem 0 2.2rem;
}
/* A stage direction standing under the chapter title */
.chapter-title.with-stage { margin-bottom: .9rem; }
.title-stage { margin: 0 0 2.4rem; }

/* ---- Scene ------------------------------------------------------------- */
.scene { margin: 0 0 3rem; }
.scene-head {
  text-align: center;
  font-weight: 600;
  font-size: 1.1rem;
  margin: 2.2rem 0 .3rem;
}
.scene-head .scene-no { font-variant: small-caps; letter-spacing: .05em; }
.scene-head .scene-loc { font-style: italic; font-weight: 400; }

/* Stage directions that stand on their own line (entrances / exits) */
.stage {
  text-align: center;
  font-style: italic;
  color: var(--note);
  margin: .8rem 0;
}
.stage.enter { font-variant: small-caps; font-style: italic; }

/* Critical comment that opens each scene's notes */
.critical {
  font-style: italic;
  color: var(--note);
  background: var(--callout);
  border-radius: 2px;
  padding: .7rem 1rem;
  margin: 1rem 0 1.6rem;
}
.critical p { margin: 0; }

/* ---- Lines container = float context for the sidenotes ----------------- */
.lines {
  padding-right: calc(100% - var(--textcol));  /* reserve the note margin */
  /* Contain the scene's own floated notes. Without this they escape the
     bottom of the scene and run into the next one — very visible on a narrow
     tall screen, where the notes need more height than the text. flow-root
     makes the box grow to enclose them without clipping or scrollbars, so a
     scene begins only once the previous scene's notes have finished. */
  display: flow-root;
}

/* Each printed line. Grid keeps a fixed gutter and lets wrapped text hang
   under the text column rather than under the number. */
.l {
  display: grid;
  grid-template-columns: var(--gutter) 1fr;
  column-gap: .4rem;
  scroll-margin-top: 4rem;
}
.l .ln {
  grid-column: 1;
  text-align: right;
  font-size: .68rem;
  line-height: inherit;
  color: var(--muted);
  padding-top: .18em;
  user-select: none;
  font-family: Georgia, serif;
}
.l .tx {
  grid-column: 2;
  /* hemistich / shared-verse indentation (set per line via --indent) */
  padding-left: var(--indent, 0);
}
/* A shared verse half-line: indented, and it shares the previous line's
   number (no gutter number of its own). */
.l.hemi .tx { padding-left: 11ch; }
.l .sp {           /* speaker prefix, e.g. Orl. */
  font-style: italic;
  font-variant: small-caps;
  letter-spacing: .02em;
}
.l .sd {           /* inline stage direction at line end, e.g. [Exit. */
  font-style: italic;
  color: var(--note);
}
.l .lem {          /* the annotated head-word, subtly marked in the text */
  border-bottom: 1px dotted var(--muted);
}

/* Verse vs. prose: verse gets a touch more air between lines */
.scene.verse .l, .l.verse { line-height: 1.5; }

/* ---- Sidenotes (float into the reserved right margin) ------------------ */
/* width + negative margin-right sum to <= 0 so the note occupies no space
   in the text column (text is never shortened); clear:right stacks them. */
.sidenote {
  float: right;
  clear: right;
  width: calc(var(--noteratio) - var(--notegap));
  margin-right: calc(-1 * var(--noteratio));
  margin-top: .1rem;
  margin-bottom: .55rem;
  font-size: .8rem;
  line-height: 1.4;
  color: var(--note);
  border-left: 2px solid var(--rule);
  padding-left: .7rem;
}
.sidenote .lem { font-weight: 600; color: var(--ink); font-style: normal; }
.sidenote .lref {
  font-size: .68rem;
  color: var(--muted);
  font-family: Georgia, serif;
  margin-right: .3rem;
}

/* ---- Prose chapter (the Introduction) ---------------------------------- */
.prose { max-width: 34rem; margin: 0 auto; }
.prose p { margin: 0 0 1.05rem; text-align: justify; hyphens: auto; }
.prose p + p { text-indent: 1.4em; }
.prose-head {
  font-variant: small-caps;
  letter-spacing: .05em;
  font-size: 1.12rem;
  font-weight: 600;
  text-align: center;
  margin: 2.4rem 0 1rem;
}
.prose .pline {           /* a run of these forms a block quotation */
  margin: 0;
  padding: .1rem 0 .1rem 1.1rem;
  border-left: 2px solid var(--rule);
  color: var(--note);
  font-style: italic;
}
.prose p + .pline { margin-top: 1.05rem; }
.prose .pline + p { margin-top: 1.05rem; }
.prose ul { margin: 0 0 1.05rem; padding-left: 1.3rem; }
.prose li { margin: .3rem 0; }
.prose .codeblock {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  line-height: 1.5;
  background: var(--callout);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .7rem .85rem;
  margin: 0 0 1.05rem;
  overflow-x: auto;       /* wide code scrolls itself, never the page */
  white-space: pre;
}
/* The prose column is wider on this chapter so code blocks breathe. */
.prose.wide { max-width: 42rem; }

/* ---- Cover / title page ------------------------------------------------ */
.cover { text-align: center; padding: 3rem 1rem 2rem; }
.cover .series { font-variant: small-caps; letter-spacing: .18em; color: var(--note);
  font-size: .8rem; border-bottom: 1px solid var(--rule); display: inline-block;
  padding-bottom: .3rem; margin-bottom: 2.4rem; }
.cover h1 { font-size: 3rem; letter-spacing: .04em; margin: .2rem 0; font-weight: 600; }
.cover .subtitle { font-size: 1.05rem; color: var(--note); font-style: italic; margin-top: .3rem; }
.cover .byline { margin-top: 2.4rem; color: var(--note); }
.cover .byline strong { color: var(--ink); font-weight: 600; }
.toc { max-width: 26rem; margin: 3rem auto 0; text-align: left; }
.toc h2 { font-variant: small-caps; letter-spacing: .06em; font-size: 1rem;
  border-bottom: 1px solid var(--rule); padding-bottom: .3rem; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li { display: flex; justify-content: space-between; padding: .35rem 0;
  border-bottom: 1px dotted var(--rule); }
.toc li .muted { color: var(--muted); font-size: .85rem; }

/* ---- Placeholder chapters --------------------------------------------- */
.placeholder { text-align: center; color: var(--note); padding: 4rem 1rem; }
.placeholder .tag { display: inline-block; font-variant: small-caps; letter-spacing: .1em;
  font-size: .75rem; color: var(--muted); border: 1px solid var(--rule);
  border-radius: 999px; padding: .2rem .8rem; margin-bottom: 1.2rem; }

.pagefoot { text-align: center; color: var(--muted); font-size: .75rem;
  padding: 2rem 1rem 3rem; border-top: 1px solid var(--rule); margin-top: 2rem; }

/* ---- Narrow screens: margin collapses, notes flow inline --------------- */
@media (max-width: 743px) {
  body { font-size: 17px; }
  .lines { padding-right: 0; }
  .critical { margin-right: 0; }
  .sidenote {
    float: none;
    clear: none;
    width: auto;
    margin: .25rem 0 .7rem var(--gutter);
    border-left: 2px solid var(--rule);
    background: transparent;
  }
}
@media (min-width: 744px) {
  .critical { margin-inline: calc(100% - var(--textcol) * 1.3); }
}

/* ---- Print: notes inline, chrome removed ------------------------------- */
@media print {
  .topbar, .pagefoot { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .lines { padding-right: 0; }
  .sidenote { float: none; width: auto; margin: .15rem 0 .5rem var(--gutter);
    color: #333; border-left: 1px solid #999; }
  .page { max-width: none; }
}
