/* Worldrig's own window (shell/window/): what every page gets before the app's own
   styles. The inherited shell's stylesheet is not loaded there, so the names of it the app's
   styles still use (fonts, sizes, layers, link lines, the named colours) get Worldrig's values
   here, and the page itself its base look. Only the own window loads this file. */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  /* Type: Worldrig's fonts (base-theme.css) under the shell's names. */
  --font-interface: var(--font-interface-theme, var(--font-sans));
  --font-text: var(--font-text-theme, var(--font-sans));
  --font-monospace: var(--font-monospace-theme, var(--font-mono));
  --font-text-size: 16px;
  /* The kit's writing (src/styles/prose.css) at the text size Settings → Appearance sets. */
  --wl-reading-size: var(--font-text-size);
  --font-ui-medium: 15px;
  --font-ui-small: 13px;
  --font-ui-smaller: 12px;
  --line-height-tight: 1.3;
  --line-height-normal: 1.5;
  /* Spacing on a 4px step, and the page title's height. */
  --size-2-1: 2px; --size-2-2: 4px; --size-2-3: 6px;
  --size-4-1: 4px; --size-4-2: 8px; --size-4-3: 12px; --size-4-4: 16px; --size-4-6: 24px; --size-4-8: 32px;
  --header-height: 40px;
  --radius-s: 4px; --radius-m: 8px;
  /* Layers: dialogs, then menus, then tooltips. */
  --layer-modal: 50; --layer-menu: 65; --layer-tooltip: 70;
  /* Links are underlined. */
  --link-decoration: underline; --link-decoration-hover: underline;
  --link-external-decoration: underline; --link-external-decoration-hover: underline;
  /* The named colours some pages use for tags and marks are tokens (theme-overrides.css). */

  overflow: hidden;
  font-family: var(--font-interface);
  font-size: var(--font-ui-medium);
  line-height: var(--line-height-tight);
  text-rendering: optimizeLegibility;
  background-color: var(--background-primary, var(--wl-bg));
  color: var(--text-normal, var(--wl-text));
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Text people type or read keeps being selectable, and follows the Appearance font size. */
input, textarea, [contenteditable="true"], .wl-prose, .markdown-rendered { user-select: text; -webkit-user-select: text; }
.wt-document-reader, .wt-document-input, .wt-source, .wb-home-intro, .wl-turn-story, .wl-prose { font-size: var(--wl-reading-size, 16px); }
:where(button, select, textarea) { font: inherit; color: inherit; }
a { color: var(--link-color, var(--wl-accent)); text-decoration-line: var(--link-decoration); }
img { max-width: 100%; }

/* Thin scroll bars that show only on the part being scrolled. */
::-webkit-scrollbar { width: 10px; height: 10px; background: transparent; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 10px; background-clip: padding-box; background-color: color-mix(in srgb, var(--wl-text-2, currentColor) 28%, transparent); }
::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--wl-text-2, currentColor) 45%, transparent); }
::-webkit-scrollbar-corner { background: transparent; }

/* The workspace fills the window; the project bar is the window's title bar. */
.wl-own-container { position: fixed; inset: 0; overflow: hidden; }
/* The kit draws its own parts (tabs, rail, panels) at its UI size; what the features draw in it
   (the project bar, the pages' content, a feature's own column such as Boris) keeps the body's size, which they were made for, unless
   a feature sets its own (the Search panel's smaller type). */
:where(body.wl-own) :where(.wl-workspace-top, .wl-page-content, .wl-workspace-body > :not(.wl-rail, .wl-side-panel, .wl-main)) { font-size: var(--font-ui-medium); line-height: var(--line-height-tight); }
/* The features' pages get the base margin around their content (two classes' weight, which the
   features' own page rules were written to override); the kit's own pages draw their own. */
.wl-page:where(:not([data-type="file-explorer"], [data-type="bookmarks"], [data-type="empty"], [data-type="canvas"], [data-type="image"], [data-type="markdown"], [data-type="settings"])) > .wl-page-content { padding: 12px 12px 32px; }

/* ---- Controls --------------------------------------------------------------------------------
   The plain look of the controls the features draw: buttons, icon buttons, dropdowns, fields,
   checkboxes, switches and sliders. :where() keeps every rule here below a feature's own, so a
   feature restyles a control as before. Colours come from Worldrig's theme (base-theme.css) and
   Midnight Prism's tokens (tokens.css): a dark control with a quiet line, brighter under the pointer,
   the control radius, and the 2px ice ring for the keyboard. */
