/* Mosaik — the primitives every surface is built from.
 *
 * Colours, type sizes, durations and easing curves are CSS variables written by
 * Python (styles/palette.py, styles/metrics.py, core/appearance.py) into
 * #theme-vars, which comes first in the document — so nothing here may declare
 * them again, or it would win. What is declared here is what belongs to the
 * page alone: the header's height, the sidebar's width, the radius scale.
 */

:root {
  --header-h: 52px;
  --sidebar-w: 264px;
  --rail-w: 56px;
  --workbench-w: 380px;
  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --ui: var(--font-ui, "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif);
  --ui-size: 13.5px;
  --ui-small: 12px;
  --ui-meta: 11.5px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  /* The neutral fills of the flat controls: the room's own text at a few
     per cent, so a button reads the same on the page, a card, a window or a
     scene. */
  --soft: color-mix(in srgb, var(--text) 6%, transparent);
  --soft-hover: color-mix(in srgb, var(--text) 10%, transparent);
  --soft-pressed: color-mix(in srgb, var(--text) 14%, transparent);
  /* The one soft shadow of what floats: menus and tips, then windows. */
  --shadow-menu: 0 0 0 1px color-mix(in srgb, var(--text) 7%, transparent), 0 2px 6px var(--shadow-soft),
    0 14px 36px -10px var(--shadow-cast);
  --shadow-window: 0 0 0 1px color-mix(in srgb, var(--text) 7%, transparent), 0 30px 80px -24px var(--shadow-cast);
  color-scheme: light dark;
}

html.dark { color-scheme: dark; }
html.light { color-scheme: light; }

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: var(--ui-size);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

body { user-select: none; }

input,
textarea,
[contenteditable="true"],
.selectable,
.body,
.bubble,
.trace,
pre,
code { user-select: text; }

button,
input,
textarea,
select { font: inherit; color: inherit; }

button { cursor: pointer; }
button:disabled { cursor: default; }

a { color: var(--link); }

::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

svg { display: block; }

.icon { display: inline-flex; width: 16px; height: 16px; flex: none; }
.icon svg { width: 100%; height: 100%; }

.display { font-family: var(--display); font-optical-sizing: auto; letter-spacing: -0.01em; }

.muted { color: var(--text2); }
.faint { color: var(--text3); }

/* ---- scrollbars ------------------------------------------------------- */
/* A thin handle in a quiet gutter, the same everywhere in the page. The
   conversations draw their own (js/scroll.js) because Chromium's gives up on a
   drag that strays sideways; everything else uses this. */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  background-clip: padding-box;
  border: 3px solid transparent;
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); background-clip: padding-box; }

/* ---- buttons ---------------------------------------------------------- */
/* Pills with a flat fill and no edge: a soft neutral by default, the accent
   for the one action a view is asking for (.primary), a hairline for a second
   choice beside it (.outline), and nothing until the pointer reaches it for
   the rest (.ghost). A press shrinks a button a little and it springs back. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  font-size: var(--ui-size);
  font-weight: 550;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease), transform 160ms var(--ease-spring);
}
.btn:hover:not(:disabled) { background: var(--soft-hover); }
.btn:active:not(:disabled) { transform: scale(0.97); background: var(--soft-pressed); transition-duration: 90ms; }
.btn:disabled { opacity: 0.42; }
.btn .icon { width: 14px; height: 14px; }

.btn.primary { background: var(--primary, var(--accent)); color: var(--primary-text, var(--accent-text)); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover, var(--accent-hover)); }
.btn.primary:active:not(:disabled) { background: var(--primary-pressed, var(--accent-pressed)); }

.btn.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }
.btn.outline:hover:not(:disabled) { background: var(--soft); }
.btn.outline:active:not(:disabled) { background: var(--soft-hover); }

.btn.danger { background: var(--danger); color: var(--danger-text); }
.btn.danger:hover:not(:disabled) { filter: brightness(1.06); background: var(--danger); }

.btn.ghost { background: transparent; color: var(--text2); }
.btn.ghost:hover:not(:disabled) { background: var(--soft); color: var(--text); }
.btn.ghost:active:not(:disabled) { background: var(--soft-hover); }

.btn.small { height: 28px; padding: 0 12px; font-size: var(--ui-small); }
.btn.large { height: 38px; padding: 0 20px; font-size: 14px; }
.btn.block { width: 100%; }

/* An icon on its own: square, quiet until pointed at. */
.ibtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text2);
  flex: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    transform 160ms var(--ease-spring);
}
.ibtn:hover:not(:disabled) { background: var(--soft); color: var(--text); }
.ibtn:active:not(:disabled) { background: var(--soft-hover); transform: scale(0.94); transition-duration: 90ms; }
.ibtn:disabled { opacity: 0.4; }
.ibtn .icon { width: 16px; height: 16px; }
.ibtn.small { width: 24px; height: 24px; }
.ibtn.small .icon { width: 14px; height: 14px; }
.ibtn.on { color: var(--accent-ink); }

