/* Roomwright app shell + component library. Owner: shell (see docs/CONTRACT.md, section 8).
   Colours come only from styles/tokens.css. 4 px grid, 32 px controls, hairline borders, quiet motion. */

/* =========================================================================================
   1. Reset and base
   ========================================================================================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-family: var(--rw-font);
  font-size: var(--rw-text-md);
  line-height: var(--rw-leading);
  color: var(--rw-ink);
  background: var(--rw-bg);
  /* no tabular figures on body text: Inter's tnum also widens the hyphen ("Two - bedroom"). Numbers opt in below. */
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
/* tabular figures only where numbers line up or tick: numeric inputs (not text inputs), status bar, zoom, metrics, areas, sizes, badges */
.rw-num, input[type="number"], input[inputmode="decimal"], input[inputmode="numeric"], .rw-input-unit__input, #statusbar, .rw-badge, .rw-kbd, .rw-progress,
[class*="__value"], [class*="__num"], [class*="__metric"], [class*="__area"], [class*="__size"], [class*="__stat"], [class*="__score"], [class*="__dims"] { font-variant-numeric: tabular-nums; }
button { cursor: pointer; background: none; border: 0; padding: 0; margin: 0; }
button:disabled { cursor: default; }
h1, h2, h3, h4, p, ul, ol, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img, svg, canvas { display: block; }
svg.rw-icon { flex: none; }
a { color: var(--rw-select); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
::selection { background: var(--rw-select-tint); }
input::placeholder, textarea::placeholder { color: var(--rw-ink-3); opacity: 1; }

/* Focus: one ring everywhere (keyboard only). */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--rw-select); outline-offset: 2px; border-radius: var(--rw-radius-xs); }
[tabindex="-1"]:focus-visible, .rw-modal:focus-visible, .rw-menu:focus-visible { outline: none; }

/* Scrollbars: thin, quiet, theme-aware. */
* { scrollbar-width: thin; scrollbar-color: var(--rw-line-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rw-line-strong); border: 3px solid transparent; border-radius: 10px; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: var(--rw-ink-3); }
::-webkit-scrollbar-corner { background: transparent; }

.rw-visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rw-icon-wrap { display: inline-flex; }

/* =========================================================================================
   2. App frame (grid)
   ========================================================================================= */
.rw-app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: var(--rw-rail-w) auto minmax(0, 1fr) auto;
  grid-template-rows: var(--rw-topbar-h) minmax(0, 1fr) var(--rw-status-h);
  grid-template-areas:
    "top top top top"
    "rail drawer view panel"
    "status status status status";
  background: var(--rw-bg);
  overflow: hidden;
}

/* ---------- top bar ---------- */
.rw-topbar {
  grid-area: top;
  position: relative; z-index: var(--rw-z-docked);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  gap: var(--rw-space-3);
  padding: 0 var(--rw-space-3) 0 var(--rw-space-3);
  background: var(--rw-bg);
  border-bottom: 1px solid var(--rw-line);
  min-width: 0;
}
.rw-topbar__start, .rw-topbar__end { display: flex; align-items: center; gap: var(--rw-space-1); min-width: 0; }
.rw-topbar__start { overflow: hidden; padding: 2px; margin: -2px; }
.rw-topbar__end { justify-content: flex-end; }
.rw-topbar__center { display: flex; align-items: center; justify-content: center; }
.rw-topbar__sep { width: 1px; height: 20px; background: var(--rw-line); margin: 0 var(--rw-space-1-5); flex: none; }

.rw-brand {
  display: inline-flex; align-items: center; gap: var(--rw-space-2);
  height: 36px; padding: 0 var(--rw-space-2) 0 var(--rw-space-1);
  border-radius: var(--rw-radius-md);
  color: var(--rw-ink); flex: none;
  transition: background-color var(--rw-dur-1) var(--rw-ease);
}
.rw-brand:hover { background: var(--rw-bg-hover); }
.rw-brand__name { font-weight: var(--rw-weight-semibold); font-size: 14px; letter-spacing: -0.01em; }
.rw-logo-mark { flex: none; border-radius: 8px; }

.rw-docname { display: grid; min-width: 0; padding-left: var(--rw-space-1); }
.rw-docname__row { display: flex; align-items: center; gap: 2px; min-width: 0; }
.rw-docname__title {
  min-width: 0; max-width: 260px;
  height: 22px; padding: 0 var(--rw-space-1-5); margin-left: calc(-1 * var(--rw-space-1-5));
  border-radius: var(--rw-radius-xs);
  font-weight: var(--rw-weight-semibold); font-size: var(--rw-text-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left;
  transition: background-color var(--rw-dur-1) var(--rw-ease);
}
.rw-docname__title:hover { background: var(--rw-bg-hover); }
.rw-docname__input {
  width: 240px; height: 22px; padding: 0 var(--rw-space-1-5); margin-left: calc(-1 * var(--rw-space-1-5));
  border: 1px solid var(--rw-select); border-radius: var(--rw-radius-xs);
  box-shadow: 0 0 0 3px var(--rw-focus-ring);
  background: var(--rw-bg); font-weight: var(--rw-weight-semibold);
}
.rw-docname__menu { width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: var(--rw-radius-xs); color: var(--rw-ink-3); flex: none; }
.rw-docname__menu:hover, .rw-docname__menu[aria-expanded="true"] { background: var(--rw-bg-hover); color: var(--rw-ink); }
.rw-savestate { display: inline-flex; align-items: center; gap: 4px; height: 16px; font-size: var(--rw-text-xs); color: var(--rw-ink-3); white-space: nowrap; }
.rw-savestate .rw-icon { width: 13px; height: 13px; }
.rw-savestate[data-state="saving"] .rw-icon { animation: rw-spin 900ms linear infinite; }
.rw-savestate[data-state="error"] { color: var(--rw-danger-ink); }

.rw-level { max-width: 180px; }
.rw-level .rw-btn__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.rw-viewswitch { box-shadow: none; }
.rw-viewswitch .rw-seg__btn { min-width: 68px; }

.rw-zoom { display: inline-flex; align-items: center; gap: 0; }
.rw-zoom__value { min-width: 56px; justify-content: center; padding: 0 var(--rw-space-1-5); font-variant-numeric: tabular-nums; }

.rw-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  background: var(--rw-bg-subtle); color: var(--rw-ink-2);
  border: 1px solid var(--rw-line);
  transition: background-color var(--rw-dur-1) var(--rw-ease), border-color var(--rw-dur-1) var(--rw-ease);
}
.rw-avatar:hover, .rw-avatar[aria-expanded="true"] { background: var(--rw-bg-active); color: var(--rw-ink); border-color: var(--rw-line-strong); }

.rw-only-phone { display: none !important; }

/* ---------- tool rail ---------- */
.rw-rail {
  grid-area: rail;
  position: relative; z-index: var(--rw-z-docked);
  display: flex; flex-direction: column; align-items: center;
  gap: var(--rw-space-1);
  padding: var(--rw-space-2) 0;
  background: var(--rw-bg);
  border-right: 1px solid var(--rw-line);
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: none;
}
.rw-rail::-webkit-scrollbar { display: none; }
.rw-rail__group { display: flex; flex-direction: column; align-items: center; gap: var(--rw-space-1); }
.rw-rail__divider { width: 24px; height: 1px; background: var(--rw-line); margin: var(--rw-space-1) 0; flex: none; }
.rw-rail__spacer { flex: 1 1 auto; min-height: var(--rw-space-2); }

.rw-tool {
  position: relative;
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: var(--rw-radius-md);
  color: var(--rw-ink-2);
  transition: background-color var(--rw-dur-1) var(--rw-ease), color var(--rw-dur-1) var(--rw-ease);
}
.rw-tool:hover { background: var(--rw-bg-hover); color: var(--rw-ink); }
.rw-tool:active { background: var(--rw-bg-active); }
.rw-tool.is-active { background: var(--rw-select-tint); color: var(--rw-select); }
.rw-tool.is-open { background: var(--rw-bg-active); color: var(--rw-ink); }
.rw-tool.is-open.is-active { background: var(--rw-select-tint); color: var(--rw-select); }
.rw-tool:focus-visible { outline-offset: 0; border-radius: var(--rw-radius-md); }
.rw-tool__caret {
  position: absolute; right: 2px; bottom: 2px;
  width: 10px; height: 10px; display: grid; place-items: center;
  border-radius: 3px; color: var(--rw-ink-3);
}
.rw-tool__caret::before { content: ""; width: 0; height: 0; border-left: 4px solid transparent; border-bottom: 4px solid currentColor; }
.rw-tool:hover .rw-tool__caret { color: var(--rw-ink-2); }
.rw-tool.is-active .rw-tool__caret { color: var(--rw-select); }
.rw-tool__label { display: none; }
.rw-tool--ai { color: var(--rw-ai); }
.rw-tool--ai:hover { color: var(--rw-ai); background: var(--rw-ai-tint); }

