Kayros is a small CSS library from the Aegis Framework, the same family as the libraries the engine is built on. Monogatari 2 bundles a copy of it inside engine/core/monogatari.css, ahead of its own rules, so every game has it without loading anything. It does two things: it evens out how browsers draw plain elements, and it adds helper classes you can put on your own HTML.

The copy in the engine is frozen: it no longer follows the Kayros library’s own releases, and what this page describes is what the engine ships.

What it does to every page

These rules apply to every game, before the engine’s and yours. They explain a few things you’ll notice when you write your own HTML:

Elements What Kayros does
Everything Sizes include the padding and border (box-sizing: border-box), so a width: 50% box with padding stays 50% wide.
html, body Full height and width, no margin, no sideways scrolling.
Headings No margins; h1 to h6 get sizes from 2em down to 1em. The engine then sets h1 and h2 to 3rem and h3 to 2rem.
Links No underline and the color of the text around them. Messages give theirs a color of their own (see CSS Variables).
Images Never wider than their container, and they can’t be selected or dragged.
Buttons, inputs, selects The browser’s own look is removed: no border, no outline, the page’s font. A light grey background (#f5f5f5), rounded corners and some padding. The engine then gives buttons the --main-color background and a fixed size.
Sliders (input[type=range]) The browser’s own look is removed; the track is half transparent black.
Tables Collapsed borders, every cell with a thin dark border and some padding.
Scrollbars Thin (5 pixels) with a translucent thumb, in Chromium-based browsers.
Selected text A light cyan highlight.
pre, code A monospace font, a light grey background for pre, and colors for highlighted code.

NOTE

Kayros removes the browser's focus outline from buttons and fields. The engine draws its own frame on a focused button instead (4px solid #222). If you restyle buttons, keep a visible :focus style so players who use the keyboard can see where they are.

Helper classes

Put these in the class attribute of your own HTML: in the body of a message, in dialog, or in a component you write.

Layout

Class What it does
horizontal Lays the children out in a row (display: flex). The engine also centers them vertically.
vertical Lays the children out in a column (display: flex; flex-direction: column).
horizontal--left, horizontal--center, horizontal--right With horizontal: puts the children at the start, the middle or the end of the row. horizontal--center also centers them vertically.
vertical--left, vertical--center, vertical--right With vertical: lines the children up on the left, the middle or the right of the column.

Position

Class What it does
middle Puts the element in the middle of its container, both ways (it becomes position: absolute).
bottom Puts the element at the bottom of its container (position: absolute, no margin).
center Centers the element horizontally with automatic side margins. It needs a width smaller than its container.
left, right Only set left: 0 or right: 0. They move the element only if it’s also positioned, for example with bottom.

On the game screen, left, center and right are also the positions of sprites and images, and the engine’s game screen rules place those differently (see CSS Classes).

Text

Class What it does
text--left, text--center, text--right, text--justify Aligns the text inside the element.

Spacing

Class What it does
padded 1rem of padding on every side.
padded-2, padded-3, padded-4, padded-5 2rem to 5rem of padding.
margin-2, margin-3, margin-4, margin-5 2rem to 5rem of margin.
margin 1rem of margin on every side. Before 2.9.0 it gave 1px, because its rule had no unit.

Cards and other

Class What it does
card A thin, light border.
card--depth--2 to card--depth--6 A shadow under the element, deeper as the number grows.
separator--material A light grey line, for an <hr>.
link--button Makes a link look like a light grey button.
unselectable The player can’t select the element’s text.
clearfix Makes an element contain its floating children.

The engine’s own helpers (block, wait, modal and others) are on the CSS Classes page.

An example

A message whose body uses a row of cards and right-aligned text:

monogatari.action('message').messages({
  'Letter': {
    title: 'A note in the sketchbook',
    body: `
      <div class="horizontal horizontal--center">
        <p class="card card--depth--2 padded">Meet me by the lamps.</p>
        <p class="card card--depth--2 padded">Come alone.</p>
      </div>
      <p class="text--right">Mio</p>
    `,
  },
});

Show it with 'show message Letter' in the script.

A white message box titled "A note in the sketchbook", with two bordered cards side by side and "Mio" aligned to the right
The message with Kayros classes