:root {
  --wrap: 1440px;
  --canvas: #f3f6fc;
  --surface: var(--bg);
  --shadow-sm: 0 5px 18px rgba(35, 58, 111, .045);
  --header-height: 68px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #171e2b;
  --bg-soft: #1b2638;
  --bg-soft-2: #233049;
  --bg-hover: #1d2940;
  --canvas: #101724;
  --text: #e8effc;
  --text-2: #bac6de;
  --text-3: #99aac5;
  --line: #2a3952;
  --line-strong: #3a4d6c;
  --shadow-sm: 0 5px 18px rgba(0, 0, 0, .16);
  color-scheme: dark;
}

body {
  --bg: #fff;
  --surface: var(--bg);
  --bg-soft: #f5f5f3;
  --bg-soft-2: #eceeeb;
  --bg-hover: #f8f8f7;
  --canvas: #f3f4f2;
  --text: #232925;
  --text-2: #48524b;
  --text-3: #5d675f;
  --line: #e0e4de;
  --line-strong: #ccd3cb;
  --accent: #4d3daf;
  --accent-soft: #eeebfb;
  --primary-gradient: #303731;
  --shadow-sm: 0 2px 7px rgba(34, 44, 38, .045);
  min-height: 100vh;
  background: var(--canvas);
  font-size: 14px;
}

:root[data-theme="dark"] body {
  --bg: #202522;
  --bg-soft: #252c27;
  --bg-soft-2: #303a33;
  --bg-hover: #282f2a;
  --canvas: #181d19;
  --text: #f0f3ef;
  --text-2: #c2ccc3;
  --text-3: #a8b4aa;
  --line: #364038;
  --line-strong: #4b584d;
  --accent: #c4b8ff;
  --accent-soft: #3a3156;
  --primary-gradient: #535f55;
  --shadow-sm: 0 2px 7px rgba(0, 0, 0, .12);
}

.masthead {
  display: block;
  height: auto;
  padding: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
}

.masthead-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  min-height: var(--header-height);
  max-width: var(--wrap);
  margin: auto;
  padding: 0 32px;
}

.brand {
  min-width: 0;
  width: max-content;
  max-width: 100%;
}

.masthead .logo {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg-soft);
}

.brand-mark {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 19px;
  letter-spacing: -.045em;
}

.topnav {
  justify-self: center;
  align-items: center;
  gap: 3px;
}

.topnav-item {
  min-height: 42px;
  padding: 0 14px;
  gap: 8px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 520;
}

.topnav-item svg {
  flex: none;
  opacity: 1;
}

.masthead-side {
  justify-self: end;
  min-width: 0;
}

.masthead .theme-toggle {
  width: 40px;
  height: 40px;
  color: var(--text-2);
  border: 0;
  border-radius: 9px;
}

.masthead .account {
  position: relative;
  gap: 10px;
  min-width: 0;
}

.masthead .avatar {
  width: 36px;
  height: 36px;
  color: var(--accent);
  background: var(--accent-soft);
}

.masthead .account-menu { display: block; }

.masthead .account-menu-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  min-inline-size: 0;
  min-block-size: 44px;
  margin: 0;
  padding: 3px 8px 3px 4px;
  border: 1px solid transparent;
  border-radius: 12px;
  list-style: none;
  cursor: pointer;
}

.masthead .account-menu-trigger:is(:hover, :focus-visible) {
  border-color: var(--line);
  background: var(--bg-soft);
}

.masthead .account-menu[open] .account-menu-trigger {
  border-color: var(--line-strong);
  background: var(--bg-soft-2);
}

.masthead .account-menu-trigger .avatar {
  color: var(--accent);
  background: var(--accent-soft);
}

.account-menu-trigger .account-name { max-inline-size: clamp(4rem, 9vw, 9rem); }
.account-menu-trigger .role { flex: none; }

.account-menu-chevron {
  display: inline-flex;
  flex: none;
  color: var(--text-3);
}

.account-menu-chevron svg { width: 14px; height: 14px; }
.account-menu[open] .account-menu-chevron { transform: rotate(180deg); }

.account-menu-trigger::-webkit-details-marker { display: none; }
.account-menu-trigger::marker { content: ""; }