/* ---------- drawer (library / templates) ---------- */
.rw-drawer {
  grid-area: drawer;
  width: var(--rw-drawer-w);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--rw-bg);
  border-right: 1px solid var(--rw-line);
  z-index: var(--rw-z-docked);
}
.rw-app:not(.has-drawer) .rw-drawer { display: none; }
.rw-pane-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--rw-space-2);
  height: 44px; flex: none;
  padding: 0 var(--rw-space-2) 0 var(--rw-space-3);
  border-bottom: 1px solid var(--rw-line);
}
.rw-pane-header .rw-tabs { border-bottom: 0; height: 44px; }
.rw-pane-header .rw-tab { height: 44px; }
.rw-pane-body { position: relative; flex: 1 1 auto; min-height: 0; }
.rw-pane {
  position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  overscroll-behavior: contain;
}
.rw-sheet-grabber { display: none; }

/* ---------- side panel ---------- */
.rw-sidepanel {
  grid-area: panel;
  width: var(--rw-panel-w);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--rw-bg);
  border-left: 1px solid var(--rw-line);
  z-index: var(--rw-z-docked);
}
.rw-app:not(.has-panel) .rw-sidepanel { display: none; }
.rw-tab__badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 2px;
  border-radius: var(--rw-radius-full);
  background: var(--rw-ai-tint); color: var(--rw-ai-ink);
  border: 1px solid var(--rw-ai-line);
  font-size: var(--rw-text-xs); font-weight: var(--rw-weight-semibold); line-height: 1;
}
.rw-tab .rw-icon--sparkle { color: var(--rw-ai); }
.rw-shell-placeholder { padding: var(--rw-space-6) var(--rw-space-4); }

/* ---------- viewport ---------- */
.rw-viewport {
  grid-area: view;
  position: relative; overflow: hidden; min-width: 0; min-height: 0;
  background: var(--cv-bg);
  --rw-split: 50%;
  isolation: isolate;
}
#plan-host, #view3d-host { position: absolute; top: 0; bottom: 0; overflow: hidden; }
#plan-host { left: 0; right: 0; z-index: var(--rw-z-canvas); }
#view3d-host { left: 0; right: 0; z-index: var(--rw-z-canvas); background: var(--cv-bg); }
.rw-viewport[data-view="plan"] #view3d-host { display: none; }
.rw-viewport[data-view="3d"] #plan-host { display: none; }
.rw-viewport[data-view="split"] #plan-host { right: calc(100% - var(--rw-split)); }
.rw-viewport[data-view="split"] #view3d-host { left: calc(var(--rw-split) + 1px); }
.rw-split-divider {
  position: absolute; top: 0; bottom: 0; left: var(--rw-split);
  width: 1px; background: var(--rw-line-strong);
  z-index: calc(var(--rw-z-viewport-overlay) + 1);
  display: none;
}
.rw-viewport[data-view="split"] .rw-split-divider { display: block; }
.rw-split-divider::before { content: ""; position: absolute; top: 0; bottom: 0; left: -5px; width: 11px; cursor: col-resize; }
.rw-split-divider::after {
  content: ""; position: absolute; top: 50%; left: -3px; width: 7px; height: 36px; margin-top: -18px;
  border-radius: 4px; background: var(--rw-bg-raised); border: 1px solid var(--rw-line-strong);
  box-shadow: var(--rw-shadow-xs);
  transition: border-color var(--rw-dur-1) var(--rw-ease), background-color var(--rw-dur-1) var(--rw-ease);
  pointer-events: none;
}
.rw-split-divider:hover::after, .rw-split-divider.is-dragging::after { border-color: var(--rw-select); background: var(--rw-select); }
.rw-viewport.is-resizing { cursor: col-resize; user-select: none; }
.rw-viewport.is-resizing #plan-host, .rw-viewport.is-resizing #view3d-host { pointer-events: none; }
#viewport-overlay { position: absolute; inset: 0; pointer-events: none; z-index: var(--rw-z-viewport-overlay); }
#viewport-overlay > * { pointer-events: auto; }
#viewport-overlay > .rw-canvas-empty { pointer-events: none; }

.rw-canvas-empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(452px, calc(100% - 32px));
  display: grid; justify-items: center; text-align: center; gap: var(--rw-space-2);
  padding: var(--rw-space-6) var(--rw-space-6) var(--rw-space-5);
  background: var(--rw-bg-raised);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-lg);
  box-shadow: var(--rw-shadow-float), inset 0 1px 0 var(--rw-highlight);
  animation: rw-pop var(--rw-dur-3) var(--rw-ease-out);
}
.rw-canvas-empty > * { pointer-events: auto; }
.rw-viewport[data-view="split"] .rw-canvas-empty { left: calc(var(--rw-split) / 2); width: min(452px, calc(var(--rw-split) - 32px)); }
.rw-canvas-empty__title { font-size: var(--rw-text-lg); font-weight: var(--rw-weight-semibold); margin-top: var(--rw-space-1); }
.rw-canvas-empty__text { color: var(--rw-ink-2); max-width: 320px; }
.rw-canvas-empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--rw-space-2); margin-top: var(--rw-space-2); }
.rw-canvas-empty__hint { font-size: var(--rw-text-sm); color: var(--rw-ink-3); margin-top: var(--rw-space-1); display: inline-flex; align-items: center; gap: var(--rw-space-1); }

/* ---------- status bar ---------- */
.rw-statusbar {
  grid-area: status;
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; gap: var(--rw-space-3);
  padding: 0 var(--rw-space-2);
  background: var(--rw-bg);
  border-top: 1px solid var(--rw-line);
  font-size: var(--rw-text-xs); color: var(--rw-ink-2);
  z-index: var(--rw-z-docked);
  white-space: nowrap; min-width: 0;
}
.rw-status__group { display: flex; align-items: center; gap: 2px; min-width: 0; overflow: hidden; }
.rw-status__group--end { justify-content: flex-end; }
.rw-status__item {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 var(--rw-space-1-5);
  border-radius: var(--rw-radius-xs);
  color: var(--rw-ink-2); flex: none;
}
.rw-status__item .rw-icon { width: 14px; height: 14px; color: var(--rw-ink-3); }
button.rw-status__item { transition: background-color var(--rw-dur-1) var(--rw-ease), color var(--rw-dur-1) var(--rw-ease); }
button.rw-status__item:hover { background: var(--rw-bg-hover); color: var(--rw-ink); }
button.rw-status__item:hover .rw-icon { color: var(--rw-ink-2); }
button.rw-status__item:focus-visible { outline-offset: 0; }
.rw-status__item.is-active { color: var(--rw-select); }
.rw-status__item.is-active .rw-icon { color: var(--rw-select); }
.rw-status__item.is-off { color: var(--rw-ink-3); }
.rw-status__item.is-off .rw-icon { color: var(--rw-ink-3); }
.rw-status__sep { width: 1px; height: 14px; background: var(--rw-line); margin: 0 var(--rw-space-1); flex: none; }
.rw-status__coords { min-width: 148px; color: var(--rw-ink-3); }
.rw-status__coords b { font-weight: var(--rw-weight-medium); color: var(--rw-ink-2); }
.rw-status__selection { justify-content: center; color: var(--rw-ink); font-weight: var(--rw-weight-medium); }
.rw-status__selection.is-empty { color: var(--rw-ink-3); font-weight: 400; }
.rw-status__selection .rw-status__dot { width: 8px; height: 8px; border-radius: 2px; background: var(--rw-select); flex: none; }
.rw-status__preview { color: var(--rw-ai-ink); background: var(--rw-ai-tint); border: 1px solid var(--rw-ai-line); height: 20px; }
.rw-status__preview .rw-icon { color: var(--rw-ai); }
.rw-status__zoom { min-width: 52px; justify-content: flex-end; }

/* ---------- overlays roots ---------- */
#modal-root, #toast-root, #popover-root { position: fixed; inset: 0; pointer-events: none; }
#popover-root { z-index: var(--rw-z-popover); }
#modal-root { z-index: var(--rw-z-modal); }
#toast-root { z-index: var(--rw-z-toast); }
#popover-root > *, #modal-root > * { pointer-events: auto; }

.rw-scrim {
  position: fixed; inset: 0;
  background: var(--rw-scrim);
  z-index: calc(var(--rw-z-sheet) - 1);
  animation: rw-fade var(--rw-dur-2) var(--rw-ease);
}

/* =========================================================================================
   3. Components
   ========================================================================================= */

/* ---------- buttons ---------- */
.rw-btn {
  --btn-bg: var(--rw-bg);
  --btn-bg-hover: var(--rw-bg-subtle);
  --btn-bg-active: var(--rw-bg-active);
  --btn-ink: var(--rw-ink);
  --btn-line: var(--rw-line-strong);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--rw-space-1-5);
  height: var(--rw-control-h); padding: 0 var(--rw-space-3);
  border: 1px solid var(--btn-line); border-radius: var(--rw-radius-control);
  background: var(--btn-bg); color: var(--btn-ink);
  font-size: var(--rw-text-md); font-weight: var(--rw-weight-medium); line-height: 1;
  white-space: nowrap; user-select: none; flex: none;
  box-shadow: var(--rw-shadow-xs);
  transition: background-color var(--rw-dur-1) var(--rw-ease), border-color var(--rw-dur-1) var(--rw-ease), color var(--rw-dur-1) var(--rw-ease), box-shadow var(--rw-dur-1) var(--rw-ease);
}
.rw-btn:hover { background: var(--btn-bg-hover); }
.rw-btn:active { background: var(--btn-bg-active); }
.rw-btn:focus-visible { outline: none; border-color: var(--rw-select); box-shadow: 0 0 0 3px var(--rw-focus-ring); }
.rw-btn:disabled, .rw-btn[aria-disabled="true"] { opacity: 0.42; pointer-events: none; box-shadow: none; }
.rw-btn .rw-icon { margin: 0 -1px; }
.rw-btn .rw-btn__label { overflow: hidden; text-overflow: ellipsis; }
.rw-btn .rw-kbd-group { margin-left: var(--rw-space-1); }

