/* The page around ratzilla's grid. Defaults to rat-dark (themes/rat-dark.toml) and
   rat-light (themes/rat-light.toml) under prefers-color-scheme: light so the first paint
   before wasm starts never flashes dark; once the app runs, Shell updates --mr-* on
   :root whenever the active theme changes (App::theme_rev). A file of its own, not a
   <style> element: the content security policy allows stylesheets only from the page's
   own origin. The grid itself is coloured by the app's theme, cell by cell. */

/* The bundled font (assets/fonts: DejaVu Sans Mono, its licence next to it). "block":
   the grid waits for it (src/dom.rs, fonts_loaded), so no other font is ever measured. */
@font-face {
  font-family: "MatrixRatMono";
  src: url("fonts/DejaVuSansMono.woff2") format("woff2");
  font-weight: normal;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: "MatrixRatMono";
  src: url("fonts/DejaVuSansMono-Bold.woff2") format("woff2");
  font-weight: bold;
  font-style: normal;
  font-display: block;
}

/* The bar's height: fixed for the whole session (ratzilla measures #term only when the
   window is resized, so nothing above it may change its height later). Taller where the
   pointer is a finger, so the Reload button can be tapped (below). */
:root {
  --bar-height: 20px;
  --mr-font-size: 15px;
  --mr-field-font-size: 16px;
  --mr-field-scale: 0.9375;
  --mr-field-inv-scale: 1.066667;
  --mr-wide-scale: 1;
  --mr-bg: #16161d;
  --mr-surface: #1f1f28;
  --mr-surface-high: #2a2a37;
  --mr-fg: #dcd7ba;
  --mr-muted: #727169;
  --mr-outline: #54546d;
  --mr-primary: #7fb4ca;
  --mr-on-primary: #16161d;
  --mr-accent: #e6c384;
}
@media (prefers-color-scheme: light) {
  :root {
    --mr-bg: #f4f1ea;
    --mr-surface: #e9e5da;
    --mr-surface-high: #dcd6c6;
    --mr-fg: #000000;
    --mr-muted: #6b665b;
    --mr-outline: #c4bdab;
    --mr-primary: #24476b;
    --mr-on-primary: #f4f1ea;
    --mr-accent: #7d5f0e;
  }
}
html {
  height: 100%;
  background: var(--mr-bg);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
/* The bar on top, the grid in the middle, and step 15's text field below it when
   `mr.text_field=always` (on phones by default `#field` is an invisible overlay over the
   focused text cells and the key bar draws inside the grid). Fixed to the visual viewport
   (--vv-width, --vv-height, --vv-top, --vv-left) at normal scale so opening a phone's soft
   keyboard shrinks the grid and keeps the composer and key bar in sight; while pinch-zoomed
   the properties are dropped and body keeps its full layout size (docs/WEB-PHASE-2.md §3). */
body {
  position: fixed;
  left: var(--vv-left, 0px);
  top: var(--vv-top, 0px);
  width: var(--vv-width, 100%);
  height: var(--vv-height, 100dvh);
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--mr-bg);
  color: var(--mr-fg);
  /* Emoji and CJK, which DejaVu Sans Mono lacks, come from the system's fonts. */
  font-family: "MatrixRatMono", monospace;
  font-size: var(--mr-font-size);
}
/* A fixed height: ratzilla measures #term only when the window is resized, so nothing
   above it may change its height later. */