:where(body.wl-own) {
  --wl-control-height: 30px;
  --wl-control-ease: var(--wl-ease);
  /* The control's edge is a hairline drawn inside it, so a feature that takes the shadow away takes the edge too. */
  --wl-control-shadow: inset 0 0 0 1px var(--wl-line);
  --wl-control-shadow-hover: inset 0 0 0 1px var(--wl-line-strong);
  --wl-focus-outline: 2px solid var(--wl-selection);
}
/* Buttons. Their size, padding and type yield to any feature rule; their shadow weighs one class
   and one element, as in the base the features were drawn over, so a feature's single-class rule
   (a card that is a button) keeps the shadow and a stronger one takes it away. */
:where(body.wl-own) :where(button) {
  display: inline-flex; align-items: center; justify-content: center;
  height: var(--wl-control-height); padding: 4px 12px;
  border: 0; border-radius: var(--r-md); background-color: var(--interactive-normal);
  font-size: var(--font-ui-small); line-height: normal; white-space: nowrap; cursor: default;
  transition: background-color var(--wl-quick) var(--wl-control-ease), color var(--wl-quick) var(--wl-control-ease), border-color var(--wl-quick) var(--wl-control-ease), box-shadow var(--wl-quick) var(--wl-control-ease);
}
/* A button's text, ground and shadow weigh one class and one element, as in the inherited base:
   a feature's one-class rule for a button (the Search panel's chips) yields to them there, so it
   does here too; a feature's stronger rule, or its hover, wins. */
:where(body.wl-own) :where(button) { --text-color: var(--text-normal); }
:where(body.wl-own) button:not(.clickable-icon) { color: var(--text-color); background-color: var(--interactive-normal); box-shadow: var(--wl-control-shadow); }
:where(body.wl-own) button:hover { background-color: var(--interactive-hover); box-shadow: var(--wl-control-shadow-hover); }
:where(body.wl-own) button.mod-warning { --text-color: var(--text-on-accent); background-color: var(--background-modifier-error); }
:where(body.wl-own) button.mod-warning:hover { background-color: var(--background-modifier-error-hover); }
:where(body.wl-own) button.mod-destructive { --text-color: var(--text-error); }
:where(body.wl-own) :where(button:disabled) { opacity: .7; cursor: not-allowed; }
:where(body.wl-own) :where(button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, kbd:focus-visible) { outline: var(--wl-focus-outline); outline-offset: 2px; }
/* A button keeps its ring even where a feature's one-class rule turns outlines off. */
:where(body.wl-own) button:not(.clickable-icon):focus-visible { outline: var(--wl-focus-outline); outline-offset: 2px; }
:where(body.wl-own) :where(.clickable-icon) {
  display: flex; align-items: center; justify-content: center;
  height: auto; padding: 4px 6px; border-radius: var(--r-sm); background-color: transparent; color: var(--text-muted); cursor: default;
  transition: background-color var(--wl-quick) var(--wl-control-ease), color var(--wl-quick) var(--wl-control-ease), border-color var(--wl-quick) var(--wl-control-ease);
}
/* An icon button: its icon a little faint until the pointer is on it, a soft ground then; as in the
   inherited base, these weigh one class and the state, so they win over a feature's one-class rule. */
:where(body.wl-own) .clickable-icon:hover { box-shadow: none; color: var(--text-muted); background-color: var(--background-modifier-hover); }
:where(body.wl-own) .clickable-icon.is-active { color: var(--text-normal); background-color: var(--background-modifier-active-hover); }
:where(body.wl-own) .clickable-icon svg { opacity: .85; }
:where(body.wl-own) .clickable-icon:hover svg { opacity: 1; }
:where(body.wl-own) :where(.clickable-icon:focus-visible) { outline: var(--wl-focus-outline); outline-offset: 2px; }
:where(body.wl-own) :where(.svg-icon) { width: 18px; height: 18px; stroke-width: 1.75px; }

/* Dropdowns: the control's colour and shadow; those marked .dropdown also have Worldrig's
   chevron at the right, never repeated (as in the inherited shell, a plain select has none). */