.account-menu-panel {
  position: absolute;
  z-index: 41;
  inset-block-start: calc(100% + 8px);
  inset-inline-end: 0;
  inline-size: min(224px, calc(100vw - 24px));
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.account-menu:not([open]) .account-menu-panel { display: none; }

.account-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  inline-size: 100%;
  min-block-size: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.account-menu-item svg { flex: none; }

.account-menu-item:is(:hover, [aria-current="page"]) {
  background: var(--bg-soft);
  color: var(--text);
}

.account-menu-item:focus-visible { outline-offset: -2px; }

.masthead .account-signin {
  padding: 9px 4px;
  white-space: nowrap;
}

.masthead .btn-sm {
  min-height: 38px;
  padding-inline: 15px;
  white-space: nowrap;
}

.account-id,
.account-name {
  min-width: 0;
}

.account-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.account .role {
  white-space: nowrap;
}

.shell {
  grid-template-columns: 212px minmax(0, 1fr) minmax(205px, 238px);
  align-items: start;
  gap: 26px;
  padding: 28px 32px 92px;
}

.shell:has(.margin:empty) {
  grid-template-columns: 212px minmax(0, 1fr);
}

body:not(:is([data-page="login"], [data-page="register"])) .shell:has(.rail:empty) {
  grid-template-columns: minmax(0, 1fr);
}

.rail:empty,
.margin:empty {
  display: none;
}

.rail,
.margin {
  top: calc(var(--header-height) + 24px);
  min-width: 0;
  max-height: calc(100dvh - var(--header-height) - 48px);
  overflow: auto;
  scrollbar-width: thin;
}

.rail {
  padding: 0;
  font-size: 14px;
}

.rail-disclosure {
  border-radius: 17px;
}

.rail-disclosure > summary {
  display: none;
}

.rail-block {
  margin: 0 0 14px;
  padding: 14px 10px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.rail-label {
  margin: 0 0 9px;
  padding: 0 10px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .025em;
}

.rail-list {
  gap: 3px;
}

.rail-item {
  min-height: 38px;
  padding: 7px 10px;
  border-radius: 8px;
  background: none;
  font-size: 13px;
  font-weight: 520;
}

.rail-item.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.rail-count {
  min-width: 22px;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--bg-soft);
  font-size: 11px;
  text-align: center;
}

.rail-item.is-active .rail-count {
  color: var(--accent);
  background: var(--surface);
}

.panel,
.section,
.post,
.margin-block {
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.margin-block {
  margin-bottom: 14px;
  padding: 16px;
  border-radius: 15px;
}

.margin-label {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
}

.btn {
  min-height: 38px;
  line-height: 1.3;
  font-size: 13px;
  font-weight: 620;
}

.btn:not(.btn-quiet):hover {
  color: white;
}

.btn-quiet {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
}

.linkish:not(:disabled):hover {
  color: var(--accent);
}

.plain-error {
  display: grid;
  place-items: center;
  padding: 20px;
}

.plain-error .error-shell {
  width: min(100%, 550px);
  margin: 0;
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.home-workspace-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.home-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.home-actions .btn { min-height: 40px; }

.home-project-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}

.home-project-icon[data-tone="1"] {
  background: color-mix(in srgb, #9b7af9 18%, var(--surface));
  color: light-dark(#6742b1, #c5abff);
}

.home-project-icon[data-tone="2"] {
  background: color-mix(in srgb, #40c8c2 18%, var(--surface));
  color: light-dark(#14736e, #83d9d4);
}

.home-project-icon[data-tone="3"] {
  background: color-mix(in srgb, #689eff 19%, var(--surface));
  color: light-dark(#2859a4, #aac9ff);
}

.home-feeds {
  display: grid;
  grid-template-columns: minmax(0, 1.38fr) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.home-feed {
  min-width: 0;
  padding: 0 18px 4px;
  border-radius: 14px;
}

.home-feed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 0 14px;
  border-bottom: 1px solid var(--line);
}

.home-feed-head h2,
.home-feed-head a {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.home-feed-head h2 {
  font-size: 17px;
  font-weight: 670;
}

.home-feed-head svg {
  flex: none;
  color: var(--accent);
}

.home-feed-head a {
  flex: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.home-feed-head a:hover {
  text-decoration: underline;
}

.home-feed .entry {
  min-height: 84px;
  padding: 14px 4px;
}

.home-feed .entry-title {
  font-size: 15px;
}

.home-feed .entry-excerpt {
  font-size: 13px;
}

.home-feed .entry-meta {
  font-size: 12px;
}

.home-feed .mark {
  font-size: 11px;
}

.home-feed .entry-marks {
  flex-direction: column;
  align-items: flex-end;
}

.home-project {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 11px;
  border-radius: 0;
  padding: 15px 3px;
  border-bottom: 1px solid var(--line);
}

.home-project:last-child {
  border-bottom: 0;
}

.home-project-content {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.home-project-name {
  font-size: 15px;
  overflow-wrap: anywhere;
}

.home-project-summary {
  color: var(--text-2);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.home-project-meta {
  color: var(--text-3);
  font-size: 12px;
}

.home-project:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.home-project > svg {
  align-self: center;
  color: var(--text-3);
}

.ask {
  right: 24px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 9px;
  pointer-events: none;
}

.ask-toggle,
.ask-panel {
  pointer-events: auto;
}

.ask-toggle {
  align-self: flex-end;
  order: 2;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 7px 23px rgba(37, 61, 112, .16);
  font-weight: 650;
}

.ask-toggle:hover,
.ask-toggle[aria-expanded="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.ask-panel {
  margin: 0;
  padding: 18px;
  border-radius: 18px;
  box-shadow: 0 15px 52px rgba(32, 54, 106, .19);
}

.ask-panel h2 {
  margin-bottom: 7px;
  font-size: 17px;
}

.ask-panel p {
  font-size: 13px;
}

.ask-form input {
  min-width: 0;
  border-radius: 9px;
  background: var(--bg-soft);
}

.ask-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ask-form button {
  border-radius: 9px;
  background: var(--primary-gradient);
  color: white;
}

.ask-answer {
  max-height: min(45vh, 360px);
  overflow: auto;
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: 9px;
  overflow-wrap: anywhere;
}

@media (max-width: 1120px) {
  .shell,
  .shell:has(.margin:empty) {
    grid-template-columns: 182px minmax(0, 1fr);
    gap: 20px;
  }

  .margin:not(:empty) {
    display: block;
    grid-column: 2;
    position: static;
    max-height: none;
    overflow: visible;
  }


}

@media (max-width: 880px) {
  .masthead-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px 12px;
    min-height: 0;
    padding: 11px 18px 8px;
  }

  .topnav {
    justify-self: stretch;
    flex-wrap: wrap;
    margin: 0;
    overflow: visible;
  }

  .topnav-item {
    justify-content: center;
    flex: 1 1 0;
    min-height: 40px;
    padding: 0 8px;
  }

  .masthead-side {
    gap: 8px;
  }

  .masthead .account-menu-trigger {
    gap: 4px;
    padding-inline: 3px 6px;
  }

  .shell,
  .shell:has(.margin:empty) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 15px;
    padding: 18px 18px 82px;
  }

  .rail,
  .margin:not(:empty) {
    position: static;
    grid-column: 1;
    max-height: none;
    overflow: visible;
  }

  .rail {
    order: 0;
  }

  .rail-disclosure {
    border: 1px solid var(--line);
    background: var(--surface);
  }

  .rail-disclosure > summary {
    display: flex;
    padding: 0 14px;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
  }

  .rail-content {
    padding: 3px 10px 10px;
  }

  .rail-block {
    margin-bottom: 8px;
    padding: 9px 6px;
    box-shadow: none;
  }

  .rail-item {
    padding-inline: 11px;
  }

  .margin:not(:empty) {
    order: 2;
  }

  .ask {
    right: 12px;
    bottom: 12px;
  }
}

@media (max-width: 670px) {

  .home-feeds {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .home-feed .entry {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .home-feed .entry-marks {
    flex-direction: row;
  }
}

@media (max-width: 380px) {
  .masthead-inner {
    padding-inline: 12px;
  }

  .masthead .account {
    gap: 4px;
  }

  .topnav-item {
    gap: 4px;
    font-size: 13px;
  }
}

/* Search stays above the current page. */
.masthead-search {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-2);
  background: var(--surface);
  white-space: nowrap;
}

.masthead-search:hover { color: var(--accent); background: var(--bg-soft) }
.masthead-search svg { width: 17px; height: 17px; flex: none }

.global-search {
  width: min(700px, calc(100% - 28px));
  max-height: calc(100dvh - 36px);
  margin: min(10dvh, 76px) auto auto;
  padding: 19px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  overflow: auto;
  box-shadow: 0 12px 48px rgba(20, 25, 22, .24);
}

.global-search::backdrop { background: rgba(21, 26, 22, .48) }
.global-search-head, .global-search-form {
  display: flex;
  align-items: center;
  gap: 9px;
}

.global-search-head {
  justify-content: space-between;
  margin-bottom: 12px;
}
.global-search-head h2 { font-size: 20px }
.global-search-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.global-search-close svg { display: block; width: 19px; height: 19px }
.global-search-close:hover { color: var(--text); background: var(--bg-soft) }
.global-search-form input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  height: 43px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  font: 16px var(--font-sans);
}
.global-search-form .btn { min-height: 43px; white-space: nowrap }
.global-search-status { margin: 8px 0; color: var(--text-2); font-size: 13px }
.global-search-status:empty { margin: 0 }
.global-search-results .community-results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px }
.global-search-results .community-panel { min-width: 0 }
.global-search-results .community-results > .empty { padding: 18px 0 8px }

body[data-page="home"] .shell,
body:is([data-page="projects"], [data-page^="project:"]) .shell { max-width: 1240px }

@media (max-width: 880px) {
  .masthead-search { width: 38px; padding: 0 }
  .masthead-search span { display: none }
}

@media (max-width: 480px) {
  .global-search { margin-top: 12px; padding: 14px; border-radius: 13px }
}

@media (max-width: 380px) {
  .masthead-search, .masthead .theme-toggle { width: 34px; height: 36px }
  .masthead-side { gap: 6px }
}