#bar {
  flex: none;
  display: flex;
  gap: 12px;
  align-items: center;
  box-sizing: border-box;
  height: var(--bar-height);
  padding: 0 8px;
  overflow: hidden;
  white-space: nowrap;
  font-size: 12px;
  line-height: var(--bar-height);
  color: var(--mr-muted);
  background: var(--mr-surface);
}
#bar[hidden] {
  display: none;
}
/* The version and the note give way (cut short) before the update prompt does. */
#bar-version,
#bar-note {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
#bar-note {
  color: var(--mr-accent);
}
/* No note: no gap for it either. */
#bar-note:empty {
  display: none;
}
#bar-update {
  flex: none;
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  color: var(--mr-fg);
}
#bar-update[hidden],
#bar-reload[hidden] {
  display: none;
}
#bar-reload {
  box-sizing: border-box;
  height: 16px;
  margin: 0;
  padding: 0 8px;
  border: 1px solid var(--mr-primary);
  border-radius: 3px;
  font: inherit;
  line-height: 14px;
  color: var(--mr-primary);
  background: transparent;
  cursor: pointer;
}
#bar-reload:hover,
#bar-reload:focus-visible {
  color: var(--mr-on-primary);
  background: var(--mr-primary);
  outline: none;
}
/* A finger: 16 px is hard to hit at the top edge of a phone, under its status bar. */
@media (pointer: coarse) {
  :root {
    --bar-height: 32px;
  }
  #bar-reload {
    height: 28px;
    padding: 0 12px;
    line-height: 26px;
  }
}
/* Wrapper pairing ratzilla's grid (#term) with the browser avatar canvas layer (#avatars)
   so ratzilla owns #term exclusively while #avatars stays pixel-aligned over it through
   resizes, key-bar/field toggles, and visual-viewport changes. */
#term-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
/* ratzilla's grid: one <pre> per row, one <span> per cell. */
#term {
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: default;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#term.mr-page-zoomed {
  touch-action: pinch-zoom;
}
/* Browser picture avatars and real pictures over ratzilla's grid tiles (one <canvas> per
   active placement). Pointer events pass straight through to #term; sits above wide
   cells (z-index: 1) and below #overlay (z-index: 10). */
#avatars {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
#avatars canvas.mr-avatar,
#avatars canvas.mr-picture {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: calc(var(--mr-cell-w, 1ch) * var(--mr-av-w, 2));
  height: calc(var(--mr-cell-h, 1.2em) * var(--mr-av-h, 1));
  transform: translate(
    calc(var(--mr-cell-w, 1ch) * var(--mr-av-x, 0)),
    calc(var(--mr-cell-h, 1.2em) * var(--mr-av-y, 0))
  );
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}
#avatars canvas.mr-avatar {
  object-fit: cover;
}
#avatars canvas.mr-avatar-user {
  border-radius: 50%;
}
#avatars canvas.mr-avatar-room {
  border-radius: 22%;
}
/* Vertically clipped 2-line room preview avatars: keep the visible outer corners rounded
   and cut the scrolled-out edge flat. */
#avatars canvas.mr-avatar-user.mr-avatar-clip-bottom {
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
}
#avatars canvas.mr-avatar-room.mr-avatar-clip-bottom {
  border-radius: 22% 22% 0 0 / 44% 44% 0 0;
}
#avatars canvas.mr-avatar-user.mr-avatar-clip-top {
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
#avatars canvas.mr-avatar-room.mr-avatar-clip-top {
  border-radius: 0 0 22% 22% / 0 0 44% 44%;
}
#avatars canvas.mr-avatar.mr-avatar-clip-both {
  border-radius: 0;
}
#term pre {
  margin: 0;
  font: inherit;
}
/* Hidden probe used once after fonts load (and on resize) to measure fallback emoji
   metrics against two cells of MatrixRatMono without inline styles (CSP). */
#term .mr-probe {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  line-height: normal;
  white-space: nowrap;
}
/* Lock every cell in ratzilla's DOM grid to exact pixel column/row geometry so fallback
   glyphs (Apple Color Emoji on iOS, Noto on Android, Braille spinners missing from our
   DejaVu subset, and width-1 pictographs like 🖼 U+1F5BC) never shift columns or rows. */