.rw-btn--primary { --btn-bg: var(--rw-primary); --btn-bg-hover: var(--rw-primary-hover); --btn-bg-active: var(--rw-primary); --btn-ink: var(--rw-on-primary); --btn-line: transparent; }
.rw-btn--ai { --btn-bg: var(--rw-ai); --btn-bg-hover: var(--rw-ai-hover); --btn-bg-active: var(--rw-ai); --btn-ink: var(--rw-on-ai); --btn-line: transparent; }
.rw-btn--ai .rw-icon { color: var(--rw-on-ai); }
.rw-btn--danger { --btn-bg: var(--rw-danger); --btn-bg-hover: var(--rw-danger-hover); --btn-bg-active: var(--rw-danger); --btn-ink: var(--rw-on-ai); --btn-line: transparent; }
.rw-btn--ghost { --btn-bg: transparent; --btn-bg-hover: var(--rw-bg-hover); --btn-ink: var(--rw-ink-2); --btn-line: transparent; box-shadow: none; }
.rw-btn--ghost:hover { color: var(--rw-ink); }
.rw-btn--subtle { --btn-bg: var(--rw-bg-subtle); --btn-bg-hover: var(--rw-bg-active); --btn-line: transparent; box-shadow: none; }
.rw-btn--ai-soft { --btn-bg: var(--rw-ai-tint); --btn-bg-hover: var(--rw-ai-tint); --btn-ink: var(--rw-ai-ink); --btn-line: var(--rw-ai-line); box-shadow: none; }
.rw-btn--ai-soft:hover { border-color: var(--rw-ai); }
.rw-btn--sm { height: var(--rw-control-h-sm); padding: 0 var(--rw-space-2-5, 10px); font-size: var(--rw-text-sm); gap: var(--rw-space-1); }
.rw-btn--lg { height: var(--rw-control-h-lg); padding: 0 var(--rw-space-4); font-size: var(--rw-text-md); }
.rw-btn--block { width: 100%; }
.rw-btn--icon { width: var(--rw-control-h); padding: 0; }
.rw-btn--icon.rw-btn--sm { width: var(--rw-control-h-sm); }
.rw-btn--icon.rw-btn--lg { width: var(--rw-control-h-lg); }
.rw-btn.is-active { --btn-bg: var(--rw-select-tint); --btn-bg-hover: var(--rw-select-tint); --btn-ink: var(--rw-select); }
.rw-btn--ghost.is-active { color: var(--rw-select); }
.rw-btn[aria-expanded="true"]:not(.rw-btn--primary):not(.rw-btn--ai) { background: var(--btn-bg-active); }

/* ---------- inputs ---------- */
.rw-input, .rw-textarea, .rw-input-unit, select.rw-select, .rw-select select {
  width: 100%;
  border: 1px solid var(--rw-line-strong); border-radius: var(--rw-radius-control);
  background: var(--rw-bg); color: var(--rw-ink);
  font-size: var(--rw-text-md);
  transition: border-color var(--rw-dur-1) var(--rw-ease), box-shadow var(--rw-dur-1) var(--rw-ease), background-color var(--rw-dur-1) var(--rw-ease);
}
.rw-input { height: var(--rw-control-h); padding: 0 var(--rw-space-2-5, 10px); }
.rw-input--sm { height: var(--rw-control-h-sm); font-size: var(--rw-text-sm); padding: 0 var(--rw-space-2); }
.rw-textarea { min-height: 76px; padding: var(--rw-space-2) var(--rw-space-2-5, 10px); resize: vertical; line-height: var(--rw-leading); display: block; }
.rw-input:hover, .rw-textarea:hover, .rw-input-unit:hover, select.rw-select:hover, .rw-select select:hover { border-color: var(--rw-ink-3); }
.rw-input:focus, .rw-textarea:focus, .rw-input-unit:focus-within, select.rw-select:focus-visible, .rw-select select:focus-visible {
  outline: none; border-color: var(--rw-select); box-shadow: 0 0 0 3px var(--rw-focus-ring);
}
.rw-input:disabled, .rw-textarea:disabled, .rw-input-unit.is-disabled, .rw-select select:disabled, select.rw-select:disabled { opacity: 0.5; pointer-events: none; background: var(--rw-bg-subtle); }
.rw-input[readonly] { background: var(--rw-bg-subtle); color: var(--rw-ink-2); }
.rw-input.is-invalid, .rw-input-unit.is-invalid { border-color: var(--rw-danger); box-shadow: 0 0 0 3px var(--rw-danger-tint); }

.rw-input-unit {
  display: flex; align-items: center;
  height: var(--rw-control-h);
  padding: 0 var(--rw-space-2-5, 10px) 0 0;
  cursor: text; min-width: 0;
}
.rw-input-unit--sm { height: var(--rw-control-h-sm); font-size: var(--rw-text-sm); }
.rw-input-unit__input, .rw-input-unit > input {
  flex: 1 1 auto; min-width: 0; width: 100%; height: 100%;
  padding: 0 var(--rw-space-1) 0 var(--rw-space-2-5, 10px);
  border: 0; background: transparent; outline: none;
  font-variant-numeric: tabular-nums;
}
.rw-input-unit--sm .rw-input-unit__input { padding-left: var(--rw-space-2); }
.rw-input-unit__suffix, .rw-input-unit > span { flex: none; color: var(--rw-ink-3); font-size: var(--rw-text-sm); pointer-events: none; }

.rw-select { position: relative; display: block; min-width: 0; }
select.rw-select, .rw-select select {
  appearance: none; -webkit-appearance: none;
  height: var(--rw-control-h); padding: 0 30px 0 var(--rw-space-2-5, 10px);
  cursor: pointer; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--rw-ink-3) 50%), linear-gradient(135deg, var(--rw-ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 11px) 52%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.rw-select--sm select, select.rw-select.rw-select--sm { height: var(--rw-control-h-sm); font-size: var(--rw-text-sm); }
select option { background: var(--rw-bg-raised); color: var(--rw-ink); }

/* switch */
.rw-switch { display: inline-flex; align-items: center; gap: var(--rw-space-2); cursor: pointer; user-select: none; min-height: 20px; }
.rw-switch input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  position: relative; width: 28px; height: 16px; border-radius: var(--rw-radius-full);
  background: var(--rw-line-strong); cursor: pointer;
  transition: background-color var(--rw-dur-2) var(--rw-ease);
}
.rw-switch input::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--rw-bg-raised); box-shadow: 0 1px 2px var(--rw-shadow-color);
  transition: transform var(--rw-dur-2) var(--rw-ease-out);
}
.rw-switch input:checked { background: var(--rw-select); }
.rw-switch input:checked::before { transform: translateX(12px); background: var(--rw-on-ai); }
.rw-switch input:focus-visible { outline: 2px solid var(--rw-select); outline-offset: 2px; }
.rw-switch input:disabled { opacity: 0.45; cursor: default; }
.rw-switch:hover input:not(:checked):not(:disabled) { background: var(--rw-ink-3); }
.rw-switch__label { color: var(--rw-ink); }
.rw-switch--ai input:checked { background: var(--rw-ai); }

/* checkbox */
.rw-checkbox { display: inline-flex; align-items: center; gap: var(--rw-space-2); cursor: pointer; user-select: none; }
.rw-checkbox input, input.rw-checkbox {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  position: relative; width: 16px; height: 16px; border-radius: var(--rw-radius-xs);
  border: 1px solid var(--rw-line-strong); background: var(--rw-bg); cursor: pointer;
  transition: background-color var(--rw-dur-1) var(--rw-ease), border-color var(--rw-dur-1) var(--rw-ease);
}
.rw-checkbox input:hover, input.rw-checkbox:hover { border-color: var(--rw-ink-3); }
.rw-checkbox input:checked, input.rw-checkbox:checked { background: var(--rw-select); border-color: var(--rw-select); }
.rw-checkbox input:checked::after, input.rw-checkbox:checked::after {
  content: ""; position: absolute; left: 4.5px; top: 1.5px; width: 4px; height: 8px;
  border: solid var(--rw-on-ai); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.rw-checkbox input:focus-visible, input.rw-checkbox:focus-visible { outline: 2px solid var(--rw-select); outline-offset: 2px; }

/* range */
.rw-range { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; background: transparent; cursor: pointer; margin: 0; --fill: 50%; }
.rw-range::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(to right, var(--rw-select) var(--fill), var(--rw-line-strong) var(--fill)); }
.rw-range::-moz-range-track { height: 4px; border-radius: 4px; background: var(--rw-line-strong); }
.rw-range::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--rw-select); }
.rw-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%;
  background: var(--rw-bg-raised); border: 1px solid var(--rw-line-strong); box-shadow: 0 1px 3px var(--rw-shadow-color);
  transition: transform var(--rw-dur-1) var(--rw-ease);
}
.rw-range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--rw-bg-raised); border: 1px solid var(--rw-line-strong); }
.rw-range:hover::-webkit-slider-thumb { transform: scale(1.1); }
.rw-range:focus-visible { outline: none; }
.rw-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--rw-focus-ring); border-color: var(--rw-select); }

