/* Cryptogram. */

.cg { container-type: inline-size; padding: 0.5rem 0 1rem; }

/* The text is set in words that stay whole. --w is the width of one letter: as wide as the
   screen allows, never under 24px (a fixed size, so that larger text cannot push a twelve-letter
   word off a narrow phone), and never so wide that a line holds too few. */
.cg-text {
  --w: clamp(24px, 7.6cqw, 1.875rem);
  --gh: calc(var(--w) * 1.2);
  display: flex; flex-wrap: wrap; gap: 0.625rem calc(var(--w) * 0.7);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
/* only a word wider than the whole line is ever broken */
.cg-word { display: flex; flex-wrap: wrap; row-gap: 0.625rem; max-width: 100%; }

/* one letter: the visitor's letter on a blank, the coded letter under it */
.cg-l {
  position: relative; width: var(--w); padding: 0; border: 0; border-radius: 4px; background: none; cursor: pointer;
  display: grid; grid-template-rows: var(--gh) auto; justify-items: center; color: var(--c);
  scroll-margin: 5rem 0 13rem;   /* when it is brought into view it clears the key pad at the foot of the screen */
  -webkit-tap-highlight-color: transparent;
}
.cg-g {
  position: relative; width: 100%; height: var(--gh); display: grid; place-items: center; border-radius: 4px 4px 0 0;
  font: 600 calc(var(--w) * 0.8)/1 var(--sans);
}
/* the blank: a rule that stops short of its neighbours, so each letter has its own */
.cg-g::after { content: ""; position: absolute; left: 2px; right: 2px; bottom: 0; border-bottom: 2px solid var(--ink); }
.cg-c { padding: 0.3125rem 0 0.125rem; color: var(--stone); font: 500 max(15px, calc(var(--w) * 0.56))/1 var(--sans); }
.cg-c::before { content: attr(data-c); }   /* drawn from data: the cell's visible text is the visitor's letter alone */
.cg-l:focus-visible { outline: 3px solid var(--ink); outline-offset: 1px; z-index: 1; }

/* punctuation stands on the line of the blanks, unchanged */
.cg-p {
  min-width: calc(var(--w) * 0.4); height: var(--gh); display: grid; place-items: end center;
  color: var(--ink); font: 600 calc(var(--w) * 0.8)/1 var(--sans);
}

/* letters that came with the puzzle or from a hint are in ink on a lighter rule: they are fixed */
.cg-l.given .cg-g, .cg-l.hinted .cg-g { color: var(--ink); font-weight: 700; }
.cg-l.given .cg-g::after { border-bottom-color: var(--rule); }
.cg-l.hinted .cg-g::after { border-bottom: 2px dotted var(--stone); }

/* every copy of the chosen coded letter, and the one the cursor is on */
.cg-l.same .cg-g { background: color-mix(in srgb, var(--c) 16%, transparent); }
.cg-l.sel .cg-g { background: color-mix(in srgb, var(--c) 30%, transparent); box-shadow: inset 0 0 0 2px var(--c); }

/* a clash is marked with a dot as well as by colour */
.cg-l.clash .cg-g { color: #A3261D; }
.cg-l.clash::after {
  content: ""; position: absolute; top: 1px; right: 1px; width: 7px; height: 7px; border-radius: 50%; background: #A3261D;
}

/* The letter keys stay at the foot of the screen while a long text scrolls behind them. */
.cg-pad {
  position: sticky; bottom: 0; z-index: 2; padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--paper); border-top: 1px solid var(--hair);
}
/* the pad sits inside the board's own gutters, so its keys line up with the text's edges */
.cg-pad .keys { padding-left: 0; padding-right: 0; }
/* however large the text is set, three rows of keys must leave room for the text above them */
.cg-pad .key { min-height: min(2.75rem, 56px); }

/* Where the system sets the colours, tints are dropped: the chosen letter and a clash keep a sign. */
@media (forced-colors: active) {
  .cg-l.sel .cg-g { outline: 3px solid Highlight; outline-offset: -3px; }
  .cg-l.same .cg-g { outline: 1px solid Highlight; outline-offset: -1px; }
  .cg-l.clash::after { background: Highlight; }
}

/* the answers page: the text as it was written, who said it, and the code */
.cg-answer { margin: 1rem 0 1.5rem; padding: 0.875rem 1rem; border-left: 3px solid var(--c); background: var(--sheet); }
.cg-answer blockquote { margin: 0; }
.cg-answer blockquote p { font: 400 1.25rem/1.4 var(--serif); }
.cg-answer figcaption { margin-top: 0.5rem; color: var(--stone); font: 400 1.0625rem/1.4 var(--sans); }
.cg-key-note { color: var(--stone); font-size: 0.9375rem; }
.cg-key { width: 100%; max-width: 26rem; margin: 0.75rem 0 1rem; border-collapse: collapse; table-layout: fixed; background: var(--sheet); border: 1px solid var(--rule); }
.cg-key th[scope="row"] { width: 0; padding: 0; border: 0; }
/* the coded letters head the columns, so a screen reader names each one with the letter under it */
.cg-key th[scope="col"], .cg-key td { height: 2rem; padding: 0; border: 1px solid var(--rule); text-align: center; color: var(--stone); font: 500 0.9375rem/1 var(--sans); }
.cg-key td { color: var(--c); font-size: 1.0625rem; }
.cg-key b { font-weight: 700; }


/* While the board loads, what follows it waits and comes in with the drawn board (game.css keeps
   the caption's line). This board's size changes with the day's puzzle (the length of its text), so no room kept
   for it would hold. Only where scripts run: without them the page shows as it is, and a script
   that cannot be fetched turns the line into a notice, which lets the page show. */
@media (scripting: enabled) {
  #main:has(> #board > .loading) > #board ~ *,
  .wrap:has(#board > .loading) > .foot { display: none; }
}