:where(body.wl-own) :where(select) {
  appearance: none; -webkit-appearance: none;
  height: var(--wl-control-height); padding: 0 1.9em 0 .8em;
  border: 0; border-radius: var(--r-md);
  background-color: var(--interactive-normal); box-shadow: var(--wl-control-shadow);
  font-size: var(--font-ui-small); font-weight: 400; line-height: var(--line-height-tight); cursor: default;
  transition: border-color var(--wl-short) var(--wl-control-ease), background-color var(--wl-short) var(--wl-control-ease);
}
:where(body.wl-own) :where(select.dropdown) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239ca3b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  /* Two layers: the chevron, then the theme's round backdrop behind it. */
  background-repeat: no-repeat, repeat; background-position: right .5em top 50%, 0 0; background-size: 1em, 100%;
}
:where(body.wl-own) :where(select:hover) { box-shadow: var(--wl-control-shadow-hover); }
:where(body.wl-own) :where(select:focus-visible) { box-shadow: none; }

/* Fields: text of every kind, a plain input (no type) included, so no field keeps the system's
   inset look. base-theme.css rounds text, search and number
   fields a little more. */
:where(body.wl-own) :where(input:is(:not([type]), [type="text"], [type="search"], [type="number"], [type="email"], [type="password"], [type="url"], [type="tel"], [type="date"], [type="time"], [type="datetime-local"])) {
  border: 1px solid var(--background-modifier-border); border-radius: var(--r-md); background-color: var(--background-modifier-form-field); color: var(--text-normal);
}
:where(body.wl-own) :where(input:is(:not([type]), [type="text"], [type="search"], [type="number"], [type="email"], [type="password"], [type="url"], [type="tel"], [type="date"], [type="time"], [type="datetime-local"]), textarea) {
  padding: 4px 8px; font-size: var(--font-ui-small);
  transition: border-color var(--wl-short) var(--wl-control-ease), background-color var(--wl-short) var(--wl-control-ease);
}
:where(body.wl-own) :where(input:is(:not([type]), [type="text"], [type="search"], [type="number"], [type="email"], [type="password"], [type="url"], [type="tel"], [type="date"], [type="time"], [type="datetime-local"])) { height: var(--wl-control-height); line-height: normal; }
:where(body.wl-own) :where(textarea) { line-height: var(--line-height-tight); }
:where(body.wl-own) ::placeholder { color: var(--text-faint); opacity: 1; }
/* A search box: the field as wide as its box, a magnifier at its start (Lucide's search, ISC). */
:where(body.wl-own) :where(.search-input-container) { position: relative; }
:where(body.wl-own) :where(.search-input-container)::before { content: ''; position: absolute; top: calc(50% - 9px); left: 8px; width: 18px; height: 18px; background-color: var(--text-muted); -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") center / contain no-repeat; }
:where(body.wl-own) :where(.search-input-container input) { display: block; width: 100%; padding-inline-start: 36px; }

/* Colours: a round swatch with a faint ring. */
:where(body.wl-own) :where(input[type="color"]) { -webkit-appearance: none; appearance: none; width: 26px; padding: 0; border: none; background-color: transparent; cursor: default; }
:where(body.wl-own) :where(input[type="color"])::-webkit-color-swatch-wrapper { padding: 2px; }
:where(body.wl-own) :where(input[type="color"])::-webkit-color-swatch { align-self: center; width: 22px; height: 22px; border: 0; border-radius: 14px; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--wl-text) 15%, transparent); }

/* Checkboxes: a square that fills with Lucide's check (ISC) when ticked. */
:where(body.wl-own) :where(input[type="checkbox"]) {
  appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: var(--checkbox-size, 16px); height: var(--checkbox-size, 16px); margin: 0 6px 0 0;
  border: 1px solid var(--checkbox-border-color); border-radius: var(--checkbox-radius);
  cursor: default; transition: background-color var(--wl-quick) var(--wl-control-ease), border-color var(--wl-quick) var(--wl-control-ease);
}
:where(body.wl-own) :where(input[type="checkbox"]:hover) { border-color: var(--checkbox-border-color-hover); }
:where(body.wl-own) :where(input[type="checkbox"]:checked) { background-color: var(--checkbox-color); border-color: var(--checkbox-color); }
:where(body.wl-own) :where(input[type="checkbox"]:checked)::after {
  content: ""; position: absolute; inset: -1px; background-color: var(--checkbox-marker-color);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 11px no-repeat;
}