/* fields */
.rw-field { display: grid; gap: var(--rw-space-1-5); min-width: 0; }
.rw-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--rw-space-2); }
.rw-field-row--3 { grid-template-columns: 1fr 1fr 1fr; }
.rw-label { font-size: var(--rw-text-sm); font-weight: var(--rw-weight-medium); color: var(--rw-ink-2); display: flex; align-items: center; justify-content: space-between; gap: var(--rw-space-2); }
.rw-label__hint { font-weight: 400; color: var(--rw-ink-3); }
.rw-help { font-size: var(--rw-text-sm); color: var(--rw-ink-3); }

/* ---------- segmented ---------- */
.rw-seg {
  display: inline-flex; align-items: stretch; gap: 2px;
  height: var(--rw-control-h); padding: 2px;
  background: var(--rw-bg-subtle);
  border: 1px solid var(--rw-line);
  border-radius: calc(var(--rw-radius-control) + 2px);
}
.rw-seg--block { display: flex; width: 100%; }
.rw-seg--block > button { flex: 1 1 0; }
.rw-seg > button, .rw-seg__btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--rw-space-1-5);
  padding: 0 var(--rw-space-2-5, 10px); min-width: 0;
  border-radius: calc(var(--rw-radius-control) - 1px);
  color: var(--rw-ink-2); font-size: var(--rw-text-md); font-weight: var(--rw-weight-medium); white-space: nowrap;
  transition: background-color var(--rw-dur-1) var(--rw-ease), color var(--rw-dur-1) var(--rw-ease), box-shadow var(--rw-dur-1) var(--rw-ease);
}
.rw-seg > button:hover { color: var(--rw-ink); background: var(--rw-bg-hover); }
.rw-seg > button.is-active { background: var(--rw-bg-raised); color: var(--rw-ink); box-shadow: 0 0 0 1px var(--rw-line), 0 1px 2px var(--rw-shadow-color-soft); }
.rw-seg > button:focus-visible { outline: 2px solid var(--rw-select); outline-offset: -1px; }
.rw-seg > button:disabled { opacity: 0.4; }
.rw-seg__btn--icon { padding: 0; aspect-ratio: 1; }
.rw-seg--sm { height: var(--rw-control-h-sm); }
.rw-seg--sm > button { font-size: var(--rw-text-sm); padding: 0 var(--rw-space-2); }

/* ---------- chips ---------- */
.rw-chip {
  display: inline-flex; align-items: center; gap: var(--rw-space-1-5);
  height: 28px; padding: 0 var(--rw-space-2-5, 10px);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-full);
  background: var(--rw-bg); color: var(--rw-ink-2);
  font-size: var(--rw-text-sm); font-weight: var(--rw-weight-medium); white-space: nowrap;
  transition: background-color var(--rw-dur-1) var(--rw-ease), border-color var(--rw-dur-1) var(--rw-ease), color var(--rw-dur-1) var(--rw-ease);
}
.rw-chip .rw-icon { width: 14px; height: 14px; }
button.rw-chip:hover { background: var(--rw-bg-subtle); border-color: var(--rw-line-strong); color: var(--rw-ink); }
.rw-chip.is-active { background: var(--rw-primary); border-color: var(--rw-primary); color: var(--rw-on-primary); }
.rw-chip--ai { background: var(--rw-ai-tint); border-color: var(--rw-ai-line); color: var(--rw-ai-ink); }
.rw-chip--ai .rw-icon { color: var(--rw-ai); }
button.rw-chip--ai:hover { background: var(--rw-ai-tint); border-color: var(--rw-ai); color: var(--rw-ai-ink); }
.rw-chip:focus-visible { outline-offset: 1px; border-radius: var(--rw-radius-full); }

/* ---------- badges ---------- */
.rw-badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 var(--rw-space-1-5);
  border-radius: var(--rw-radius-xs);
  background: var(--rw-bg-subtle); color: var(--rw-ink-2);
  border: 1px solid var(--rw-line);
  font-size: var(--rw-text-xs); font-weight: var(--rw-weight-medium); line-height: 1; white-space: nowrap;
  vertical-align: middle; flex: none;
}
.rw-badge .rw-icon { width: 12px; height: 12px; }
.rw-badge--ai { background: var(--rw-ai-tint); color: var(--rw-ai-ink); border-color: var(--rw-ai-line); }
.rw-badge--ok { background: var(--rw-ok-tint); color: var(--rw-ok-ink); border-color: transparent; }
.rw-badge--warn { background: var(--rw-warn-tint); color: var(--rw-warn-ink); border-color: transparent; }
.rw-badge--danger { background: var(--rw-danger-tint); color: var(--rw-danger-ink); border-color: transparent; }
.rw-badge--select { background: var(--rw-select-tint); color: var(--rw-select); border-color: transparent; }
.rw-badge--pro { background: var(--rw-primary); color: var(--rw-on-primary); border-color: transparent; font-weight: var(--rw-weight-semibold); letter-spacing: 0.01em; height: 18px; padding: 0 5px; }
.rw-badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- kbd ---------- */
.rw-kbd-group { display: inline-flex; align-items: center; gap: 2px; flex: none; }
.rw-kbd {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  border: 1px solid var(--rw-kbd-line); border-radius: var(--rw-radius-xs);
  background: var(--rw-kbd-bg); color: var(--rw-ink-2);
  box-shadow: inset 0 -1px 0 var(--rw-kbd-line);
  font-family: var(--rw-font); font-size: var(--rw-text-xs); font-weight: var(--rw-weight-medium); line-height: 1;
}

/* ---------- cards ---------- */
.rw-card {
  display: block; position: relative;
  background: var(--rw-bg-raised);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-card);
  box-shadow: inset 0 1px 0 var(--rw-highlight);
  text-align: left; color: var(--rw-ink);
}
.rw-card--interactive { cursor: pointer; transition: border-color var(--rw-dur-1) var(--rw-ease), box-shadow var(--rw-dur-2) var(--rw-ease), transform var(--rw-dur-2) var(--rw-ease); }
.rw-card--interactive:hover { border-color: var(--rw-line-strong); box-shadow: var(--rw-shadow-sm), inset 0 1px 0 var(--rw-highlight); }
.rw-card--interactive:active { transform: translateY(0.5px); }
.rw-card--interactive:focus-visible { outline: none; border-color: var(--rw-select); box-shadow: 0 0 0 3px var(--rw-focus-ring); }
.rw-card.is-active { border-color: var(--rw-select); box-shadow: 0 0 0 1px var(--rw-select); }
.rw-card--ai { background: var(--rw-ai-tint); border-color: var(--rw-ai-line); }

/* ---------- sections ---------- */
.rw-section { padding: var(--rw-space-4); border-bottom: 1px solid var(--rw-line); }
.rw-section:last-child { border-bottom: 0; }
.rw-section--flush { padding-left: 0; padding-right: 0; }
.rw-section__header { display: flex; align-items: center; justify-content: space-between; gap: var(--rw-space-2); min-height: 24px; margin-bottom: var(--rw-space-3); }
.rw-section__title { font-size: var(--rw-text-md); font-weight: var(--rw-weight-semibold); color: var(--rw-ink); display: flex; align-items: baseline; gap: var(--rw-space-2); min-width: 0; }
.rw-section__hint { font-size: var(--rw-text-sm); font-weight: 400; color: var(--rw-ink-3); }
.rw-section__actions { display: flex; align-items: center; gap: var(--rw-space-1); margin-right: calc(-1 * var(--rw-space-1)); }
.rw-section__body { display: grid; gap: var(--rw-space-3); min-width: 0; }
.rw-panel-title { font-size: var(--rw-text-lg); font-weight: var(--rw-weight-semibold); letter-spacing: -0.005em; }

/* ---------- lists ---------- */
.rw-list { display: grid; gap: 1px; }
.rw-list__row {
  display: flex; align-items: center; gap: var(--rw-space-2);
  min-height: 32px; padding: var(--rw-space-1) var(--rw-space-2);
  border-radius: var(--rw-radius-control);
  color: var(--rw-ink); text-align: left; width: 100%;
  transition: background-color var(--rw-dur-1) var(--rw-ease);
}
.rw-list__row .rw-icon { color: var(--rw-ink-3); }
button.rw-list__row:hover, .rw-list__row--interactive:hover { background: var(--rw-bg-hover); cursor: pointer; }
.rw-list__row.is-active, .rw-list__row.is-selected { background: var(--rw-select-tint); }
.rw-list__row.is-active .rw-icon, .rw-list__row.is-selected .rw-icon { color: var(--rw-select); }
.rw-list__row:focus-visible { outline-offset: -2px; }
.rw-list__meta { margin-left: auto; color: var(--rw-ink-3); font-size: var(--rw-text-sm); flex: none; }

