/* Minimal academic light theme. System font stack, one handwritten file. */

:root {
  --ink: #1c1c1e;
  --ink-muted: #55565a;
  --paper: #fbfbfa;
  --line: #d8d8d3;
  --accent: #1a4d8f;
  --accent-ink: #ffffff;
  --error: #8f1a1a;
  --focus: #0b5cad;
  /* design.md §§5.4, 5.7: one row-height step equals the body line height
     (1rem × line-height 1.6). Kept in sync with ROW_HEIGHT_UNIT_REM in
     core/modules.py. */
  --row-height-unit: 1.6rem;
  --sidebar-width: 13rem;
  --sidebar-space: 13rem;
  --main-width: 57rem;
  --content-pad: 1rem;
  --rail-width: 17rem;
  --editor-gap: 1.6rem;
}

* {
  box-sizing: border-box;
}

/* Short and long pages reserve the same native scrollbar space. This keeps
   the public and editor grids equal when only one page needs vertical scroll. */
html { overflow-y: scroll; scrollbar-gutter: stable; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
}

/* Keyboard focus is always visible. */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  padding: 0.4rem 0.8rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 0 0 0.25rem 0.25rem;
  z-index: 10;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0;
}

.content {
  width: 100%;
  max-width: var(--main-width);
  min-width: 0;
  margin: 0;
  padding: 2rem var(--content-pad) 3rem;
}

/* One shell for workspace, public, simple and error pages (design §7.7). */
.layout {
  display: flex;
  container-type: inline-size;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 1.2rem 1rem;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  margin: 0 0 1rem;
}

.sidebar .brand a {
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.sidebar-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-nav a {
  color: var(--accent);
  text-decoration: none;
}

.sidebar-nav a:hover {
  text-decoration: underline;
}

.sidebar-login {
  margin-top: auto;
}

.sidebar-login:not(:only-child) {
  padding-top: 1rem;
}

.layout .content {
  --page-available: calc(100cqw - var(--sidebar-space) - 2 * var(--content-pad));
  --logical-canvas-width: min(55rem, var(--page-available));
  flex: 0 1 var(--main-width);
  min-width: 0;
  margin: 0;
}
.layout .public-content { flex: 1; max-width: none; }

.site-menu { min-height: 0; flex: 1; }
.site-menu > summary { cursor: pointer; padding: 0.3rem 0.6rem; border: 1px solid var(--line); border-radius: 0.3rem; }
@media (min-width: 40.001rem) {
  .site-menu > summary { display: none; }
  /* Native details stay useful without JavaScript on desktop too. */
  .site-menu::details-content { content-visibility: visible; display: contents; }
  .sidebar { overflow-y: auto; }
  /* Keep the focus outline inside the scrollport at its edges. */
  .sidebar-login :focus-visible { outline-offset: -3px; }
}

/* Shared horizontal author/workspace page navigation. */
.page-tabs ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0 0 1.4rem;
  padding: 0;
  border-bottom: 1px solid var(--line);
}