/* A pill in a toolbar: an icon and a word. */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  white-space: nowrap;
  max-width: 100%;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}
.pill:hover:not(:disabled) { background: var(--soft); color: var(--text); }
.pill:active:not(:disabled) { background: var(--soft-hover); }
.pill .icon { width: 14px; height: 14px; }
.pill .chev { width: 12px; height: 12px; color: var(--text3); }
.pill .label { overflow: hidden; text-overflow: ellipsis; }
.pill.active { background: var(--accent-wash); color: var(--accent-ink); }
.pill.active:hover { background: color-mix(in srgb, var(--accent-wash) 80%, var(--accent) 20%); }
.pill.strong .label { color: var(--text); }

/* ---- fields ------------------------------------------------------------ */
.field {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font-size: var(--ui-size);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
textarea.field { height: auto; min-height: 84px; padding: 9px 11px; line-height: 1.5; resize: vertical; }
.field::placeholder { color: var(--text3); }
.field:hover { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text3)); }
.field:focus {
  border-color: var(--text2);
  box-shadow: inset 0 0 0 0.5px var(--text2);
  outline: none;
}
/* A choice from a list is a soft pill, as the buttons are. */
select.field {
  padding-right: 30px;
  appearance: none;
  background-image: none;
  border-color: transparent;
  border-radius: 999px;
  background-color: var(--soft);
  font-weight: 550;
  transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
select.field:hover { border-color: transparent; background-color: var(--soft-hover); }
select.field:focus { border-color: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); }
/* Its list is drawn by the system, on the room's own colours. */
select.field option { background: var(--raised); color: var(--text); }
.select { position: relative; }
.select::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--text3);
  border-bottom: 1.5px solid var(--text3);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  line-height: 1.45;
}
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  flex: none;
  width: 36px;
  height: 20px;
  margin-top: 0;
  border-radius: 999px;
  background: var(--soft-pressed);
  position: relative;
  transition: background var(--dur) var(--ease);
}
.check .box::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  transition: transform 220ms var(--ease-spring), background var(--dur) var(--ease);
}
.check:hover input:not(:checked):not(:disabled) + .box { background: color-mix(in srgb, var(--text) 20%, transparent); }
.check input:checked + .box { background: var(--accent); }
.check input:checked + .box::after { transform: translateX(16px); background: var(--switch-knob, #fff); }
.check input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
/* A switch that can't be changed while something else is off: faint, and
   the pointer passes over it. */
.check:has(> input:disabled) { opacity: 0.5; cursor: default; }

kbd {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  font-family: var(--ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  background: var(--soft);
}

/* ---- tags: a kind of work, as a small coloured tile ----------------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-hover);
  color: var(--text2);
}
.tag .icon { width: 11px; height: 11px; }
.tag.code { background: var(--tag-code-bg); color: var(--tag-code-fg); }
.tag.design, .tag.visual { background: var(--tag-design-bg); color: var(--tag-design-fg); }
.tag.writing { background: var(--tag-writing-bg); color: var(--tag-writing-fg); }
.tag.research { background: var(--tag-research-bg); color: var(--tag-research-fg); }
.tag.accent { background: var(--accent-wash); color: var(--accent-ink); }

.tile {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: none;
}
.tile.navy { background: var(--tile-navy); }
.tile.amber { background: var(--tile-amber); }
.tile.oxblood { background: var(--tile-oxblood); }
.tile.teal { background: var(--tile-teal); }
.tile.gold { background: var(--tile-gold); }

/* ---- the logo ----------------------------------------------------------- */
.logo { display: inline-block; flex: none; }
.logo img, .logo svg { width: 100%; height: 100%; display: block; }

/* ---- the mosaic strip -------------------------------------------------- */
/* Along the top of everything that floats (App.mosaicStrip). The card it
   tops clips it to its own corners. */
.mosaic-strip { display: block; width: 100%; height: 5px; flex: none; }

/* The top of a floating window, by which it is moved (App.draggable). The
   controls in it keep their own cursor. */
.drag-handle { cursor: grab; user-select: none; -webkit-user-select: none; }
.dragging .drag-handle { cursor: grabbing; }

/* ---- popovers and menus ------------------------------------------------ */
/* Over everything that floats (dialogs from 70, the palette at 80, tips at
   85), since a menu is opened from inside any of them; under the tooltip and
   the toasts. App.popover lifts one higher still if its anchor is higher. */
.popover {
  position: fixed;
  z-index: 88;
  min-width: 180px;
  max-width: 360px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: var(--raised);
  box-shadow: var(--shadow-menu);
  transform-origin: var(--origin, top left);
  animation: pop-in 140ms var(--ease-out) both;
  overflow: hidden;
}
/* Thinner on a tip than on a window, a hint of the tiles rather than a band.
   Menus, drop-downs, the list under the message box and a source's card
   have none. */
.tip-card > .mosaic-strip { height: 3px; }
.popover.leaving { animation: pop-out 100ms var(--ease) both; pointer-events: none; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(var(--pop-y, -4px)) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-out {
  to { opacity: 0; transform: translateY(var(--pop-y, -4px)) scale(0.98); }
}

/* A menu taller than the window scrolls inside it rather than running off the bottom. */
.popover > .menu { max-height: calc(100vh - 36px); overflow-y: auto; overscroll-behavior: contain; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 32px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--ui-size);
  text-align: left;
  transition: background var(--dur-fast) var(--ease);
}
.menu-item:hover,
.menu-item.hot { background: var(--soft); }
.menu-item:disabled { color: var(--text3); background: transparent; }
.menu-item .icon { width: 15px; height: 15px; color: var(--text2); }
.menu-item .hint { margin-left: auto; color: var(--text3); font-size: var(--ui-small); padding-left: 16px; }
.menu-item .check-mark { margin-left: auto; color: var(--accent-ink); width: 15px; height: 15px; }
.menu-item .more-mark { margin-left: auto; color: var(--text3); width: 14px; height: 14px; }
.menu-back { color: var(--text2); font-weight: 600; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger .icon { color: var(--danger); }
.menu-item .sub { display: block; color: var(--text3); font-size: var(--ui-small); margin-top: 1px; }
.menu-item .text { display: flex; flex-direction: column; min-width: 0; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--border); }
.menu-title {
  padding: 8px 10px 4px;
  font-size: var(--ui-small);
  font-weight: 600;
  color: var(--text3);
}

.menu-note {
  max-width: 300px;
  padding: 8px 10px 6px;
  font-size: var(--ui-small);
  line-height: 1.45;
  color: var(--text2);
}

/* ---- tooltips ---------------------------------------------------------- */
#tooltip {
  position: fixed;
  z-index: 90;
  max-width: 300px;
  padding: 5px 9px;
  border-radius: 8px;
  /* A dark tip in both themes, set off from whatever it lies over. */
  border: 0;
  background: var(--tip-bg);
  color: var(--tip-fg);
  box-shadow: 0 4px 14px -6px var(--shadow-cast);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: pre-line;
  overflow-wrap: anywhere;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 120ms var(--ease), transform 120ms var(--ease);
}
#tooltip.shown { opacity: 1; transform: none; }
#tooltip kbd {
  height: 17px;
  margin-left: 6px;
  padding: 0 5px;
  background: color-mix(in srgb, var(--tip-fg) 14%, transparent);
  color: var(--tip-fg);
}

/* ---- toasts ------------------------------------------------------------ */
/* Under the header, where nothing lives that a toast could cover. */
#toasts {
  position: fixed;
  left: 50%;
  top: calc(var(--header-h) + 14px);
  z-index: 95;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 520px;
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 19px;
  /* The room's own colours, one raised surface with the soft shadow of what floats. */
  border: 0;
  background: var(--raised);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow-menu);
  animation: toast-in 200ms var(--ease-out) both;
}
.toast.leaving { animation: toast-out 160ms var(--ease) both; }
.toast > .icon { color: var(--text2); flex: none; }
.toast.danger { border-color: transparent; background: var(--danger); color: var(--danger-text); }
.toast.danger > .icon { color: inherit; }
.toast .toast-action {
  pointer-events: auto;
  margin: -3px -8px -3px 4px;
  padding: 5px 11px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 10%, transparent);
  color: inherit;
  font: 600 12.5px/1.2 var(--ui);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.toast .toast-action:hover { background: color-mix(in srgb, currentColor 18%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px); } }

/* ---- shared motion ------------------------------------------------------ */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes settle-in { from { opacity: 0; transform: scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }


.reduced-motion *,
.reduced-motion *::before,
.reduced-motion *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 1ms !important;
  scroll-behavior: auto !important;
}

/* A minimized window: every loop holds still until it is seen again. */
.window-hidden *,
.window-hidden *::before,
.window-hidden *::after { animation-play-state: paused !important; }

/* ---- empty states ------------------------------------------------------ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 28px 22px;
  text-align: center;
  color: var(--text3);
}
.empty .icon { width: 22px; height: 22px; margin-bottom: 4px; }
.empty .headline { color: var(--text2); font-weight: 600; font-size: 13.5px; }
.empty .detail { font-size: 12.5px; line-height: 1.5; max-width: 30ch; white-space: pre-line; }
.empty .btn { margin-top: 8px; }