/* ---------- swatches ---------- */
.rw-swatches { display: flex; flex-wrap: wrap; gap: var(--rw-space-1-5); }
.rw-swatch {
  position: relative; width: 24px; height: 24px; flex: none;
  border-radius: var(--rw-radius-sm);
  background-color: var(--swatch, var(--rw-bg-subtle)); background-size: cover; background-position: center;
  box-shadow: inset 0 0 0 1px var(--rw-line-strong);
  transition: transform var(--rw-dur-1) var(--rw-ease), box-shadow var(--rw-dur-1) var(--rw-ease);
}
.rw-swatches--lg .rw-swatch { width: 32px; height: 32px; border-radius: var(--rw-radius-md); }
.rw-swatch:hover { transform: translateY(-1px); }
.rw-swatch.is-active { box-shadow: inset 0 0 0 1px var(--rw-line-strong), 0 0 0 2px var(--rw-bg), 0 0 0 4px var(--rw-select); }
.rw-swatch:focus-visible { outline: none; box-shadow: inset 0 0 0 1px var(--rw-line-strong), 0 0 0 2px var(--rw-bg), 0 0 0 4px var(--rw-focus-ring); }

/* ---------- divider ---------- */
.rw-divider { height: 1px; background: var(--rw-line); border: 0; margin: var(--rw-space-2) 0; flex: none; }
.rw-divider--v { width: 1px; height: 20px; margin: 0 var(--rw-space-1); }

/* ---------- empty state ---------- */
.rw-empty { display: grid; justify-items: center; text-align: center; gap: var(--rw-space-1-5); padding: var(--rw-space-8) var(--rw-space-6); color: var(--rw-ink-2); }
.rw-empty--compact { padding: var(--rw-space-5) var(--rw-space-4); }
.rw-empty__icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--rw-radius-lg); background: var(--rw-bg-subtle); border: 1px solid var(--rw-line); color: var(--rw-ink-2); margin-bottom: var(--rw-space-1-5); }
.rw-empty__icon--ai { background: var(--rw-ai-tint); border-color: var(--rw-ai-line); color: var(--rw-ai); }
.rw-empty__title { font-weight: var(--rw-weight-semibold); color: var(--rw-ink); }
.rw-empty__text { font-size: var(--rw-text-sm); max-width: 260px; }
.rw-empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--rw-space-2); margin-top: var(--rw-space-2); }

/* ---------- skeleton ---------- */
.rw-skeleton {
  display: block; border-radius: var(--rw-radius-sm); min-height: 12px;
  background: linear-gradient(90deg, var(--rw-skeleton) 0%, var(--rw-skeleton-hi) 40%, var(--rw-skeleton) 80%);
  background-size: 300% 100%;
  animation: rw-shimmer 1.4s ease-in-out infinite;
}

/* ---------- progress ---------- */
.rw-progress { position: relative; height: 4px; border-radius: var(--rw-radius-full); background: var(--rw-bg-subtle); box-shadow: inset 0 0 0 1px var(--rw-line); overflow: hidden; }
.rw-progress__bar { height: 100%; width: 0; border-radius: inherit; background: var(--rw-select); transition: width var(--rw-dur-3) var(--rw-ease); }
.rw-progress--ai .rw-progress__bar { background: var(--rw-ai); }
.rw-progress--indeterminate .rw-progress__bar { width: 36%; animation: rw-indeterminate 1.3s var(--rw-ease) infinite; }

/* ---------- steps ---------- */
.rw-steps { display: grid; gap: 0; counter-reset: rw-step; }
.rw-steps > li, .rw-steps__item {
  position: relative; display: grid; grid-template-columns: 20px 1fr; gap: var(--rw-space-2);
  padding: 0 0 var(--rw-space-3) 0; color: var(--rw-ink-3); font-size: var(--rw-text-sm);
}
.rw-steps > li:last-child, .rw-steps__item:last-child { padding-bottom: 0; }
.rw-steps > li::before, .rw-steps__item::before {
  content: ""; width: 16px; height: 16px; margin: 1px 2px 0;
  border-radius: 50%; border: 1.5px solid var(--rw-line-strong); background: var(--rw-bg);
  box-sizing: border-box; z-index: 1;
}
.rw-steps > li::after, .rw-steps__item::after {
  content: ""; position: absolute; left: 9.25px; top: 19px; bottom: 1px; width: 1.5px; background: var(--rw-line);
}
.rw-steps > li:last-child::after, .rw-steps__item:last-child::after { display: none; }
.rw-steps .is-done { color: var(--rw-ink-2); }
.rw-steps .is-done::before { border-color: var(--rw-ok); background: var(--rw-ok); box-shadow: inset 0 0 0 3px var(--rw-bg); }
.rw-steps .is-done::after { background: var(--rw-ok); opacity: 0.4; }
.rw-steps .is-active { color: var(--rw-ink); font-weight: var(--rw-weight-medium); }
.rw-steps .is-active::before { border-color: var(--rw-ai) var(--rw-ai-line) var(--rw-ai-line) var(--rw-ai-line); border-width: 2px; animation: rw-spin 800ms linear infinite; }
.rw-steps .is-error { color: var(--rw-danger-ink); }
.rw-steps .is-error::before { border-color: var(--rw-danger); }

/* ---------- floating surfaces ---------- */
.rw-float {
  display: inline-flex; align-items: center; gap: 2px;
  padding: var(--rw-space-1);
  background: var(--rw-bg-raised);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-lg);
  box-shadow: var(--rw-shadow-float), inset 0 1px 0 var(--rw-highlight);
  pointer-events: auto;
}
.rw-float .rw-divider--v { height: 20px; margin: 0 2px; }
.rw-float--ai { border-color: var(--rw-ai-line); }

/* ---------- menu ---------- */
.rw-menu {
  position: fixed; min-width: 216px; max-width: 320px; max-height: min(480px, calc(100vh - 24px));
  overflow-y: auto; overscroll-behavior: contain;
  padding: var(--rw-space-1);
  background: var(--rw-bg-raised);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-lg);
  box-shadow: var(--rw-shadow-float), inset 0 1px 0 var(--rw-highlight);
  animation: rw-pop var(--rw-dur-2) var(--rw-ease-out);
  transform-origin: var(--rw-origin, top left);
}
.rw-menu__item {
  display: flex; align-items: center; gap: var(--rw-space-2);
  width: 100%; min-height: 32px; padding: 0 var(--rw-space-2);
  border-radius: var(--rw-radius-sm);
  color: var(--rw-ink); text-align: left; font-size: var(--rw-text-md);
}
.rw-menu__item .rw-icon { color: var(--rw-ink-2); width: 16px; height: 16px; }
.rw-menu__item:hover, .rw-menu__item.is-focused, .rw-menu__item:focus-visible { background: var(--rw-bg-hover); outline: none; }
.rw-menu__item:disabled, .rw-menu__item[aria-disabled="true"] { color: var(--rw-ink-3); background: none; cursor: default; }
.rw-menu__item:disabled .rw-icon { color: var(--rw-ink-3); }
.rw-menu__item--danger, .rw-menu__item--danger .rw-icon { color: var(--rw-danger-ink); }
.rw-menu__item--danger:hover, .rw-menu__item--danger.is-focused { background: var(--rw-danger-tint); }
.rw-menu__item--ai .rw-icon { color: var(--rw-ai); }
.rw-menu__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rw-menu__hint { color: var(--rw-ink-3); font-size: var(--rw-text-sm); flex: none; }
.rw-menu__shortcut { margin-left: auto; padding-left: var(--rw-space-4); color: var(--rw-ink-3); font-size: var(--rw-text-sm); flex: none; letter-spacing: 0.02em; }
.rw-menu__check { width: 16px; height: 16px; flex: none; display: grid; place-items: center; color: var(--rw-select); }
.rw-menu__check .rw-icon { color: var(--rw-select); }
.rw-menu__swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px var(--rw-shadow-color); }
.rw-menu__sep { height: 1px; background: var(--rw-line); margin: var(--rw-space-1) calc(-1 * var(--rw-space-1)); }
.rw-menu__heading { padding: var(--rw-space-2) var(--rw-space-2) var(--rw-space-1); font-size: var(--rw-text-xs); font-weight: var(--rw-weight-medium); color: var(--rw-ink-3); }
.rw-menu__header { display: grid; gap: 2px; padding: var(--rw-space-2) var(--rw-space-2) var(--rw-space-2); }
.rw-menu__header strong { font-weight: var(--rw-weight-semibold); }
.rw-menu__header span { color: var(--rw-ink-3); font-size: var(--rw-text-sm); }