/* Radio buttons: a round box that fills with the accent colour, a dark dot in it, when chosen. */
:where(body.wl-own) :where(input[type="radio"]) {
  appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: var(--checkbox-size, 16px); height: var(--checkbox-size, 16px); margin: 0 6px 0 0; padding: 0;
  border: 1px solid var(--checkbox-border-color); border-radius: 50%;
  cursor: default; transition: background-color var(--wl-quick) var(--wl-control-ease), border-color var(--wl-quick) var(--wl-control-ease);
}
:where(body.wl-own) :where(input[type="radio"]:hover) { border-color: var(--checkbox-border-color-hover); }
:where(body.wl-own) :where(input[type="radio"]:checked) { background-color: var(--interactive-accent); border-color: var(--interactive-accent); }
:where(body.wl-own) :where(input[type="radio"]:checked:hover) { background-color: var(--checkbox-color-hover); border-color: var(--checkbox-color-hover); }
:where(body.wl-own) :where(input[type="radio"]:checked)::after {
  content: ""; position: absolute; inset: -1px; background-color: var(--checkbox-marker-color);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Ccircle cx='6' cy='6' r='6'/%3E%3C/svg%3E") center / 50% no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Ccircle cx='6' cy='6' r='6'/%3E%3C/svg%3E") center / 50% no-repeat;
}
/* Both show the keyboard's place with the ice ring, not the pointer's. */
:where(body.wl-own) :where(input:is([type="radio"], [type="checkbox"]):focus) { outline: 0; }
:where(body.wl-own) :where(input:is([type="radio"], [type="checkbox"]):focus-visible) { outline: var(--wl-focus-outline); outline-offset: 2px; }

/* Switches (.checkbox-container): a track with a square knob that slides across. */
:where(body.wl-own) :where(.checkbox-container) {
  display: inline-block; position: relative; flex: none;
  width: var(--toggle-width); height: calc(var(--toggle-thumb-height) + 2 * var(--toggle-border-width));
  border-radius: var(--toggle-radius); box-shadow: inset 0 0 0 1px var(--background-modifier-border-hover);
  cursor: default; transition: background-color var(--wl-quick) var(--wl-control-ease), box-shadow var(--wl-quick) var(--wl-control-ease), opacity var(--wl-quick) var(--wl-control-ease);
}
:where(body.wl-own) :where(.checkbox-container)::after {
  content: ""; position: absolute; top: var(--toggle-border-width); left: 0;
  width: var(--toggle-thumb-width); height: var(--toggle-thumb-height); border-radius: var(--toggle-thumb-radius);
  background-color: var(--background-modifier-border-hover);
  transform: translateX(var(--toggle-border-width)); transition: transform var(--wl-quick) var(--wl-control-ease), background-color var(--wl-quick) var(--wl-control-ease);
}
:where(body.wl-own) :where(.checkbox-container.is-enabled) { background-color: var(--interactive-accent); box-shadow: inset 0 0 0 1px var(--interactive-accent); }
:where(body.wl-own) :where(.checkbox-container.is-enabled)::after { background-color: var(--background-primary); transform: translateX(calc(var(--toggle-width) - var(--toggle-thumb-width) - var(--toggle-border-width))); }
:where(body.wl-own) :where(.checkbox-container input[type="checkbox"]) { position: absolute; inset: 0; opacity: 0; }

/* Sliders: a thin track and a small square knob, like the switches'. */
:where(body.wl-own) :where(input[type="range"]) {
  appearance: none; -webkit-appearance: none; height: var(--slider-track-height); margin: 2px;
  border-radius: 2px; background-color: var(--slider-track-background); cursor: default;
}
:where(body.wl-own) :where(input[type="range"])::-webkit-slider-thumb {
  -webkit-appearance: none; width: var(--slider-thumb-width); height: var(--slider-thumb-height);
  border: 0; border-radius: var(--slider-thumb-radius); background: var(--wl-text); box-shadow: 0 1px 3px color-mix(in srgb, var(--wl-bg) 60%, transparent); cursor: default;
}

/* A highlight in writing (==text==): a warm tint under the text's own colour. */
:where(body.wl-own) :where(mark) { background-color: var(--text-highlight-bg); color: inherit; }