.page-tabs a {
  display: inline-block;
  padding: 0.35rem 0.8rem;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 0.25rem 0.25rem 0 0;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.page-tabs li { min-width: 0; max-width: 100%; }

.page-tabs a:hover {
  text-decoration: underline;
}

.page-tabs a.active {
  color: var(--ink);
  font-weight: 600;
  background: #ffffff;
  border-color: var(--line);
}

h1 {
  font-size: 1.7rem;
  line-height: 1.25;
  margin: 0 0 1rem;
}

h2 {
  font-size: 1.2rem;
  margin: 1.8rem 0 0.6rem;
}

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

.muted {
  color: var(--ink-muted);
}

.badge {
  display: inline-block;
  min-width: 1.2em;
  padding: 0 0.3em;
  border-radius: 0.6em;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.8em;
  text-align: center;
}

.banner {
  border: 1px solid #e3c46b;
  background: #fdf6e0;
  padding: 0.6rem 0.8rem;
  border-radius: 0.25rem;
}

.messages {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.message {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.4rem;
  background: #ffffff;
}

.message.error {
  border-left-color: var(--error);
}

.error-list {
  border: 1px solid var(--error);
  background: #fdf0f0;
  color: var(--error);
  padding: 0.6rem 0.8rem 0.6rem 2rem;
  border-radius: 0.25rem;
}

form p {
  margin: 0 0 1rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

input[type="email"],
input[type="text"],
input[type="password"],
.ssh-keys textarea,
select {
  width: 100%;
  max-width: 26rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  font: inherit;
  background: #ffffff;
  color: var(--ink);
}

small {
  display: block;
  color: var(--ink-muted);
  margin-top: 0.2rem;
}

button,
.button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 0.25rem;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.button:hover {
  filter: brightness(1.08);
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
}

.link-button:hover {
  text-decoration: underline;
  filter: none;
}

.inline-form {
  display: inline;
}

.card {
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: #ffffff;
  padding: 1rem 1.2rem;
  margin: 0 0 1.4rem;
}

.card h2:first-child {
  margin-top: 0;
}

.state-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 1rem;
}

.state-list dt {
  font-weight: 600;
}

.state-list dd {
  margin: 0;
}

.user-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6rem 0 1.4rem;
  font-size: 0.95rem;
}

.user-table th,
.user-table td {
  border: 1px solid var(--line);
  padding: 0.4rem 0.6rem;
  text-align: left;
  vertical-align: top;
}

.user-table thead th {
  background: #f0f0ec;
}

.user-table .inline-form {
  display: block;
  margin-bottom: 0.3rem;
}

.user-table .inline-form button,
.user-table form button {
  padding: 0.25rem 0.6rem;
  font-size: 0.9rem;
}

.one-time-link {
  word-break: break-all;
  background: #f0f0ec;
  padding: 0.4rem 0.6rem;
  display: inline-block;
  border-radius: 0.25rem;
}

.notification-list {
  list-style: none;
  padding: 0;
}

.notification {
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: #ffffff;
  padding: 0.6rem 1rem;
  margin-bottom: 0.8rem;
}

.notification.unread {
  border-left: 4px solid var(--accent);
}

/* Small screens: tighten spacing, stack table cells readably. */
@media (max-width: 40rem) {
  :root { --sidebar-space: 0rem; --content-pad: 0.8rem; }
  .layout {
    display: block;
    min-height: 0;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 0.8rem;
    display: flow-root;
  }

  .sidebar-nav ul {
    flex-direction: column;
    gap: 0.4rem 1.2rem;
  }
  .sidebar .brand { float: left; margin: 0.25rem 0.8rem 0.25rem 0; }
  .site-menu > summary { width: max-content; margin-left: auto; }
  .sidebar-nav { clear: both; min-height: 0; padding-top: 0.8rem; }

  .content {
    padding: 1.2rem var(--content-pad) 2rem;
  }

  .user-table {
    font-size: 0.88rem;
  }

  .user-table th,
  .user-table td {
    padding: 0.3rem 0.4rem;
  }
}

/* Workbench columns depend on the card, not the viewport. */
.dashboard-table-card { container: dashboard-pages / inline-size; }
.dashboard-language-table th:first-child,
.dashboard-language-table td:first-child { min-width: 12rem; }
.dashboard-language-table th:nth-child(2),
.dashboard-language-table td:nth-child(2),
.dashboard-language-table th:nth-child(3),
.dashboard-language-table td:nth-child(3),
.dashboard-language-table th:nth-child(4),
.dashboard-language-table .actions a { white-space: nowrap; overflow-wrap: normal; }
.dashboard-language-table td:nth-child(4) { overflow-wrap: normal; }
.dashboard-language-table select { width: auto; max-width: none; }
.dashboard-language-table :is(th, td):nth-child(2) { text-align: center; }
.dashboard-language-table [data-page-language] { text-align: center; text-align-last: center; }
.dashboard-page-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.5rem; }
.dashboard-page-heading strong { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.dashboard-page-order { display: flex; gap: 0.25rem; }
.dashboard-page-order form { margin: 0; }
.dashboard-page-address { overflow-wrap: anywhere; }
.dashboard-label-form { margin-top: 0.65rem; }
.mobile-column-label { display: none; }

@container dashboard-pages (width < 45rem) {
  .dashboard-language-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  .dashboard-language-table,
  .dashboard-language-table tbody,
  .dashboard-language-table tr { display: block; }
  .dashboard-language-table tr + tr { margin-top: 0.9rem; }
  .dashboard-language-table td {
    display: block;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 0.45rem 0.65rem;
  }
  .dashboard-language-table td:first-child { min-width: 0; }
  .dashboard-language-table tr { border: 1px solid var(--line); border-radius: 0.3rem; }
  .dashboard-language-table td:last-child { border-bottom: 0; }
  .mobile-column-label { display: block; font-size: 0.83rem; color: var(--ink-muted); }
}

/* --- Module editor and rendered modules (design.md §5.2) --- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.module-note {
  font-size: 0.85rem;
  margin: 0.3rem 0 0.8rem;
}

.module-form textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  font: inherit;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92rem;
  background: #ffffff;
  color: var(--ink);
}

.tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  margin-bottom: 0.55rem;
  padding: 0.2rem;
  background: #eeefef;
  border-radius: 0.4rem;
}

.tabs [role="tab"],
.rte-toolbar button {
  padding: 0.25rem 0.5rem;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 0.86rem;
}

.tabs [aria-selected="true"] {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 4px rgb(0 0 0 / 15%);
}

.rich-editor {
  border: 1px solid var(--line);
  border-radius: 0.35rem;
}
.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  padding: 0.25rem;
  border-bottom: 1px solid var(--line);
}
.rte-toolbar button:hover, .tabs [role="tab"]:hover { color: var(--accent); }
.rte-area { min-height: 6rem; padding: 0.5rem 0.6rem; }

.md-preview {
  border: 1px dashed var(--line);
  border-radius: 0.25rem;
  padding: 0.5rem 0.6rem;
  margin: 0.4rem 0 0.6rem;
  min-height: 2rem;
  background: #fdfdfb;
}

.md-preview:empty::before {
  content: "Preview";
  color: var(--ink-muted);
  font-size: 0.85rem;
}

.body-attachment-tools { margin-bottom: 0.45rem; }
.body-attachment-dialog { width: min(28rem, calc(100% - 2rem)); }
.body-attachment-dialog select, .body-attachment-dialog input { width: 100%; }
.body-attachment-dialog .form-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.body-attachment-image { max-width: 100%; height: auto; vertical-align: middle; }
:is([data-rte], [data-md-preview]) .body-attachment-missing {
  text-decoration: underline dotted;
  text-underline-offset: 0.15em;
}
[data-rte] :is([data-body-link], [data-body-image]) { cursor: pointer; }
[data-rte], .md-preview { overflow-wrap: anywhere; }

.add-modules {
  list-style: none;
  margin: 0 0 0.6rem;
  padding: 0;
}

.add-module-menu {
  display: flex;
  align-items: stretch;
  gap: 0.3rem;
}

.add-module-primary {
  flex: 1;
  text-align: left;
}

.add-menu-button { flex: 0 0 auto; }

.add-menu-list {
  left: 0;
  right: auto;
  max-height: min(60vh, 24rem);
  overflow-y: auto;
}

.add-module-button {
  display: block;
  width: 100%;
  cursor: grab;
  text-align: left;
}

.add-type-check { display: inline-block; width: 1.2em; visibility: hidden; }
.add-module-button[aria-checked="true"] .add-type-check { visibility: visible; }

.add-module-button:focus-visible,
.add-menu-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Rendered modules (shared by the canvas and public page, design.md §§5.2, 6.5.1) */

.mod {
  margin: 0 0 1.2rem;
}

.mod-heading {
  margin-top: 1.8rem;
}

.mod-image {
  margin: 1.4rem 0;
}

.mod-image img {
  display: block;
  height: auto;
}

.mod-image--original img {
  max-width: 100%;
}

.mod-image--wide img {
  width: 100%;
}

.mod-image--medium {
  width: 60%;
  margin-left: auto;
  margin-right: auto;
}

.mod-image--medium img {
  width: 100%;
}

.mod-image figcaption {
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-top: 0.3rem;
}

.mod-attachment p {
  margin: 0 0 0.2rem;
}


/* --- Editor two-column layout: module column + right action rail --- */

.layout .content-editor {
  flex-basis: calc(100% - var(--sidebar-space) - var(--rail-width) - var(--editor-gap));
  max-width: none;
}

.editor-layout {
  display: grid;
  /* The fixed rail ends at the client boundary. Main's own right padding
     precedes the inter-column gap; surplus space belongs to main alone. */
  width: calc(var(--page-available) + var(--content-pad));
  grid-template-columns: minmax(0, 1fr) var(--rail-width);
  align-items: stretch;
  column-gap: calc(var(--content-pad) + var(--editor-gap));
  position: relative;
}

.editor-column { min-width: 0; }
.editor-sticky {
  position: sticky; top: 0; z-index: 22; min-width: 0;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.editor-navigation { display: flex; align-items: flex-start; gap: 0.5rem; max-height: calc(50dvh - 1.1rem); overflow-y: auto; }
.editor-navigation .page-tabs { flex: 1; min-width: 0; }
.editor-navigation .page-tabs ul { margin-bottom: 0; border-bottom: none; }
.canvas-scrollbar { width: 100%; height: 1.1rem; overflow-x: auto; overflow-y: hidden; }
.canvas-scrollbar > div { height: 1px; }
html:has([data-editor-workspace]) { scroll-padding-top: calc(var(--editor-sticky-height, 0px) + 0.6rem); }
.canvas :is(.cell, .row, input, textarea, select, button, [contenteditable]) {
  scroll-margin-top: calc(var(--editor-sticky-height, 0px) + 0.6rem);
}

.editor-main {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.editor-main::-webkit-scrollbar { display: none; }

.editor-rail {
  grid-column: 2; grid-row: 1;
  min-width: 0;
  position: sticky;
  top: 1rem;
  max-height: calc(100dvh - 2rem);
  align-self: start;
  overflow: auto;
  padding: 0.2rem;
}
.editor-layout .tools-trigger, .editor-layout .tools-close { display: none; }
.editor-tools-panel > [data-public-view] { margin: 0.5rem 0 1rem; }

.rail-block {
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  background: #ffffff;
  padding: 0.8rem 1rem;
  margin: 0 0 1rem;
}

.rail-block h2 {
  margin-top: 0;
  font-size: 1rem;
}

.rail-block h3 {
  font-size: 0.95rem;
  margin: 1rem 0 0.4rem;
}

.rail-block form + form { margin-top: 0.65rem; }

.rail-warning {
  margin: 0 0 1rem;
  font-size: 0.92rem;
}

.menu {
  position: relative;
}

.menu-button {
  padding: 0.5rem 0.7rem;
}

.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 0.2rem);
  z-index: 20;
  list-style: none;
  margin: 0;
  padding: 0.3rem;
  min-width: 11rem;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 0.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.menu-list a,
.menu-list button {
  display: block;
  width: 100%;
  padding: 0.35rem 0.6rem;
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-list a:hover,
.menu-list button:hover {
  background: #f0f0ec;
}

@media (max-width: 40rem) {
  .layout .content-editor { flex-basis: 100%; }
  .editor-layout { width: 100%; grid-template-columns: minmax(0, 1fr); gap: 0; }
  .editor-rail { display: contents; }
  .editor-layout .tools-trigger { display: block; flex: 0 0 auto; padding-inline: 0.5rem; }
  .editor-layout .tools-close { display: block; margin-left: auto; }
  .editor-layout:not(.tools-open) .editor-tools-panel { display: none; }
  .editor-tools-panel {
    position: fixed; right: 0.8rem; top: calc(var(--editor-sticky-height, 3rem) + 0.5rem); z-index: 24;
    width: min(17rem, calc(100vw - 1.6rem));
    max-height: calc(100dvh - var(--save-strip-height, 9rem) - var(--editor-sticky-height, 3rem) - 1rem);
    overflow: auto; padding: 0.8rem; background: white;
    border: 1px solid var(--line); border-radius: 0.3rem;
    box-shadow: 0 0.25rem 1rem rgb(0 0 0 / 12%);
  }
}

/* One horizontal author navigation, with a native language dropdown right. */
.public-navigation { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.5rem; border-bottom: 1px solid var(--line); }
.public-navigation .page-tabs { flex: 1; min-width: 0; }
.public-navigation .page-tabs ul { margin-bottom: 0; border-bottom: none; }
.public-navigation .language-fallback { flex: 0 0 100%; margin: 0 0 0.5rem; }
.language-menu { position: relative; flex: 0 0 auto; max-width: 45%; }
.language-menu summary { cursor: pointer; padding: 0.35rem 0.6rem; color: var(--accent); border: 1px solid var(--line); border-radius: 0.25rem; }
.language-options { position: absolute; inset: 100% 0 auto auto; z-index: 24; width: max-content; max-width: min(24rem, calc(100cqw - var(--sidebar-space) - 2 * var(--content-pad))); padding: 0.3rem; border: 1px solid var(--line); background: white; box-shadow: 0 2px 8px rgb(0 0 0 / 10%); border-radius: 0.25rem; }
.language-options ul { list-style: none; margin: 0; padding: 0; }
.language-options a { display: block; padding: 0.35rem 0.6rem; text-decoration: none; }
.language-options a:is(:hover, :focus-visible) { background: #e8f1fc; }
.language-options [aria-current] { font-weight: 700; }




/* ======================================================================
   Canvas editor and 12-column row layout (design.md §§5.2, 5.3, 5.7).
   The SAME .row/.cell/.mod markup serves the public page and the canvas;
   every edit control below is a pure overlay (.cell-controls, .edit-card,
   .row-controls) and is hidden in public-view mode.
   ====================================================================== */

.page-grid {
  container: page-grid / inline-size;
  width: var(--logical-canvas-width);
  padding-block-start: 0.6rem;
}

/* --- Row grid: 12 equal columns, modules side by side by span (design.md §5.3) --- */

.row {
  --row-inline-inset: 0.5rem;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: 1.2rem;
  align-items: start;
  min-height: var(--row-min-height, auto);
  position: relative;
  padding: 0.5rem;
}
.row + .row { margin-top: 0.75rem; }

.cell {
  min-width: 0;
  position: relative;
  display: flow-root;
}
.settings-card-header, .ssh-key-row, .ssh-key-name, .agent-sign-in-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.settings-card-header, .ssh-key-row { justify-content: space-between; }
.settings-card-header, .agent-sign-in-actions { flex-wrap: wrap; }
.settings-card-header h2, .settings-card-header form, .ssh-key-row form { margin: 0; }
.settings-card-header button, .ssh-key-row form, .ssh-key-name .button-small { flex: none; }
.settings-card-rule { border-top: 1px solid var(--line); padding-block: 0.5rem; }
.ssh-key-name { min-width: 0; }
.ssh-key-title {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-align: left;
  text-decoration: underline;
  overflow-wrap: anywhere;
}
.ssh-add, .ssh-key-rename, .ssh-key-details { margin-top: 0.65rem; }
.settings-card-facts, .settings-card-disclosure { --settings-card-inset: 0.75rem; }
.settings-card-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
  gap: 0.55rem 1rem;
  margin: 0;
  padding: 0.55rem var(--settings-card-inset);
  border-radius: 0.25rem;
  background: var(--paper);
}
.settings-card-fact-wide { grid-column: 1 / -1; }
.settings-card-facts dt { color: var(--ink-muted); font-size: 0.875rem; }
.settings-card-facts dd { margin-inline-start: 0; overflow-wrap: anywhere; }
.settings-card-disclosure { margin-top: 0.5rem; }
.settings-card-disclosure > summary {
  display: list-item;
  list-style-position: outside;
  padding-block: 0.2rem;
  color: var(--accent);
  font-size: 0.875rem;
  cursor: pointer;
}
.settings-card-disclosure > :not(summary) { margin-block: 0.5rem 0; }
.settings-card-disclosure > :is(summary, form, pre) { margin-inline: var(--settings-card-inset); }
.ssh-public-key { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.875rem; }
.ssh-keys textarea { resize: vertical; }
.agent-sign-in-actions { justify-content: flex-end; margin-inline-start: auto; }
.agent-sign-in-readiness { margin-top: 0.5rem; padding-bottom: 0; }
.agent-sign-in-readiness small { display: block; }

/* Shared content boundaries (design.md §5.4): row padding owns outer
   spacing; retain actual internal paragraphs, lists and authored blank lines. */
.mod { margin-block: 0; }
.mod > :first-child { margin-top: 0; }
.mod > :last-child,
.mod [data-inline-rich] > :last-child { margin-bottom: 0; }
.mod :is(p, li):empty { min-height: 1lh; }

.span-1 { grid-column: span 1; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-9 { grid-column: span 9; }
.span-10 { grid-column: span 10; }
.span-11 { grid-column: span 11; }
.span-12 { grid-column: span 12; }

/* Module vertical alignment within the row (design.md §5.4) — only visible when the
   row is taller than the module's content. */
.valign-top { align-self: start; }
.valign-middle { align-self: center; }
.valign-bottom { align-self: end; }

/* Text/heading content horizontal alignment (design.md §5.4). Left is the default. */
.halign-center { text-align: center; }
.halign-right { text-align: right; }

/* Narrow page grids (design.md §§5.3, 7.7): stack the modules vertically;
   span, minimum row height, vertical alignment AND content horizontal
   alignment are all inert. The pointer-only width/height handles are hidden
   too (they drive exactly those inert properties). */
@container page-grid (max-width: 40rem) {
  .row {
    display: block;
    min-height: 0 !important;
  }

  .halign-center,
  .halign-right {
    text-align: left;
  }

  .edge-zone,
  .row-height-handle {
    display: none;
  }
}

/* --- Canvas actions: save, unsaved hint, and Preview (design.md §§5.2, 5.5) --- */

.save-strip {
  display: grid;
  gap: 0.5rem;
}

#publish-section button,
[data-save-draft],
[data-public-view] {
  width: 100%;
  min-height: 2.4rem;
  padding: 0.35rem 0.65rem;
}

#publish-section p { margin: 0.25rem 0 0; font-size: 0.875rem; }
.save-status, .save-strip .error-list { font-size: 0.875rem; }
.save-status .actions { margin-top: 0.25rem; }
.unsaved-hint { color: var(--error); }

@media (max-width: 40rem) {
  html:has([data-editor-workspace]) { scroll-padding-bottom: calc(var(--save-strip-height, 0px) + 0.6rem); }
  .editor-layout { padding-bottom: var(--save-strip-height, 9rem); }
  .save-strip {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
    max-height: 65dvh;
    overflow: auto;
    background: white;
    padding: 0.55rem 0.8rem max(0.55rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
  }
  .save-strip > :not(#publish-section, [data-save-draft]) { grid-column: 1 / -1; }
  .save-strip #publish-section { display: flex; flex-direction: column; }
  .save-strip #publish-section p { order: -1; }
  .public-view .editor-layout { padding-bottom: 0; }
}

/* --- Dimmed page frame: real context, not editable (E09). The frame
   mirrors the public page chrome (tab strip, brand heading, language
   links) with the same data; dimming + inertness mark it as context. --- */

.chrome-dimmed {
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}

/* A single control-height entry gutter; rows keep public content geometry. */
.canvas { position: relative; padding-block-end: 4.4rem; }
body:not(.public-view) .canvas { padding-block-start: 1.55rem; }
.canvas .cell:focus, .canvas .row:focus { outline: none; }
.canvas .cell { cursor: default; }
.canvas [data-inline-field][contenteditable="true"] { cursor: text; }
.canvas [data-inline-field]:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.canvas [data-inline-field][aria-invalid="true"] { outline: 2px solid var(--error); outline-offset: 1px; }
.canvas a { cursor: pointer; }
.canvas [data-inline-field][contenteditable="true"] a { cursor: text; }
.canvas [data-inline-placeholder][contenteditable="true"][data-inline-empty] { min-height: 1lh; }
.canvas [data-inline-placeholder][data-inline-empty] { position: relative; }
.canvas [data-inline-placeholder][data-inline-empty]::before { content: attr(data-inline-placeholder); position: absolute; inset: 0 0 auto; min-height: 1.6rem; color: var(--ink-muted); pointer-events: auto; }
.public-view [data-inline-placeholder][data-inline-empty]::before { display: none; }
.public-view .canvas .cell { cursor: auto; }
.inline-errors { margin: 0; font-size: 0.875rem; }
.edit-card-type { font-size: 1rem; margin: 0 0 0.75rem; }
/* Keep the shared row's .5rem inset at the visible scrolling edge, too.
   This is paint clipping only; module boxes and public geometry are intact. */
.canvas .mod.is-viewport-clipped { clip-path: inset(-100vmax -100vmax -100vmax var(--visible-inset)); }

.cell-controls {
  position: absolute;
  inset: var(--cell-controls-top, -1rem) var(--cell-controls-right, 0px) auto auto;
  z-index: 12;
  display: flex;
  gap: 0.1rem;
  pointer-events: none;
}
.cell-controls button {
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 0.25rem;
  background: transparent;
  color: var(--ink-muted);
  opacity: 0;
  pointer-events: none;
}
.cell-controls-extra { display: flex; gap: 0.1rem; }
.cell-controls.controls-wrap { width: 1.4rem; }
/* The gutter holds a vertical group when the full strip cannot fit left. */
.controls-wrap .cell-controls-extra { position: fixed; left: var(--controls-left); top: var(--controls-top); display: grid; grid-template-columns: 1.4rem; gap: 0; z-index: 26; }
.controls-wrap .edit-toggle { position: fixed; left: var(--dot-left); top: var(--dot-top); }
.cell-controls svg {
  width: 0.95rem;
  height: 0.95rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cell-controls .edit-toggle {
  color: #6b7b90;
  opacity: 1;
  pointer-events: auto;
}
.cell-controls .edit-toggle:disabled { color: #818995; cursor: default; }
.cell:hover > .cell-controls,
.cell:focus-within > .cell-controls { z-index: 14; }
.cell:is(:hover, :focus-within, .is-selected-cell) > .cell-controls button {
  opacity: 1;
  pointer-events: auto;
}
.cell:is(:hover, :focus-within, .is-selected-cell) > .cell-controls {
  background: white;
  border-radius: 0.25rem;
}
.cell:is(:hover, :focus-within, .is-selected-cell) > .cell-controls::after {
  content: "";
  position: absolute;
  inset: 100% 0 auto;
  height: 0.16rem;
  pointer-events: auto;
}
.cell-controls button:is(:hover, :focus-visible):not(:disabled) {
  border-color: var(--line);
  background: #f0f4f8;
  color: var(--accent);
}
.cell-controls .cell-remove:hover { color: var(--error); }
.cell-controls .cell-drag { cursor: grab; user-select: none; }
.cell-controls .cell-drag:active { cursor: grabbing; }

.edge-zone {
  position: absolute;
  top: var(--edge-top, 0px);
  bottom: var(--edge-bottom, 0px);
  width: 0.5rem;
  cursor: col-resize;
  z-index: 11;
}
/* At column one the left resize zone meets the row grip at the row edge. */
.edge-left {
  left: calc(-1 * var(--row-inline-inset));
  width: var(--row-inline-inset);
}
.edge-right { right: calc(-1 * var(--row-inline-inset)); width: var(--row-inline-inset); }

.canvas .row:is(:hover, :focus-within, .is-selected-row, .is-height-dragging, .is-drop-target)::after,
.canvas .cell:is(:hover, :focus-within, .is-selected-cell, .is-edge-dragging):not(.is-card-open)::after {
  content: "";
  position: absolute;
  inset: -0.3rem;
  border: 1px solid rgb(26 77 143 / 50%);
  border-radius: 0.35rem;
  background: transparent;
  pointer-events: none;
  z-index: 9;
}
.canvas .row:is(:hover, :focus-within, .is-selected-row, .is-height-dragging, .is-drop-target)::after {
  inset: 0;
  border-color: rgb(26 77 143 / 26%);
  z-index: 6;
}
.canvas .row:has(> :where(.row-drag-handle:is(:hover, :focus-visible)))::after {
  border: 1.5px solid var(--accent);
}
.canvas .row.is-selected-row::after { border: 2px dashed var(--accent); }
.canvas .row.is-height-dragging::after { border: 2px solid var(--accent); }
.canvas .row.is-drop-target::after { border-color: var(--accent); }
.canvas .cell:is(.is-selected-cell, .is-edge-dragging):not(.is-card-open)::after,
.canvas .cell:not(.is-card-open):has(.cell-drag:is(:hover, :focus-visible))::after {
  border: 2px solid var(--accent);
}

/* Width readout that follows the drag ("span n columns"). */
.cell-edge-readout,
.row-height-readout {
  position: absolute;
  z-index: 11;
  padding: 0.1rem 0.45rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 0.2rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.cell-edge-readout {
  right: 0;
  top: -1.7rem;
}

.row-drag-handle {
  position: fixed;
  top: var(--row-grip-top, 0px);
  left: var(--row-grip-left, 0px);
  z-index: 26;
  display: grid;
  place-items: center start;
  width: 1.4rem;
  height: 1.9rem;
  padding: 0;
  border: 0;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  cursor: grab;
  user-select: none;
}
.row:is(:hover, :focus-within, .is-selected-row) > .row-drag-handle {
  opacity: 1;
  pointer-events: auto;
}
.row-drag-handle:active { cursor: grabbing; }
.row-grip {
  display: grid;
  place-items: center;
  width: 1.1rem;
  height: 1.9rem;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  color: var(--accent);
  background: white;
}
.row-grip svg { width: 0.65rem; height: 1.05rem; }
.row-drag-handle:is(:hover, :focus-visible) .row-grip { border-color: var(--accent); }
.is-selected-row > .row-drag-handle .row-grip {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

/* A left edge with nowhere to take columns from says so, instead of doing
   nothing when dragged. */
.edge-zone.is-at-limit,
.edge-zone.is-at-limit:active {
  cursor: not-allowed;
}

.edit-card {
  margin: 0;
  padding: min(1rem, 5%);
  min-width: 0;
  overflow-wrap: anywhere;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  box-shadow: 0 2px 10px rgb(0 0 0 / 8%);
}
.edit-card label {
  color: var(--ink-muted);
  font-size: 0.86rem;
  font-weight: normal;
}
.edit-card fieldset, .edit-card input, .edit-card select { min-width: 0; }
.edit-card :is(button, input, select) { max-width: 100%; }
.edit-card button { overflow-wrap: anywhere; }
.edit-card .compact-field { display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem 0.6rem; }
.edit-card .compact-field label { margin: 0; }
.edit-card .compact-field select { width: auto; }
.is-card-open > .cell-controls,
.is-card-open > :is(.mod-text, .mod-heading) { display: none; }

/* The row's BOTTOM BORDER is the height drag target: an invisible zone with
   an ns-resize cursor. No standing strip and no tint (site owner 2026-10-05:
   those read as stray blue bars); while dragging, the row draws the same
   light-blue frame as a hovered module. */
.row-height-handle {
  position: absolute;
  left: var(--height-left, 0px);
  right: var(--height-right, 0px);
  bottom: 0;
  height: 0.8rem;
  cursor: ns-resize;
  background: transparent;
}

.row-height-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Live "min height n" bubble while the border is dragged (the only height
   feedback there is, now that the −/+ buttons are gone). */
.row-height-readout {
  position: absolute;
  right: 0;
  bottom: -1.9rem;
  z-index: 11;
  padding: 0.1rem 0.45rem;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 0.2rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* All row and module spacing comes from the shared public rules. */
.is-control-clipped, .is-control-clipped button { opacity: 0 !important; pointer-events: none !important; }

/* Drag feedback stays outside the grid flow. */
.drop-gap {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  z-index: 13;
}
.drop-gap::before {
  content: "";
  position: absolute;
  inset: -0.8rem 0;
}
.drop-marker {
  position: absolute;
  z-index: 16;
  pointer-events: none;
  background: var(--accent);
}
.drop-marker-horizontal { height: 2px; }
.drop-marker-vertical { width: 3px; border-radius: 2px; }
.drop-marker-slot { border: 2px solid var(--accent); border-radius: 0.25rem; background: transparent; }
.editor-layout:focus { outline: none; }
body:not(.public-view) .is-new > .mod:empty { min-height: 1.6rem; }
.drop-marker-horizontal::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 0.4rem;
  height: 0.4rem;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent);
}
.canvas .is-drag-source { opacity: 0.45; }
.drag-thumbnail {
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 100;
  max-height: 8rem;
  overflow: hidden;
  pointer-events: none;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 0.35rem;
  background: white;
}

/* --- Author Preview (design.md §5.2) --- */

body.public-view .canvas-empty,
body.public-view .cell-controls,
body.public-view .edit-card,
body.public-view .row-controls,
body.public-view .edge-zone,
body.public-view .row-height-handle,
body.public-view .row-drag-handle,
body.public-view .drop-gap,
body.public-view #add-modules {
  display: none;
}

body.public-view .save-strip,
body.public-view .editor-tools-panel > :not([data-public-view], [data-tools-close]) {
  display: none;
}


body.public-view .canvas .row::after,
body.public-view .canvas .cell::after {
  display: none;
}

body.public-view .is-card-open > :is(.mod-text, .mod-heading) { display: revert; }

/* ======================================================================
   Formula segments and environment blocks (design.md §§6.3, 6.4).
   ====================================================================== */

/* Formula segments arrive as whitelisted spans holding \( \) / \[ \] TeX
   source; MathJax replaces the content in place. Before MathJax runs (and
   inside edit cards, which it skips) the source shows as subdued
   monospace text so it stays readable and recognizable. */
.math-i {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}

.math-d {
  display: block;
  margin: 0.8rem 0;
  text-align: center;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}

/* MathJax's container takes over the fonts; long formulas scroll sideways
   instead of breaking the layout (mobile readability, W03/T01). */
.mod mjx-container {
  font-family: inherit;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.mod mjx-container[display="true"] {
  margin: 0.8rem 0;
}

/* Environment block (design.md §6.4, T04). */
.mod-env {
  padding: 0.2rem 0 0.2rem 0.9rem;
  border-left: 3px solid var(--line);
}

.mod-env-title {
  margin: 0 0 0.4rem;
}

/* Formula source inside the rich-text editor (edit cards are excluded
   from MathJax): keep the TeX source visually distinct while editing. */
.edit-card .math-i,
.edit-card .math-d {
  background: rgba(26, 77, 143, 0.07);
  border-radius: 0.2rem;
  padding: 0 0.15rem;
}


[hidden] { display: none !important; }
.content, .sidebar { overflow-wrap: anywhere; }
input, select, textarea { max-width: 100%; }
.sidebar-nav [aria-current="page"]:not([hidden]) {
  display: block;
  border-inline-start: 0.2rem solid var(--accent);
  padding-inline-start: 0.45rem;
  font-weight: 700;
}
.sidebar-group-title { margin: 0.85rem 0 0.35rem; font-weight: 700; font-size: 0.88rem; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.actions form { margin: 0; }
.table-scroll { position: relative; max-width: 100%; overflow-x: auto; padding: 0.15rem; }
.table-scroll .user-table { margin: 0; }
.table-scroll .user-table :is(th, td) { overflow-wrap: break-word; }
.table-scroll .table-token { white-space: nowrap; }
.table-scroll .user-table select { width: auto; max-width: none; }
.button-small { padding: 0.25rem 0.6rem; font-size: 0.9rem; }
.button-secondary, .button-danger {
  display: inline-block;
  background: white;
  color: var(--accent);
  border: 1px solid currentColor;
}
.button-danger, .danger-link { color: var(--error); }
button:not(:disabled, .cell-controls button, .drag-handle):active, .button:active { transform: translateY(1px); }
.button-secondary:hover { background: #e8f1fc; }
.button-danger:hover { background: #fceaea; }
button:disabled:not(.edit-toggle) {
  border-color: #c1c1c1;
  background: #e9e9e9;
  color: #505050;
  cursor: default;
  filter: none;
}
button[aria-pressed="true"], button[aria-selected="true"] {
  box-shadow: inset 0 0 0 2px currentColor;
  font-weight: 700;
}
:is(.confirmation, .body-attachment-dialog) {
  max-width: min(30rem, calc(100vw - 2rem));
  padding: 1.2rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: white;
  color: var(--ink);
}
:is(.confirmation, .body-attachment-dialog) h2 { margin-top: 0; }
:is(.confirmation, .body-attachment-dialog)::backdrop { background: rgb(0 0 0 / 50%); }
.confirmation .button-danger { background: var(--error); color: white; border-color: var(--error); }

@media print {
  html { overflow-y: visible; scrollbar-gutter: auto; }
  body, .public-frame { color: black; background: white; }
  .public-frame .sidebar,
  .public-frame .public-navigation,
  .skip-link { display: none; }
  .public-frame { display: block; }
  .public-frame .public-content { width: 100%; max-width: none; padding: 0; }
  .public-frame .page-grid { width: 100%; padding-block-start: 0; }
  .public-frame .row { padding-inline: 0; }
  .public-frame a { color: black; }
  .public-frame a[href^="http://"]::after,
  .public-frame a[href^="https://"]::after,
  .public-frame a[href^="mailto:"]::after { content: " (" attr(href) ")"; }
  .public-frame img, .public-frame .mod-env,
  .public-frame h1, .public-frame h2, .public-frame h3 { break-inside: avoid; }
  .public-frame h1, .public-frame h2, .public-frame h3 { break-after: avoid; }
}