/* ---------- modal ---------- */
.rw-modal-layer {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: var(--rw-space-6);
  background: var(--rw-scrim);
  animation: rw-fade var(--rw-dur-2) var(--rw-ease);
  overflow-y: auto;
}
.rw-modal-layer.is-closing { animation: rw-fade-out var(--rw-dur-1) var(--rw-ease) forwards; }
.rw-modal {
  position: relative;
  width: 100%; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: var(--rw-bg-raised);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-modal);
  box-shadow: var(--rw-shadow-modal), inset 0 1px 0 var(--rw-highlight);
  animation: rw-modal-in var(--rw-dur-3) var(--rw-ease-out);
  overflow: hidden;
}
.rw-modal-layer.is-closing .rw-modal { animation: rw-modal-out var(--rw-dur-1) var(--rw-ease) forwards; }
.rw-modal--sm { max-width: 420px; }
.rw-modal--md { max-width: 560px; }
.rw-modal--lg { max-width: 760px; }
.rw-modal--xl { max-width: 980px; }
.rw-modal__header { display: flex; align-items: flex-start; gap: var(--rw-space-3); padding: var(--rw-space-5) var(--rw-space-5) var(--rw-space-4) var(--rw-space-6); flex: none; }
.rw-modal__heading { flex: 1 1 auto; min-width: 0; display: grid; gap: var(--rw-space-1); padding-top: 2px; }
.rw-modal__title { font-size: var(--rw-text-xl); font-weight: var(--rw-weight-semibold); letter-spacing: -0.01em; line-height: 1.3; }
.rw-modal__subtitle { color: var(--rw-ink-2); }
.rw-modal__close { margin-top: -2px; }
.rw-modal__body { padding: 0 var(--rw-space-6) var(--rw-space-6); overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.rw-modal__footer {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--rw-space-2);
  padding: var(--rw-space-3) var(--rw-space-5) var(--rw-space-3) var(--rw-space-6);
  border-top: 1px solid var(--rw-line);
  background: var(--rw-bg-subtle);
  flex: none;
}
.rw-modal__footer-start { margin-right: auto; display: flex; align-items: center; gap: var(--rw-space-2); color: var(--rw-ink-3); font-size: var(--rw-text-sm); }
.rw-modal--sm .rw-modal__title { font-size: var(--rw-text-lg); }
.rw-modal--sm .rw-modal__body { color: var(--rw-ink-2); }
.rw-modal--bare .rw-modal__header { position: absolute; right: 0; top: 0; padding: var(--rw-space-4); z-index: 2; }
.rw-modal--bare .rw-modal__body { padding: 0; }

/* ---------- toast ---------- */
#toast-root { display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-start; gap: var(--rw-space-2); padding: 0 var(--rw-space-4) calc(var(--rw-status-h) + var(--rw-space-4)); }
.rw-toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--rw-space-2-5, 10px);
  min-height: 44px; max-width: min(480px, calc(100vw - 32px));
  padding: var(--rw-space-1-5) var(--rw-space-1-5) var(--rw-space-1-5) var(--rw-space-3);
  background: var(--rw-bg-raised); color: var(--rw-ink);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-lg);
  box-shadow: var(--rw-shadow-float), inset 0 1px 0 var(--rw-highlight);
  animation: rw-toast-in var(--rw-dur-3) var(--rw-ease-out);
}
.rw-toast.is-leaving { animation: rw-toast-out var(--rw-dur-2) var(--rw-ease) forwards; }
.rw-toast__icon { flex: none; display: grid; place-items: center; width: 20px; height: 20px; color: var(--rw-ink-2); }
.rw-toast--success .rw-toast__icon { color: var(--rw-ok); }
.rw-toast--warn .rw-toast__icon { color: var(--rw-warn); }
.rw-toast--error .rw-toast__icon { color: var(--rw-danger); }
.rw-toast--ai .rw-toast__icon { color: var(--rw-ai); }
.rw-toast--ai { border-color: var(--rw-ai-line); }
.rw-toast__msg { flex: 1 1 auto; min-width: 0; padding: var(--rw-space-1) 0; }
.rw-toast__actions { display: flex; align-items: center; gap: 2px; flex: none; }
.rw-toast__action { color: var(--rw-select); font-weight: var(--rw-weight-semibold); }
.rw-toast__action:hover { color: var(--rw-select-hover); }

/* ---------- tabs ---------- */
.rw-tabs { display: flex; align-items: stretch; gap: var(--rw-space-4); height: 40px; border-bottom: 1px solid var(--rw-line); min-width: 0; }
.rw-tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--rw-space-1-5);
  height: 40px; padding: 0 2px;
  color: var(--rw-ink-3); font-weight: var(--rw-weight-medium); white-space: nowrap;
  transition: color var(--rw-dur-1) var(--rw-ease);
}
.rw-tab .rw-icon { width: 16px; height: 16px; }
.rw-tab:hover { color: var(--rw-ink); }
.rw-tab.is-active { color: var(--rw-ink); }
.rw-tab::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: transparent; transition: background-color var(--rw-dur-2) var(--rw-ease); }
.rw-tab.is-active::after { background: var(--rw-ink); }
.rw-tab:focus-visible { outline-offset: -2px; }

/* ---------- tooltip ---------- */
.rw-tooltip {
  position: fixed; left: 0; top: 0; z-index: var(--rw-z-tooltip);
  display: inline-flex; flex-direction: column; gap: 2px;
  max-width: 280px; padding: 5px var(--rw-space-2);
  background: var(--rw-tooltip-bg); color: var(--rw-tooltip-ink);
  border: 1px solid var(--rw-tooltip-line); border-radius: var(--rw-radius-sm);
  box-shadow: 0 4px 14px var(--rw-shadow-color);
  font-size: var(--rw-text-sm); font-weight: var(--rw-weight-medium); line-height: 1.35;
  pointer-events: none;
  animation: rw-tip-in var(--rw-dur-1) var(--rw-ease-out);
}
.rw-tooltip__row { display: inline-flex; align-items: center; gap: var(--rw-space-2); }
.rw-tooltip__sub { color: var(--rw-tooltip-ink-2); font-weight: 400; font-size: var(--rw-text-xs); }
.rw-tooltip .rw-kbd { background: transparent; color: var(--rw-tooltip-ink-2); border-color: var(--rw-tooltip-ink-2); box-shadow: none; opacity: 0.85; min-width: 16px; height: 16px; font-size: 10.5px; }

/* =========================================================================================
   4. Shell dialogs and palette
   ========================================================================================= */

/* ---------- command palette ---------- */
.rw-palette-layer {
  position: fixed; inset: 0;
  display: flex; justify-content: center; align-items: flex-start;
  padding: min(14vh, 120px) var(--rw-space-4) var(--rw-space-4);
  background: var(--rw-scrim);
  animation: rw-fade var(--rw-dur-2) var(--rw-ease);
}
.rw-palette-layer.is-closing { animation: rw-fade-out var(--rw-dur-1) var(--rw-ease) forwards; }
.rw-palette {
  width: min(640px, 100%);
  display: flex; flex-direction: column; max-height: min(520px, calc(100vh - 2 * min(14vh, 120px)));
  background: var(--rw-bg-raised);
  border: 1px solid var(--rw-line); border-radius: var(--rw-radius-xl);
  box-shadow: var(--rw-shadow-modal), inset 0 1px 0 var(--rw-highlight);
  overflow: hidden;
  animation: rw-modal-in var(--rw-dur-3) var(--rw-ease-out);
}
.rw-palette__search { display: flex; align-items: center; gap: var(--rw-space-2-5, 10px); height: 52px; padding: 0 var(--rw-space-4); border-bottom: 1px solid var(--rw-line); flex: none; }
.rw-palette__search .rw-icon { color: var(--rw-ink-3); }
.rw-palette__input { flex: 1 1 auto; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; font-size: 15px; }
.rw-palette__list { flex: 1 1 auto; overflow-y: auto; padding: var(--rw-space-1) var(--rw-space-2) var(--rw-space-2); overscroll-behavior: contain; scroll-padding: 32px 0 8px; }
.rw-palette__group { padding: var(--rw-space-2-5, 10px) var(--rw-space-2) var(--rw-space-1); font-size: var(--rw-text-xs); font-weight: var(--rw-weight-medium); color: var(--rw-ink-3); }
.rw-palette__item {
  display: flex; align-items: center; gap: var(--rw-space-2-5, 10px);
  height: 36px; padding: 0 var(--rw-space-2);
  border-radius: var(--rw-radius-md); cursor: pointer;
  color: var(--rw-ink);
}
.rw-palette__item.is-active { background: var(--rw-bg-active); }
.rw-palette__icon { width: 24px; height: 24px; display: grid; place-items: center; flex: none; border-radius: var(--rw-radius-sm); color: var(--rw-ink-2); }
.rw-palette__item--ai .rw-palette__icon { background: var(--rw-ai-tint); color: var(--rw-ai); box-shadow: inset 0 0 0 1px var(--rw-ai-line); }
.rw-palette__item--ai .rw-palette__title b { color: var(--rw-ai-ink); }
.rw-palette__thumb { width: 24px; height: 24px; border-radius: var(--rw-radius-xs); background: var(--cv-furn-fill); box-shadow: inset 0 0 0 1px var(--rw-line); flex: none; object-fit: contain; }
.rw-palette__swatch { width: 12px; height: 12px; border-radius: 3px; box-shadow: inset 0 0 0 1px var(--rw-shadow-color); }
.rw-palette__title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rw-palette__title mark { background: none; color: inherit; font-weight: var(--rw-weight-semibold); text-decoration: underline; text-decoration-color: var(--rw-line-strong); text-underline-offset: 3px; }
.rw-palette__hint { color: var(--rw-ink-3); font-size: var(--rw-text-sm); flex: none; white-space: nowrap; }
.rw-palette__empty { padding: var(--rw-space-8) var(--rw-space-4); text-align: center; color: var(--rw-ink-3); }
.rw-palette__footer { display: flex; align-items: center; gap: var(--rw-space-4); height: 36px; padding: 0 var(--rw-space-4); border-top: 1px solid var(--rw-line); background: var(--rw-bg-subtle); color: var(--rw-ink-3); font-size: var(--rw-text-xs); flex: none; }
.rw-palette__footer span { display: inline-flex; align-items: center; gap: var(--rw-space-1-5); }
.rw-palette__footer .rw-kbd { height: 16px; min-width: 16px; font-size: 10.5px; }
.rw-palette__footer .rw-badge { margin-left: auto; }