#term_ratzilla_grid pre {
  white-space: nowrap;
  height: var(--mr-cell-h) !important;
  line-height: var(--mr-cell-h, normal);
  overflow: clip;
  contain: layout paint style;
}
#term_ratzilla_grid pre > span {
  display: inline-block !important;
  width: var(--mr-cell-w, 1ch) !important;
  height: var(--mr-cell-h, 100%);
  line-height: var(--mr-cell-h, normal);
  vertical-align: top;
  box-sizing: border-box;
  overflow: clip;
}
/* A width-2 cell (or width-1 pictograph like 🖼 followed by a space) draws centred over
   column x and its follower column x+1 while keeping every span's left edge locked at
   column * --mr-cell-w. Scaled down via --mr-wide-scale when the device's emoji font is
   wider or taller than two MatrixRatMono cells; its own background covers both cells so
   selected/reversed rows have no hole. */
#term_ratzilla_grid pre > span.mr-wide {
  position: relative;
  z-index: 1;
  width: calc(var(--mr-cell-w, 1ch) * 2) !important;
  margin-right: calc(var(--mr-cell-w, 1ch) * -1);
  text-align: center;
  font-size: calc(var(--mr-font-size, 15px) * var(--mr-wide-scale, 1));
}
#term_ratzilla_grid pre > span.mr-wide-tail {
  background-color: transparent !important;
}
/* Visible text cursor in ratzilla's DOM grid (follows ratatui's Frame::set_cursor_position).
   Uses a CSS class rather than inline styles (CSP), themed with --mr-fg / --mr-bg so it
   stays crisp on empty spaces and characters in every dark and light theme. */
#term span.mr-cursor {
  background-color: var(--mr-fg) !important;
  color: var(--mr-bg) !important;
  border-radius: 1px;
}
/* Visible 52 px native text field and Send button below #term (step 15; shown when
   mr.text_field=always for desktop IME users / fallback). Font size is 16 px so iOS
   Safari never auto-zooms on focus. */
#field {
  flex: none;
  display: flex;
  gap: 8px;
  align-items: center;
  box-sizing: border-box;
  height: 52px;
  padding: 4px 8px;
  background: var(--mr-surface);
  border-top: 1px solid var(--mr-surface-high);
}
/* Phone default (Task 129): invisible native <textarea> / <input> placed right over the
   focused text cells (--mr-field-*) so iOS/Android soft keyboards, autocorrect, dictation,
   IME, and native Paste callouts land in the right spot while text and cursor draw in the
   grid. Takes 0 px of flex layout height; pointer-events stay none until focused so taps
   on "3 Message" hit #term and open the keyboard synchronously. */
#field.mr-field-overlay {
  position: absolute;
  left: var(--mr-field-left, 0px);
  top: var(--mr-field-top, 0px);
  width: var(--mr-field-width, 1px);
  height: var(--mr-field-height, 1px);
  z-index: 3;
  display: block;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  /* Full opacity: background, color, caret-color, and ::selection stay transparent so the
     overlay remains invisible, while opacity: 1 lets iOS WebKit render native
     Copy/Cut/Paste callouts and selection handles at full opacity instead of 1%. */
  opacity: 1;
  pointer-events: none;
  overflow: hidden;
}
/* Focused composer and secret overlays keep `pointer-events: auto` so iOS Safari shows
   its native long-press Paste callout inside them (for secret fields, tapping inside a
   long horizontally scrolled secret therefore follows the native input's own scroll
   rather than the engine's `…` view; accepted so native iOS Paste remains available).
   One-line plain fields (`.mr-field-line`) keep `pointer-events: none` even when focused
   so taps go through `#term` -> `LineEdit::place()` -> `setSelectionRange` (matching the
   engine's horizontal `scroll_col` and leading `…` column); paste in those fields comes
   from the key bar's Paste key and hardware Ctrl-V still works via DOM focus. */