/* Keys, rules and headings. */
:where(body.wl-own) :where(kbd) { padding: .1em .25em; border-radius: var(--r-xs); background-color: var(--code-background); font-family: var(--font-monospace); font-size: .875em; }
:where(body.wl-own) :where(hr) { height: 0; margin: 2rem 0; border: 0; border-top: 2px solid var(--background-modifier-border); }
:where(body.wl-own) :where(b, strong) { font-weight: 600; }
:where(body.wl-own) :where(h1, h2, h3) { margin: 16px 0; font-weight: 600; line-height: 1.15; }
:where(body.wl-own) :where(h1) { font-family: var(--h1-font); }
:where(body.wl-own) :where(h2) { font-family: var(--h2-font); }
:where(body.wl-own) :where(h3) { font-family: var(--h3-font); }
:where(body.wl-own) :where(h1) { font-size: 1.618em; letter-spacing: -.015em; }
:where(body.wl-own) :where(h2) { font-size: 1.462em; letter-spacing: -.011em; }
:where(body.wl-own) :where(h3) { font-size: 1.318em; letter-spacing: -.008em; }
/* Settings sections: a slightly smaller checkbox, and headings at a group heading's size, set in
   by the rows' padding. */
:where(body.wl-own) :where(.wl-settings-section) { --checkbox-size: 15px; }
:where(body.wl-own) :where(.wl-settings-section) :where(h1, h2, h3, h4) { margin: 0 0 16px; padding: 0 16px; font-size: var(--font-ui-medium); }
body.wl-own .wb-project-bar { -webkit-app-region: drag; }
body.wl-own .wb-project-bar :is(button, input, a, [role="button"]) { -webkit-app-region: no-drag; }

/* Projects covers the workspace row under the bar, as the inherited window hides its row there. */
body.wl-own.wb-projects-open .wl-workspace-body { visibility: hidden; }

/* The window's Minimize, Maximize and Close (app/host/own/window-buttons.js): 44px wide, the bar's
   height, in the space the bar keeps free at its right end. They sit inside the bar (or the start
   page's strip), as Windows only lets clicks through a not-draggable part inside the draggable one. */
.wl-window-buttons { position: absolute; top: 0; right: 0; z-index: 2; display: flex; height: var(--wb-bar-height, 60px); -webkit-app-region: no-drag; }
.wl-window-strip { position: fixed; inset: 0 0 auto 0; z-index: 1000; height: var(--wb-bar-height, 60px); -webkit-app-region: drag; pointer-events: none; }
.wl-window-strip > .wl-window-buttons { pointer-events: auto; }
/* They stay in Play, which hides the rest of the bar (game.css), and over Projects, which hides the bar. */
body.wb-game-open .wb-project-bar > .wl-window-buttons.is-in-bar { display: flex; }
.wl-window-buttons { visibility: visible; }
/* Quiet until pointed at; Close then turns rose (the start page has no tokens, so each colour falls back to its text). */
body .wl-window-buttons > button.wl-window-button { width: 44px; height: 100%; display: grid; place-items: center; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--wl-text-2, currentColor); cursor: default; box-shadow: none; }
body .wl-window-buttons > button.wl-window-button:hover { background: color-mix(in srgb, var(--wl-text, currentColor) 8%, transparent); color: var(--wl-text, currentColor); }
body .wl-window-buttons > button.wl-window-button.mod-close:hover { background: var(--wl-danger, color-mix(in srgb, currentColor 14%, transparent)); color: var(--wl-on-accent, currentColor); }
body .wl-window-buttons > button.wl-window-button:focus-visible { outline: 2px solid var(--wl-selection, currentColor); outline-offset: -2px; }
.wl-window-button svg { pointer-events: none; }
/* A page's header sticks to the very top of its scroll area: the area's top padding goes onto
   the header instead, so text scrolled under it doesn't show in a strip above it. */
body.wl-own .wl-page-content:has(> .wt-pagebar) { padding-top: 0; }
/* Its line runs the page's full width, from the sheet's edge to the scroll bar: the area's side padding (12px) goes into
   the header's own, so the line doesn't stop short of the edges with the words where they were. */
body.wl-own .wl-page-content > .wt-pagebar { margin: 12px -12px 0; padding-inline: 30px 24px; }
body.wl-own .wl-page[data-type="world-builder-map-location"] > .wl-page-content > .wt-pagebar { padding-inline: 24px; }