/* ---------- start dialog ---------- */
.rw-start { padding: var(--rw-space-8) var(--rw-space-8) var(--rw-space-6); }
.rw-start__step { font-size: var(--rw-text-sm); color: var(--rw-ink-3); font-weight: var(--rw-weight-medium); margin-bottom: var(--rw-space-2); display: flex; align-items: center; gap: var(--rw-space-2); }
.rw-start__headline { font-size: var(--rw-text-2xl); font-weight: var(--rw-weight-semibold); letter-spacing: -0.02em; line-height: 1.2; }
.rw-start__lede { color: var(--rw-ink-2); font-size: 14px; margin-top: var(--rw-space-2); max-width: 560px; }
.rw-start__types { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--rw-space-3); margin-top: var(--rw-space-6); }
.rw-type-card { display: grid; align-content: start; gap: var(--rw-space-1); padding: var(--rw-space-3) var(--rw-space-3) var(--rw-space-4); }
.rw-type-card__art {
  height: 96px; border-radius: var(--rw-radius-md); margin-bottom: var(--rw-space-2);
  display: grid; place-items: center; color: var(--cv-ink);
  background: var(--tint, var(--rw-bg-subtle));
  background-image: linear-gradient(var(--cv-grid) 1px, transparent 1px), linear-gradient(90deg, var(--cv-grid) 1px, transparent 1px);
  background-size: 12px 12px; background-position: -1px -1px;
  box-shadow: inset 0 0 0 1px var(--rw-line);
}
.rw-type-card__art .rw-type-card__glyph { width: 52px; height: 52px; border-radius: var(--rw-radius-lg); display: grid; place-items: center; background: var(--tint); box-shadow: 0 0 0 1px var(--rw-line), var(--rw-shadow-sm); }
.rw-type-card__title { font-weight: var(--rw-weight-semibold); }
.rw-type-card__text { font-size: var(--rw-text-sm); color: var(--rw-ink-2); }
.rw-start__how { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--rw-space-3); margin-top: var(--rw-space-6); }
.rw-how-ai { padding: var(--rw-space-5); display: grid; gap: var(--rw-space-3); align-content: start; cursor: default; min-width: 0; }
.rw-how-ai__head { display: flex; align-items: center; gap: var(--rw-space-2-5, 10px); }
.rw-how-ai__icon { width: 36px; height: 36px; border-radius: var(--rw-radius-md); display: grid; place-items: center; background: var(--rw-ai); color: var(--rw-on-ai); flex: none; }
.rw-how-ai__title { font-size: var(--rw-text-lg); font-weight: var(--rw-weight-semibold); }
.rw-how-ai__text { color: var(--rw-ink-2); }
.rw-how-ai .rw-textarea { min-height: 96px; background: var(--rw-bg-raised); border-color: var(--rw-ai-line); }
.rw-how-ai .rw-textarea:focus { border-color: var(--rw-ai); box-shadow: 0 0 0 3px var(--rw-ai-tint); }
.rw-how-ai__chips { display: flex; flex-wrap: wrap; gap: var(--rw-space-1-5); }
.rw-how-ai__foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--rw-space-2); }
.rw-how-list { display: grid; gap: var(--rw-space-3); align-content: start; min-width: 0; }
.rw-how-option { display: grid; grid-template-columns: 40px 1fr 16px; align-items: center; gap: var(--rw-space-3); padding: var(--rw-space-4); }
.rw-how-option__icon { width: 40px; height: 40px; border-radius: var(--rw-radius-md); display: grid; place-items: center; background: var(--rw-bg-subtle); border: 1px solid var(--rw-line); color: var(--rw-ink-2); }
.rw-how-option__title { font-weight: var(--rw-weight-semibold); }
.rw-how-option__text { font-size: var(--rw-text-sm); color: var(--rw-ink-2); }
.rw-how-option > .rw-icon { color: var(--rw-ink-3); transition: transform var(--rw-dur-2) var(--rw-ease); }
.rw-how-option:hover > .rw-icon { transform: translateX(2px); color: var(--rw-ink-2); }
.rw-start__templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); gap: var(--rw-space-3); margin-top: var(--rw-space-6); }
.rw-tpl-card { overflow: hidden; display: grid; }
.rw-tpl-card__thumb { aspect-ratio: 4 / 3; background: var(--cv-bg); border-bottom: 1px solid var(--rw-line); display: grid; place-items: center; overflow: hidden; color: var(--rw-ink-3); }
.rw-tpl-card__thumb img { width: 100%; height: 100%; object-fit: contain; }
.rw-tpl-card__body { padding: var(--rw-space-3); display: grid; gap: 2px; }
.rw-tpl-card__title { font-weight: var(--rw-weight-semibold); display: flex; align-items: center; gap: var(--rw-space-2); }
.rw-tpl-card__meta { font-size: var(--rw-text-sm); color: var(--rw-ink-3); }

/* ---------- export dialog ---------- */
.rw-export { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--rw-space-5); }
.rw-export__figure { display: grid; gap: var(--rw-space-2); align-content: start; min-width: 0; }
.rw-export__preview {
  position: relative; aspect-ratio: 1.414 / 1; width: 100%; max-height: 520px; border-radius: var(--rw-radius-lg); overflow: hidden;
  background: var(--rw-bg-subtle); border: 1px solid var(--rw-line);
  display: grid; place-items: center;
}
.rw-export__preview img { width: 100%; height: 100%; object-fit: contain; display: block; }
.rw-export__preview .rw-skeleton { position: absolute; inset: 0; border-radius: 0; }
.rw-export__caption { justify-self: start; }
.rw-export__rows { display: grid; gap: var(--rw-space-2); align-content: start; }
.rw-export-row { padding: var(--rw-space-3) var(--rw-space-4); display: grid; gap: var(--rw-space-2-5, 10px); }
.rw-export-row__head { display: grid; grid-template-columns: 32px 1fr auto; gap: var(--rw-space-3); align-items: center; }
.rw-export-row__icon { width: 32px; height: 32px; border-radius: var(--rw-radius-md); display: grid; place-items: center; background: var(--rw-bg-subtle); border: 1px solid var(--rw-line); color: var(--rw-ink-2); }
.rw-export-row__title { font-weight: var(--rw-weight-semibold); display: flex; align-items: center; gap: var(--rw-space-2); }
.rw-export-row__text { font-size: var(--rw-text-sm); color: var(--rw-ink-3); }
.rw-export-row__controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--rw-space-2); padding-left: 44px; }
.rw-export-row__controls .rw-select { width: auto; }

/* ---------- share dialog ---------- */
.rw-share { display: grid; gap: var(--rw-space-4); }
.rw-share__link { display: flex; gap: var(--rw-space-2); }
.rw-share__link .rw-input { font-family: var(--rw-font-mono); font-size: var(--rw-text-sm); }
.rw-share__access { display: grid; grid-template-columns: 36px 1fr auto; gap: var(--rw-space-3); align-items: center; }
.rw-share__access-icon { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--rw-bg-subtle); border: 1px solid var(--rw-line); color: var(--rw-ink-2); }
.rw-callout { display: grid; grid-template-columns: 20px 1fr; gap: var(--rw-space-2-5, 10px); padding: var(--rw-space-3); border-radius: var(--rw-radius-md); background: var(--rw-bg-subtle); border: 1px solid var(--rw-line); color: var(--rw-ink-2); font-size: var(--rw-text-sm); }
.rw-callout > .rw-icon { color: var(--rw-ink-3); margin-top: 1px; }
.rw-callout strong { color: var(--rw-ink); font-weight: var(--rw-weight-semibold); }
.rw-callout__actions { display: flex; gap: var(--rw-space-2); margin-top: var(--rw-space-2); }
.rw-callout--ai { background: var(--rw-ai-tint); border-color: var(--rw-ai-line); }
.rw-callout--ai > .rw-icon { color: var(--rw-ai); }

/* ---------- shortcuts sheet ---------- */
.rw-shortcuts { columns: 2 300px; column-gap: var(--rw-space-8); }
.rw-shortcuts__group { break-inside: avoid; margin-bottom: var(--rw-space-5); }
.rw-shortcuts__title { font-size: var(--rw-text-sm); font-weight: var(--rw-weight-semibold); color: var(--rw-ink); padding-bottom: var(--rw-space-1-5); margin-bottom: var(--rw-space-1); border-bottom: 1px solid var(--rw-line); }
.rw-shortcuts__row { display: flex; align-items: center; justify-content: space-between; gap: var(--rw-space-3); min-height: 30px; color: var(--rw-ink-2); }
.rw-shortcuts__keys { display: inline-flex; align-items: center; gap: var(--rw-space-1-5); color: var(--rw-ink-3); font-size: var(--rw-text-xs); }
.rw-shortcuts__search { margin-bottom: var(--rw-space-5); max-width: 320px; }
/* the list scrolls: fade its bottom edge and leave room so the last row never sits sliced against the border */
.rw-modal--shortcuts .rw-modal__body { padding-bottom: var(--rw-space-6); -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 28px), transparent); }
.rw-modal--shortcuts .rw-shortcuts { padding-bottom: var(--rw-space-6); }