#field.mr-field-overlay.mr-field-focused:not(.mr-field-line) {
  pointer-events: auto;
}
#field.mr-field-overlay #field-text::placeholder,
#field.mr-field-overlay #field-secret::placeholder {
  color: transparent;
  opacity: 0;
}
#field.mr-field-overlay #field-text::selection,
#field.mr-field-overlay #field-secret::selection {
  color: transparent;
  background: transparent;
}
#field.mr-field-overlay #field-text::spelling-error,
#field.mr-field-overlay #field-text::grammar-error {
  text-decoration: none;
}
#field.mr-field-overlay #field-text,
#field.mr-field-overlay #field-secret {
  display: block;
  box-sizing: border-box;
  /* Keep computed font-size >= 16px against iOS Safari auto-zoom, while scaling to match
     --mr-font-size horizontal advance and line height. Add < 0.5 cell slack so exact
     N-char lines never wrap prematurely from Blink's caret margin while N+1 still wraps. */
  width: calc((100% + var(--mr-cell-w, 9px) * 0.35) * var(--mr-field-inv-scale, 1.066667));
  height: calc(100% * var(--mr-field-inv-scale, 1.066667));
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-family: "MatrixRatMono", monospace;
  font-size: var(--mr-field-font-size, 16px);
  line-height: calc(var(--mr-cell-h, 18px) * var(--mr-field-inv-scale, 1.066667));
  transform: scale(var(--mr-field-scale, 0.9375));
  transform-origin: top left;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow: hidden;
  outline: none;
  -webkit-touch-callout: default;
}
/* Single-line fields stay on one horizontally scrolling row inside the invisible overlay
   so tapping the right side never snaps the caret onto a wrapped line 1 boundary. */
#field.mr-field-overlay.mr-field-line #field-text {
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  overflow-y: hidden;
}
#field.mr-field-overlay #field-send {
  display: none;
}
#field[hidden],
#field-text[hidden],
#field-secret[hidden] {
  display: none;
}
#field-text,
#field-secret {
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  height: 44px;
  margin: 0;
  /* 16 px or more: iOS Safari zooms the page when focusing smaller fields. */
  font-family: inherit;
  font-size: 16px;
  line-height: 22px;
  color: var(--mr-fg);
  background: var(--mr-bg);
  border: 1px solid var(--mr-outline);
  border-radius: 4px;
  -webkit-appearance: none;
  appearance: none;
  -webkit-user-select: text;
  user-select: text;
}
#field-text::placeholder,
#field-secret::placeholder {
  color: var(--mr-muted);
  opacity: 1;
}
#field-text {
  padding: 10px 8px;
  resize: none;
  overflow-x: hidden;
  overflow-y: auto;
}
#field-secret {
  padding: 0 8px;
}
#field-text:focus,
#field-secret:focus {
  border-color: var(--mr-primary);
  outline: none;
}
#field-text:disabled,
#field-secret:disabled {
  color: var(--mr-muted);
  border-color: var(--mr-surface-high);
  opacity: 0.7;
}
#field-send {
  flex: none;
  box-sizing: border-box;
  height: 44px;
  min-width: 56px;
  margin: 0;
  padding: 0 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  white-space: nowrap;
  color: var(--mr-on-primary);
  background: var(--mr-primary);
  border: 0;
  border-radius: 4px;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#field-send:disabled {
  color: var(--mr-muted);
  background: var(--mr-surface-high);
  cursor: default;
}
#file-picker {
  display: none;
}
/* Over the page under the bar (which keeps saying the version and update prompt) when the
   app cannot go on, or does not start. Absolute inside the fixed body (above #term and
   #field) so it follows --bar-height and the visual viewport and never lets #field
   bleed through. */
#overlay {
  position: absolute;
  inset: var(--bar-height) 0 0 0;
  z-index: 10;
  box-sizing: border-box;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: color-mix(in srgb, var(--mr-bg) 94%, transparent);
}
#overlay[hidden] {
  display: none;
}
#overlay a {
  color: var(--mr-primary);
}
#overlay button {
  font: inherit;
  color: var(--mr-on-primary);
  background: var(--mr-primary);
  border: 0;
  padding: 6px 16px;
  cursor: pointer;
}
#overlay button[hidden] {
  display: none;
}
.noscript {
  padding: 16px;
}