/* =========================================================================================
   5. Motion
   ========================================================================================= */
@keyframes rw-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rw-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes rw-pop { from { opacity: 0; transform: scale(0.97) translateY(-2px); } to { opacity: 1; transform: none; } }
@keyframes rw-modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes rw-modal-out { to { opacity: 0; transform: translateY(4px) scale(0.99); } }
@keyframes rw-toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes rw-toast-out { to { opacity: 0; transform: translateY(4px) scale(0.98); } }
@keyframes rw-tip-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rw-spin { to { transform: rotate(360deg); } }
@keyframes rw-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes rw-indeterminate { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@keyframes rw-slide-left { from { transform: translateX(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rw-slide-right { from { transform: translateX(12px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rw-sheet-up { from { transform: translateY(24px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes rw-step-in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }
.rw-step-enter { animation: rw-step-in var(--rw-dur-3) var(--rw-ease-out); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
  .rw-skeleton { animation: none; }
  .rw-steps .is-active::before, .rw-savestate[data-state="saving"] .rw-icon { animation: none; }
}

/* =========================================================================================
   6. Responsive
   ========================================================================================= */

/* Top bar compaction on smaller desktops */
@media (max-width: 1379px) {
  .rw-topbar [data-collapse="label"] .rw-btn__label { display: none; }
  .rw-topbar [data-collapse="label"] { width: var(--rw-control-h); padding: 0; }
  .rw-zoom .rw-zoom__step { display: none; }
}
@media (max-width: 1279px) {
  .rw-level { display: none; }
  .rw-brand__name { display: none; }
  .rw-topbar__slash { display: none; }
}

/* 900-1199: drawer overlays the canvas, panel 300 px */
@media (max-width: 1199px) {
  :root { --rw-panel-w: 300px; }
  .rw-drawer {
    grid-area: auto;
    position: absolute; left: var(--rw-rail-w); top: var(--rw-topbar-h); bottom: var(--rw-status-h);
    z-index: var(--rw-z-drawer-overlay);
    box-shadow: var(--rw-shadow-float);
    animation: rw-slide-left var(--rw-dur-3) var(--rw-ease-out);
  }
  .rw-savestate__text { display: none; }
}

/* 600-899: panel becomes an overlay sheet from the right */
@media (max-width: 899px) {
  :root { --rw-panel-w: 340px; }
  .rw-sidepanel {
    grid-area: auto;
    position: absolute; right: 0; top: var(--rw-topbar-h); bottom: var(--rw-status-h);
    width: min(var(--rw-panel-w), calc(100vw - var(--rw-rail-w) - 16px));
    z-index: var(--rw-z-panel-overlay);
    box-shadow: var(--rw-shadow-float);
    animation: rw-slide-right var(--rw-dur-3) var(--rw-ease-out);
  }
  .rw-topbar { gap: var(--rw-space-2); }
  .rw-topbar [data-collapse="phone-label"] .rw-btn__label { display: none; }
  .rw-topbar [data-collapse="phone-label"] { width: var(--rw-control-h); padding: 0; }
  .rw-viewswitch .rw-seg__btn { min-width: 0; }
  .rw-viewswitch .rw-seg__btn span { display: none; }
  .rw-viewswitch .rw-seg__btn { width: 36px; padding: 0; }
  .rw-docname__title { max-width: none; } /* no fixed cap: the name shrinks (with an ellipsis) only when the bar runs out of room */
  .rw-zoom { display: none; }
  .rw-status__totals, .rw-status__sep--totals { display: none; }
  .rw-status__coords, .rw-status__coords + .rw-status__sep { display: none; }
  .rw-status__item[data-snap] span { display: none; }
  .rw-start__types { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rw-start__how { grid-template-columns: 1fr; }
  .rw-export { grid-template-columns: 1fr; }
}

@media (max-width: 759px) {
  .rw-hide-sm { display: none !important; }
  .rw-status__coords { min-width: 0; }
}

/* <600: compact top bar, bottom tool bar, bottom sheets, no status bar */
@media (max-width: 599px) {
  :root { --rw-topbar-h: 52px; }
  .rw-app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--rw-topbar-h) minmax(0, 1fr) var(--rw-bottombar-h);
    grid-template-areas: "top" "view" "rail";
  }
  .rw-statusbar { display: none; }
  .rw-only-phone { display: inline-flex !important; }
  .rw-hide-phone { display: none !important; }
  .rw-topbar { grid-template-columns: minmax(0, 1fr) auto auto; padding: 0 var(--rw-space-2); gap: var(--rw-space-2); }
  .rw-topbar__start { gap: var(--rw-space-1); }
  .rw-docname__title { max-width: 128px; }
  .rw-savestate { display: none; }

  .rw-rail {
    flex-direction: row; justify-content: flex-start;
    padding: 0 var(--rw-space-2); gap: var(--rw-space-1);
    border-right: 0; border-top: 1px solid var(--rw-line);
    overflow-x: auto; overflow-y: hidden;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .rw-rail__group { flex-direction: row; }
  .rw-rail__divider { width: 1px; height: 24px; margin: 0 var(--rw-space-1); }
  .rw-rail__spacer { display: none; }
  .rw-tool { width: 44px; height: 44px; }

  .rw-drawer, .rw-sidepanel {
    position: fixed; left: 0; right: 0; top: auto; bottom: 0;
    /* opens at about half height so the plan stays in view above it; the grabber toggles the tall size */
    width: auto; height: min(52vh, 52dvh); max-height: 75vh;
    transition: height var(--rw-dur-2, 160ms) var(--rw-ease-out);
    border: 1px solid var(--rw-line); border-bottom: 0;
    border-radius: var(--rw-radius-xl) var(--rw-radius-xl) 0 0;
    z-index: var(--rw-z-sheet);
    box-shadow: var(--rw-shadow-modal);
    background: var(--rw-bg-raised);
    animation: rw-sheet-up var(--rw-dur-3) var(--rw-ease-out);
  }
  .rw-drawer.is-expanded, .rw-sidepanel.is-expanded { height: min(75vh, 75dvh); }
  .rw-sheet-grabber { display: block; height: 20px; flex: none; position: relative; cursor: grab; touch-action: none; }
  .rw-sheet-grabber::before { content: ""; position: absolute; left: 50%; top: 6px; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--rw-line-strong); }
  .rw-pane-header { height: 40px; }
  .rw-pane-header .rw-tabs, .rw-pane-header .rw-tab { height: 40px; }

  .rw-viewport[data-view="split"] #plan-host { right: 0; bottom: 50%; }
  .rw-viewport[data-view="split"] #view3d-host { left: 0; top: calc(50% + 1px); }
  .rw-viewport[data-view="split"] .rw-split-divider { left: 0; right: 0; top: 50%; bottom: auto; width: auto; height: 1px; }
  .rw-viewport[data-view="split"] .rw-split-divider::before, .rw-viewport[data-view="split"] .rw-split-divider::after { display: none; }

  #toast-root { padding-bottom: calc(var(--rw-bottombar-h) + var(--rw-space-3)); }
  .rw-modal-layer { padding: var(--rw-space-3); align-items: end; }
  .rw-modal { max-height: calc(100vh - 24px); }
  .rw-modal__header { padding: var(--rw-space-4) var(--rw-space-3) var(--rw-space-3) var(--rw-space-4); }
  .rw-modal__body { padding: 0 var(--rw-space-4) var(--rw-space-4); }
  .rw-modal__footer { padding: var(--rw-space-3) var(--rw-space-4); flex-wrap: wrap; }
  .rw-start { padding: var(--rw-space-6) var(--rw-space-4) var(--rw-space-4); }
  .rw-start__headline { font-size: 22px; }
  .rw-how-ai { padding: var(--rw-space-4); }
  .rw-how-option { padding: var(--rw-space-3); }
  .rw-start__types { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rw-type-card__art { height: 72px; }
  .rw-palette-layer { padding-top: var(--rw-space-3); }
  .rw-canvas-empty { padding: var(--rw-space-5) var(--rw-space-4) var(--rw-space-4); }
}

/* Chip rows that scroll sideways fade at the end that hides more chips (data-fade is set by the shell) */
[data-fade="r"] { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); }
[data-fade="l"] { -webkit-mask-image: linear-gradient(90deg, transparent, #000 44px); mask-image: linear-gradient(90deg, transparent, #000 44px); }
[data-fade="lr"] { -webkit-mask-image: linear-gradient(90deg, transparent, #000 44px, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(90deg, transparent, #000 44px, #000 calc(100% - 44px), transparent); }

/* In 3D and Split the 3D camera bar floats at the bottom of the viewport: toasts stack above it */
body:has(#viewport[data-view="3d"]) #toast-root,
body:has(#viewport[data-view="split"]) #toast-root { padding-bottom: calc(var(--rw-status-h) + 16px + 44px + var(--rw-space-4)); }
@media (max-width: 599px) {
  body:has(#viewport[data-view="3d"]) #toast-root,
  body:has(#viewport[data-view="split"]) #toast-root { padding-bottom: calc(var(--rw-bottombar-h) + 12px + 44px + var(--rw-space-3)); }
}
/* Phone sheets leave the plan visible above them: a light scrim, so edits can be watched while they happen */
#rw-sheet-scrim { background: color-mix(in srgb, var(--rw-scrim) 30%, transparent); }
